Search in sources :

Example 11 with IteratorSetting

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

the class SimpleProxyBase method iteratorFunctionality.

@Test
public void iteratorFunctionality() throws Exception {
    // iterators
    HashMap<String, String> options = new HashMap<>();
    options.put("type", "STRING");
    options.put("columns", "cf");
    IteratorSetting setting = new IteratorSetting(10, tableName, SummingCombiner.class.getName(), options);
    client.attachIterator(creds, tableName, setting, EnumSet.allOf(IteratorScope.class));
    for (int i = 0; i < 10; i++) {
        client.updateAndFlush(creds, tableName, mutation("row1", "cf", "cq", "1"));
    }
    // 10 updates of "1" in the value w/ SummingCombiner should return value of "10"
    assertScan(new String[][] { { "row1", "cf", "cq", "10" } }, tableName);
    try {
        client.checkIteratorConflicts(creds, tableName, setting, EnumSet.allOf(IteratorScope.class));
        fail("checkIteratorConflicts did not throw an exception");
    } catch (Exception ex) {
    // Expected
    }
    client.deleteRows(creds, tableName, null, null);
    client.removeIterator(creds, tableName, "test", EnumSet.allOf(IteratorScope.class));
    String[][] expected = new String[10][];
    for (int i = 0; i < 10; i++) {
        client.updateAndFlush(creds, tableName, mutation("row" + i, "cf", "cq", "" + i));
        expected[i] = new String[] { "row" + i, "cf", "cq", "" + i };
        client.flushTable(creds, tableName, null, null, true);
    }
    assertScan(expected, tableName);
}
Also used : IteratorSetting(org.apache.accumulo.proxy.thrift.IteratorSetting) HashMap(java.util.HashMap) SummingCombiner(org.apache.accumulo.core.iterators.user.SummingCombiner) IteratorScope(org.apache.accumulo.proxy.thrift.IteratorScope) 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) Test(org.junit.Test)

Example 12 with IteratorSetting

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

the class SimpleProxyBase method checkNamespaceIteratorConflictsLoginFailure.

@Test(expected = AccumuloSecurityException.class, timeout = 5000)
public void checkNamespaceIteratorConflictsLoginFailure() throws Exception {
    IteratorSetting setting = new IteratorSetting(100, "DebugTheThings", DebugIterator.class.getName(), Collections.emptyMap());
    client.checkNamespaceIteratorConflicts(badLogin, namespaceName, setting, EnumSet.allOf(IteratorScope.class));
}
Also used : DebugIterator(org.apache.accumulo.core.iterators.DebugIterator) IteratorSetting(org.apache.accumulo.proxy.thrift.IteratorSetting) IteratorScope(org.apache.accumulo.proxy.thrift.IteratorScope) Test(org.junit.Test)

Example 13 with IteratorSetting

use of org.apache.accumulo.proxy.thrift.IteratorSetting 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)

Example 14 with IteratorSetting

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

the class TestProxyReadWrite method readWriteOneShotWithFilterIterator.

/**
 * Insert 100000 cells which have as the row [0..99999] (padded with zeros). Filter the results so only the even numbers come back.
 */
@Test
public void readWriteOneShotWithFilterIterator() throws Exception {
    int maxInserts = 10000;
    Map<ByteBuffer, List<ColumnUpdate>> mutations = new HashMap<>();
    String format = "%1$05d";
    for (int i = 0; i < maxInserts; i++) {
        addMutation(mutations, String.format(format, i), "cf" + i, "cq" + i, Util.randString(10));
        if (i % 1000 == 0 || i == maxInserts - 1) {
            tpc.proxy().updateAndFlush(userpass, testtable, mutations);
            mutations.clear();
        }
    }
    String regex = ".*[02468]";
    org.apache.accumulo.core.client.IteratorSetting is = new org.apache.accumulo.core.client.IteratorSetting(50, regex, RegExFilter.class);
    RegExFilter.setRegexs(is, regex, null, null, null, false);
    IteratorSetting pis = Util.iteratorSetting2ProxyIteratorSetting(is);
    ScanOptions opts = new ScanOptions();
    opts.iterators = Collections.singletonList(pis);
    String cookie = tpc.proxy().createScanner(userpass, testtable, opts);
    int i = 0;
    boolean hasNext = true;
    int k = 1000;
    while (hasNext) {
        ScanResult kvList = tpc.proxy().nextK(cookie, k);
        for (KeyValue kv : kvList.getResults()) {
            assertEquals(Integer.parseInt(new String(kv.getKey().getRow())), i);
            i += 2;
        }
        hasNext = kvList.isMore();
    }
}
Also used : ScanResult(org.apache.accumulo.proxy.thrift.ScanResult) KeyValue(org.apache.accumulo.proxy.thrift.KeyValue) HashMap(java.util.HashMap) ByteBuffer(java.nio.ByteBuffer) IteratorSetting(org.apache.accumulo.proxy.thrift.IteratorSetting) List(java.util.List) ScanOptions(org.apache.accumulo.proxy.thrift.ScanOptions) BatchScanOptions(org.apache.accumulo.proxy.thrift.BatchScanOptions) Test(org.junit.Test)

Aggregations

IteratorSetting (org.apache.accumulo.proxy.thrift.IteratorSetting)14 Test (org.junit.Test)14 IteratorScope (org.apache.accumulo.proxy.thrift.IteratorScope)9 NumericValueConstraint (org.apache.accumulo.test.constraints.NumericValueConstraint)6 ByteBuffer (java.nio.ByteBuffer)5 HashMap (java.util.HashMap)5 List (java.util.List)4 DebugIterator (org.apache.accumulo.core.iterators.DebugIterator)4 BatchScanOptions (org.apache.accumulo.proxy.thrift.BatchScanOptions)4 NamespaceNotFoundException (org.apache.accumulo.proxy.thrift.NamespaceNotFoundException)4 ScanOptions (org.apache.accumulo.proxy.thrift.ScanOptions)4 TableNotFoundException (org.apache.accumulo.proxy.thrift.TableNotFoundException)4 ArrayList (java.util.ArrayList)3 Client (org.apache.accumulo.proxy.thrift.AccumuloProxy.Client)3 AccumuloSecurityException (org.apache.accumulo.proxy.thrift.AccumuloSecurityException)3 KeyValue (org.apache.accumulo.proxy.thrift.KeyValue)3 MutationsRejectedException (org.apache.accumulo.proxy.thrift.MutationsRejectedException)3 NamespaceExistsException (org.apache.accumulo.proxy.thrift.NamespaceExistsException)3 NamespaceNotEmptyException (org.apache.accumulo.proxy.thrift.NamespaceNotEmptyException)3 ScanResult (org.apache.accumulo.proxy.thrift.ScanResult)3