commit 623b60280136b54b6e3f777bcaeadd91a200156f Author: John Leach Date: Mon Aug 22 15:43:47 2016 -0500 HBASE-16468 Use Array Implementation vs. a List Implementation on batchMutate 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 86c02ea..bb4823e 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 @@ -250,7 +250,6 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi // - the row itself private final ConcurrentHashMap lockedRows = new ConcurrentHashMap(); - protected final Map stores = new ConcurrentSkipListMap( Bytes.BYTES_RAWCOMPARATOR); @@ -3043,7 +3042,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi WriteEntry writeEntry = null; int cellCount = 0; /** Keep track of the locks we hold so we can release them in finally clause */ - List acquiredRowLocks = Lists.newArrayListWithCapacity(batchOp.operations.length); + RowLock[] acquiredRowLocks = new RowLock[batchOp.operations.length]; long addedSize = 0; try { // STEP 1. Try to acquire as many locks as we can, and ensure we acquire at least one. @@ -3066,7 +3065,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi // We failed to grab another lock break; // Stop acquiring more rows for this batch } else { - acquiredRowLocks.add(rowLock); + acquiredRowLocks[lastIndexExclusive] = rowLock; } lastIndexExclusive++; @@ -3163,7 +3162,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi checkAndPrepareMutation(cpMutation, replay, cpFamilyMap, now); // Acquire row locks. If not, the whole batch will fail. - acquiredRowLocks.add(getRowLockInternal(cpMutation.getRow(), true)); + acquiredRowLocks[j] = getRowLockInternal(cpMutation.getRow(), true); if (cpMutation.getDurability() == Durability.SKIP_WAL) { recordMutationWithoutWal(cpFamilyMap); @@ -5271,12 +5270,13 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi } @Override - public void releaseRowLocks(List rowLocks) { + public void releaseRowLocks(RowLock[] rowLocks) { if (rowLocks != null) { - for (int i = 0; i < rowLocks.size(); i++) { - rowLocks.get(i).release(); + for (int i = 0; i < rowLocks.length; i++) { + if (rowLocks[i] != null) + rowLocks[i].release(); + rowLocks[i] = null; } - rowLocks.clear(); } } @@ -6976,7 +6976,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi } boolean locked; - List acquiredRowLocks; + RowLock[] acquiredRowLocks; long addedSize = 0; List mutations = new ArrayList(); Collection rowsToLock = processor.getRowsToLock(); @@ -6985,14 +6985,16 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi WriteEntry writeEntry = null; try { // STEP 2. Acquire the row lock(s) - acquiredRowLocks = new ArrayList(rowsToLock.size()); + acquiredRowLocks = new RowLock[rowsToLock.size()]; + int i = 0; for (byte[] row : rowsToLock) { // Attempt to lock all involved rows, throw if any lock times out // use a writer lock for mixed reads and writes - acquiredRowLocks.add(getRowLockInternal(row, false)); + acquiredRowLocks[i] = getRowLockInternal(row, false); + i++; } // STEP 3. Region lock - lock(this.updatesLock.readLock(), acquiredRowLocks.size() == 0 ? 1 : acquiredRowLocks.size()); + lock(this.updatesLock.readLock(), acquiredRowLocks.length == 0 ? 1 : acquiredRowLocks.length); locked = true; boolean success = false; long now = EnvironmentEdgeManager.currentTime(); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/Region.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/Region.java index efd68b8..17982e4 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/Region.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/Region.java @@ -293,9 +293,9 @@ public interface Region extends ConfigurationObserver { RowLock getRowLock(byte[] row, boolean waitForLock) throws IOException; /** - * If the given list of row locks is not null, releases all locks. + * If the given array of row locks is not null, releases all locks. */ - void releaseRowLocks(List rowLocks); + void releaseRowLocks(RowLock[] rowLocks); /////////////////////////////////////////////////////////////////////////// // Region operations