5
votes

I'm having problems setting row timestamp using java api.

When I'm trying to add a timestamp value to put constructor (or into put.add()) nothing happens and after reading rows from table I get system provided timestamps.

public static boolean addRecord(String tableName, String rowKey,
    String family, String qualifier, Object value)
{
    try {
        HTable table = new HTable(conf, tableName);
        Put put = new Put(Bytes.toBytes(rowKey), 12345678l);
        put.add(Bytes.toBytes(family), Bytes.toBytes(qualifier), Bytes.toBytes(value.toString()));
        table.put(put);
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

HBase 0.92.1 running in standalone mode.

Thanks in advance for any help!

1
Can you provide more information? What version of HBase are you using? Are there concurrent writes to that row? It might be that version 12345678L gets successfully stored, but you have system provided timestamps that are newer than 12345678L. Try getting all versions of that row and checking whether 12345678L is there. - André Staltz
HBase 0.92.1. There is only one version of that row (I've set max versions number in get and checked). - user898722
Could you paste the output of "hbase> describe 't1'" (HBase Shell) for your table t1 (whatever name it has)? This will give us information about the column families you are trying to write to. There might be issues such as Time To Live for the families. Also try writing to an empty row, you should definitely get the timestamp you want, since there should be no other version. - André Staltz
{NAME => 'TestTableName', FAMILIES => [{NAME => 'Family1', BLOOMFILTER => 'NONE', REPLICATION_SCOPE => '0', VERSIONS => '3', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => '2147483647', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}, {NAME => 'Family2', BLOOMFILTER => 'NONE', REPLIC ATION_SCOPE => '0', VERSIONS => '3', COMPRESSION =>'NONE', MIN_VERSIONS => '0', TTL => '2147483647', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}]} - user898722

1 Answers

8
votes

Most likely, you already have rows in the table that have timestamp > 12345678l. To confirm that this is not the case, try it with a very large value for timestamp, say Long.MAX_VALUE.

If it is indeed the case, you can simply delete the older versions. Then this entry will show up.