Adding Secondary index on Cassandra indexes historical data?

坚强是说给别人听的谎言 提交于 2019-12-11 08:48:46

问题


if on a particular column family i add a index on a column later on will it index the historical data too or data which comes now after adding the index.

Here in this When does Cassandra DB index data after updating a column as secondary index The accepted answer says it will index only data which is inserted after creating the index.

I tried creating a CF with index on a column.(i am using Cassandra 1.0.7)

create column family users with comparator=UTF8Type and column_metadata=[{column_name: full_name, validation_class: UTF8Type}, {column_name: birth_date, validation_class: LongType, index_type: KEYS}, {column_name: state, validation_class: UTF8Type, index_type: KEYS}];

Added some data , then did

removed index by drop index users.birth_date then added it back by updating CF

update column family users with comparator=UTF8Type and column_metadata=[{column_name: full_name, validation_class: UTF8Type}, {column_name: birth_date, validation_class: LongType, index_type: KEYS}, {column_name: state, validation_class: UTF8Type, index_type: KEYS}];

and then added some data again

But when i am querying on birth_data i get historical data too ?

Can someone clear my confusion on this ? Are there two ways to create index , one with historical data and one without ?


回答1:


Maybe the previous version of Cassandra didn't build indexes for historical data, but according to the code post Cassandra 1.2, the index creation is an async process that does happen on historical data if you add a secondary index:

https://github.com/apache/cassandra/blob/cassandra-1.2.15/src/java/org/apache/cassandra/db/index/SecondaryIndexManager.java#L240

In your scenario, what has happened is that you removed the index and added the index. Because the old index files where already loaded and not removed from disk, Cassandra linked them for usage again. Otherwise, it would have attempted to create them.

In case you are not sure about your secondary indexes being in sync, you can use:

nodetool rebuild_index


来源:https://stackoverflow.com/questions/21686816/adding-secondary-index-on-cassandra-indexes-historical-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!