hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r815466 - in /hadoop/hbase/branches/0.20: ./ src/contrib/transactional/src/java/org/apache/hadoop/hbase/regionserver/tableindexed/ src/contrib/transactional/src/test/org/apache/hadoop/hbase/client/tableindexed/
Date Tue, 15 Sep 2009 20:23:06 GMT
Author: stack
Date: Tue Sep 15 20:23:05 2009
New Revision: 815466

URL: http://svn.apache.org/viewvc?rev=815466&view=rev
Log:
HBASE-1840 RowLock fails when used with IndexTable

Modified:
    hadoop/hbase/branches/0.20/CHANGES.txt
    hadoop/hbase/branches/0.20/src/contrib/transactional/src/java/org/apache/hadoop/hbase/regionserver/tableindexed/IndexedRegion.java
    hadoop/hbase/branches/0.20/src/contrib/transactional/src/test/org/apache/hadoop/hbase/client/tableindexed/TestIndexedTable.java

Modified: hadoop/hbase/branches/0.20/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/CHANGES.txt?rev=815466&r1=815465&r2=815466&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/CHANGES.txt (original)
+++ hadoop/hbase/branches/0.20/CHANGES.txt Tue Sep 15 20:23:05 2009
@@ -13,6 +13,7 @@
    HBASE-1838  [javadoc] Add javadoc to Delete explaining behavior when no
                timestamp provided
    HBASE-1821  Filtering by SingleColumnValueFilter bug
+   HBASE-1840  RowLock fails when used with IndexTable
 
   IMPROVEMENTS
    HBASE-1819  Update to 0.20.1 hadoop and zk 3.2.1

Modified: hadoop/hbase/branches/0.20/src/contrib/transactional/src/java/org/apache/hadoop/hbase/regionserver/tableindexed/IndexedRegion.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/contrib/transactional/src/java/org/apache/hadoop/hbase/regionserver/tableindexed/IndexedRegion.java?rev=815466&r1=815465&r2=815466&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/src/contrib/transactional/src/java/org/apache/hadoop/hbase/regionserver/tableindexed/IndexedRegion.java
(original)
+++ hadoop/hbase/branches/0.20/src/contrib/transactional/src/java/org/apache/hadoop/hbase/regionserver/tableindexed/IndexedRegion.java
Tue Sep 15 20:23:05 2009
@@ -93,11 +93,11 @@
   @Override
   public void put(Put put, Integer lockId, boolean writeToWAL)
       throws IOException {
-    updateIndexes(put); // Do this first because will want to see the old row
+    updateIndexes(put, lockId); // Do this first because will want to see the old row
     super.put(put, lockId, writeToWAL);
   }
 
