0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ComplexColumn tombstones

Last updated at Posted at 2019-12-08

CassandraのComplexColumn tombstonesについて

ComplexColumn tombstoneは、セット、リスト、マップなどのコレクション型の列を新規設置(ないし再設置)するときに生成 .... 削除の処理でなくて、新規設置のときに生成されるので、知らないとちょっと吃驚する。( ただし、frozenで定義する場合は生成されない )

コレクション型のtombstone生成有無整理

ComplexColumn tombstoneの生成を踏まえて、コレクション型の列(set、list、mapなど)を更新するときのtombstone生成有無を整理

(tombstone生成 - リスト型の例) v1がリスト型の列

||CQL例|非frozenの場合|frozenの場合 |
|---|---|---|---|---|
|① 新規設置|insert into test_list ( pkey1, v1 ) values ( 1, [ 'tama', 'kuro', 'shiro' ] );|生成あり|生成しない|
|② 非増分更新(設置し直し)|update test_list set v1 = [ 'hachi', 'goro' ] where pkey1 = 1;|生成あり|生成しない|
|③ 更新(先頭への追加)|update test_list set v1 = [ 'ron' ] + v1 where pkey1 = 1;|生成しない|(操作不可)|
|④ 更新(末尾への追加)|update test_list set v1 = v1 + [ 'tabi' ] where pkey1 = 1;|生成しない|(操作不可)|
|⑤ 更新(特定位置)|update test_list set v1[2] = 'yume' where pkey1 = 1; |生成しない|(操作不可)|
|⑥ 更新(特定値を持つ要素の削除)|update test_list set v1 = v1 - [ 'hachi' ] where pkey1 = 1; |生成あり|(操作不可)|
|⑦ 削除|delete v1 from test_list where pkey1 = 1; |生成あり|生成あり|

① 新規設置

( 非frozenの場合 ) 
新規設置でdeletion_infoがもれなく生成

cqlsh:sitest01> desc test_list;

CREATE TABLE sitest01.test_list (
    pkey1 int PRIMARY KEY,
    v1 list<text>
) WITH bloom_filter_fp_chance = 0.01
  :
 (略)
  :

cqlsh:sitest01> select * from test_list;

 pkey1 | v1
-------+----

cqlsh:sitest01> insert into test_list ( pkey1, v1 ) values ( 1, [ 'tama', 'kuro', 'shiro' ] );
cqlsh:sitest01> select * from test_list;

 pkey1 | v1
-------+---------------------------
     1 | ['tama', 'kuro', 'shiro']

[
  {
    "partition" : {
      "key" : [ "1" ],
      "position" : 0
    },
    "rows" : [
      {
        "type" : "row",
        "position" : 95,
        "liveness_info" : { "tstamp" : "2019-12-14T23:38:38.292657Z" },
        "cells" : [
          { "name" : "v1", "deletion_info" : { "marked_deleted" : "2019-12-14T23:38:38.292656Z", "local_delete_time" : "2019-12-14T23:38:38Z" } },
          { "name" : "v1", "path" : [ "da4d0852-1eca-11ea-bdbd-218e650a2913" ], "value" : "tama" },
          { "name" : "v1", "path" : [ "da4d0853-1eca-11ea-bdbd-218e650a2913" ], "value" : "kuro" },
          { "name" : "v1", "path" : [ "da4d0854-1eca-11ea-bdbd-218e650a2913" ], "value" : "shiro" }
        ]
      }
    ]
  }
]

sstablemetadataから情報抽出

Estimated droppable tombstones: 0.3333333333333333
Estimated tombstone drop times:
1576366740:         1
Count               Row Size        Cell Count
3                          0                 1
103                        1                 0

①’ 新規設置 ( frozenの場合 )

deletion_infoは生成されない

cqlsh:sitest01> desc test_list2;

CREATE TABLE sitest01.test_list2 (
    pkey1 int PRIMARY KEY,
    v1 frozen<list<text>>
) WITH bloom_filter_fp_chance = 0.01
  :
 (略)
  :

cqlsh:sitest01> select * from test_list2;

 pkey1 | v1
-------+----

cqlsh:sitest01> insert into test_list2 ( pkey1, v1 ) values ( 1, [ 'tama', 'kuro', 'shiro' ] );
cqlsh:sitest01> select * from test_list;

 pkey1 | v1
-------+---------------------------
     1 | ['tama', 'kuro', 'shiro']

