Кэширование строк работает только в том случае, если таблица имеет первичный ключ из одного столбца, в противном случае, если в таблицу добавлен ключ кластеризации, кэширование строк больше не работает.Версия Cassandra, с которой я проверял это, - 3.11.0, но проблема также очевидна в 3.11.3, которая является самой последней на момент написания этой статьи.
Я использую конфиги Cassandra по умолчанию плюс:
key_cache_size_in_mb:
key_cache_save_period: 14400
row_cache_size_in_mb: 128
row_cache_save_period: 14400
Это выглядит как очень фундаментальная особенность, поэтому я не совсем уверен, что это ошибка или что-то, чего мне не хватает:
cqlsh> CREATE TABLE test.table1 (k text, v text, PRIMARY KEY (k)) WITH caching = {'keys': 'ALL', 'rows_per_partition': '100'};
cqlsh> CREATE TABLE test.table2 (k text, v text, PRIMARY KEY (k, v)) WITH caching = {'keys': 'ALL', 'rows_per_partition': '100'};
cqlsh> insert into test.table1 (k,v) values('k1', 'v1');
cqlsh> insert into test.table2 (k,v) values('k1', 'v1');
cqlsh> tracing on;
Now Tracing is enabled
cqlsh> select * from test.table1 where k='k1';
k | v
----+----
k1 | v1
(1 rows)
Tracing session: e81f1640-ebcb-11e8-b19a-8f0e04450cb9
activity | timestamp | source | source_elapsed | client
-----------------------------------------------------------------------------------------+----------------------------+-----------+----------------+-----------
Execute CQL3 query | 2018-11-19 07:22:44.004000 | 127.0.0.1 | 0 | 127.0.0.1
Parsing select * from test.table1 where k='k1'; [Native-Transport-Requests-1] | 2018-11-19 07:22:44.005000 | 127.0.0.1 | 225 | 127.0.0.1
Preparing statement [Native-Transport-Requests-1] | 2018-11-19 07:22:44.005000 | 127.0.0.1 | 395 | 127.0.0.1
Row cache miss [ReadStage-3] | 2018-11-19 07:22:44.005000 | 127.0.0.1 | 930 | 127.0.0.1
Executing single-partition query on table1 [ReadStage-3] | 2018-11-19 07:22:44.005000 | 127.0.0.1 | 1047 | 127.0.0.1
Acquiring sstable references [ReadStage-3] | 2018-11-19 07:22:44.006000 | 127.0.0.1 | 1106 | 127.0.0.1
Skipped 0/0 non-slice-intersecting sstables, included 0 due to tombstones [ReadStage-3] | 2018-11-19 07:22:44.006000 | 127.0.0.1 | 1180 | 127.0.0.1
Caching 1 rows [ReadStage-3] | 2018-11-19 07:22:44.006000 | 127.0.0.1 | 1282 | 127.0.0.1
Merged data from memtables and 0 sstables [ReadStage-3] | 2018-11-19 07:22:44.006001 | 127.0.0.1 | 1529 | 127.0.0.1
Read 1 live and 0 tombstone cells [ReadStage-3] | 2018-11-19 07:22:44.006001 | 127.0.0.1 | 1670 | 127.0.0.1
Request complete | 2018-11-19 07:22:44.005903 | 127.0.0.1 | 1903 | 127.0.0.1
cqlsh> select * from test.table1 where k='k1';
k | v
----+----
k1 | v1
(1 rows)
Tracing session: edf0cd70-ebcb-11e8-b19a-8f0e04450cb9
activity | timestamp | source | source_elapsed | client
------------------------------------------------------------------------------+----------------------------+-----------+----------------+-----------
Execute CQL3 query | 2018-11-19 07:22:53.767000 | 127.0.0.1 | 0 | 127.0.0.1
Parsing select * from test.table1 where k='k1'; [Native-Transport-Requests-1] | 2018-11-19 07:22:53.767000 | 127.0.0.1 | 160 | 127.0.0.1
Preparing statement [Native-Transport-Requests-1] | 2018-11-19 07:22:53.767000 | 127.0.0.1 | 335 | 127.0.0.1
Row cache hit [ReadStage-3] | 2018-11-19 07:22:53.768000 | 127.0.0.1 | 915 | 127.0.0.1
Read 1 live and 0 tombstone cells [ReadStage-3] | 2018-11-19 07:22:53.768000 | 127.0.0.1 | 1066 | 127.0.0.1
Request complete | 2018-11-19 07:22:53.768255 | 127.0.0.1 | 1255 | 127.0.0.1
cqlsh> select * from test.table2 where k='k1' and v='v1';
k | v
----+----
k1 | v1
(1 rows)
Tracing session: f7c26200-ebcb-11e8-b19a-8f0e04450cb9
activity | timestamp | source | source_elapsed | client
--------------------------------------------------------------------------------------------------------------+----------------------------+-----------+----------------+-----------
Execute CQL3 query | 2018-11-19 07:23:10.240000 | 127.0.0.1 | 0 | 127.0.0.1
Parsing select * from test.table2 where k='k1' and v='v1'; [Native-Transport-Requests-1] | 2018-11-19 07:23:10.240000 | 127.0.0.1 | 168 | 127.0.0.1
Preparing statement [Native-Transport-Requests-1] | 2018-11-19 07:23:10.240000 | 127.0.0.1 | 343 | 127.0.0.1
Row cache miss [ReadStage-2] | 2018-11-19 07:23:10.241000 | 127.0.0.1 | 824 | 127.0.0.1
Fetching data but not populating cache as query does not query from the start of the partition [ReadStage-2] | 2018-11-19 07:23:10.241000 | 127.0.0.1 | 891 | 127.0.0.1
Executing single-partition query on table2 [ReadStage-2] | 2018-11-19 07:23:10.241000 | 127.0.0.1 | 923 | 127.0.0.1
Acquiring sstable references [ReadStage-2] | 2018-11-19 07:23:10.241000 | 127.0.0.1 | 949 | 127.0.0.1
Merging memtable contents [ReadStage-2] | 2018-11-19 07:23:10.241000 | 127.0.0.1 | 978 | 127.0.0.1
Read 1 live and 0 tombstone cells [ReadStage-2] | 2018-11-19 07:23:10.241000 | 127.0.0.1 | 1132 | 127.0.0.1
Request complete | 2018-11-19 07:23:10.241338 | 127.0.0.1 | 1338 | 127.0.0.1
cqlsh> select * from test.table2 where k='k1' and v='v1';
k | v
----+----
k1 | v1
(1 rows)
Tracing session: f9d6c310-ebcb-11e8-b19a-8f0e04450cb9
activity | timestamp | source | source_elapsed | client
--------------------------------------------------------------------------------------------------------------+----------------------------+-----------+----------------+-----------
Execute CQL3 query | 2018-11-19 07:23:13.729000 | 127.0.0.1 | 0 | 127.0.0.1
Parsing select * from test.table2 where k='k1' and v='v1'; [Native-Transport-Requests-2] | 2018-11-19 07:23:13.729000 | 127.0.0.1 | 182 | 127.0.0.1
Preparing statement [Native-Transport-Requests-2] | 2018-11-19 07:23:13.729000 | 127.0.0.1 | 355 | 127.0.0.1
Row cache miss [ReadStage-3] | 2018-11-19 07:23:13.730000 | 127.0.0.1 | 839 | 127.0.0.1
Fetching data but not populating cache as query does not query from the start of the partition [ReadStage-3] | 2018-11-19 07:23:13.730000 | 127.0.0.1 | 902 | 127.0.0.1
Executing single-partition query on table2 [ReadStage-3] | 2018-11-19 07:23:13.730000 | 127.0.0.1 | 942 | 127.0.0.1
Acquiring sstable references [ReadStage-3] | 2018-11-19 07:23:13.730000 | 127.0.0.1 | 967 | 127.0.0.1
Merging memtable contents [ReadStage-3] | 2018-11-19 07:23:13.730000 | 127.0.0.1 | 992 | 127.0.0.1
Read 1 live and 0 tombstone cells [ReadStage-3] | 2018-11-19 07:23:13.730000 | 127.0.0.1 | 1116 | 127.0.0.1
Request complete | 2018-11-19 07:23:13.730307 | 127.0.0.1 | 1307 | 127.0.0.1
Глядя на журнал трассировки, кажется, что строки с ключами кластеризации могут быть недоступны для кэширования - Выборка данных, но не заполнение кэша, так как запрос не запрашивает с начала раздела ?