vitess.io/vitess@v0.16.2/web/vtadmin/src/components/routes/tablet/Advanced.tsx (about) 1 /** 2 * Copyright 2022 The Vitess Authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 import React from 'react'; 18 import { UseMutationResult } from 'react-query'; 19 import { useHistory } from 'react-router-dom'; 20 import { DeleteTabletParams } from '../../../api/http'; 21 import { 22 useDeleteTablet, 23 useRefreshTabletReplicationSource, 24 useSetReadOnly, 25 useSetReadWrite, 26 useStartReplication, 27 useStopReplication, 28 } from '../../../hooks/api'; 29 import { topodata, vtadmin } from '../../../proto/vtadmin'; 30 import { isPrimary } from '../../../util/tablets'; 31 import ActionPanel from '../../ActionPanel'; 32 import { success, warn } from '../../Snackbar'; 33 34 interface AdvancedProps { 35 alias: string; 36 clusterID: string; 37 tablet: vtadmin.Tablet | undefined; 38 } 39 40 const Advanced: React.FC<AdvancedProps> = ({ alias, clusterID, tablet }) => { 41 const history = useHistory(); 42 const primary = isPrimary(tablet); 43 44 const deleteParams: DeleteTabletParams = { alias, clusterID }; 45 if (tablet?.tablet?.type === topodata.TabletType.PRIMARY) { 46 deleteParams.allowPrimary = true; 47 } 48 49 const deleteTabletMutation = useDeleteTablet(deleteParams, { 50 onSuccess: () => { 51 success( 52 `Initiated deletion for tablet ${alias}. It may take some time for the tablet to disappear from the topology.` 53 ); 54 history.push('/tablets'); 55 }, 56 onError: (error) => warn(`There was an error deleting tablet: ${error}`), 57 }); 58 59 const refreshTabletReplicationSourceMutation = useRefreshTabletReplicationSource( 60 { alias, clusterID }, 61 { 62 onSuccess: (result) => { 63 success( 64 `Successfully refreshed tablet replication source for tablet ${alias} to replicate from primary ${result.primary}`, 65 { autoClose: 7000 } 66 ); 67 }, 68 onError: (error) => warn(`There was an error refreshing tablet replication source: ${error}`), 69 } 70 ); 71 72 const setReadOnlyMutation = useSetReadOnly( 73 { alias, clusterID }, 74 { 75 onSuccess: () => { 76 success(`Successfully set tablet ${alias} to read-only`); 77 }, 78 onError: (error) => warn(`There was an error setting tablet ${alias} to read-only: ${error}`), 79 } 80 ); 81 82 const setReadWriteMutation = useSetReadWrite( 83 { alias, clusterID }, 84 { 85 onSuccess: () => { 86 success(`Successfully set tablet ${alias} to read-write`); 87 }, 88 onError: (error) => warn(`There was an error setting tablet ${alias} to read-write: ${error}`), 89 } 90 ); 91 92 const startReplicationMutation = useStartReplication( 93 { alias, clusterID }, 94 { 95 onSuccess: () => { 96 success(`Successfully started replication on tablet ${alias}.`, { autoClose: 7000 }); 97 }, 98 onError: (error) => warn(`There was an error starting replication on tablet: ${error}`), 99 } 100 ); 101 102 const stopReplicationMutation = useStopReplication( 103 { alias, clusterID }, 104 { 105 onSuccess: () => success(`Successfully stopped replication on tablet ${alias}.`, { autoClose: 7000 }), 106 onError: (error) => warn(`There was an error stopping replication on tablet: ${error}`), 107 } 108 ); 109 110 return ( 111 <div className="pt-4"> 112 <div className="my-8"> 113 <h3 className="mb-4">Replication</h3> 114 <div> 115 <ActionPanel 116 confirmationValue="" 117 description={ 118 <> 119 This will run the underlying database command to start replication on tablet{' '} 120 <span className="font-bold">{alias}</span>. For example, in mysql 8, this will be{' '} 121 <span className="font-mono text-sm p-1 bg-gray-100">start replication</span>. 122 </> 123 } 124 disabled={primary} 125 documentationLink="https://vitess.io/docs/reference/programs/vtctl/tablets/#startreplication" 126 loadedText="Start Replication" 127 loadingText="Starting Replication..." 128 mutation={startReplicationMutation as UseMutationResult} 129 title="Start Replication" 130 warnings={[primary && 'Command StartReplication cannot be run on the primary tablet.']} 131 /> 132 133 <ActionPanel 134 confirmationValue="" 135 description={ 136 <> 137 This will run the underlying database command to stop replication on tablet{' '} 138 <span className="font-bold">{alias}</span>. For example, in mysql 8, this will be{' '} 139 <span className="font-mono text-sm p-1 bg-gray-100">stop replication</span>. 140 </> 141 } 142 disabled={primary} 143 documentationLink="https://vitess.io/docs/reference/programs/vtctl/tablets/#stopreplication" 144 loadedText="Stop Replication" 145 loadingText="Stopping Replication..." 146 mutation={stopReplicationMutation as UseMutationResult} 147 title="Stop Replication" 148 warnings={[primary && 'Command StopReplication cannot be run on the primary tablet.']} 149 /> 150 </div> 151 </div> 152 153 <div className="my-8"> 154 <h3 className="mb-4">Reparent</h3> 155 <div> 156 <ActionPanel 157 confirmationValue="" 158 description={ 159 <> 160 Refresh replication source for tablet <span className="font-bold">{alias}</span> to the 161 current shard primary tablet. This only works if the current replication position 162 matches the last known reparent action. 163 </> 164 } 165 disabled={primary} 166 documentationLink="https://vitess.io/docs/reference/programs/vtctl/tablets/#reparenttablet" 167 loadedText="Refresh" 168 loadingText="Refreshing..." 169 mutation={refreshTabletReplicationSourceMutation as UseMutationResult} 170 title="Refresh Replication Source" 171 warnings={[primary && 'Command ReparentTablet cannot be run on the primary tablet.']} 172 /> 173 </div> 174 </div> 175 <div className="my-8"> 176 <h3 className="mb-4">Danger</h3> 177 <div> 178 {primary && ( 179 <> 180 <ActionPanel 181 confirmationValue={alias} 182 danger 183 description={ 184 <> 185 Set tablet <span className="font-bold">{alias}</span> to read-only. 186 </> 187 } 188 documentationLink="https://vitess.io/docs/reference/programs/vtctl/tablets/#setreadonly" 189 loadingText="Setting..." 190 loadedText="Set to read-only" 191 mutation={setReadOnlyMutation as UseMutationResult} 192 title="Set Read-Only" 193 warnings={[ 194 `This will disable writing on the primary tablet ${alias}. Use with caution.`, 195 ]} 196 /> 197 198 <ActionPanel 199 confirmationValue={alias} 200 danger 201 description={ 202 <> 203 Set tablet <span className="font-bold">{alias}</span> to read-write. 204 </> 205 } 206 documentationLink="https://vitess.io/docs/reference/programs/vtctl/tablets/#setreadwrite" 207 mutation={setReadWriteMutation as UseMutationResult} 208 loadingText="Setting..." 209 loadedText="Set to read-write" 210 title="Set Read-Write" 211 warnings={[ 212 `This will re-enable writing on the primary tablet ${alias}. Use with caution.`, 213 ]} 214 /> 215 </> 216 )} 217 <ActionPanel 218 confirmationValue={alias} 219 danger 220 description={ 221 <> 222 Delete tablet <span className="font-bold">{alias}</span>. Doing so will remove it from 223 the topology, but vttablet and MySQL won't be touched. 224 </> 225 } 226 documentationLink="https://vitess.io/docs/reference/programs/vtctl/tablets/#deletetablet" 227 loadingText="Deleting..." 228 loadedText="Delete" 229 mutation={deleteTabletMutation as UseMutationResult} 230 title="Delete Tablet" 231 warnings={[ 232 primary && ( 233 <> 234 Tablet {alias} is the primary tablet. Flag{' '} 235 <span className="font-mono bg-red-100 p-1 text-sm">-allow_primary=true</span> will 236 be applied in order to delete the primary tablet. 237 </> 238 ), 239 ]} 240 /> 241 </div> 242 </div> 243 </div> 244 ); 245 }; 246 247 export default Advanced;