如何通过thrift2 cpp api设置hbase cell ttl(生存时间)?

yxyvkwin  于 2021-06-07  发布在  Hbase
关注(0)|答案(0)|浏览(218)

我试图通过Thrift2API(在cpp中生成的代码)和ttl在hbase中放入一行。正如官方的java测试代码所示,attribute对象将有如下帮助

long ttlTimeMs = 2000L;

// the _ttl attribute is a number of ms ttl for key values in this put.
attributes.put(wrap(Bytes.toBytes("_ttl")), wrap(Bytes.toBytes(ttlTimeMs)));
// Attach the attributes
put.setAttributes(attributes);
// Send it.
handler.put(table, put);

但是,当我在cpp中执行相同的操作时,代码如下。它不起作用。

std::map<std::string, std::string> val;
val["_ttl"] = "30000000"; // 30000 000ms roughly equal 9 hour
tput.__set_attributes(val);

client_->put(tableName, tput);

24小时后该行仍然存在

hbase(main):019:0> scan "shonejiang1026", {VERSIONS => 99}
ROW               COLUMN+CELL                                                                                          
 10010            column=cf1:age, timestamp=1606124973760, value=1998                                                  
 damao_ttl_17:48  column=cf1:name, timestamp=1605779312661, value=london 
2 row(s) in 0.0300 seconds

我检查了hbase日志,这一行的ttl属性是一个比我设置的大得多的长整数。

Found row: keyvalues={damao_ttl_17:48/cf1:name/1605779312661/Put/vlen=6/seqid=0}
    Cell: damao_ttl_17:48/cf1:name/1605779312661/Put/vlen=6/seqid=0
    tag: 8 10000000
cell ts = 1605779312661, ttl = 3544385890265608240

那么,用ttl向hbase添加行的正确方法是什么呢?
ps:这是Thrift2API,ThriftAPI不适合这个问题!

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题