[
  {
    "partition" : {
      "key" : [ "1" ],
      "position" : 0
    },
    "rows" : [
      {
        "type" : "row",
        "position" : 53,
        "liveness_info" : { "tstamp" : "2019-12-08T10:15:09.501821Z" },
        "cells" : [
          { "name" : "v1", "value" : ["tama", "kuro", "shiro"] }
        ]
      }
    ]
  }
]

② 非増分更新(設置し直し)

( 非frozenの場合 ) 
再設置でdeletion_infoがもれなく生成

cqlsh:sitest01> update test_list set v1 = [ 'hachi', 'goro' ] where pkey1 = 1;
cqlsh:sitest01> select * from test_list;

 pkey1 | v1
-------+-------------------
     1 | ['hachi', 'goro']

[
  {
    "partition" : {
      "key" : [ "1" ],
      "position" : 0
    },
    "rows" : [
      {
        "type" : "row",
        "position" : 87,
        "liveness_info" : { "tstamp" : "2019-12-14T23:38:38.292657Z" },
        "cells" : [
          { "name" : "v1", "deletion_info" : { "marked_deleted" : "2019-12-14T23:43:16.394982Z", "local_delete_time" : "2019-12-14T23:43:16Z" } },
          { "name" : "v1", "path" : [ "80102ec1-1ecb-11ea-bdbd-218e650a2913" ], "value" : "hachi", "tstamp" : "2019-12-14T23:43:16.394983Z" },
          { "name" : "v1", "path" : [ "80102ec2-1ecb-11ea-bdbd-218e650a2913" ], "value" : "goro", "tstamp" : "2019-12-14T23:43:16.394983Z" }
        ]
      }
    ]
  }
]

sstablemetadataから情報抽出

Estimated droppable tombstones: 0.5
Estimated tombstone drop times:
1576367040:         1
Count               Row Size        Cell Count
2                          0                 1
103                        1                 0

②’ 新規設置(設置し直し) ( frozenの場合 ) 

deletion_infoは生成されない

cqlsh:sitest01> update test_list2 set v1 = [ 'hachi', 'goro' ] where pkey1 = 1;
cqlsh:sitest01> select * from test_list2;

 pkey1 | v1
-------+-------------------
     1 | ['hachi', 'goro']

[
  {
    "partition" : {
      "key" : [ "1" ],
      "position" : 0
    },
    "rows" : [
      {
        "type" : "row",
        "position" : 30,
        "liveness_info" : { "tstamp" : "2019-12-14T23:38:38.292657Z" },
        "cells" : [
          { "name" : "v1", "deletion_info" : { "marked_deleted" : "2019-12-15T00:01:29.673453Z", "local_delete_time" : "2019-12-15T00:01:29Z" } }
        ]
      }
    ]
  }
]

③ 更新(先頭への追加)

( 非frozenの場合 )
新たなdeletion_info生成はない

cqlsh:sitest01> update test_list set v1 = [ 'ron' ] + v1 where pkey1 = 1;
cqlsh:sitest01> select * from test_list;

 pkey1 | v1
-------+-------------------------
     1 | ['ron', 'hachi', 'goro']

[
  {
    "partition" : {
      "key" : [ "1" ],
      "position" : 0
    },
    "rows" : [
      {
        "type" : "row",
        "position" : 113,
        "liveness_info" : { "tstamp" : "2019-12-14T23:38:38.292657Z" },
        "cells" : [
          { "name" : "v1", "deletion_info" : { "marked_deleted" : "2019-12-14T23:43:16.394982Z", "local_delete_time" : "2019-12-14T23:43:16Z" } },
          { "name" : "v1", "path" : [ "f5b7a27f-ce04-11d3-bdbd-218e650a2913" ], "value" : "ron", "tstamp" : "2019-12-14T23:48:37.848331Z" },
          { "name" : "v1", "path" : [ "80102ec1-1ecb-11ea-bdbd-218e650a2913" ], "value" : "hachi", "tstamp" : "2019-12-14T23:43:16.394983Z" },
          { "name" : "v1", "path" : [ "80102ec2-1ecb-11ea-bdbd-218e650a2913" ], "value" : "goro", "tstamp" : "2019-12-14T23:43:16.394983Z" }
        ]
      }
    ]
  }
]

sstablemetadataから情報抽出

Estimated droppable tombstones: 0.3333333333333333
Estimated tombstone drop times:
1576367040:         1
Count               Row Size        Cell Count
3                          0                 1
124                        1                 0

③’ 更新(先頭への追加) ( frozenの場合 )

