use of org.apache.accumulo.core.client.MutationsRejectedException in project presto by prestodb.
the class AccumuloPageSink method finish.
@Override
public CompletableFuture<Collection<Slice>> finish() {
try {
// Done serializing rows, so flush and close the writer and indexer
writer.flush();
writer.close();
if (indexer.isPresent()) {
indexer.get().close();
}
} catch (MutationsRejectedException e) {
throw new PrestoException(UNEXPECTED_ACCUMULO_ERROR, "Mutation rejected by server on flush", e);
}
// TODO Look into any use of the metadata for writing out the rows
return completedFuture(ImmutableList.of());
}
use of org.apache.accumulo.core.client.MutationsRejectedException in project gora by apache.
the class AccumuloStore method put.
@Override
public void put(K key, T val) throws GoraException {
try {
Mutation m = new Mutation(new Text(toBytes(key)));
Schema schema = val.getSchema();
List<Field> fields = schema.getFields();
int count = 0;
for (int i = 0; i < fields.size(); i++) {
if (!val.isDirty(i)) {
continue;
}
Field field = fields.get(i);
Object o = val.get(field.pos());
Pair<Text, Text> col = mapping.fieldMap.get(field.name());
if (col == null) {
throw new GoraException("Please define the gora to accumulo mapping for field " + field.name());
}
switch(field.schema().getType()) {
case MAP:
count = putMap(m, count, field.schema().getValueType(), o, col, field.name());
break;
case ARRAY:
count = putArray(m, count, o, col, field.name());
break;
case // default value of null acts like union with null
UNION:
Schema effectiveSchema = field.schema().getTypes().get(firstNotNullSchemaTypeIndex(field.schema()));
// map and array need to compute qualifier
if (effectiveSchema.getType() == Type.ARRAY) {
count = putArray(m, count, o, col, field.name());
break;
} else if (effectiveSchema.getType() == Type.MAP) {
count = putMap(m, count, effectiveSchema.getValueType(), o, col, field.name());
break;
}
// continue like a regular top-level union
case RECORD:
final SpecificDatumWriter<Object> writer = new SpecificDatumWriter<>(field.schema());
final byte[] byteData = IOUtils.serialize(writer, o);
m.put(col.getFirst(), col.getSecond(), new Value(byteData));
count++;
break;
default:
m.put(col.getFirst(), col.getSecond(), new Value(toBytes(o)));
count++;
}
}
if (count > 0)
try {
getBatchWriter().addMutation(m);
} catch (MutationsRejectedException e) {
LOG.error(e.getMessage(), e);
}
} catch (GoraException e) {
throw e;
} catch (Exception e) {
throw new GoraException(e);
}
}
use of org.apache.accumulo.core.client.MutationsRejectedException in project accumulo by apache.
the class InsertCommand method execute.
@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, IOException, ConstraintViolationException {
final String tableName = OptUtil.getTableOpt(cl, shellState);
final Mutation m = new Mutation(new Text(cl.getArgs()[0].getBytes(Shell.CHARSET)));
final Text colf = new Text(cl.getArgs()[1].getBytes(Shell.CHARSET));
final Text colq = new Text(cl.getArgs()[2].getBytes(Shell.CHARSET));
final Value val = new Value(cl.getArgs()[3].getBytes(Shell.CHARSET));
if (cl.hasOption(insertOptAuths.getOpt())) {
final ColumnVisibility le = new ColumnVisibility(cl.getOptionValue(insertOptAuths.getOpt()));
Shell.log.debug("Authorization label will be set to: {}", le);
if (cl.hasOption(timestampOpt.getOpt()))
m.put(colf, colq, le, Long.parseLong(cl.getOptionValue(timestampOpt.getOpt())), val);
else
m.put(colf, colq, le, val);
} else if (cl.hasOption(timestampOpt.getOpt()))
m.put(colf, colq, Long.parseLong(cl.getOptionValue(timestampOpt.getOpt())), val);
else
m.put(colf, colq, val);
final BatchWriterConfig cfg = new BatchWriterConfig().setMaxMemory(Math.max(m.estimatedMemoryUsed(), 1024)).setMaxWriteThreads(1).setTimeout(getTimeout(cl), TimeUnit.MILLISECONDS);
if (cl.hasOption(durabilityOption.getOpt())) {
String userDurability = cl.getOptionValue(durabilityOption.getOpt());
switch(userDurability) {
case "sync":
cfg.setDurability(Durability.SYNC);
break;
case "flush":
cfg.setDurability(Durability.FLUSH);
break;
case "none":
cfg.setDurability(Durability.NONE);
break;
case "log":
cfg.setDurability(Durability.NONE);
break;
default:
throw new IllegalArgumentException("Unknown durability: " + userDurability);
}
}
final BatchWriter bw = shellState.getAccumuloClient().createBatchWriter(tableName, cfg);
bw.addMutation(m);
try {
bw.close();
} catch (MutationsRejectedException e) {
final ArrayList<String> lines = new ArrayList<>();
if (!e.getSecurityErrorCodes().isEmpty()) {
lines.add("\tAuthorization Failures:");
}
for (Entry<TabletId, Set<SecurityErrorCode>> entry : e.getSecurityErrorCodes().entrySet()) {
lines.add("\t\t" + entry);
}
if (!e.getConstraintViolationSummaries().isEmpty()) {
lines.add("\tConstraint Failures:");
}
for (ConstraintViolationSummary cvs : e.getConstraintViolationSummaries()) {
lines.add("\t\t" + cvs);
}
if (lines.isEmpty() || e.getUnknownExceptions() > 0) {
// must always print something
lines.add(" " + e.getClass().getName() + " : " + e.getMessage());
if (e.getCause() != null)
lines.add(" Caused by : " + e.getCause().getClass().getName() + " : " + e.getCause().getMessage());
}
shellState.printLines(lines.iterator(), false);
return 1;
}
return 0;
}
use of org.apache.accumulo.core.client.MutationsRejectedException in project accumulo by apache.
the class TestMultiTableIngest method main.
public static void main(String[] args) throws Exception {
ArrayList<String> tableNames = new ArrayList<>();
Opts opts = new Opts();
opts.parseArgs(TestMultiTableIngest.class.getName(), args);
// create the test table within accumulo
try (AccumuloClient client = Accumulo.newClient().from(opts.getClientProps()).build()) {
for (int i = 0; i < opts.tables; i++) {
tableNames.add(String.format(opts.prefix + "%04d", i));
}
if (!opts.readonly) {
for (String table : tableNames) client.tableOperations().create(table);
MultiTableBatchWriter b;
try {
b = client.createMultiTableBatchWriter();
} catch (Exception e) {
throw new RuntimeException(e);
}
// populate
for (int i = 0; i < opts.count; i++) {
Mutation m = new Mutation(new Text(String.format("%06d", i)));
m.put("col" + ((i % 3) + 1), "qual", "junk");
b.getBatchWriter(tableNames.get(i % tableNames.size())).addMutation(m);
}
try {
b.close();
} catch (MutationsRejectedException e) {
throw new RuntimeException(e);
}
}
try {
readBack(opts, client, tableNames);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
use of org.apache.accumulo.core.client.MutationsRejectedException in project accumulo by apache.
the class MultiTableBatchWriterIT method testTableDelete.
@Test
public void testTableDelete() throws Exception {
boolean mutationsRejected = false;
try {
final String[] names = getUniqueNames(2);
final String table1 = names[0], table2 = names[1];
TableOperations tops = accumuloClient.tableOperations();
tops.create(table1);
tops.create(table2);
BatchWriter bw1 = mtbw.getBatchWriter(table1), bw2 = mtbw.getBatchWriter(table2);
Mutation m1 = new Mutation("foo");
m1.put("col1", "", "val1");
m1.put("col2", "", "val2");
bw1.addMutation(m1);
bw2.addMutation(m1);
tops.delete(table1);
tops.delete(table2);
Mutation m2 = new Mutation("bar");
m2.put("col1", "", "val1");
m2.put("col2", "", "val2");
try {
bw1.addMutation(m2);
bw2.addMutation(m2);
} catch (MutationsRejectedException e) {
// Pass - Mutations might flush immediately
mutationsRejected = true;
}
} finally {
if (mtbw != null) {
try {
// Mutations might have flushed before the table offline occurred
mtbw.close();
} catch (MutationsRejectedException e) {
// Pass
mutationsRejected = true;
}
}
}
assertTrue("Expected mutations to be rejected.", mutationsRejected);
}
Aggregations