@Override public void close() { if (executor != null) { executor.shutdown(); while (!executor.isTerminated()) { try { executor.awaitTermination(3, TimeUnit.SECONDS); } catch (InterruptedException e) { throw new RuntimeException(e); } } } if (exceptionRef.get() != null) { throw new RuntimeException(exceptionRef.get()); } // wait for any async mutations that transactions write to flush env.getSharedResources().getBatchWriter().waitForAsyncFlush(); }
private void writeWeakNotifications(long commitTs) { if (weakNotifications.size() > 0) { SharedBatchWriter sbw = env.getSharedResources().getBatchWriter(); ArrayList<Mutation> mutations = new ArrayList<>(); for (Entry<Bytes, Set<Column>> entry : weakNotifications.entrySet()) { Flutation m = new Flutation(env, entry.getKey()); for (Column col : entry.getValue()) { Notification.put(env, m, col, commitTs); } mutations.add(m); } sbw.writeMutations(mutations); } }
void deleteWeakRow() { if (weakNotification != null) { env.getSharedResources().getBatchWriter() .writeMutation(weakNotification.newDelete(env, startTs)); } }
@Override public void commit() { super.commit(); // wait for any async mutations that transaction write to flush env.getSharedResources().getBatchWriter().waitForAsyncFlush(); } };
public boolean finishCommit(CommitData cd, Stamp commitStamp) throws TableNotFoundException, MutationsRejectedException { long commitTs = commitStamp.getTxTimestamp(); // delete locks and add writes for other columns ArrayList<Mutation> mutations = new ArrayList<>(updates.size() + 1); for (Entry<Bytes, Map<Column, Bytes>> rowUpdates : updates.entrySet()) { Flutation m = new Flutation(env, rowUpdates.getKey()); boolean isTriggerRow = isTriggerRow(rowUpdates.getKey()); for (Entry<Column, Bytes> colUpdates : rowUpdates.getValue().entrySet()) { ColumnUtil.commitColumn(env, isTriggerRow && colUpdates.getKey().equals(notification.getColumn()), false, colUpdates.getKey(), colUpdates.getValue() != null, colUpdates.getValue() == DELETE, startTs, commitTs, observedColumns, m); } mutations.add(m); } ArrayList<Mutation> afterFlushMutations = new ArrayList<>(2); Flutation m = new Flutation(env, cd.prow); // mark transaction as complete for garbage collection purposes m.put(cd.pcol, ColumnConstants.TX_DONE_PREFIX | commitTs, EMPTY); afterFlushMutations.add(m); if (weakNotification != null) { afterFlushMutations.add(weakNotification.newDelete(env, startTs)); } if (notification != null) { afterFlushMutations.add(notification.newDelete(env, startTs)); } env.getSharedResources().getBatchWriter().writeMutationsAsync(mutations, afterFlushMutations); return true; }
private void rollback(CommitData cd) throws MutationsRejectedException { // roll back locks // TODO let rollback be done lazily? this makes GC more difficult Flutation m; ArrayList<Mutation> mutations = new ArrayList<>(cd.acceptedRows.size()); for (Bytes row : cd.acceptedRows) { m = new Flutation(env, row); for (Column col : updates.get(row).keySet()) { m.put(col, ColumnConstants.DEL_LOCK_PREFIX | startTs, DelLockValue.encode(startTs, false, true)); } mutations.add(m); } env.getSharedResources().getBatchWriter().writeMutations(mutations); // mark transaction as complete for garbage collection purposes m = new Flutation(env, cd.prow); // TODO timestamp? // TODO writing the primary column with a batch writer is iffy m.put(cd.pcol, ColumnConstants.DEL_LOCK_PREFIX | startTs, DelLockValue.encode(startTs, false, true)); m.put(cd.pcol, ColumnConstants.TX_DONE_PREFIX | startTs, EMPTY); env.getSharedResources().getBatchWriter().writeMutation(m); }
env.getSharedResources().getBatchWriter().writeMutations(new ArrayList<>(mutations.values()));
env.getSharedResources().getBatchWriter().waitForAsyncFlush(); count = scan(modParams, tabletInfo.getRange()); tabletsScanned++;
env.getSharedResources().getBatchWriter() .writeMutationAsync(notification.newDelete(env)); return true;