List<RowLock> acquiredRowLocks = Lists.newArrayListWithCapacity(batchOp.size()); try { miniBatchOp = batchOp.lockRowsAndBuildMiniBatch(acquiredRowLocks); batchOp.prepareMiniBatchOperations(miniBatchOp, now, acquiredRowLocks); List<Pair<NonceKey, WALEdit>> walEdits = batchOp.buildWALEdits(miniBatchOp); writeEntry = doWALAppend(walEdit, batchOp.durability, batchOp.getClusterIds(), now, nonceKey.getNonceGroup(), nonceKey.getNonce(), batchOp.getOrigLogSeqNum()); writeEntry = batchOp.writeMiniBatchOperationsToMemStore(miniBatchOp, writeEntry); batchOp.completeMiniBatchOperations(miniBatchOp, writeEntry); writeEntry = null; success = true; miniBatchOp != null ? miniBatchOp.getLastIndexExclusive() : batchOp.size(); final boolean finalSuccess = success; batchOp.visitBatchOperations(true, finalLastIndexExclusive, (int i) -> { batchOp.retCodeDetails[i] = finalSuccess ? OperationStatus.SUCCESS : OperationStatus.FAILURE; }); batchOp.doPostOpCleanupForMiniBatch(miniBatchOp, walEdit, finalSuccess);
protected void checkAndPrepareMutation(int index, long timestamp) throws IOException { Mutation mutation = getMutation(index); try { this.checkAndPrepareMutation(mutation, timestamp); if (isAtomic()) { // fail, atomic means all or none throw nscfe; if (isAtomic()) { throw fsce; if (isAtomic()) { throw we;
int lastIndexExclusive = 0; RowLock prevRowLock = null; for (; lastIndexExclusive < size(); lastIndexExclusive++) { if (!isAtomic() && (readyToWriteCount == region.miniBatchSize)) { break; if (!isOperationPending(lastIndexExclusive)) { continue; getMutation(lastIndexExclusive).getFamilyCellMap(); try { } catch (RegionTooBusyException rtbe) { region.storeHotnessProtector.finish(curFamilyCellMap); if (isAtomic()) { throw rtbe; Mutation mutation = getMutation(lastIndexExclusive); rowLock = region.getRowLockInternal(mutation.getRow(), !isAtomic(), prevRowLock); } catch (TimeoutIOException | InterruptedIOException e) { } catch (IOException ioe) { LOG.warn("Failed getting lock, row=" + Bytes.toStringBinary(mutation.getRow()), ioe); if (isAtomic()) { // fail, atomic means all or none throwException = true; throw ioe;
final WALEdit walEdit, boolean success) throws IOException { super.doPostOpCleanupForMiniBatch(miniBatchOp, walEdit, success); if (miniBatchOp != null) {
batchOp.startRegionOperation(); try { while (!batchOp.isDone()) { if (!batchOp.isInReplay()) { checkReadOnly(); this.writeRequestsCount.add(batchOp.size()); batchOp.checkAndPrepare(); initialized = true; batchOp.closeRegionOperation();
protected void writeMiniBatchOperationsToMemStore( final MiniBatchOperationInProgress<Mutation> miniBatchOp, final long writeNumber) throws IOException { MemStoreSizing memStoreAccounting = new NonThreadSafeMemStoreSizing(); visitBatchOperations(true, miniBatchOp.getLastIndexExclusive(), (int index) -> { // We need to update the sequence id for following reasons. // 1) If the op is in replay mode, FSWALEntry#stampRegionSequenceId won't stamp sequence id. // 2) If no WAL, FSWALEntry won't be used // we use durability of the original mutation for the mutation passed by CP. if (isInReplay() || getMutation(index).getDurability() == Durability.SKIP_WAL) { region.updateSequenceId(familyCellMaps[index].values(), writeNumber); } applyFamilyMapToMemStore(familyCellMaps[index], memStoreAccounting); return true; }); // update memStore size region.incMemStoreSize(memStoreAccounting.getDataSize(), memStoreAccounting.getHeapSize(), memStoreAccounting.getOffHeapSize(), memStoreAccounting.getCellsCount()); }
/** * Helper method that checks and prepares only one mutation. This can be used to implement * {@link #checkAndPrepare()} for entire Batch. * NOTE: As CP prePut()/ preDelete() hooks may modify mutations, this method should be called * after prePut()/ preDelete() CP hooks are run for the mutation */ protected void checkAndPrepareMutation(Mutation mutation, final long timestamp) throws IOException { region.checkRow(mutation.getRow(), "batchMutate"); if (mutation instanceof Put) { // Check the families in the put. If bad, skip this one. checkAndPreparePut((Put) mutation); region.checkTimestamps(mutation.getFamilyCellMap(), timestamp); } else { region.prepareDelete((Delete) mutation); } }
public void doPostOpCleanupForMiniBatch( final MiniBatchOperationInProgress<Mutation> miniBatchOp, final WALEdit walEdit, boolean success) throws IOException { doFinishHotnessProtector(miniBatchOp); }
@Override public void completeMiniBatchOperations( final MiniBatchOperationInProgress<Mutation> miniBatchOp, final WriteEntry writeEntry) throws IOException { super.completeMiniBatchOperations(miniBatchOp, writeEntry); region.mvcc.advanceTo(getOrigLogSeqNum()); } }
@Override public List<Pair<NonceKey, WALEdit>> buildWALEdits(final MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException { List<Pair<NonceKey, WALEdit>> walEdits = super.buildWALEdits(miniBatchOp); // for MutationBatchOperation, more than one nonce is not allowed if (walEdits.size() > 1) { throw new IOException("Found multiple nonce keys per batch!"); } return walEdits; }
@Override public void completeMiniBatchOperations( final MiniBatchOperationInProgress<Mutation> miniBatchOp, final WriteEntry writeEntry) throws IOException { // TODO: can it be done after completing mvcc? // calling the post CP hook for batch mutation if (region.coprocessorHost != null) { region.coprocessorHost.postBatchMutate(miniBatchOp); } super.completeMiniBatchOperations(miniBatchOp, writeEntry); }