Search in sources :

Example 1 with ActiveCompaction

use of org.apache.accumulo.proxy.thrift.ActiveCompaction in project accumulo by apache.

the class SimpleProxyBase method attachIteratorWithCompactions.

@Test
public void attachIteratorWithCompactions() throws Exception {
    if (client.tableExists(creds, "slow")) {
        client.deleteTable(creds, "slow");
    }
    // create a table that's very slow, so we can look for compactions
    client.createTable(creds, "slow", true, TimeType.MILLIS);
    IteratorSetting setting = new IteratorSetting(100, "slow", SlowIterator.class.getName(), Collections.singletonMap("sleepTime", "250"));
    client.attachIterator(creds, "slow", setting, EnumSet.allOf(IteratorScope.class));
    // Should take 10 seconds to read every record
    for (int i = 0; i < 40; i++) {
        client.updateAndFlush(creds, "slow", mutation("row" + i, "cf", "cq", "value"));
    }
    Map<String, String> map = client.tableIdMap(creds);
    // start a compaction
    Thread t = new Thread() {

        @Override
        public void run() {
            TestProxyClient proxyClient2 = null;
            try {
                if (isKerberosEnabled()) {
                    UserGroupInformation.loginUserFromKeytab(clientPrincipal, clientKeytab.getAbsolutePath());
                    proxyClient2 = new TestProxyClient(hostname, proxyPort, factory, proxyPrimary, UserGroupInformation.getCurrentUser());
                } else {
                    proxyClient2 = new TestProxyClient(hostname, proxyPort, factory);
                }
                Client client2 = proxyClient2.proxy();
                client2.compactTable(creds, "slow", null, null, null, true, true, null);
            } catch (Exception e) {
                throw new RuntimeException(e);
            } finally {
                if (null != proxyClient2) {
                    proxyClient2.close();
                }
            }
        }
    };
    t.start();
    final String desiredTableId = map.get("slow");
    // Make sure we can find the slow table
    assertNotNull(desiredTableId);
    // try to catch it in the act
    List<ActiveCompaction> compactions = new ArrayList<>();
    for (int i = 0; i < 100 && compactions.isEmpty(); i++) {
        // Iterate over the tservers
        for (String tserver : client.getTabletServers(creds)) {
            // And get the compactions on each
            List<ActiveCompaction> compactionsOnServer = client.getActiveCompactions(creds, tserver);
            for (ActiveCompaction compact : compactionsOnServer) {
                // case we want to prune out those that aren't for our slow table
                if (desiredTableId.equals(compact.getExtent().tableId)) {
                    compactions.add(compact);
                }
            }
            // If we found a compaction for the table we wanted, so we can stop looking
            if (!compactions.isEmpty())
                break;
        }
        sleepUninterruptibly(10, TimeUnit.MILLISECONDS);
    }
    t.join();
    // verify the compaction information
    assertFalse(compactions.isEmpty());
    for (ActiveCompaction c : compactions) {
        if (desiredTableId.equals(c.getExtent().tableId)) {
            assertTrue(c.inputFiles.isEmpty());
            assertEquals(CompactionType.MINOR, c.getType());
            assertEquals(CompactionReason.USER, c.getReason());
            assertEquals("", c.localityGroup);
            assertTrue(c.outputFile.contains("default_tablet"));
            return;
        }
    }
    fail("Expection to find running compaction for table 'slow' but did not find one");
}
Also used : ActiveCompaction(org.apache.accumulo.proxy.thrift.ActiveCompaction) ArrayList(java.util.ArrayList) NumericValueConstraint(org.apache.accumulo.test.constraints.NumericValueConstraint) TableNotFoundException(org.apache.accumulo.proxy.thrift.TableNotFoundException) MutationsRejectedException(org.apache.accumulo.proxy.thrift.MutationsRejectedException) NamespaceNotEmptyException(org.apache.accumulo.proxy.thrift.NamespaceNotEmptyException) AccumuloSecurityException(org.apache.accumulo.proxy.thrift.AccumuloSecurityException) TException(org.apache.thrift.TException) NamespaceExistsException(org.apache.accumulo.proxy.thrift.NamespaceExistsException) NamespaceNotFoundException(org.apache.accumulo.proxy.thrift.NamespaceNotFoundException) TApplicationException(org.apache.thrift.TApplicationException) TableExistsException(org.apache.accumulo.proxy.thrift.TableExistsException) IteratorSetting(org.apache.accumulo.proxy.thrift.IteratorSetting) IteratorScope(org.apache.accumulo.proxy.thrift.IteratorScope) Client(org.apache.accumulo.proxy.thrift.AccumuloProxy.Client) SlowIterator(org.apache.accumulo.test.functional.SlowIterator) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 Client (org.apache.accumulo.proxy.thrift.AccumuloProxy.Client)1 AccumuloSecurityException (org.apache.accumulo.proxy.thrift.AccumuloSecurityException)1 ActiveCompaction (org.apache.accumulo.proxy.thrift.ActiveCompaction)1 IteratorScope (org.apache.accumulo.proxy.thrift.IteratorScope)1 IteratorSetting (org.apache.accumulo.proxy.thrift.IteratorSetting)1 MutationsRejectedException (org.apache.accumulo.proxy.thrift.MutationsRejectedException)1 NamespaceExistsException (org.apache.accumulo.proxy.thrift.NamespaceExistsException)1 NamespaceNotEmptyException (org.apache.accumulo.proxy.thrift.NamespaceNotEmptyException)1 NamespaceNotFoundException (org.apache.accumulo.proxy.thrift.NamespaceNotFoundException)1 TableExistsException (org.apache.accumulo.proxy.thrift.TableExistsException)1 TableNotFoundException (org.apache.accumulo.proxy.thrift.TableNotFoundException)1 NumericValueConstraint (org.apache.accumulo.test.constraints.NumericValueConstraint)1 SlowIterator (org.apache.accumulo.test.functional.SlowIterator)1 TApplicationException (org.apache.thrift.TApplicationException)1 TException (org.apache.thrift.TException)1 Test (org.junit.Test)1