Search in sources :

Example 41 with AccumuloClient

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

the class BinaryIT method testPreSplit.

@Test
public void testPreSplit() throws Exception {
    String tableName = getUniqueNames(1)[0];
    try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) {
        SortedSet<Text> splits = new TreeSet<>();
        splits.add(new Text("8"));
        splits.add(new Text("256"));
        NewTableConfiguration ntc = new NewTableConfiguration().withSplits(splits);
        c.tableOperations().create(tableName, ntc);
        runTest(c, tableName);
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) TreeSet(java.util.TreeSet) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) Text(org.apache.hadoop.io.Text) Test(org.junit.Test)

Example 42 with AccumuloClient

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

the class UserCompactionStrategyIT method testDropNone.

private void testDropNone(Map<String, String> options) throws Exception {
    try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) {
        String tableName = getUniqueNames(1)[0];
        c.tableOperations().create(tableName);
        writeFlush(c, tableName, "a");
        writeFlush(c, tableName, "b");
        CompactionStrategyConfig csConfig = new CompactionStrategyConfig(TestCompactionStrategy.class.getName());
        csConfig.setOptions(options);
        c.tableOperations().compact(tableName, new CompactionConfig().setWait(true).setCompactionStrategy(csConfig));
        assertEquals(Set.of("a", "b"), getRows(c, tableName));
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) CompactionStrategyConfig(org.apache.accumulo.core.client.admin.CompactionStrategyConfig) CompactionConfig(org.apache.accumulo.core.client.admin.CompactionConfig)

Example 43 with AccumuloClient

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

the class UserCompactionStrategyIT method testPerTableClasspath.

@Test
public void testPerTableClasspath() throws Exception {
    // Can't assume that a test-resource will be on the server's classpath
    assumeTrue(getClusterType() == ClusterType.MINI);
    // test per-table classpath + user specified compaction strategy
    try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) {
        final String tableName = getUniqueNames(1)[0];
        File target = new File(System.getProperty("user.dir"), "target");
        assertTrue(target.mkdirs() || target.isDirectory());
        var destFile = initJar("/org/apache/accumulo/test/TestCompactionStrat.jar", "TestCompactionStrat", target.getAbsolutePath());
        c.instanceOperations().setProperty(Property.VFS_CONTEXT_CLASSPATH_PROPERTY.getKey() + "context1", destFile.toString());
        HashMap<String, String> props = new HashMap<>();
        props.put(Property.TABLE_CLASSLOADER_CONTEXT.getKey(), "context1");
        SortedSet<Text> splits = new TreeSet<>(Arrays.asList(new Text("efg")));
        var ntc = new NewTableConfiguration().setProperties(props).withSplits(splits);
        c.tableOperations().create(tableName, ntc);
        writeFlush(c, tableName, "a");
        writeFlush(c, tableName, "b");
        writeFlush(c, tableName, "h");
        writeFlush(c, tableName, "i");
        assertEquals(4, FunctionalTestUtils.countRFiles(c, tableName));
        // EfgCompactionStrat will only compact a tablet w/ end row of 'efg'. No other tablets are
        // compacted.
        CompactionStrategyConfig csConfig = new CompactionStrategyConfig("org.apache.accumulo.test.EfgCompactionStrat");
        c.tableOperations().compact(tableName, new CompactionConfig().setWait(true).setCompactionStrategy(csConfig));
        assertEquals(3, FunctionalTestUtils.countRFiles(c, tableName));
        c.tableOperations().compact(tableName, new CompactionConfig().setWait(true));
        assertEquals(2, FunctionalTestUtils.countRFiles(c, tableName));
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) CompactionStrategyConfig(org.apache.accumulo.core.client.admin.CompactionStrategyConfig) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) CompactionConfig(org.apache.accumulo.core.client.admin.CompactionConfig) Text(org.apache.hadoop.io.Text) File(java.io.File) Test(org.junit.Test)

Example 44 with AccumuloClient

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

the class GarbageCollectorCommunicatesWithTServersIT method getFilesForTable.

/**
 * Fetch all of the rfiles referenced by tablets in the metadata table for this table
 */
private Set<String> getFilesForTable(String tableName) throws Exception {
    final AccumuloClient client = Accumulo.newClient().from(getClientProperties()).build();
    final TableId tableId = TableId.of(client.tableOperations().tableIdMap().get(tableName));
    assertNotNull("Could not determine table ID for " + tableName, tableId);
    Set<String> rfiles = new HashSet<>();
    try (Scanner s = client.createScanner(MetadataTable.NAME, Authorizations.EMPTY)) {
        Range r = TabletsSection.getRange(tableId);
        s.setRange(r);
        s.fetchColumnFamily(DataFileColumnFamily.NAME);
        for (Entry<Key, Value> entry : s) {
            log.debug("Reading RFiles: {}={}", entry.getKey().toStringNoTruncate(), entry.getValue());
            // uri://path/to/wal
            String cq = entry.getKey().getColumnQualifier().toString();
            String path = new Path(cq).toString();
            log.debug("Normalize path to rfile: {}", path);
            rfiles.add(path);
        }
    }
    return rfiles;
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) TableId(org.apache.accumulo.core.data.TableId) Path(org.apache.hadoop.fs.Path) Scanner(org.apache.accumulo.core.client.Scanner) Value(org.apache.accumulo.core.data.Value) Range(org.apache.accumulo.core.data.Range) Key(org.apache.accumulo.core.data.Key) HashSet(java.util.HashSet)

Example 45 with AccumuloClient

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

the class GarbageCollectorCommunicatesWithTServersIT method getMetadataStatusForTable.

/**
 * Get the replication status messages for the given table that exist in the metadata table (~repl
 * entries)
 */
private Map<String, Status> getMetadataStatusForTable(String tableName) throws Exception {
    final AccumuloClient client = Accumulo.newClient().from(getClientProperties()).build();
    final String tableId = client.tableOperations().tableIdMap().get(tableName);
    assertNotNull("Could not determine table ID for " + tableName, tableId);
    Map<String, Status> fileToStatus = new HashMap<>();
    try (Scanner s = client.createScanner(MetadataTable.NAME, Authorizations.EMPTY)) {
        Range r = ReplicationSection.getRange();
        s.setRange(r);
        s.fetchColumn(ReplicationSection.COLF, new Text(tableId));
        for (Entry<Key, Value> entry : s) {
            Text file = new Text();
            ReplicationSection.getFile(entry.getKey(), file);
            Status status = Status.parseFrom(entry.getValue().get());
            log.info("Got status for {}: {}", file, ProtobufUtil.toString(status));
            fileToStatus.put(file.toString(), status);
        }
    }
    return fileToStatus;
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) Status(org.apache.accumulo.server.replication.proto.Replication.Status) Scanner(org.apache.accumulo.core.client.Scanner) HashMap(java.util.HashMap) Value(org.apache.accumulo.core.data.Value) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range) Key(org.apache.accumulo.core.data.Key)

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