Search in sources :

Example 1 with Key

use of org.apache.accumulo.core.data.Key in project YCSB by brianfrankcooper.

the class AccumuloClient method deleteRow.

/**
   * Deletes a row, given a Scanner of JUST that row.
   */
private void deleteRow(Scanner scanner) throws MutationsRejectedException {
    Mutation deleter = null;
    // iterate through the keys
    for (Entry<Key, Value> entry : scanner) {
        // create a mutation for the row
        if (deleter == null) {
            deleter = new Mutation(entry.getKey().getRow());
        }
        // the remove function adds the key with the delete flag set to true
        deleter.putDelete(entry.getKey().getColumnFamily(), entry.getKey().getColumnQualifier());
    }
    bw.addMutation(deleter);
}
Also used : Value(org.apache.accumulo.core.data.Value) Mutation(org.apache.accumulo.core.data.Mutation) Key(org.apache.accumulo.core.data.Key)

Example 2 with Key

use of org.apache.accumulo.core.data.Key in project YCSB by brianfrankcooper.

the class AccumuloTest method runWorkload.

/**
   * go through a workload cycle.
   * <ol>
   *   <li>initialize thread-specific state
   *   <li>load the workload dataset
   *   <li>run workload transactions
   * </ol>
   */
private void runWorkload() throws Exception {
    final Object state = workload.initThread(workloadProps, 0, 0);
    LOG.debug("load");
    for (int i = 0; i < INSERT_COUNT; i++) {
        assertTrue("insert failed.", workload.doInsert(client, state));
    }
    // Ensure we wait long enough for the batch writer to flush
    // TODO accumulo client should be flushing per insert by default.
    Thread.sleep(2000);
    LOG.debug("verify number of cells");
    final Scanner scanner = cluster.getConnector("root", "protectyaneck").createScanner(CoreWorkload.TABLENAME_PROPERTY_DEFAULT, Authorizations.EMPTY);
    int count = 0;
    for (Entry<Key, Value> entry : scanner) {
        count++;
    }
    assertEquals("Didn't get enough total cells.", (Integer.valueOf(CoreWorkload.FIELD_COUNT_PROPERTY_DEFAULT) * INSERT_COUNT), count);
    LOG.debug("run");
    for (int i = 0; i < TRANSACTION_COUNT; i++) {
        assertTrue("transaction failed.", workload.doTransaction(client, state));
    }
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key)

Example 3 with Key

use of org.apache.accumulo.core.data.Key in project Gaffer by gchq.

the class SampleDataAndCreateSplitsFileTool method run.

@Override
public int run(final String[] strings) throws OperationException {
    try {
        LOGGER.info("Creating job using SampleDataForSplitPointsJobFactory");
        job = new SampleDataForSplitPointsJobFactory().createJob(operation, store);
    } catch (final IOException e) {
        LOGGER.error("Failed to create Hadoop job: {}", e.getMessage());
        throw new OperationException("Failed to create the Hadoop job: " + e.getMessage(), e);
    }
    try {
        LOGGER.info("Running SampleDataForSplitPoints job (job name is {})", job.getJobName());
        job.waitForCompletion(true);
    } catch (final IOException | InterruptedException | ClassNotFoundException e) {
        LOGGER.error("Exception running job: {}", e.getMessage());
        throw new OperationException("Error while waiting for job to complete: " + e.getMessage(), e);
    }
    try {
        if (!job.isSuccessful()) {
            LOGGER.error("Job was not successful (job name is {})", job.getJobName());
            throw new OperationException("Error running job");
        }
    } catch (final IOException e) {
        LOGGER.error("Exception running job: {}", e.getMessage());
        throw new OperationException("Error running job" + e.getMessage(), e);
    }
    // Find the number of records output
    // NB In the following line use mapred.Task.Counter.REDUCE_OUTPUT_RECORDS rather than
    // mapreduce.TaskCounter.REDUCE_OUTPUT_RECORDS as this is more compatible with earlier
    // versions of Hadoop.
    Counter counter;
    try {
        counter = job.getCounters().findCounter(Task.Counter.REDUCE_OUTPUT_RECORDS);
        LOGGER.info("Number of records output = {}", counter);
    } catch (final IOException e) {
        LOGGER.error("Failed to get counter org.apache.hadoop.mapred.Task.Counter.REDUCE_OUTPUT_RECORDS from job: {}", e.getMessage());
        throw new OperationException("Failed to get counter: " + Task.Counter.REDUCE_OUTPUT_RECORDS, e);
    }
    int numberTabletServers;
    try {
        numberTabletServers = store.getConnection().instanceOperations().getTabletServers().size();
        LOGGER.info("Number of tablet servers is {}", numberTabletServers);
    } catch (final StoreException e) {
        LOGGER.error("Exception thrown getting number of tablet servers: {}", e.getMessage());
        throw new OperationException(e.getMessage(), e);
    }
    long outputEveryNthRecord = counter.getValue() / (numberTabletServers - 1);
    final Path resultsFile = new Path(operation.getOutputPath(), "part-r-00000");
    LOGGER.info("Will output every {}-th record from {}", outputEveryNthRecord, resultsFile);
    // Read through resulting file, pick out the split points and write to file.
    final Configuration conf = getConf();
    final FileSystem fs;
    try {
        fs = FileSystem.get(conf);
    } catch (final IOException e) {
        LOGGER.error("Exception getting filesystem: {}", e.getMessage());
        throw new OperationException("Failed to get filesystem from configuration: " + e.getMessage(), e);
    }
    LOGGER.info("Writing splits to {}", operation.getResultingSplitsFilePath());
    final Key key = new Key();
    final Value value = new Value();
    long count = 0;
    int numberSplitPointsOutput = 0;
    try (final SequenceFile.Reader reader = new SequenceFile.Reader(fs, resultsFile, conf);
        final PrintStream splitsWriter = new PrintStream(new BufferedOutputStream(fs.create(new Path(operation.getResultingSplitsFilePath()), true)), false, CommonConstants.UTF_8)) {
        while (reader.next(key, value) && numberSplitPointsOutput < numberTabletServers - 1) {
            count++;
            if (count % outputEveryNthRecord == 0) {
                LOGGER.debug("Outputting split point number {} ({})", numberSplitPointsOutput, Base64.encodeBase64(key.getRow().getBytes()));
                numberSplitPointsOutput++;
                splitsWriter.println(new String(Base64.encodeBase64(key.getRow().getBytes()), CommonConstants.UTF_8));
            }
        }
        LOGGER.info("Total number of records read was {}", count);
    } catch (final IOException e) {
        LOGGER.error("Exception reading results file and outputting split points: {}", e.getMessage());
        throw new OperationException(e.getMessage(), e);
    }
    try {
        fs.delete(resultsFile, true);
        LOGGER.info("Deleted the results file {}", resultsFile);
    } catch (final IOException e) {
        LOGGER.error("Failed to delete the results file {}", resultsFile);
        throw new OperationException("Failed to delete the results file: " + e.getMessage(), e);
    }
    return SUCCESS_RESPONSE;
}
Also used : SampleDataForSplitPointsJobFactory(uk.gov.gchq.gaffer.accumulostore.operation.hdfs.handler.job.factory.SampleDataForSplitPointsJobFactory) Path(org.apache.hadoop.fs.Path) PrintStream(java.io.PrintStream) Configuration(org.apache.hadoop.conf.Configuration) IOException(java.io.IOException) StoreException(uk.gov.gchq.gaffer.store.StoreException) Counter(org.apache.hadoop.mapreduce.Counter) SequenceFile(org.apache.hadoop.io.SequenceFile) FileSystem(org.apache.hadoop.fs.FileSystem) Value(org.apache.accumulo.core.data.Value) BufferedOutputStream(java.io.BufferedOutputStream) OperationException(uk.gov.gchq.gaffer.operation.OperationException) Key(org.apache.accumulo.core.data.Key)

