private void addIndexMutation(ByteBuffer row, ByteBuffer family, ColumnVisibility visibility, byte[] qualifier) { // Create the mutation and add it to the batch writer Mutation indexMutation = new Mutation(row.array()); indexMutation.put(family.array(), qualifier, visibility, EMPTY_BYTES); try { indexWriter.addMutation(indexMutation); } catch (MutationsRejectedException e) { throw new PrestoException(UNEXPECTED_ACCUMULO_ERROR, "Index mutation rejected by server", e); } // Increment the cardinality metrics for this value of index // metrics is a mapping of row ID to column family MetricsKey key = new MetricsKey(row, family, visibility); AtomicLong count = metrics.get(key); if (count == null) { count = new AtomicLong(0); metrics.put(key, count); } count.incrementAndGet(); }
/** * Deletes a row, given a Scanner of JUST that row. */ private void deleteRow(Scanner scanner, BatchWriter bw) throws MutationsRejectedException { Mutation deleter = null; // iterate through the keys final Text row = new Text(); final Text cf = new Text(); final Text cq = new Text(); for (Entry<Key, Value> entry : scanner) { // create a mutation for the row if (deleter == null) { entry.getKey().getRow(row); deleter = new Mutation(row); } entry.getKey().getColumnFamily(cf); entry.getKey().getColumnQualifier(cq); // the remove function adds the key with the delete flag set to true deleter.putDelete(cf, cq); } bw.addMutation(deleter); } }
@Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, IOException, ConstraintViolationException { shellState.checkTableState(); 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)); if (cl.hasOption(deleteOptAuths.getOpt())) { final ColumnVisibility le = new ColumnVisibility(cl.getOptionValue(deleteOptAuths.getOpt())); if (cl.hasOption(timestampOpt.getOpt())) { m.putDelete(colf, colq, le, Long.parseLong(cl.getOptionValue(timestampOpt.getOpt()))); } else { m.putDelete(colf, colq, le); } } else if (cl.hasOption(timestampOpt.getOpt())) { m.putDelete(colf, colq, Long.parseLong(cl.getOptionValue(timestampOpt.getOpt()))); } else { m.putDelete(colf, colq); } final BatchWriter bw = shellState.getAccumuloClient().createBatchWriter( shellState.getTableName(), new BatchWriterConfig().setMaxMemory(Math.max(m.estimatedMemoryUsed(), 1024)) .setMaxWriteThreads(1).setTimeout(getTimeout(cl), TimeUnit.MILLISECONDS)); bw.addMutation(m); bw.close(); return 0; }
@Override public void unsuspend(Collection<TabletLocationState> tablets) throws DistributedStoreException { BatchWriter writer = createBatchWriter(); try { for (TabletLocationState tls : tablets) { if (tls.suspend != null) { continue; } Mutation m = new Mutation(tls.extent.getMetadataEntry()); SuspendingTServer.clearSuspension(m); writer.addMutation(m); } } catch (Exception ex) { throw new DistributedStoreException(ex); } finally { try { writer.close(); } catch (MutationsRejectedException e) { throw new DistributedStoreException(e); } } }
Mutation m = new Mutation(cloneTablet.getExtent().getMetadataEntry()); bw.addMutation(m); bw.addMutation(createCloneMutation(srcTableId, tableId, st.getKeyValues())); Mutation m = new Mutation(cloneTablet.getExtent().getMetadataEntry()); m.put(ClonedColumnFamily.NAME, new Text(""), new Value("OK".getBytes(UTF_8))); bw.addMutation(m);
/** * Record the updated Status for this file and target * * @param filePath * Path to file being replicated * @param status * Updated Status after replication * @param target * Peer that was replicated to */ public void recordNewStatus(Path filePath, Status status, ReplicationTarget target) throws AccumuloException, TableNotFoundException { try (BatchWriter bw = context.createBatchWriter(ReplicationTable.NAME, new BatchWriterConfig())) { log.debug("Recording new status for {}, {}", filePath, ProtobufUtil.toString(status)); Mutation m = new Mutation(filePath.toString()); WorkSection.add(m, target.toText(), ProtobufUtil.toValue(status)); bw.addMutation(m); } } }
log.info("Adding work records for {} to targets {}", file, targets); try { Mutation m = new Mutation(file); writer.addMutation(m); } catch (MutationsRejectedException e) { log.warn("Failed to write work mutations for replication, will retry", e);
@Override public void delete() throws MutationsRejectedException { BatchWriter bw = null; try { bw = new BatchWriterImpl(context, tableId, bwConfig); Iterator<Entry<Key,Value>> iter = super.iterator(); while (iter.hasNext()) { Entry<Key,Value> next = iter.next(); Key k = next.getKey(); Mutation m = new Mutation(k.getRow()); m.putDelete(k.getColumnFamily(), k.getColumnQualifier(), new ColumnVisibility(k.getColumnVisibility()), k.getTimestamp()); bw.addMutation(m); } } finally { if (bw != null) bw.close(); } }
@Override public Status update(String table, String key, Map<String, ByteIterator> values) { BatchWriter bw = null; try { bw = getWriter(table); } catch (TableNotFoundException e) { System.err.println("Error opening batch writer to Accumulo table " + table); e.printStackTrace(); return Status.ERROR; } Mutation mutInsert = new Mutation(key.getBytes(UTF_8)); for (Map.Entry<String, ByteIterator> entry : values.entrySet()) { mutInsert.put(colFamBytes, entry.getKey().getBytes(UTF_8), entry.getValue().toArray()); } try { bw.addMutation(mutInsert); } catch (MutationsRejectedException e) { System.err.println("Error performing update."); e.printStackTrace(); return Status.ERROR; } return Status.BATCHED_OK; }
/** * Deletes a row, given a Scanner of JUST that row. */ private void deleteRow(Scanner scanner, BatchWriter bw) throws MutationsRejectedException { Mutation deleter = null; // iterate through the keys final Text row = new Text(); final Text cf = new Text(); final Text cq = new Text(); for (Entry<Key, Value> entry : scanner) { // create a mutation for the row if (deleter == null) { entry.getKey().getRow(row); deleter = new Mutation(row); } entry.getKey().getColumnFamily(cf); entry.getKey().getColumnQualifier(cq); // the remove function adds the key with the delete flag set to true deleter.putDelete(cf, cq); } bw.addMutation(deleter); } }
@Override public void setFutureLocations(Collection<Assignment> assignments) throws DistributedStoreException { BatchWriter writer = createBatchWriter(); try { for (Assignment assignment : assignments) { Mutation m = new Mutation(assignment.tablet.getMetadataEntry()); SuspendingTServer.clearSuspension(m); assignment.server.putFutureLocation(m); writer.addMutation(m); } } catch (Exception ex) { throw new DistributedStoreException(ex); } finally { try { writer.close(); } catch (MutationsRejectedException e) { throw new DistributedStoreException(e); } } }
Master.log.info("Removing entry {}", entry); BatchWriter bw = this.master.getContext().createBatchWriter(table, new BatchWriterConfig()); Mutation m = new Mutation(entry.getKey().getRow()); m.putDelete(entry.getKey().getColumnFamily(), entry.getKey().getColumnQualifier()); bw.addMutation(m); bw.close(); return;
@Override public Status update(String table, String key, Map<String, ByteIterator> values) { BatchWriter bw = null; try { bw = getWriter(table); } catch (TableNotFoundException e) { System.err.println("Error opening batch writer to Accumulo table " + table); e.printStackTrace(); return Status.ERROR; } Mutation mutInsert = new Mutation(key.getBytes(UTF_8)); for (Map.Entry<String, ByteIterator> entry : values.entrySet()) { mutInsert.put(colFamBytes, entry.getKey().getBytes(UTF_8), entry.getValue().toArray()); } try { bw.addMutation(mutInsert); } catch (MutationsRejectedException e) { System.err.println("Error performing update."); e.printStackTrace(); return Status.ERROR; } return Status.BATCHED_OK; }
/** * Deletes a row, given a Scanner of JUST that row. */ private void deleteRow(Scanner scanner, BatchWriter bw) throws MutationsRejectedException { Mutation deleter = null; // iterate through the keys final Text row = new Text(); final Text cf = new Text(); final Text cq = new Text(); for (Entry<Key, Value> entry : scanner) { // create a mutation for the row if (deleter == null) { entry.getKey().getRow(row); deleter = new Mutation(row); } entry.getKey().getColumnFamily(cf); entry.getKey().getColumnQualifier(cq); // the remove function adds the key with the delete flag set to true deleter.putDelete(cf, cq); } bw.addMutation(deleter); } }
@Override public void setLocations(Collection<Assignment> assignments) throws DistributedStoreException { BatchWriter writer = createBatchWriter(); try { for (Assignment assignment : assignments) { Mutation m = new Mutation(assignment.tablet.getMetadataEntry()); assignment.server.putLocation(m); assignment.server.clearFutureLocation(m); SuspendingTServer.clearSuspension(m); writer.addMutation(m); } } catch (Exception ex) { throw new DistributedStoreException(ex); } finally { try { writer.close(); } catch (MutationsRejectedException e) { throw new DistributedStoreException(e); } } }
shellState.checkTableState(); 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)); 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); bw.addMutation(m); try { bw.close(); } catch (MutationsRejectedException e) { final ArrayList<String> lines = new ArrayList<>();
@Override public Status update(String table, String key, Map<String, ByteIterator> values) { BatchWriter bw = null; try { bw = getWriter(table); } catch (TableNotFoundException e) { System.err.println("Error opening batch writer to Accumulo table " + table); e.printStackTrace(); return Status.ERROR; } Mutation mutInsert = new Mutation(key.getBytes(UTF_8)); for (Map.Entry<String, ByteIterator> entry : values.entrySet()) { mutInsert.put(colFamBytes, entry.getKey().getBytes(UTF_8), entry.getValue().toArray()); } try { bw.addMutation(mutInsert); } catch (MutationsRejectedException e) { System.err.println("Error performing update."); e.printStackTrace(); return Status.ERROR; } return Status.BATCHED_OK; }
private static void putMarkerDeleteMutation(final String delete, final BatchWriter writer) throws MutationsRejectedException { Mutation m = new Mutation(MetadataSchema.DeletesSection.getRowPrefix() + delete); m.putDelete(EMPTY_TEXT, EMPTY_TEXT); writer.addMutation(m); }
serializedRow.getKey().getRow(), entry.getKey(), entry.getValue()); Mutation replMutation = new Mutation(buffer); replBw.addMutation(replMutation); } catch (MutationsRejectedException e) { log.error("Error writing mutations to update replication Status" replBw.close(); } catch (MutationsRejectedException e) { log.error("Error writing mutations to update replication Status"
public static void removeBulkLoadEntries(AccumuloClient client, Table.ID tableId, long tid) throws Exception { try ( Scanner mscanner = new IsolatedScanner( client.createScanner(MetadataTable.NAME, Authorizations.EMPTY)); BatchWriter bw = client.createBatchWriter(MetadataTable.NAME, new BatchWriterConfig())) { mscanner.setRange(new KeyExtent(tableId, null, null).toMetadataRange()); mscanner.fetchColumnFamily(TabletsSection.BulkFileColumnFamily.NAME); byte[] tidAsBytes = Long.toString(tid).getBytes(UTF_8); for (Entry<Key,Value> entry : mscanner) { log.trace("Looking at entry {} with tid {}", entry, tid); if (Arrays.equals(entry.getValue().get(), tidAsBytes)) { log.trace("deleting entry {}", entry); Key key = entry.getKey(); Mutation m = new Mutation(key.getRow()); m.putDelete(key.getColumnFamily(), key.getColumnQualifier()); bw.addMutation(m); } } } }