-  private void updateIndexes(Put put) throws IOException {
+  private void updateIndexes(Put put, Integer lockId) throws IOException {
     List<IndexSpecification> indexesToUpdate = new LinkedList<IndexSpecification>();
 
     // Find the indexes we need to update
@@ -119,7 +119,7 @@
       oldGet.addColumn(neededCol);  
     }
     
-    Result oldResult = super.get(oldGet, null);
+    Result oldResult = super.get(oldGet, lockId);
     
     // Add the old values to the new if they are not there
     if (oldResult != null && oldResult.raw() != null) {

Modified: hadoop/hbase/branches/0.20/src/contrib/transactional/src/test/org/apache/hadoop/hbase/client/tableindexed/TestIndexedTable.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/contrib/transactional/src/test/org/apache/hadoop/hbase/client/tableindexed/TestIndexedTable.java?rev=815466&r1=815465&r2=815466&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/src/contrib/transactional/src/test/org/apache/hadoop/hbase/client/tableindexed/TestIndexedTable.java
(original)
+++ hadoop/hbase/branches/0.20/src/contrib/transactional/src/test/org/apache/hadoop/hbase/client/tableindexed/TestIndexedTable.java
Tue Sep 15 20:23:05 2009
@@ -34,6 +34,7 @@
 import org.apache.hadoop.hbase.client.Put;
 import org.apache.hadoop.hbase.client.Result;
 import org.apache.hadoop.hbase.client.ResultScanner;
+import org.apache.hadoop.hbase.client.RowLock; 
 import org.apache.hadoop.hbase.regionserver.tableindexed.IndexedRegionServer;
 import org.apache.hadoop.hbase.util.Bytes;
 
@@ -55,6 +56,7 @@
   private IndexedTableAdmin admin;
   private IndexedTable table;
   private Random random = new Random();
+  private HTableDescriptor desc;
 
   /** constructor */
   public TestIndexedTable() {
@@ -68,7 +70,7 @@
   protected void setUp() throws Exception {
     super.setUp();
 
-    HTableDescriptor desc = new HTableDescriptor(TABLE_NAME);
+    desc = new HTableDescriptor(TABLE_NAME);
     desc.addFamily(new HColumnDescriptor(FAMILY_COLON));
 
     IndexedTableDescriptor indexDesc = new IndexedTableDescriptor(desc);
@@ -118,6 +120,68 @@
     Assert.assertEquals(numRowsExpected, numRows);
   }
 
+  private void assertRowUpdated(int updatedRow, int expectedRowValue)
+      throws IndexNotFoundException, IOException {
+    ResultScanner scanner = table.getIndexedScanner(INDEX_COL_A, null, null,
+        null, null, null);
+    byte[] persistedRowValue = null;
+    for (Result rowResult : scanner) {
+      byte[] row = rowResult.getRow();
+      byte[] value = rowResult.getValue(COL_A);
+      if (Bytes.toString(row).equals(Bytes.toString(PerformanceEvaluation.format(updatedRow))))
{        
+        persistedRowValue = value;
+        LOG.info("update found: row [" + Bytes.toString(row)
+          + "] value [" + Bytes.toString(value) + "]");
+      }
+      else
+        LOG.info("updated index scan : row [" + Bytes.toString(row)
+          + "] value [" + Bytes.toString(value) + "]");
+    }
+    scanner.close();
+
+    Assert.assertEquals(Bytes.toString(PerformanceEvaluation.format(expectedRowValue)), 

+                                    Bytes.toString(persistedRowValue));
+  }
+
+  private void updateRow(int row, int newValue) throws IOException {
+      Put update = new Put(PerformanceEvaluation.format(row));
+      byte[] valueA = PerformanceEvaluation.format(newValue);
+      update.add(FAMILY, QUAL_A, valueA);
+      table.put(update);
+      LOG.info("Updated row [" + Bytes.toString(update.getRow()) + "] val: ["
+          + Bytes.toString(valueA) + "]");
+  }
+
+  private void updateLockedRow(int row, int newValue) throws IOException {
+      RowLock lock = table.lockRow(PerformanceEvaluation.format(row));
+      Put update = new Put(PerformanceEvaluation.format(row), lock);
+      byte[] valueA = PerformanceEvaluation.format(newValue);
+      update.add(FAMILY, QUAL_A, valueA);
+      LOG.info("Updating row [" + Bytes.toString(update.getRow()) + "] val: ["
+          + Bytes.toString(valueA) + "]");
+      table.put(update);
+      LOG.info("Updated row [" + Bytes.toString(update.getRow()) + "] val: ["
+          + Bytes.toString(valueA) + "]");
+      table.unlockRow(lock);
+  } 
+
+  private void updateLockedRowNoAutoFlush(int row, int newValue) throws IOException {
+      table.flushCommits();
+      table.setAutoFlush(false);
+      RowLock lock = table.lockRow(PerformanceEvaluation.format(row));
+      Put update = new Put(PerformanceEvaluation.format(row), lock);
+      byte[] valueA = PerformanceEvaluation.format(newValue);
+      update.add(FAMILY, QUAL_A, valueA);
+      LOG.info("Updating row [" + Bytes.toString(update.getRow()) + "] val: ["
+          + Bytes.toString(valueA) + "]");
+      table.put(update);
+      LOG.info("Updated row [" + Bytes.toString(update.getRow()) + "] val: ["
+          + Bytes.toString(valueA) + "]");
+      table.flushCommits();
+      table.close();
+      table = new IndexedTable(conf, desc.getName());
+  } 
+
   public void testMultipleWrites() throws IOException {
     writeInitalRows();
     writeInitalRows(); // Update the rows.
@@ -131,4 +195,28 @@
     
     assertRowsInOrder(NUM_ROWS - 1);    
   }
+
+  public void testRowUpdate() throws IOException {
+    writeInitalRows();
+    int row = NUM_ROWS - 2;
+    int value = MAX_VAL + 111;
+    updateRow(row, value);
+    assertRowUpdated(row, value);
+  }
+
+  public void testLockedRowUpdate() throws IOException {
+    writeInitalRows();
+    int row = NUM_ROWS - 2;
+    int value = MAX_VAL + 111;
+    updateLockedRow(row, value);
+    assertRowUpdated(row, value);
+  } 
+
+  public void testLockedRowUpdateNoAutoFlush() throws IOException {
+    writeInitalRows();
+    int row = NUM_ROWS - 4;
+    int value = MAX_VAL + 2222;
+    updateLockedRowNoAutoFlush(row, value);
+    assertRowUpdated(row, value);
+  } 
 }



Mime
View raw message