Skip to content

Commit 370a7de

Browse files
authored
refactored findTabletsNeedingAttention test to handle new return type. (apache#4418)
1 parent 4081f46 commit 370a7de

File tree

1 file changed

+68
-25
lines changed

1 file changed

+68
-25
lines changed

test/src/main/java/org/apache/accumulo/test/functional/TabletManagementIteratorIT.java

+68-25
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818
*/
1919
package org.apache.accumulo.test.functional;
2020

21+
import static org.apache.accumulo.core.manager.state.TabletManagement.ManagementAction.NEEDS_LOCATION_UPDATE;
2122
import static org.junit.jupiter.api.Assertions.assertEquals;
2223

2324
import java.io.IOException;
2425
import java.time.Duration;
2526
import java.util.ArrayList;
2627
import java.util.Collections;
28+
import java.util.HashMap;
2729
import java.util.HashSet;
2830
import java.util.Iterator;
2931
import java.util.List;
@@ -141,15 +143,30 @@ public void test() throws AccumuloException, AccumuloSecurityException, TableExi
141143
// examine a clone of the metadata table, so we can manipulate it
142144
copyTable(client, AccumuloTable.METADATA.tableName(), metaCopy1);
143145

146+
var tableId1 = getServerContext().getTableId(t1);
147+
var tableId3 = getServerContext().getTableId(t3);
148+
var tableId4 = getServerContext().getTableId(t4);
149+
150+
// Create expected KeyExtents to test output of findTabletsNeedingAttention
151+
KeyExtent endR1 = new KeyExtent(tableId1, new Text("some split"), null);
152+
KeyExtent endR3 = new KeyExtent(tableId3, new Text("some split"), null);
153+
KeyExtent endR4 = new KeyExtent(tableId4, new Text("some split"), null);
154+
KeyExtent prevR1 = new KeyExtent(tableId1, null, new Text("some split"));
155+
KeyExtent prevR3 = new KeyExtent(tableId3, null, new Text("some split"));
156+
KeyExtent prevR4 = new KeyExtent(tableId4, null, new Text("some split"));
157+
Map<KeyExtent,Set<TabletManagement.ManagementAction>> expected;
158+
144159
TabletManagementParameters tabletMgmtParams = createParameters(client);
145-
int tabletsInFlux = findTabletsNeedingAttention(client, metaCopy1, tabletMgmtParams);
146-
while (tabletsInFlux > 0) {
160+
Map<KeyExtent,Set<TabletManagement.ManagementAction>> tabletsInFlux =
161+
findTabletsNeedingAttention(client, metaCopy1, tabletMgmtParams);
162+
while (!tabletsInFlux.isEmpty()) {
147163
log.debug("Waiting for {} tablets for {}", tabletsInFlux, metaCopy1);
148164
UtilWaitThread.sleep(500);
149165
copyTable(client, AccumuloTable.METADATA.tableName(), metaCopy1);
150166
tabletsInFlux = findTabletsNeedingAttention(client, metaCopy1, tabletMgmtParams);
151167
}
152-
assertEquals(0, findTabletsNeedingAttention(client, metaCopy1, tabletMgmtParams),
168+
expected = Map.of();
169+
assertEquals(expected, findTabletsNeedingAttention(client, metaCopy1, tabletMgmtParams),
153170
"No tables should need attention");
154171

155172
// The metadata table stabilized and metaCopy1 contains a copy suitable for testing. Before
@@ -165,72 +182,93 @@ public void test() throws AccumuloException, AccumuloSecurityException, TableExi
165182
// t3 is hosted, setting to never will generate a change to unhost tablets
166183
setTabletAvailability(client, metaCopy1, t3, TabletAvailability.UNHOSTED.name());
167184
tabletMgmtParams = createParameters(client);
168-
assertEquals(4, findTabletsNeedingAttention(client, metaCopy1, tabletMgmtParams),
185+
expected = Map.of(endR1, Set.of(NEEDS_LOCATION_UPDATE), prevR1, Set.of(NEEDS_LOCATION_UPDATE),
186+
endR3, Set.of(NEEDS_LOCATION_UPDATE), prevR3, Set.of(NEEDS_LOCATION_UPDATE));
187+
assertEquals(expected, findTabletsNeedingAttention(client, metaCopy1, tabletMgmtParams),
169188
"Should have four tablets with hosting availability changes");
170189

171190
// test the assigned case (no location)
172191
removeLocation(client, metaCopy1, t3);
173-
assertEquals(2, findTabletsNeedingAttention(client, metaCopy1, tabletMgmtParams),
192+
expected =
193+
Map.of(endR1, Set.of(NEEDS_LOCATION_UPDATE), prevR1, Set.of(NEEDS_LOCATION_UPDATE));
194+
assertEquals(expected, findTabletsNeedingAttention(client, metaCopy1, tabletMgmtParams),
174195
"Should have two tablets without a loc");
175196

176197
// Test setting the operation id on one of the tablets in table t1. Table t1 has two tablets
177198
// w/o a location. Only one should need attention because of the operation id.
178199
setOperationId(client, metaCopy1, t1, new Text("some split"), TabletOperationType.SPLITTING);
179-
assertEquals(1, findTabletsNeedingAttention(client, metaCopy1, tabletMgmtParams),
200+
expected = Map.of(prevR1, Set.of(NEEDS_LOCATION_UPDATE));
201+
assertEquals(expected, findTabletsNeedingAttention(client, metaCopy1, tabletMgmtParams),
180202
"Should have tablets needing attention because of operation id");
181203

182204
// test the cases where the assignment is to a dead tserver
183205
reassignLocation(client, metaCopy2, t3);
184-
assertEquals(1, findTabletsNeedingAttention(client, metaCopy2, tabletMgmtParams),
206+
expected = Map.of(endR3, Set.of(NEEDS_LOCATION_UPDATE));
207+
assertEquals(expected, findTabletsNeedingAttention(client, metaCopy2, tabletMgmtParams),
185208
"Only 1 of 2 tablets in table t1 should be returned");
186209

187210
// Test the recovery cases
188211
createLogEntry(client, metaCopy5, t1);
189212
setTabletAvailability(client, metaCopy5, t1, TabletAvailability.UNHOSTED.name());
190-
assertEquals(1, findTabletsNeedingAttention(client, metaCopy5, tabletMgmtParams),
213+
expected = Map.of(endR1,
214+
Set.of(NEEDS_LOCATION_UPDATE, TabletManagement.ManagementAction.NEEDS_RECOVERY));
215+
assertEquals(expected, findTabletsNeedingAttention(client, metaCopy5, tabletMgmtParams),
191216
"Only 1 of 2 tablets in table t1 should be returned");
192217
setTabletAvailability(client, metaCopy5, t1, TabletAvailability.ONDEMAND.name());
193-
assertEquals(1, findTabletsNeedingAttention(client, metaCopy5, tabletMgmtParams),
218+
expected = Map.of(endR1,
219+
Set.of(NEEDS_LOCATION_UPDATE, TabletManagement.ManagementAction.NEEDS_RECOVERY));
220+
assertEquals(expected, findTabletsNeedingAttention(client, metaCopy5, tabletMgmtParams),
194221
"Only 1 of 2 tablets in table t1 should be returned");
195222
setTabletAvailability(client, metaCopy5, t1, TabletAvailability.HOSTED.name());
196-
assertEquals(2, findTabletsNeedingAttention(client, metaCopy5, tabletMgmtParams),
223+
expected = Map.of(endR1,
224+
Set.of(NEEDS_LOCATION_UPDATE, TabletManagement.ManagementAction.NEEDS_RECOVERY), prevR1,
225+
Set.of(NEEDS_LOCATION_UPDATE));
226+
assertEquals(expected, findTabletsNeedingAttention(client, metaCopy5, tabletMgmtParams),
197227
"2 tablets in table t1 should be returned");
198228

199229
// Remove location and set merge operation id on both tablets
200230
// These tablets should not need attention as they have no WALs
201231
setTabletAvailability(client, metaCopy4, t4, TabletAvailability.HOSTED.name());
202232
removeLocation(client, metaCopy4, t4);
203-
assertEquals(2, findTabletsNeedingAttention(client, metaCopy4, tabletMgmtParams),
233+
expected =
234+
Map.of(endR4, Set.of(NEEDS_LOCATION_UPDATE), prevR4, Set.of(NEEDS_LOCATION_UPDATE));
235+
assertEquals(expected, findTabletsNeedingAttention(client, metaCopy4, tabletMgmtParams),
204236
"Tablets have no location and a tablet availability of hosted, so they should need attention");
205237

206238
// Test MERGING and SPLITTING do not need attention with no location or wals
207239
setOperationId(client, metaCopy4, t4, null, TabletOperationType.MERGING);
208-
assertEquals(0, findTabletsNeedingAttention(client, metaCopy4, tabletMgmtParams),
240+
expected = Map.of();
241+
assertEquals(expected, findTabletsNeedingAttention(client, metaCopy4, tabletMgmtParams),
209242
"Should have no tablets needing attention for merge as they have no location");
210243
setOperationId(client, metaCopy4, t4, null, TabletOperationType.SPLITTING);
211-
assertEquals(0, findTabletsNeedingAttention(client, metaCopy4, tabletMgmtParams),
244+
assertEquals(expected, findTabletsNeedingAttention(client, metaCopy4, tabletMgmtParams),
212245
"Should have no tablets needing attention for merge as they have no location");
213246

214247
// Create a log entry for one of the tablets, this tablet will now need attention
215248
// for both MERGING and SPLITTING
216249
setOperationId(client, metaCopy4, t4, null, TabletOperationType.MERGING);
217250
createLogEntry(client, metaCopy4, t4);
218-
assertEquals(1, findTabletsNeedingAttention(client, metaCopy4, tabletMgmtParams),
251+
expected = Map.of(endR4,
252+
Set.of(NEEDS_LOCATION_UPDATE, TabletManagement.ManagementAction.NEEDS_RECOVERY));
253+
assertEquals(expected, findTabletsNeedingAttention(client, metaCopy4, tabletMgmtParams),
219254
"Should have a tablet needing attention because of wals");
220255
// Switch op to SPLITTING which should also need attention like MERGING
221256
setOperationId(client, metaCopy4, t4, null, TabletOperationType.SPLITTING);
222-
assertEquals(1, findTabletsNeedingAttention(client, metaCopy4, tabletMgmtParams),
257+
assertEquals(expected, findTabletsNeedingAttention(client, metaCopy4, tabletMgmtParams),
223258
"Should have a tablet needing attention because of wals");
224259

225260
// Switch op to delete, no tablets should need attention even with WALs
226261
setOperationId(client, metaCopy4, t4, null, TabletOperationType.DELETING);
227-
assertEquals(0, findTabletsNeedingAttention(client, metaCopy4, tabletMgmtParams),
262+
expected = Map.of();
263+
assertEquals(expected, findTabletsNeedingAttention(client, metaCopy4, tabletMgmtParams),
228264
"Should have no tablets needing attention for delete");
229265

230266
// test the bad tablet location state case (inconsistent metadata)
231267
tabletMgmtParams = createParameters(client);
232268
addDuplicateLocation(client, metaCopy3, t3);
233-
assertEquals(1, findTabletsNeedingAttention(client, metaCopy3, tabletMgmtParams),
269+
expected = Map.of(prevR3,
270+
Set.of(NEEDS_LOCATION_UPDATE, TabletManagement.ManagementAction.BAD_STATE));
271+
assertEquals(expected, findTabletsNeedingAttention(client, metaCopy3, tabletMgmtParams),
234272
"Should have 1 tablet that needs a metadata repair");
235273

236274
// test the volume replacements case. Need to insert some files into
@@ -240,25 +278,29 @@ public void test() throws AccumuloException, AccumuloSecurityException, TableExi
240278
Map<Path,Path> replacements =
241279
Map.of(new Path("file:/vol1/accumulo/inst_id"), new Path("file:/vol2/accumulo/inst_id"));
242280
tabletMgmtParams = createParameters(client, replacements);
243-
assertEquals(1, findTabletsNeedingAttention(client, metaCopy4, tabletMgmtParams),
281+
expected = Map.of(prevR4, Set.of(TabletManagement.ManagementAction.NEEDS_VOLUME_REPLACEMENT));
282+
assertEquals(expected, findTabletsNeedingAttention(client, metaCopy4, tabletMgmtParams),
244283
"Should have one tablet that needs a volume replacement");
245284

246285
// In preparation for split an offline testing ensure nothing needs attention
247286
tabletMgmtParams = createParameters(client);
248287
addFiles(client, metaCopy6, t4);
249-
assertEquals(0, findTabletsNeedingAttention(client, metaCopy6, tabletMgmtParams),
288+
expected = Map.of();
289+
assertEquals(expected, findTabletsNeedingAttention(client, metaCopy6, tabletMgmtParams),
250290
"No tablets should need attention");
251291
// Lower the split threshold for the table, should cause the files added to need attention.
252292
client.tableOperations().setProperty(tables[3], Property.TABLE_SPLIT_THRESHOLD.getKey(),
253293
"1K");
254-
assertEquals(1, findTabletsNeedingAttention(client, metaCopy6, tabletMgmtParams),
294+
expected = Map.of(prevR4, Set.of(TabletManagement.ManagementAction.NEEDS_SPLITTING));
295+
assertEquals(expected, findTabletsNeedingAttention(client, metaCopy6, tabletMgmtParams),
255296
"Should have one tablet that needs splitting");
256297

257298
// Take the table offline which should prevent the tablet from being returned for needing to
258299
// split
259300
client.tableOperations().offline(tables[3], false);
260301
tabletMgmtParams = createParameters(client);
261-
assertEquals(0, findTabletsNeedingAttention(client, metaCopy6, tabletMgmtParams),
302+
expected = Map.of();
303+
assertEquals(expected, findTabletsNeedingAttention(client, metaCopy6, tabletMgmtParams),
262304
"No tablets should need attention");
263305

264306
// clean up
@@ -379,17 +421,18 @@ private void removeLocation(AccumuloClient client, String table, String tableNam
379421
deleter.close();
380422
}
381423

382-
private int findTabletsNeedingAttention(AccumuloClient client, String table,
383-
TabletManagementParameters tabletMgmtParams) throws TableNotFoundException, IOException {
384-
int results = 0;
424+
private Map<KeyExtent,Set<TabletManagement.ManagementAction>> findTabletsNeedingAttention(
425+
AccumuloClient client, String table, TabletManagementParameters tabletMgmtParams)
426+
throws TableNotFoundException, IOException {
427+
Map<KeyExtent,Set<TabletManagement.ManagementAction>> results = new HashMap<>();
385428
List<KeyExtent> resultList = new ArrayList<>();
386429
try (Scanner scanner = client.createScanner(table, Authorizations.EMPTY)) {
387430
TabletManagementIterator.configureScanner(scanner, tabletMgmtParams);
388431
scanner.updateScanIteratorOption("tabletChange", "debug", "1");
389432
for (Entry<Key,Value> e : scanner) {
390433
if (e != null) {
391434
TabletManagement mti = TabletManagementIterator.decode(e);
392-
results++;
435+
results.put(mti.getTabletMetadata().getExtent(), mti.getActions());
393436
log.debug("Found tablets that changed state: {}", mti.getTabletMetadata().getExtent());
394437
log.debug("actions : {}", mti.getActions());
395438
log.debug("metadata: {}", mti.getTabletMetadata());

0 commit comments

Comments
 (0)