5

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!

4
  • 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. May 31, 2012 at 10:11
  • HBase 0.92.1. There is only one version of that row (I've set max versions number in get and checked).
    – user898722
    May 31, 2012 at 10:46
  • 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. Jun 1, 2012 at 11:26
  • {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
    Jun 1, 2012 at 15:16

1 Answer 1

8

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.

7
  • In official hbase book hbase.apache.org/book/versions.html it is said "Doing a put always creates a new version of a cell, at a certain timestamp. By default the system uses the server's currentTimeMillis, but you can specify the version (= the long integer) yourself, on a per-column level. This means you could assign a time in the past or the future, or use the long value for non-time purposes."
    – user898722
    May 31, 2012 at 16:11
  • Yes, but the version with maximum timestamp will be shown if you use get(), unless you use setMaxVersions() to get the 'older' (i.e, with lower timestamp) versions. So if there already exist the same cell with timestamp > 12345678, then that one will be shown.
    – Hari Menon
    May 31, 2012 at 17:11
  • I've already tried setting max versions number to 10 - there is only one version of this row.
    – user898722
    May 31, 2012 at 22:43
  • What is the timestamp of the version that you get?
    – Hari Menon
    Jun 1, 2012 at 4:05
  • And how are you "getting" the row? Is through the Java API or through HBase Shell? In HBase Shell you should specify many versions, like "hbase> get 't1', 'r1', {VERSIONS => 100}". In the Java API, the Result object from HTable.get(Get) has two methods: getColumnLatest and getColumn. The latter is a list of versions. Jun 1, 2012 at 11:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.