CassandraのTTL tombstonesについて
TTLの有効期間が終了すると、TTL tombstoneとなる。
1.セルへのTTL設定
before
cqlsh:sitest01> select * from test_tomb where pkey1 = 'rei' and pkey2 =1;
pkey1 | pkey2 | skey1 | v1
-------+-------+-------+---------------------
rei | 1 | 1 | Bombay
rei | 1 | 2 | Brazilian Shorthair
(2 rows)
{
"partition" : {
"key" : [ "rei", "1" ],
"position" : 291
},
"rows" : [
{
"type" : "row",
"position" : 337,
"clustering" : [ 1 ],
"liveness_info" : { "tstamp" : "2019-12-15T13:15:14.076960Z" },
"cells" : [
{ "name" : "v1", "value" : "Bombay" }
]
},
{
"type" : "row",
"position" : 337,
"clustering" : [ 2 ],
"liveness_info" : { "tstamp" : "2019-12-15T13:15:14.080867Z" },
"cells" : [
{ "name" : "v1", "value" : "Brazilian Shorthair" }
]
}
]
}
update
特定セルをTTL付きで更新
update test_tomb using TTL 300 set v1 = 'Chartreux' where pkey1 = 'rei' and pkey2 = 1 and skey1 = 2;
TTL有効期間経過前
・Estimated tombstone drop timesには5分後=1576416240 ( 2019/12/15 22:24:00 )が設定される
cqlsh:sitest01> select * from test_tomb where pkey1 = 'rei' and pkey2 =1;
pkey1 | pkey2 | skey1 | v1
-------+-------+-------+---------------------
rei | 1 | 1 | null
rei | 1 | 2 | Brazilian Shorthair
(2 rows)
{
"partition" : {
"key" : [ "rei", "1" ],
"position" : 291
},
"rows" : [
{
"type" : "row",
"position" : 337,
"clustering" : [ 1 ],
"liveness_info" : { "tstamp" : "2019-12-15T13:15:14.076960Z" },
"cells" : [
{ "name" : "v1", "value" : "Bombay" }
]
},
{
"type" : "row",
"position" : 337,
"clustering" : [ 2 ],
"liveness_info" : { "tstamp" : "2019-12-15T13:15:14.080867Z" },
"cells" : [
{ "name" : "v1", "value" : "Chartreux", "tstamp" : "2019-12-15T13:18:49.691480Z", "ttl" : 300, "expires_at" : "2019-12-15T13:23:49Z", "expired" : false }
]
}
]
}
Estimated droppable tombstones: 0.0
SSTable Level: 0
Repaired at: 0
Replay positions covered: {ReplayPosition(segmentId=1576361531027, position=3814)=ReplayPosition(segmentId=1576361531027, position=422532)}
Estimated tombstone drop times:
1576416240: 1
TTL有効期間経過後
・selectで当該セルがnull表示となる
・sstabledumpでは、"expired" : trueとなり、sstablemetadataの率は上昇
cqlsh:sitest01> select * from test_tomb where pkey1 = 'rei' and pkey2 =1;
pkey1 | pkey2 | skey1 | v1
-------+-------+-------+--------
rei | 1 | 1 | Bombay
rei | 1 | 2 | null
(2 rows)
{
"partition" : {
"key" : [ "rei", "1" ],
"position" : 291
},
"rows" : [
{
"type" : "row",
"position" : 337,
"clustering" : [ 1 ],
"liveness_info" : { "tstamp" : "2019-12-15T13:15:14.076960Z" },
"cells" : [
{ "name" : "v1", "value" : "Bombay" }
]
},
{
"type" : "row",
"position" : 337,
"clustering" : [ 2 ],
"liveness_info" : { "tstamp" : "2019-12-15T13:15:14.080867Z" },
"cells" : [
{ "name" : "v1", "value" : "Chartreux", "tstamp" : "2019-12-15T13:18:49.691480Z", "ttl" : 300, "expires_at" : "2019-12-15T13:23:49Z", "expired" : true }
]
}
]
}
Estimated droppable tombstones: 0.037037037037037035
SSTable Level: 0
Repaired at: 0
Replay positions covered: {ReplayPosition(segmentId=1576361531027, position=3814)=ReplayPosition(segmentId=1576361531027, position=422532)}
Estimated tombstone drop times:
1576416240: 1
2.TTL設定付き行のinsert
insert
TTL付きで行を挿入
insert into test_tomb ( pkey1, pkey2, skey1, v1 ) values ( 'rei',5,1,'Maine Coon' ) USING TTL 300;
TTL有効期間経過前
・Estimated tombstone drop timesには5分後=1576415400 ( 2019/12/15 22:10:00 )が設定される
cqlsh:sitest01> select * from test_tomb where pkey1 = 'rei' and pkey2 = 5;
pkey1 | pkey2 | skey1 | v1
-------+-------+-------+------------
rei | 5 | 1 | Maine Coon
(1 rows)
{
"partition" : {
"key" : [ "rei", "5" ],
"position" : 765
},
"rows" : [
{
"type" : "row",
"position" : 819,
"clustering" : [ 1 ],
"liveness_info" : { "tstamp" : "2019-12-15T13:04:04.352410Z", "ttl" : 300, "expires_at" : "2019-12-15T13:09:04Z", "expired" : false },
"cells" : [
{ "name" : "v1", "value" : "Maine Coon" }
]
}
]
}
Estimated droppable tombstones: 0.0
SSTable Level: 0
Repaired at: 0
Replay positions covered: {ReplayPosition(segmentId=1576361531026, position=2382)=ReplayPosition(segmentId=1576361531026, position=421734)}
Estimated tombstone drop times:
1576415400: 2
TTL有効期間経過後
・selectで当該行が非表示となる
・sstabledumpでは、"expired" : trueとなり、sstablemetadataの率は上昇
cqlsh:sitest01> select * from test_tomb where pkey1 = 'rei' and pkey2 = 5;
pkey1 | pkey2 | skey1 | v1
-------+-------+-------+----
(0 rows)
{
"partition" : {
"key" : [ "rei", "5" ],
"position" : 765
},
"rows" : [
{
"type" : "row",
"position" : 819,
"clustering" : [ 1 ],
"liveness_info" : { "tstamp" : "2019-12-15T13:04:04.352410Z", "ttl" : 300, "expires_at" : "2019-12-15T13:09:04Z", "expired" : true },
"cells" : [
{ "name" : "v1", "value" : "Maine Coon" }
]
}
]
}
cqlsh:sitest01>
Estimated droppable tombstones: 0.06666666666666667
SSTable Level: 0
Repaired at: 0
Replay positions covered: {ReplayPosition(segmentId=1576361531026, position=2382)=ReplayPosition(segmentId=1576361531026, position=421734)}
Estimated tombstone drop times:
1576415400: 2