HBase
  1. HBase
  2. HBASE-3725

HBase increments from old value after delete and write to disk

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 0.90.1
    • Fix Version/s: 0.92.3
    • Component/s: io, regionserver
    • Labels:
      None

      Description

      Deleted row values are sometimes used for starting points on new increments.

      To reproduce:
      Create a row "r". Set column "x" to some default value.
      Force hbase to write that value to the file system (such as restarting the cluster).
      Delete the row.
      Call table.incrementColumnValue with "some_value"
      Get the row.
      The returned value in the column was incremented from the old value before the row was deleted instead of being initialized to "some_value".

      Code to reproduce:

      
      import java.io.IOException;
      import org.apache.hadoop.conf.Configuration;
      import org.apache.hadoop.hbase.HBaseConfiguration;
      import org.apache.hadoop.hbase.HColumnDescriptor;
      import org.apache.hadoop.hbase.HTableDescriptor;
      import org.apache.hadoop.hbase.client.Delete;
      import org.apache.hadoop.hbase.client.Get;
      import org.apache.hadoop.hbase.client.HBaseAdmin;
      import org.apache.hadoop.hbase.client.HTableInterface;
      import org.apache.hadoop.hbase.client.HTablePool;
      import org.apache.hadoop.hbase.client.Increment;
      import org.apache.hadoop.hbase.client.Result;
      import org.apache.hadoop.hbase.util.Bytes;
      
      public class HBaseTestIncrement
      {
      	static String tableName  = "testIncrement";
      
      	static byte[] infoCF = Bytes.toBytes("info");
      
      	static byte[] rowKey = Bytes.toBytes("test-rowKey");
      
      	static byte[] newInc = Bytes.toBytes("new");
      	static byte[] oldInc = Bytes.toBytes("old");
      
      	/**
      	 * This code reproduces a bug with increment column values in hbase
      	 * Usage: First run part one by passing '1' as the first arg
      	 *        Then restart the hbase cluster so it writes everything to disk
      	 *	  Run part two by passing '2' as the first arg
      	 *
      	 * This will result in the old deleted data being found and used for the increment calls
      	 *
      	 * @param args
      	 * @throws IOException
      	 */
      	public static void main(String[] args) throws IOException
      	{
      		if("1".equals(args[0]))
      			partOne();
      		if("2".equals(args[0]))
      			partTwo();
      		if ("both".equals(args[0]))
      		{
      			partOne();
      			partTwo();
      		}
      	}
      
      	/**
      	 * Creates a table and increments a column value 10 times by 10 each time.
      	 * Results in a value of 100 for the column
      	 *
      	 * @throws IOException
      	 */
      	static void partOne()throws IOException
      	{
      
      		Configuration conf = HBaseConfiguration.create();
      
      
      		HBaseAdmin admin = new HBaseAdmin(conf);
      		HTableDescriptor tableDesc = new HTableDescriptor(tableName);
      		tableDesc.addFamily(new HColumnDescriptor(infoCF));
      		if(admin.tableExists(tableName))
      		{
      			admin.disableTable(tableName);
      			admin.deleteTable(tableName);
      		}
      		admin.createTable(tableDesc);
      
      		HTablePool pool = new HTablePool(conf, Integer.MAX_VALUE);
      		HTableInterface table = pool.getTable(Bytes.toBytes(tableName));
      
      		//Increment unitialized column
      		for (int j = 0; j < 10; j++)
      		{
      			table.incrementColumnValue(rowKey, infoCF, oldInc, (long)10);
      			Increment inc = new Increment(rowKey);
      			inc.addColumn(infoCF, newInc, (long)10);
      			table.increment(inc);
      		}
      
      		Get get = new Get(rowKey);
      		Result r = table.get(get);
      		System.out.println("initial values: new " + Bytes.toLong(r.getValue(infoCF, newInc)) + " old " + Bytes.toLong(r.getValue(infoCF, oldInc)));
      
      	}
      
      	/**
      	 * First deletes the data then increments the column 10 times by 1 each time
      	 *
      	 * Should result in a value of 10 but it doesn't, it results in a values of 110
      	 *
      	 * @throws IOException
      	 */
      	static void partTwo()throws IOException
      	{
      		Configuration conf = HBaseConfiguration.create();
      
      		HTablePool pool = new HTablePool(conf, Integer.MAX_VALUE);
      		HTableInterface table = pool.getTable(Bytes.toBytes(tableName));
      		
      		Delete delete = new Delete(rowKey);
      		table.delete(delete);
      
      
      		//Increment columns
      		for (int j = 0; j < 10; j++)
      		{
      			table.incrementColumnValue(rowKey, infoCF, oldInc, (long)1);
      			Increment inc = new Increment(rowKey);
      			inc.addColumn(infoCF, newInc, (long)1);
      			table.increment(inc);
      		}
      
      
      		Get get = new Get(rowKey);
      		Result r = table.get(get);
      		System.out.println("after delete values: new " + Bytes.toLong(r.getValue(infoCF, newInc)) + " old " + Bytes.toLong(r.getValue(infoCF, oldInc)));
      
      	}
      }
      
      1. HBASE-3725.patch
        2 kB
        Nathaniel Cook
      2. HBASE-3725-0.92-V1.patch
        7 kB
        ShiXing
      3. HBASE-3725-0.92-V2.patch
        7 kB
        ShiXing
      4. HBASE-3725-0.92-V3.patch
        7 kB
        ShiXing
      5. HBASE-3725-0.92-V4.patch
        7 kB
        ShiXing
      6. HBASE-3725-0.92-V5.patch
        4 kB
        ShiXing
      7. HBASE-3725-0.92-V6.patch
        5 kB
        ShiXing
      8. HBASE-3725-Test-v1.patch
        2 kB
        Jonathan Gray
      9. HBASE-3725-v3.patch
        4 kB
        Jonathan Gray

        Activity

        Nathaniel Cook created issue -
        Nathaniel Cook made changes -
        Field Original Value New Value
        Attachment HBASE-3725.patch [ 12475440 ]
        Jonathan Gray made changes -
        Attachment HBASE-3725-Test-v1.patch [ 12477669 ]
        Jonathan Gray made changes -
        Attachment HBASE-3725-v3.patch [ 12477671 ]
        Jonathan Gray made changes -
        Status Open [ 1 ] Patch Available [ 10002 ]
        Assignee Jonathan Gray [ streamy ]
        stack made changes -
        Fix Version/s 0.92.0 [ 12314223 ]
        stack made changes -
        Fix Version/s 0.92.0 [ 12314223 ]
        ShiXing made changes -
        Attachment HBASE-3725-0.92-V1.patch [ 12533934 ]
        ShiXing made changes -
        Attachment HBASE-3725-0.92-V2.patch [ 12533939 ]
        ShiXing made changes -
        Attachment HBASE-3725-0.92-V3.patch [ 12533945 ]
        ShiXing made changes -
        Attachment HBASE-3725-0.92-V4.patch [ 12535627 ]
        ShiXing made changes -
        Attachment HBASE-3725-0.92-V5.patch [ 12537128 ]
        Ted Yu made changes -
        Status Patch Available [ 10002 ] Open [ 1 ]
        ShiXing made changes -
        Attachment HBASE-3725-0.92-V6.patch [ 12537305 ]
        Ted Yu made changes -
        Assignee Jonathan Gray [ streamy ] ShiXing [ xingshi ]
        Ted Yu made changes -
        Fix Version/s 0.92.2 [ 12319888 ]
        Ted Yu made changes -
        Fix Version/s 0.92.3 [ 12321692 ]
        Fix Version/s 0.92.2 [ 12319888 ]

          People

          • Assignee:
            ShiXing
            Reporter:
            Nathaniel Cook
          • Votes:
            3 Vote for this issue
            Watchers:
            15 Start watching this issue

            Dates

            • Created:
              Updated:

              Development