You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2009/09/15 22:22:02 UTC
svn commit: r815463 - in /hadoop/hbase/trunk: ./
src/contrib/transactional/src/java/org/apache/hadoop/hbase/regionserver/tableindexed/
src/contrib/transactional/src/test/org/apache/hadoop/hbase/client/tableindexed/
Author: stack
Date: Tue Sep 15 20:22:02 2009
New Revision: 815463
URL: http://svn.apache.org/viewvc?rev=815463&view=rev
Log:
HBASE-1840 RowLock fails when used with IndexTable
Modified:
hadoop/hbase/trunk/CHANGES.txt
hadoop/hbase/trunk/src/contrib/transactional/src/java/org/apache/hadoop/hbase/regionserver/tableindexed/IndexedRegion.java
hadoop/hbase/trunk/src/contrib/transactional/src/test/org/apache/hadoop/hbase/client/tableindexed/TestIndexedTable.java
Modified: hadoop/hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/CHANGES.txt?rev=815463&r1=815462&r2=815463&view=diff
==============================================================================
--- hadoop/hbase/trunk/CHANGES.txt (original)
+++ hadoop/hbase/trunk/CHANGES.txt Tue Sep 15 20:22:02 2009
@@ -25,6 +25,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 (Keith Thomas via Stack)
IMPROVEMENTS
HBASE-1760 Cleanup TODOs in HTable
Modified: hadoop/hbase/trunk/src/contrib/transactional/src/java/org/apache/hadoop/hbase/regionserver/tableindexed/IndexedRegion.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/contrib/transactional/src/java/org/apache/hadoop/hbase/regionserver/tableindexed/IndexedRegion.java?rev=815463&r1=815462&r2=815463&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/contrib/transactional/src/java/org/apache/hadoop/hbase/regionserver/tableindexed/IndexedRegion.java (original)
+++ hadoop/hbase/trunk/src/contrib/transactional/src/java/org/apache/hadoop/hbase/regionserver/tableindexed/IndexedRegion.java Tue Sep 15 20:22:02 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/trunk/src/contrib/transactional/src/test/org/apache/hadoop/hbase/client/tableindexed/TestIndexedTable.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/contrib/transactional/src/test/org/apache/hadoop/hbase/client/tableindexed/TestIndexedTable.java?rev=815463&r1=815462&r2=815463&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/contrib/transactional/src/test/org/apache/hadoop/hbase/client/tableindexed/TestIndexedTable.java (original)
+++ hadoop/hbase/trunk/src/contrib/transactional/src/test/org/apache/hadoop/hbase/client/tableindexed/TestIndexedTable.java Tue Sep 15 20:22:02 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);
+ }
}