This is an automated email from the ASF dual-hosted git repository. kturner pushed a commit to branch 2.0 in repository https://gitbox.apache.org/repos/asf/accumulo.git
commit 95c92ed95404ec1663ea97d8b4b00d58c26ba762 Merge: f63da3d 556c29e Author: Keith Turner <ktur...@apache.org> AuthorDate: Thu Aug 15 14:01:51 2019 -0400 Merge branch '1.9' into 2.0 .../functional/TabletStateChangeIteratorIT.java | 73 ++++++++++++++++------ 1 file changed, 53 insertions(+), 20 deletions(-) diff --cc test/src/main/java/org/apache/accumulo/test/functional/TabletStateChangeIteratorIT.java index b83e735,2fd8589..35c53cc --- a/test/src/main/java/org/apache/accumulo/test/functional/TabletStateChangeIteratorIT.java +++ b/test/src/main/java/org/apache/accumulo/test/functional/TabletStateChangeIteratorIT.java @@@ -35,7 -34,10 +36,9 @@@ import org.apache.accumulo.core.client. import org.apache.accumulo.core.client.BatchDeleter; import org.apache.accumulo.core.client.BatchWriter; import org.apache.accumulo.core.client.BatchWriterConfig; -import org.apache.accumulo.core.client.Connector; + import org.apache.accumulo.core.client.IsolatedScanner; import org.apache.accumulo.core.client.MutationsRejectedException; + import org.apache.accumulo.core.client.RowIterator; import org.apache.accumulo.core.client.Scanner; import org.apache.accumulo.core.client.TableExistsException; import org.apache.accumulo.core.client.TableNotFoundException; @@@ -81,70 -81,70 +84,75 @@@ public class TabletStateChangeIteratorI @Test public void test() throws AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException { - String[] tables = getUniqueNames(6); - final String t1 = tables[0]; - final String t2 = tables[1]; - final String t3 = tables[2]; - final String metaCopy1 = tables[3]; - final String metaCopy2 = tables[4]; - final String metaCopy3 = tables[5]; - - // create some metadata - createTable(t1, true); - createTable(t2, false); - createTable(t3, true); - - // examine a clone of the metadata table, so we can manipulate it - copyTable(MetadataTable.NAME, metaCopy1); - - State state = new State(); - while (findTabletsNeedingAttention(metaCopy1, state) > 0) { - UtilWaitThread.sleep(500); - copyTable(MetadataTable.NAME, metaCopy1); - } - assertEquals("No tables should need attention", 0, - findTabletsNeedingAttention(metaCopy1, state)); - - // The metadata table stabilized and metaCopy1 contains a copy suitable for testing. Before - // metaCopy1 is modified, copy it for subsequent test. - copyTable(metaCopy1, metaCopy2); - copyTable(metaCopy1, metaCopy3); - - // test the assigned case (no location) - removeLocation(metaCopy1, t3); - assertEquals("Should have two tablets without a loc", 2, - findTabletsNeedingAttention(metaCopy1, state)); - - // test the cases where the assignment is to a dead tserver - reassignLocation(metaCopy2, t3); - assertEquals("Should have one tablet that needs to be unassigned", 1, - findTabletsNeedingAttention(metaCopy2, state)); - - // test the cases where there is ongoing merges - state = new State() { - @Override - public Collection<MergeInfo> merges() { - String tableIdToModify = getConnector().tableOperations().tableIdMap().get(t3); - return Collections.singletonList( - new MergeInfo(new KeyExtent(tableIdToModify, null, null), MergeInfo.Operation.MERGE)); + + try (AccumuloClient client = Accumulo.newClient().from(getClientProps()).build()) { + - String[] tables = getUniqueNames(4); ++ String[] tables = getUniqueNames(6); + final String t1 = tables[0]; + final String t2 = tables[1]; + final String t3 = tables[2]; - final String cloned = tables[3]; ++ final String metaCopy1 = tables[3]; ++ final String metaCopy2 = tables[4]; ++ final String metaCopy3 = tables[5]; + + // create some metadata + createTable(client, t1, true); + createTable(client, t2, false); + createTable(client, t3, true); + + // examine a clone of the metadata table, so we can manipulate it - cloneMetadataTable(client, cloned); ++ copyTable(client, MetadataTable.NAME, metaCopy1); + + State state = new State(client); - while (findTabletsNeedingAttention(client, cloned, state) > 0) { ++ while (findTabletsNeedingAttention(client, metaCopy1, state) > 0) { + UtilWaitThread.sleep(500); ++ copyTable(client, MetadataTable.NAME, metaCopy1); } - }; - assertEquals("Should have 2 tablets that need to be chopped or unassigned", 1, - findTabletsNeedingAttention(metaCopy2, state)); - - // test the bad tablet location state case (inconsistent metadata) - state = new State(); - addDuplicateLocation(metaCopy3, t3); - assertEquals("Should have 1 tablet that needs a metadata repair", 1, - findTabletsNeedingAttention(metaCopy3, state)); - - // clean up - dropTables(t1, t2, t3, metaCopy1, metaCopy2, metaCopy3); + assertEquals("No tables should need attention", 0, - findTabletsNeedingAttention(client, cloned, state)); ++ findTabletsNeedingAttention(client, metaCopy1, state)); ++ ++ // The metadata table stabilized and metaCopy1 contains a copy suitable for testing. Before ++ // metaCopy1 is modified, copy it for subsequent test. ++ copyTable(client, metaCopy1, metaCopy2); ++ copyTable(client, metaCopy1, metaCopy3); + + // test the assigned case (no location) - removeLocation(client, cloned, t3); ++ removeLocation(client, metaCopy1, t3); + assertEquals("Should have two tablets without a loc", 2, - findTabletsNeedingAttention(client, cloned, state)); ++ findTabletsNeedingAttention(client, metaCopy1, state)); + + // test the cases where the assignment is to a dead tserver - client.tableOperations().delete(cloned); - cloneMetadataTable(client, cloned); - reassignLocation(client, cloned, t3); ++ reassignLocation(client, metaCopy2, t3); + assertEquals("Should have one tablet that needs to be unassigned", 1, - findTabletsNeedingAttention(client, cloned, state)); ++ findTabletsNeedingAttention(client, metaCopy2, state)); + + // test the cases where there is ongoing merges + state = new State(client) { + @Override + public Collection<MergeInfo> merges() { + TableId tableIdToModify = TableId.of(client.tableOperations().tableIdMap().get(t3)); + return Collections.singletonList( + new MergeInfo(new KeyExtent(tableIdToModify, null, null), MergeInfo.Operation.MERGE)); + } + }; + assertEquals("Should have 2 tablets that need to be chopped or unassigned", 1, - findTabletsNeedingAttention(client, cloned, state)); ++ findTabletsNeedingAttention(client, metaCopy2, state)); + + // test the bad tablet location state case (inconsistent metadata) + state = new State(client); - cloneMetadataTable(client, cloned); - addDuplicateLocation(client, cloned, t3); ++ addDuplicateLocation(client, metaCopy3, t3); + assertEquals("Should have 1 tablet that needs a metadata repair", 1, - findTabletsNeedingAttention(client, cloned, state)); ++ findTabletsNeedingAttention(client, metaCopy3, state)); + + // clean up - dropTables(client, t1, t2, t3, cloned); ++ dropTables(client, t1, t2, t3, metaCopy1, metaCopy2, metaCopy3); + } } - private void addDuplicateLocation(String table, String tableNameToModify) + private void addDuplicateLocation(AccumuloClient client, String table, String tableNameToModify) throws TableNotFoundException, MutationsRejectedException { - String tableIdToModify = getConnector().tableOperations().tableIdMap().get(tableNameToModify); + TableId tableIdToModify = + TableId.of(client.tableOperations().tableIdMap().get(tableNameToModify)); Mutation m = new Mutation(new KeyExtent(tableIdToModify, null, null).getMetadataEntry()); m.put(MetadataSchema.TabletsSection.CurrentLocationColumnFamily.NAME, new Text("1234567"), new Value("fake:9005".getBytes(UTF_8))); @@@ -185,17 -183,16 +193,18 @@@ deleter.close(); } - private int findTabletsNeedingAttention(String table, State state) throws TableNotFoundException { + private int findTabletsNeedingAttention(AccumuloClient client, String table, State state) + throws TableNotFoundException { int results = 0; - Scanner scanner = getConnector().createScanner(table, Authorizations.EMPTY); - MetaDataTableScanner.configureScanner(scanner, state); - scanner.updateScanIteratorOption("tabletChange", "debug", "1"); - for (Entry<Key,Value> e : scanner) { - if (e != null) - results++; + try (Scanner scanner = client.createScanner(table, Authorizations.EMPTY)) { + MetaDataTableScanner.configureScanner(scanner, state); + scanner.updateScanIteratorOption("tabletChange", "debug", "1"); + for (Entry<Key,Value> e : scanner) { + if (e != null) + results++; + } } + return results; } @@@ -212,20 -209,43 +221,44 @@@ } } - private void cloneMetadataTable(AccumuloClient client, String cloned) throws AccumuloException, - private void copyTable(String source, String copy) throws AccumuloException, -- AccumuloSecurityException, TableNotFoundException, TableExistsException { ++ private void copyTable(AccumuloClient client, String source, String copy) ++ throws AccumuloException, AccumuloSecurityException, TableNotFoundException, ++ TableExistsException { try { - dropTables(client, cloned); - dropTables(copy); ++ dropTables(client, copy); } catch (TableNotFoundException ex) { // ignored } - client.tableOperations().clone(MetadataTable.NAME, cloned, true, null, null); + - getConnector().tableOperations().create(copy); ++ client.tableOperations().create(copy); + - try (Scanner scanner = getConnector().createScanner(source, Authorizations.EMPTY); - BatchWriter writer = getConnector().createBatchWriter(copy, new BatchWriterConfig())) { ++ try (Scanner scanner = client.createScanner(source, Authorizations.EMPTY); ++ BatchWriter writer = client.createBatchWriter(copy, new BatchWriterConfig())) { + RowIterator rows = new RowIterator(new IsolatedScanner(scanner)); + + while (rows.hasNext()) { + Iterator<Entry<Key,Value>> row = rows.next(); + Mutation m = null; + + while (row.hasNext()) { + Entry<Key,Value> entry = row.next(); + Key k = entry.getKey(); + if (m == null) + m = new Mutation(k.getRow()); + + m.put(k.getColumnFamily(), k.getColumnQualifier(), k.getColumnVisibilityParsed(), + k.getTimestamp(), entry.getValue()); + } + + writer.addMutation(m); + } + } } - private void dropTables(String... tables) + private void dropTables(AccumuloClient client, String... tables) throws AccumuloException, AccumuloSecurityException, TableNotFoundException { for (String t : tables) { - getConnector().tableOperations().delete(t); + client.tableOperations().delete(t); } }