Example 4 with Key

use of org.apache.accumulo.core.data.Key in project Gaffer by gchq.

the class AbstractAccumuloElementConverterTest method shouldReturnAccumuloKeyConverterMultipleCQPropertiesEntity.

@Test
public void shouldReturnAccumuloKeyConverterMultipleCQPropertiesEntity() throws SchemaException, AccumuloElementConversionException, IOException {
    // Given
    final Entity entity = new Entity(TestGroups.ENTITY);
    entity.setVertex("3");
    entity.putProperty(AccumuloPropertyNames.COLUMN_QUALIFIER, 100);
    // When
    final Pair<Key> keys = converter.getKeysFromElement(entity);
    final Entity newEntity = (Entity) converter.getElementFromKey(keys.getFirst());
    // Then
    assertEquals("3", newEntity.getVertex());
    assertEquals(100, newEntity.getProperty(AccumuloPropertyNames.COLUMN_QUALIFIER));
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 5 with Key

use of org.apache.accumulo.core.data.Key in project Gaffer by gchq.

the class AbstractAccumuloElementConverterTest method shouldGetFlippedEdgeWithMatchAsSourceFalse.

@Test
public void shouldGetFlippedEdgeWithMatchAsSourceFalse() throws SchemaException, AccumuloElementConversionException, IOException {
    // Given
    final Edge edge = new Edge(TestGroups.EDGE);
    edge.setDestination("2");
    edge.setSource("1");
    edge.setDirected(true);
    edge.putProperty(AccumuloPropertyNames.COLUMN_QUALIFIER, 100);
    final Pair<Key> keys = converter.getKeysFromElement(edge);
    final Map<String, String> options = new HashMap<>();
    options.put(AccumuloStoreConstants.OPERATION_RETURN_MATCHED_SEEDS_AS_EDGE_SOURCE, "true");
    // When
    final Edge newEdge = (Edge) converter.getElementFromKey(keys.getSecond(), options);
    // Then
    assertEquals("2", newEdge.getSource());
    assertEquals("1", newEdge.getDestination());
    assertEquals(true, newEdge.isDirected());
    assertEquals(100, newEdge.getProperty(AccumuloPropertyNames.COLUMN_QUALIFIER));
}
Also used : HashMap(java.util.HashMap) Edge(uk.gov.gchq.gaffer.data.element.Edge) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Aggregations

Key (org.apache.accumulo.core.data.Key)1004 Value (org.apache.accumulo.core.data.Value)798 Test (org.junit.Test)401 Text (org.apache.hadoop.io.Text)359 Range (org.apache.accumulo.core.data.Range)324 Scanner (org.apache.accumulo.core.client.Scanner)315 Mutation (org.apache.accumulo.core.data.Mutation)201 PartialKey (org.apache.accumulo.core.data.PartialKey)191 BatchWriter (org.apache.accumulo.core.client.BatchWriter)183 TreeMap (java.util.TreeMap)161 Connector (org.apache.accumulo.core.client.Connector)141 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)136 HashMap (java.util.HashMap)124 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)123 ArrayList (java.util.ArrayList)119 Entry (java.util.Map.Entry)113 Authorizations (org.apache.accumulo.core.security.Authorizations)109 Map (java.util.Map)88 IOException (java.io.IOException)82 SortedMapIterator (org.apache.accumulo.core.iterators.SortedMapIterator)82