You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ji...@apache.org on 2008/06/28 04:32:28 UTC

svn commit: r672456 - in /hadoop/hbase/trunk: CHANGES.txt src/java/org/apache/hadoop/hbase/regionserver/HStore.java

Author: jimk
Date: Fri Jun 27 19:32:28 2008
New Revision: 672456

URL: http://svn.apache.org/viewvc?rev=672456&view=rev
Log:
HBASE-716   TestGet2.testGetClosestBefore fails with hadoop-0.17.1

Modified:
    hadoop/hbase/trunk/CHANGES.txt
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/HStore.java

Modified: hadoop/hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/CHANGES.txt?rev=672456&r1=672455&r2=672456&view=diff
==============================================================================
--- hadoop/hbase/trunk/CHANGES.txt (original)
+++ hadoop/hbase/trunk/CHANGES.txt Fri Jun 27 19:32:28 2008
@@ -72,6 +72,7 @@
                before rather than after its parent in .META.
    HBASE-714   Showing bytes in log when should be string (2)
    HBASE-627   Disable table doesn't work reliably
+   HBASE-716   TestGet2.testGetClosestBefore fails with hadoop-0.17.1
    
    
   IMPROVEMENTS

Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/HStore.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/HStore.java?rev=672456&r1=672455&r2=672456&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/HStore.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/HStore.java Fri Jun 27 19:32:28 2008
@@ -1544,7 +1544,6 @@
   private void rowAtOrBeforeFromMapFile(MapFile.Reader map, final byte [] row, 
     SortedMap<HStoreKey, Long> candidateKeys)
   throws IOException {
-    HStoreKey searchKey = null;
     ImmutableBytesWritable readval = new ImmutableBytesWritable();
     HStoreKey readkey = new HStoreKey();
 
@@ -1585,52 +1584,72 @@
       return;
     }
     
-    // seek to the exact row, or the one that would be immediately before it
-    readkey = (HStoreKey)map.getClosest(searchKey, readval, true);
-  
-    if (readkey == null) {
-      // didn't find anything that would match, so return
-      return;
-    }
-  
-    do {
-      // if we have an exact match on row, and it's not a delete, save this
-      // as a candidate key
-      if (Bytes.equals(readkey.getRow(), row)) {
-        if (!HLogEdit.isDeleted(readval.get())) {
-          if (ttl == HConstants.FOREVER || 
+    HStoreKey deletedOrExpiredRow = null;
+    boolean foundCandidate = false;
+    while (!foundCandidate) {
+      // seek to the exact row, or the one that would be immediately before it
+      readkey = (HStoreKey)map.getClosest(searchKey, readval, true);
+
+      if (readkey == null) {
+        // didn't find anything that would match, so return
+        return;
+      }
+
+      do {
+        // if we have an exact match on row, and it's not a delete, save this
+        // as a candidate key
+        if (Bytes.equals(readkey.getRow(), row)) {
+          if (!HLogEdit.isDeleted(readval.get())) {
+            if (ttl == HConstants.FOREVER || 
                 now < readkey.getTimestamp() + ttl) {
-            candidateKeys.put(stripTimestamp(readkey), 
-              new Long(readkey.getTimestamp()));
-          } else {
+              candidateKeys.put(stripTimestamp(readkey), 
+                  new Long(readkey.getTimestamp()));
+              foundCandidate = true;
+              continue;
+            }
             if (LOG.isDebugEnabled()) {
               LOG.debug("rowAtOrBeforeFromMapFile:" + readkey +
-                ": expired, skipped");
+              ": expired, skipped");
             }
           }
-        }
-      } else if (Bytes.compareTo(readkey.getRow(), row) > 0 ) {
-        // if the row key we just read is beyond the key we're searching for,
-        // then we're done. return.
-        return;
-      } else {
-        // so, the row key doesn't match, but we haven't gone past the row
-        // we're seeking yet, so this row is a candidate for closest
-        // (assuming that it isn't a delete).
-        if (!HLogEdit.isDeleted(readval.get())) {
-          if (ttl == HConstants.FOREVER || 
-                  now < readkey.getTimestamp() + ttl) {
-            candidateKeys.put(stripTimestamp(readkey), 
-              new Long(readkey.getTimestamp()));
-          } else {
+          deletedOrExpiredRow = stripTimestamp(readkey);
+        } else if (Bytes.compareTo(readkey.getRow(), row) > 0 ) {
+          // if the row key we just read is beyond the key we're searching for,
+          // then we're done. return.
+          break;
+        } else {
+          // so, the row key doesn't match, but we haven't gone past the row
+          // we're seeking yet, so this row is a candidate for closest
+          // (assuming that it isn't a delete).
+          if (!HLogEdit.isDeleted(readval.get())) {
+            if (ttl == HConstants.FOREVER || 
+                now < readkey.getTimestamp() + ttl) {
+              candidateKeys.put(stripTimestamp(readkey), 
+                  new Long(readkey.getTimestamp()));
+              foundCandidate = true;
+              continue;
+            }
             if (LOG.isDebugEnabled()) {
               LOG.debug("rowAtOrBeforeFromMapFile:" + readkey +
-                ": expired, skipped");
+              ": expired, skipped");
             }
           }
-        }
-      }        
-    } while(map.next(readkey, readval));
+          deletedOrExpiredRow = stripTimestamp(readkey);
+        }        
+      } while(map.next(readkey, readval));
+      
+      // If we get here and have no candidates but we did find a deleted or
+      // expired candidate, we need to look at the key before that
+      
+      if (!foundCandidate && deletedOrExpiredRow != null) {
+        searchKey = deletedOrExpiredRow;
+        deletedOrExpiredRow = null;
+        
+      } else {
+        // No candidates and no deleted or expired candidates. Give up.
+        break;
+      }
+    }
   
     // arriving here just means that we consumed the whole rest of the map
     // without going "past" the key we're searching for. we can just fall