Search in sources :

Example 21 with AccumuloClient

use of org.apache.accumulo.core.client.AccumuloClient in project accumulo by apache.

the class ExternalCompaction_3_IT method testCoordinatorRestartsDuringCompaction.

@Test
public void testCoordinatorRestartsDuringCompaction() throws Exception {
    getCluster().getClusterControl().startCoordinator(CompactionCoordinator.class);
    getCluster().getClusterControl().startCompactors(ExternalDoNothingCompactor.class, 1, QUEUE2);
    String table1 = this.getUniqueNames(1)[0];
    try (AccumuloClient client = Accumulo.newClient().from(getCluster().getClientProperties()).build()) {
        createTable(client, table1, "cs2", 2);
        writeData(client, table1);
        compact(client, table1, 2, QUEUE2, false);
        TableId tid = getCluster().getServerContext().getTableId(table1);
        // Wait for the compaction to start by waiting for 1 external compaction column
        Set<ExternalCompactionId> ecids = waitForCompactionStartAndReturnEcids(getCluster().getServerContext(), tid);
        // Stop the Coordinator
        getCluster().getClusterControl().stop(ServerType.COMPACTION_COORDINATOR);
        // Restart the coordinator while the compaction is running
        getCluster().getClusterControl().startCoordinator(CompactionCoordinator.class);
        // Confirm compaction is still running
        int matches = 0;
        while (matches == 0) {
            TExternalCompactionList running = getRunningCompactions(getCluster().getServerContext());
            if (running.getCompactions() != null) {
                for (ExternalCompactionId ecid : ecids) {
                    TExternalCompaction tec = running.getCompactions().get(ecid.canonical());
                    if (tec != null && tec.getUpdates() != null && !tec.getUpdates().isEmpty()) {
                        matches++;
                        assertEquals(TCompactionState.IN_PROGRESS, getLastState(tec));
                    }
                }
            }
            UtilWaitThread.sleep(250);
        }
        assertTrue(matches > 0);
        // We need to cancel the compaction or delete the table here because we initiate a user
        // compaction above in the test. Even though the external compaction was cancelled
        // because we split the table, FaTE will continue to queue up a compaction
        client.tableOperations().cancelCompaction(table1);
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) TableId(org.apache.accumulo.core.data.TableId) ExternalCompactionId(org.apache.accumulo.core.metadata.schema.ExternalCompactionId) TExternalCompactionList(org.apache.accumulo.core.compaction.thrift.TExternalCompactionList) TExternalCompaction(org.apache.accumulo.core.compaction.thrift.TExternalCompaction) Test(org.junit.Test)

Example 22 with AccumuloClient

use of org.apache.accumulo.core.client.AccumuloClient in project accumulo by apache.

the class ExternalCompaction_3_IT method testMergeCancelsExternalCompaction.

@Test
public void testMergeCancelsExternalCompaction() throws Exception {
    getCluster().getClusterControl().startCoordinator(CompactionCoordinator.class);
    getCluster().getClusterControl().startCompactors(ExternalDoNothingCompactor.class, 1, QUEUE1);
    String table1 = this.getUniqueNames(1)[0];
    try (AccumuloClient client = Accumulo.newClient().from(getCluster().getClientProperties()).build()) {
        createTable(client, table1, "cs1", 2);
        // set compaction ratio to 1 so that majc occurs naturally, not user compaction
        // user compaction blocks merge
        client.tableOperations().setProperty(table1, Property.TABLE_MAJC_RATIO.toString(), "1.0");
        // cause multiple rfiles to be created
        writeData(client, table1);
        writeData(client, table1);
        writeData(client, table1);
        writeData(client, table1);
        TableId tid = getCluster().getServerContext().getTableId(table1);
        // Wait for the compaction to start by waiting for 1 external compaction column
        Set<ExternalCompactionId> ecids = waitForCompactionStartAndReturnEcids(getCluster().getServerContext(), tid);
        var md = new ArrayList<TabletMetadata>();
        try (TabletsMetadata tm = getCluster().getServerContext().getAmple().readTablets().forTable(tid).fetch(ColumnType.PREV_ROW).build()) {
            tm.forEach(t -> md.add(t));
            assertEquals(2, md.size());
        }
        // Merge - blocking operation
        Text start = md.get(0).getPrevEndRow();
        Text end = md.get(1).getEndRow();
        client.tableOperations().merge(table1, start, end);
        confirmCompactionCompleted(getCluster().getServerContext(), ecids, TCompactionState.CANCELLED);
        // ensure compaction ids were deleted by merge operation from metadata table
        try (TabletsMetadata tm = getCluster().getServerContext().getAmple().readTablets().forTable(tid).fetch(ColumnType.ECOMP).build()) {
            Set<ExternalCompactionId> ecids2 = tm.stream().flatMap(t -> t.getExternalCompactions().keySet().stream()).collect(Collectors.toSet());
            // keep checking until test times out
            while (!Collections.disjoint(ecids, ecids2)) {
                UtilWaitThread.sleep(25);
                ecids2 = tm.stream().flatMap(t -> t.getExternalCompactions().keySet().stream()).collect(Collectors.toSet());
            }
        }
        // We need to cancel the compaction or delete the table here because we initiate a user
        // compaction above in the test. Even though the external compaction was cancelled
        // because we split the table, FaTE will continue to queue up a compaction
        client.tableOperations().delete(table1);
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) TableId(org.apache.accumulo.core.data.TableId) TableId(org.apache.accumulo.core.data.TableId) BeforeClass(org.junit.BeforeClass) TabletsMetadata(org.apache.accumulo.core.metadata.schema.TabletsMetadata) UtilWaitThread(org.apache.accumulo.fate.util.UtilWaitThread) ExternalCompactionTestUtils.compact(org.apache.accumulo.test.compaction.ExternalCompactionTestUtils.compact) ExternalCompactionTestUtils.writeData(org.apache.accumulo.test.compaction.ExternalCompactionTestUtils.writeData) Text(org.apache.hadoop.io.Text) ExternalCompactionTestUtils.getRunningCompactions(org.apache.accumulo.test.compaction.ExternalCompactionTestUtils.getRunningCompactions) Accumulo(org.apache.accumulo.core.client.Accumulo) QUEUE1(org.apache.accumulo.test.compaction.ExternalCompactionTestUtils.QUEUE1) QUEUE2(org.apache.accumulo.test.compaction.ExternalCompactionTestUtils.QUEUE2) ArrayList(java.util.ArrayList) TabletMetadata(org.apache.accumulo.core.metadata.schema.TabletMetadata) CompactionCoordinator(org.apache.accumulo.coordinator.CompactionCoordinator) TCompactionState(org.apache.accumulo.core.compaction.thrift.TCompactionState) ExternalCompactionId(org.apache.accumulo.core.metadata.schema.ExternalCompactionId) MiniAccumuloConfigImpl(org.apache.accumulo.miniclusterImpl.MiniAccumuloConfigImpl) Configuration(org.apache.hadoop.conf.Configuration) After(org.junit.After) ExternalCompactionTestUtils.getLastState(org.apache.accumulo.test.compaction.ExternalCompactionTestUtils.getLastState) Property(org.apache.accumulo.core.conf.Property) ServerType(org.apache.accumulo.minicluster.ServerType) ExternalCompactionTestUtils.confirmCompactionCompleted(org.apache.accumulo.test.compaction.ExternalCompactionTestUtils.confirmCompactionCompleted) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) TExternalCompaction(org.apache.accumulo.core.compaction.thrift.TExternalCompaction) MiniClusterConfigurationCallback(org.apache.accumulo.harness.MiniClusterConfigurationCallback) Test(org.junit.Test) Collectors(java.util.stream.Collectors) AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) SharedMiniClusterBase(org.apache.accumulo.harness.SharedMiniClusterBase) TExternalCompactionList(org.apache.accumulo.core.compaction.thrift.TExternalCompactionList) ExternalCompactionTestUtils.waitForCompactionStartAndReturnEcids(org.apache.accumulo.test.compaction.ExternalCompactionTestUtils.waitForCompactionStartAndReturnEcids) ExternalCompactionTestUtils.createTable(org.apache.accumulo.test.compaction.ExternalCompactionTestUtils.createTable) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ColumnType(org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType) ExternalCompactionId(org.apache.accumulo.core.metadata.schema.ExternalCompactionId) TabletsMetadata(org.apache.accumulo.core.metadata.schema.TabletsMetadata) ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text) Test(org.junit.Test)