cqlsh:sitest01> update test_list2 set v1 = [ 'ron' ] + v1 where pkey1 = 1;
InvalidRequest: Error from server: code=2200 [Invalid query] message="Invalid operation (v1 = ['ron'] - v1) for frozen list column v1"

④ 更新(末尾への追加)

( 非frozenの場合 )
新たなdeletion_info生成はない


cqlsh:sitest01> update test_list set v1 = v1 + [ 'tabi' ] where pkey1 = 1;
cqlsh:sitest01> select * from test_list;

 pkey1 | v1
-------+----------------------------------
     1 | ['ron', 'hachi', 'goro', 'tabi']

[
  {
    "partition" : {
      "key" : [ "1" ],
      "position" : 0
    },
    "rows" : [
      {
        "type" : "row",
        "position" : 141,
        "liveness_info" : { "tstamp" : "2019-12-14T23:38:38.292657Z" },
        "cells" : [
          { "name" : "v1", "deletion_info" : { "marked_deleted" : "2019-12-14T23:43:16.394982Z", "local_delete_time" : "2019-12-14T23:43:16Z" } },
          { "name" : "v1", "path" : [ "f5b7a27f-ce04-11d3-bdbd-218e650a2913" ], "value" : "ron", "tstamp" : "2019-12-14T23:48:37.848331Z" },
          { "name" : "v1", "path" : [ "80102ec1-1ecb-11ea-bdbd-218e650a2913" ], "value" : "hachi", "tstamp" : "2019-12-14T23:43:16.394983Z" },
          { "name" : "v1", "path" : [ "80102ec2-1ecb-11ea-bdbd-218e650a2913" ], "value" : "goro", "tstamp" : "2019-12-14T23:43:16.394983Z" },
          { "name" : "v1", "path" : [ "9d573042-1ecc-11ea-bdbd-218e650a2913" ], "value" : "tabi", "tstamp" : "2019-12-14T23:51:15.011726Z" }
        ]
      }
    ]
  }
]

sstablemetadataから情報抽出

Estimated droppable tombstones: 0.25
Estimated tombstone drop times:
1576367040:         1
Count               Row Size        Cell Count
4                          0                 1
149                        1                 0

④' 更新(末尾への追加)( frozenの場合 )

cqlsh:sitest01> update test_list2 set v1 = v1 + [ 'tabi' ] where pkey1 = 1;
InvalidRequest: Error from server: code=2200 [Invalid query] message="Invalid operation (v1 = v1 + ['tabi']) for frozen collection column v1"

⑤ 更新(特定位置)

( 非frozenの場合 )
新たなdeletion_info生成はない

cqlsh:sitest01> update test_list set v1[2] = 'yume' where pkey1 = 1;
cqlsh:sitest01> select * from test_list;

 pkey1 | v1
-------+----------------------------------
     1 | ['ron', 'hachi', 'yume', 'tabi']

[
  {
    "partition" : {
      "key" : [ "1" ],
      "position" : 0
    },
    "rows" : [
      {
        "type" : "row",
        "position" : 141,
        "liveness_info" : { "tstamp" : "2019-12-14T23:38:38.292657Z" },
        "cells" : [
          { "name" : "v1", "deletion_info" : { "marked_deleted" : "2019-12-14T23:43:16.394982Z", "local_delete_time" : "2019-12-14T23:43:16Z" } },
          { "name" : "v1", "path" : [ "f5b7a27f-ce04-11d3-bdbd-218e650a2913" ], "value" : "ron", "tstamp" : "2019-12-14T23:48:37.848331Z" },
          { "name" : "v1", "path" : [ "80102ec1-1ecb-11ea-bdbd-218e650a2913" ], "value" : "hachi", "tstamp" : "2019-12-14T23:43:16.394983Z" },
          { "name" : "v1", "path" : [ "80102ec2-1ecb-11ea-bdbd-218e650a2913" ], "value" : "yume", "tstamp" : "2019-12-14T23:55:20.864790Z" },
          { "name" : "v1", "path" : [ "9d573042-1ecc-11ea-bdbd-218e650a2913" ], "value" : "tabi", "tstamp" : "2019-12-14T23:51:15.011726Z" }
        ]
      }
    ]
  }
]

sstablemetadataから情報抽出

Estimated droppable tombstones: 0.25
Estimated tombstone drop times:
1576367040:         1
Count               Row Size        Cell Count
4                          0                 1
149                        1                 0

