You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hbase.apache.org by Tost <nc...@gmail.com> on 2011/01/11 01:52:52 UTC

Hbase transaction mode. recreate row key.

Hello.

I'm testing hbase transaction module. but it's little bit strange.

Can I delete a row all (with all family,columns and key also) ?

This transaction code is

Delete : delete row
Put      : recreate same row key.
commit : ok do it.

but, I couldn't get new row data.

Is there the way recreate row key in transaction mode ?

I have another question.

If I use transaction, is it row locking or table locking ??

======================================================

My transaction class, is written as followed:

public void testTransaction() throws IOException {
// byte[] key0 = Bytes.toBytes("key-29");
byte[] key = Bytes.toBytes("key-30");
getRow(key);
 TransactionManager tran = new TransactionManager(config);
TransactionState state=null;
TransactionalTable table = null;
try{
 // table locking.
state = tran.beginTransaction();
table = new TransactionalTable(config,TABLE);
table.setAutoFlush(false);
 Delete del = new Delete(key); // delete row with all families.
table.delete(state,del);
 Get get = new Get(key);
Result result = table.get(state,get);
log.debug("result={}",result);
 Put p = new Put(key);
p.add(COL_FAMILY_USER_B, ("name").getBytes(), ("macula500").getBytes());
p.add(COL_FAMILY_USER_B, ("age").getBytes(), ("500").getBytes());

table.put(state,p);
 tran.tryCommit(state); // prepare & do commit.
log.debug("transaction test finished.");
}catch(Exception e){
e.printStackTrace();
if(tran!=null) tran.abort(state);
log.debug("transaction commit failed.");
} finally{
if(table!=null) table.close();
}
// getRow(key0);
getRow(key);
}

Thanks.
Tost