Example 23 with AccumuloClient

use of org.apache.accumulo.core.client.AccumuloClient in project accumulo by apache.

the class ConfigurableMajorCompactionIT method test.

@Test
public void test() throws Exception {
    try (AccumuloClient client = Accumulo.newClient().from(getClientProperties()).build()) {
        String tableName = getUniqueNames(1)[0];
        client.tableOperations().create(tableName);
        client.tableOperations().setProperty(tableName, Property.TABLE_COMPACTION_STRATEGY.getKey(), TestCompactionStrategy.class.getName());
        writeFile(client, tableName);
        writeFile(client, tableName);
        writeFile(client, tableName);
        writeFile(client, tableName);
        UtilWaitThread.sleep(2_000);
        assertEquals(4, countFiles(client));
        writeFile(client, tableName);
        int count = countFiles(client);
        assertTrue(count == 1 || count == 5);
        while (count != 1) {
            UtilWaitThread.sleep(250);
            count = countFiles(client);
        }
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) Test(org.junit.Test)

Example 24 with AccumuloClient

use of org.apache.accumulo.core.client.AccumuloClient in project accumulo by apache.

the class ExternalCompactionProgressIT method testProgress.

@Test
public void testProgress() throws Exception {
    String table1 = this.getUniqueNames(1)[0];
    try (AccumuloClient client = Accumulo.newClient().from(getCluster().getClientProperties()).build()) {
        createTable(client, table1, "cs1");
        writeData(client, table1, ROWS);
        cluster.getClusterControl().startCompactors(Compactor.class, 1, QUEUE1);
        cluster.getClusterControl().startCoordinator(CompactionCoordinator.class);
        Thread checkerThread = startChecker();
        checkerThread.start();
        IteratorSetting setting = new IteratorSetting(50, "Slow", SlowIterator.class);
        SlowIterator.setSleepTime(setting, 1);
        client.tableOperations().attachIterator(table1, setting, EnumSet.of(IteratorUtil.IteratorScope.majc));
        log.info("Compacting table");
        compact(client, table1, 2, "DCQ1", true);
        verify(client, table1, 2, ROWS);
        log.info("Done Compacting table");
        compactionFinished.set(true);
        checkerThread.join();
        verifyProgress();
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) Test(org.junit.Test)

Example 25 with AccumuloClient

use of org.apache.accumulo.core.client.AccumuloClient in project accumulo by apache.

the class AccumuloClientIT method testGetAccumuloClientFromConnector.

@SuppressWarnings("deprecation")
@Test
public void testGetAccumuloClientFromConnector() throws Exception {
    try (AccumuloClient client1 = Accumulo.newClient().from(getClientProps()).build()) {
        org.apache.accumulo.core.client.Connector c = org.apache.accumulo.core.client.Connector.from(client1);
        String tableName = getUniqueNames(1)[0];
        c.tableOperations().create(tableName);
        try (AccumuloClient client2 = org.apache.accumulo.core.client.Connector.newClient(c)) {
            assertTrue(client2.tableOperations().list().contains(tableName));
        }
        // closing client2 should not have had an impact on the connector or client1
        assertTrue(client1.tableOperations().list().contains(tableName));
        assertTrue(c.tableOperations().list().contains(tableName));
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) Test(org.junit.Test)

Aggregations

AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)500 Test (org.junit.Test)411 BatchWriter (org.apache.accumulo.core.client.BatchWriter)149 Text (org.apache.hadoop.io.Text)143 Mutation (org.apache.accumulo.core.data.Mutation)138 Scanner (org.apache.accumulo.core.client.Scanner)122 Value (org.apache.accumulo.core.data.Value)118 Key (org.apache.accumulo.core.data.Key)108 NewTableConfiguration (org.apache.accumulo.core.client.admin.NewTableConfiguration)91 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)64 HashMap (java.util.HashMap)61 Range (org.apache.accumulo.core.data.Range)51 TreeSet (java.util.TreeSet)50 ArrayList (java.util.ArrayList)47 Entry (java.util.Map.Entry)41 Path (org.apache.hadoop.fs.Path)39 CompactionConfig (org.apache.accumulo.core.client.admin.CompactionConfig)34 Authorizations (org.apache.accumulo.core.security.Authorizations)34 BatchScanner (org.apache.accumulo.core.client.BatchScanner)32 HashSet (java.util.HashSet)31