⑤' 更新(特定位置) ( frozenの場合 )

cqlsh:sitest01> update test_list2 set v1[2] = 'yume' where pkey1 = 1;
InvalidRequest: Error from server: code=2200 [Invalid query] message="Invalid operation (v1[2] = 'yume') for frozen collection column v1"

⑥ 更新(特定値を持つ要素の削除)

( 非frozenの場合 )
この場合は当該要素にdeleteion_info付与

cqlsh:sitest01> update test_list set v1 = v1 - [ 'hachi' ] where pkey1 = 1;
cqlsh:sitest01> select * from test_list;

 pkey1 | v1
-------+-------------------------
     1 | ['ron', 'yume', 'tabi']

[
  {
    "partition" : {
      "key" : [ "1" ],
      "position" : 0
    },
    "rows" : [
      {
        "type" : "row",
        "position" : 137,
        "liveness_info" : { "tstamp" : "2019-12-14T23:38:38.292657Z" },
        "cells" : [
          { "name" : "v1", "deletion_info" : { "marked_deleted" : "2019-12-14T23:43:16.394982Z", "local_delete_time" : "2019-12-14T23:43:16Z" } },
          { "name" : "v1", "path" : [ "f5b7a27f-ce04-11d3-bdbd-218e650a2913" ], "value" : "ron", "tstamp" : "2019-12-14T23:48:37.848331Z" },
          { "name" : "v1", "path" : [ "80102ec1-1ecb-11ea-bdbd-218e650a2913" ], "deletion_info" : { "local_delete_time" : "2019-12-14T23:58:24Z" },
            "tstamp" : "2019-12-14T23:58:24.564980Z"
          },
          { "name" : "v1", "path" : [ "80102ec2-1ecb-11ea-bdbd-218e650a2913" ], "value" : "yume", "tstamp" : "2019-12-14T23:55:20.864790Z" },
          { "name" : "v1", "path" : [ "9d573042-1ecc-11ea-bdbd-218e650a2913" ], "value" : "tabi", "tstamp" : "2019-12-14T23:51:15.011726Z" }
        ]
      }
    ]
  }
][root@cs7ds4001 test_list-b1ad8eb21eca11eabdbd218e650a2913]# 


sstablemetadataから情報抽出

Estimated droppable tombstones: 0.5
Estimated tombstone drop times:
1576367040:         1
1576367940:         1
Count               Row Size        Cell Count
4                          0                 1
149                        1                 0

⑥' 更新(特定値を持つ要素の削除) ( frozenの場合 )

cqlsh:sitest01> update test_list2 set v1 = v1 - [ 'hachi' ] where pkey1 = 1;
InvalidRequest: Error from server: code=2200 [Invalid query] message="Invalid operation (v1 = v1 - ['hachi']) for frozen collection column v1"

⑦ 削除

( 非frozenの場合 )

cqlsh:sitest01> delete v1 from test_list where pkey1 = 1 ;
cqlsh:sitest01> select * from test_list;

 pkey1 | v1
-------+------
     1 | null

[
  {
    "partition" : {
      "key" : [ "1" ],
      "position" : 0
    },
    "rows" : [
      {
        "type" : "row",
        "position" : 30,
        "liveness_info" : { "tstamp" : "2019-12-14T23:38:38.292657Z" },
        "cells" : [
          { "name" : "v1", "deletion_info" : { "marked_deleted" : "2019-12-15T00:01:29.673453Z", "local_delete_time" : "2019-12-15T00:01:29Z" } }
        ]
      }
    ]
  }
]

sstablemetadataから情報抽出

Estimated droppable tombstones: 1.0
Estimated tombstone drop times:
1576368120:         1
Count               Row Size        Cell Count
1                          0                 1
35                         1                 0

⑦' 削除 ( frozenの場合 )

cqlsh:sitest01> delete v1 from test_list2 where pkey1 = 1 ;
cqlsh:sitest01> select * from test_list2;

 pkey1 | v1
-------+------
     1 | null

[
  {
    "partition" : {
      "key" : [ "1" ],
      "position" : 0
    },
    "rows" : [
      {
        "type" : "row",
        "position" : 29,
        "liveness_info" : { "tstamp" : "2019-12-08T10:15:09.501821Z" },
        "cells" : [
          { "name" : "v1", "deletion_info" : { "local_delete_time" : "2019-12-08T10:24:48Z" },
            "tstamp" : "2019-12-08T10:24:48.458508Z"
          }
        ]
      }
    ]
  }
]

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?