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);
}
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));
}
}
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;
}
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));
}
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));
}
Aggregations