2
votes

I'm using Spring Boot 1.5.1.RELEASE with spring-boot-starter-data-cassandra.

I'm running into an issue where I'm using CassandraOperations.insert and it is causing a bunch of cell tombstones. This appears to be caused by: https://jira.spring.io/browse/DATACASS-182. Since Spring Data now inserts an actual null for null values, that causes cell tombstones. I haven't found any way to tell Spring Data to not do this. Is there a configuration or something where I can say "for this insert, do not insert actual null values"?

2
That's not possible. Do you care to file a ticket so we can discuss how to improve? - mp911de
Sure, I will file a ticket. It would be nice if you could include something like that in the WriteOptions so it could be done at the query level. - cloudwalker
AFAIU writing null on insert creates unwanted tombstones. From a query perspective it should not matter where there is a written null or the cell wasn't written at all. Is there any case in which you would want to create cell tombstones on insert? - mp911de
We have ran into this issue as well. Any null insert into Cassandra creates a tombstone. We have some cases where we have a cell with 1k+ tombstones that causes performance problems. - gsteiner
@mp911de Well, according to jira.spring.io/browse/DATACASS-182, some people want to create the tombstones on write in the event that they are nulling out a value in a cell that was previously set. So, I think it would be useful to have the option at the query level to say whether or not you want literal nulls to be written. That way you don't suffer performance issues on inserts where you do not want the literal nulls, but you still have the ability to do "updates" where you can overwrite a previously set value with a null. I'll work on filing a ticket today. Thanks! - cloudwalker

2 Answers

1
votes

One of the easiest and non intrusive solutions is to use

CassandraTemplate.insert()/CassandraBatchOperations.insert()

Basically tombstones are created when generated CQL has explicit null values. e.g following query will insert one tombstone.

Insert into KeyspaceName.TableName(ColumnName1, ColumnName2, ColumnName3)
values (Column1Value, Column2Value, null)

Cassandra treats insert as upsert and for each null it tries to delete the existing column value without performing check if column value exists or not. So for each null value it creates a tombstone which means value has been deleted.

However following query will not create tombstone.

Insert into KeyspaceName.TableName(ColumnName1, ColumnName2)
values (Column1Value, Column2Value)

Query generated by CassandraTemplate.insert()/CassandraBatchOperations.insert() ignores columns with null values and generates CQL with columns with non-null values. Hence doesn't create tombstones.

0
votes

This is currently a limitation with Spring Data Cassandra. I've created https://jira.spring.io/browse/DATACASS-420 to track this. What I did to get around it temporarily was to create a custom class that extends MappingCassandraConverter and I rewrote the writeInsertFromWrapper method to not insert nulls.