hbase-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tatsuya Kawano <tatsuy...@snowcocoa.info>
Subject Unique row ID constraint
Date Wed, 28 Apr 2010 14:40:26 GMT

I'd like to implement unique row ID constraint (like the primary key
constraint in RDBMS) in my application framework.

Here is a code fragment from my current implementation (HBase
0.20.4rc) written in Scala. It works as expected, but is there any
better (shorter) way to do this like checkAndPut()?  I'd like to pass
a single Put object to my function (method) rather than passing rowId,
family, qualifier and value separately. I can't do this now because I
have to give the rowLock object when I instantiate the Put.

def insert(table: HTable, rowId: Array[Byte], family: Array[Byte],
                               qualifier: Array[Byte], value:
Array[Byte]): Unit = {

    val get = new Get(rowId)

    val lock = table.lockRow(rowId) // will expire in one minute
    try {
      if (table.exists(get)) {
        throw new DuplicateRowException("Tried to insert a duplicate row: "
                + Bytes.toString(rowId))

      } else {
        val put = new Put(rowId, lock)
        put.add(family, qualifier, value)


    } finally {



河野 達也
Tatsuya Kawano (Mr.)
Tokyo, Japan

twitter: http://twitter.com/tatsuya6502

View raw message