hbase git commit: HBASE-18962 Support atomic (all or none) BatchOperations through batchMutate()
Repository: hbase Updated Branches: refs/heads/branch-2 07b0ac416 -> 85227d6a7 HBASE-18962 Support atomic (all or none) BatchOperations through batchMutate() Signed-off-by: Apekshit SharmaSigned-off-by: Michael Stack Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/85227d6a Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/85227d6a Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/85227d6a Branch: refs/heads/branch-2 Commit: 85227d6a726ab8237ed63c9f4e56fc5ad033d7f6 Parents: 07b0ac4 Author: Umesh Agashe Authored: Thu Oct 19 11:05:01 2017 -0700 Committer: Michael Stack Committed: Thu Nov 9 12:15:16 2017 -0800 -- .../hadoop/hbase/regionserver/HRegion.java | 55 +-- .../hbase/regionserver/RSRpcServices.java | 34 +++-- .../hadoop/hbase/regionserver/TestHRegion.java | 147 +-- 3 files changed, 166 insertions(+), 70 deletions(-) -- http://git-wip-us.apache.org/repos/asf/hbase/blob/85227d6a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java -- diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java index f6890af..492325e 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java @@ -2952,6 +2952,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi protected final ObservedExceptionsInBatch observedExceptions; //Durability of the batch (highest durability of all operations) protected Durability durability; +protected boolean atomic = false; public BatchOperation(final HRegion region, T[] operations) { this.operations = operations; @@ -3067,6 +3068,10 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi return getMutation(0).getClusterIds(); } +boolean isAtomic() { + return atomic; +} + /** * Helper method that checks and prepares only one mutation. This can be used to implement * {@link #checkAndPrepare()} for entire Batch. @@ -3097,16 +3102,19 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi if (tmpDur.ordinal() > durability.ordinal()) { durability = tmpDur; } - } catch (NoSuchColumnFamilyException nscf) { + } catch (NoSuchColumnFamilyException nscfe) { final String msg = "No such column family in batch mutation. "; if (observedExceptions.hasSeenNoSuchFamily()) { - LOG.warn(msg + nscf.getMessage()); + LOG.warn(msg + nscfe.getMessage()); } else { - LOG.warn(msg, nscf); + LOG.warn(msg, nscfe); observedExceptions.sawNoSuchFamily(); } retCodeDetails[index] = new OperationStatus( -OperationStatusCode.BAD_FAMILY, nscf.getMessage()); +OperationStatusCode.BAD_FAMILY, nscfe.getMessage()); +if (isAtomic()) { // fail, atomic means all or none + throw nscfe; +} } catch (FailedSanityCheckException fsce) { final String msg = "Batch Mutation did not pass sanity check. "; if (observedExceptions.hasSeenFailedSanityCheck()) { @@ -3117,6 +3125,9 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi } retCodeDetails[index] = new OperationStatus( OperationStatusCode.SANITY_CHECK_FAILURE, fsce.getMessage()); +if (isAtomic()) { + throw fsce; +} } catch (WrongRegionException we) { final String msg = "Batch mutation had a row that does not belong to this region. "; if (observedExceptions.hasSeenWrongRegion()) { @@ -3127,6 +3138,9 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi } retCodeDetails[index] = new OperationStatus( OperationStatusCode.SANITY_CHECK_FAILURE, we.getMessage()); +if (isAtomic()) { + throw we; +} } } @@ -3150,15 +3164,22 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi // If we haven't got any rows in our batch, we should block to get the next one. RowLock rowLock = null; try { - rowLock = region.getRowLockInternal(mutation.getRow(), true); + // if atomic then get exclusive lock, else shared lock + rowLock = region.getRowLockInternal(mutation.getRow(), !isAtomic()); }
hbase git commit: HBASE-18962 Support atomic (all or none) BatchOperations through batchMutate()
Repository: hbase Updated Branches: refs/heads/master 0ec96a5ff -> 5bb2a2498 HBASE-18962 Support atomic (all or none) BatchOperations through batchMutate() Signed-off-by: Apekshit SharmaSigned-off-by: Michael Stack Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/5bb2a249 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/5bb2a249 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/5bb2a249 Branch: refs/heads/master Commit: 5bb2a249847d391c9008590f2f92b95ff327cd0d Parents: 0ec96a5 Author: Umesh Agashe Authored: Thu Oct 19 11:05:01 2017 -0700 Committer: Michael Stack Committed: Thu Nov 9 12:14:33 2017 -0800 -- .../hadoop/hbase/regionserver/HRegion.java | 55 +-- .../hbase/regionserver/RSRpcServices.java | 34 +++-- .../hadoop/hbase/regionserver/TestHRegion.java | 147 +-- 3 files changed, 166 insertions(+), 70 deletions(-) -- http://git-wip-us.apache.org/repos/asf/hbase/blob/5bb2a249/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java -- diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java index f6890af..492325e 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java @@ -2952,6 +2952,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi protected final ObservedExceptionsInBatch observedExceptions; //Durability of the batch (highest durability of all operations) protected Durability durability; +protected boolean atomic = false; public BatchOperation(final HRegion region, T[] operations) { this.operations = operations; @@ -3067,6 +3068,10 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi return getMutation(0).getClusterIds(); } +boolean isAtomic() { + return atomic; +} + /** * Helper method that checks and prepares only one mutation. This can be used to implement * {@link #checkAndPrepare()} for entire Batch. @@ -3097,16 +3102,19 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi if (tmpDur.ordinal() > durability.ordinal()) { durability = tmpDur; } - } catch (NoSuchColumnFamilyException nscf) { + } catch (NoSuchColumnFamilyException nscfe) { final String msg = "No such column family in batch mutation. "; if (observedExceptions.hasSeenNoSuchFamily()) { - LOG.warn(msg + nscf.getMessage()); + LOG.warn(msg + nscfe.getMessage()); } else { - LOG.warn(msg, nscf); + LOG.warn(msg, nscfe); observedExceptions.sawNoSuchFamily(); } retCodeDetails[index] = new OperationStatus( -OperationStatusCode.BAD_FAMILY, nscf.getMessage()); +OperationStatusCode.BAD_FAMILY, nscfe.getMessage()); +if (isAtomic()) { // fail, atomic means all or none + throw nscfe; +} } catch (FailedSanityCheckException fsce) { final String msg = "Batch Mutation did not pass sanity check. "; if (observedExceptions.hasSeenFailedSanityCheck()) { @@ -3117,6 +3125,9 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi } retCodeDetails[index] = new OperationStatus( OperationStatusCode.SANITY_CHECK_FAILURE, fsce.getMessage()); +if (isAtomic()) { + throw fsce; +} } catch (WrongRegionException we) { final String msg = "Batch mutation had a row that does not belong to this region. "; if (observedExceptions.hasSeenWrongRegion()) { @@ -3127,6 +3138,9 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi } retCodeDetails[index] = new OperationStatus( OperationStatusCode.SANITY_CHECK_FAILURE, we.getMessage()); +if (isAtomic()) { + throw we; +} } } @@ -3150,15 +3164,22 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi // If we haven't got any rows in our batch, we should block to get the next one. RowLock rowLock = null; try { - rowLock = region.getRowLockInternal(mutation.getRow(), true); + // if atomic then get exclusive lock, else shared lock + rowLock = region.getRowLockInternal(mutation.getRow(), !isAtomic()); } catch