diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ReversedStoreScanner.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ReversedStoreScanner.java index 7bd580d..daaf17a 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ReversedStoreScanner.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ReversedStoreScanner.java @@ -122,24 +122,12 @@ class ReversedStoreScanner extends StoreScanner implements KeyValueScanner { @Override public boolean seekToPreviousRow(KeyValue key) throws IOException { - lock.lock(); - try { - checkReseek(); return this.heap.seekToPreviousRow(key); - } finally { - lock.unlock(); - } } @Override public boolean backwardSeek(KeyValue key) throws IOException { - lock.lock(); - try { - checkReseek(); return this.heap.backwardSeek(key); - } finally { - lock.unlock(); - } } } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java index fc034ed..4546548 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java @@ -101,7 +101,7 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner // A flag whether use pread for scan private boolean scanUsePread = false; - protected ReentrantLock lock = new ReentrantLock(); + protected CountDownLatch latch = new CountDownLatch(1); private final long readPt; @@ -381,15 +381,10 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner @Override public KeyValue peek() { - lock.lock(); - try { if (this.heap == null) { return this.lastTop; } return this.heap.peek(); - } finally { - lock.unlock(); - } } @Override @@ -400,8 +395,6 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner @Override public void close() { - lock.lock(); - try { if (this.closing) return; this.closing = true; // under test, we dont have a this.store @@ -411,21 +404,14 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner this.heap.close(); this.heap = null; // CLOSED! this.lastTop = null; // If both are null, we are closed. - } finally { - lock.unlock(); - } + + latch.countDown(); } @Override public boolean seek(KeyValue key) throws IOException { - lock.lock(); - try { // reset matcher state, in case that underlying store changed - checkReseek(); return this.heap.seek(key); - } finally { - lock.unlock(); - } } /** @@ -436,12 +422,6 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner */ @Override public boolean next(List outResult, int limit) throws IOException { - lock.lock(); - try { - if (checkReseek()) { - return true; - } - // if the heap was left null, then the scanners had previously run out anyways, close and // return. if (this.heap == null) { @@ -570,9 +550,6 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner // No more keys close(); return false; - } finally { - lock.unlock(); - } } /* @@ -615,51 +592,11 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner // Implementation of ChangedReadersObserver @Override public void updateReaders() throws IOException { - lock.lock(); try { - if (this.closing) return; - - // All public synchronized API calls will call 'checkReseek' which will cause - // the scanner stack to reseek if this.heap==null && this.lastTop != null. - // But if two calls to updateReaders() happen without a 'next' or 'peek' then we - // will end up calling this.peek() which would cause a reseek in the middle of a updateReaders - // which is NOT what we want, not to mention could cause an NPE. So we early out here. - if (this.heap == null) return; - - // this could be null. - this.lastTop = this.peek(); - - //DebugPrint.println("SS updateReaders, topKey = " + lastTop); - - // close scanners to old obsolete Store files - this.heap.close(); // bubble thru and close all scanners. - this.heap = null; // the re-seeks could be slow (access HDFS) free up memory ASAP - - // Let the next() call handle re-creating and seeking - } finally { - lock.unlock(); - } - } - - /** - * @return true if top of heap has changed (and KeyValueHeap has to try the - * next KV) - * @throws IOException - */ - protected boolean checkReseek() throws IOException { - if (this.heap == null && this.lastTop != null) { - resetScannerStack(this.lastTop); - if (this.heap.peek() == null - || store.getComparator().compareRows(this.lastTop, this.heap.peek()) != 0) { - LOG.debug("Storescanner.peek() is changed where before = " - + this.lastTop.toString() + ",and after = " + this.heap.peek()); - this.lastTop = null; - return true; - } - this.lastTop = null; // gone! + latch.await(); + } catch (InterruptedException x) { + throw new IOException(x); } - // else dont need to reseek - return false; } protected void resetScannerStack(KeyValue lastTopKey) throws IOException { @@ -728,19 +665,10 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner @Override public boolean reseek(KeyValue kv) throws IOException { - lock.lock(); - try { - //Heap will not be null, if this is called from next() which. - //If called from RegionScanner.reseek(...) make sure the scanner - //stack is reset if needed. - checkReseek(); if (explicitColumnQuery && lazySeekEnabledGlobally) { return heap.requestSeek(kv, true, useRowColBloom); } return heap.reseek(kv); - } finally { - lock.unlock(); - } } @Override