EntityPersister Updates and Astyanax Collections

Background

Astyanax Entity Persister stores an object map in multiple columns. Format: mapVariable.key

Problem:

Astyanax Entity Persister does not remove deleted key / value pairs from cassandra when updating a map in an object

The solution I'm using right now (bad approach)

I delete the whole line and then insert it again

Additional Information

I save my java objects in cassandra using astyanax Entity Persister (com.netflix.astyanax.entitystore).

I noticed that when an object map is saved, say, with two values: testkey: testvalue and testkey2: testvalue2, and the next time the same object map is saved with one value (one key / value pair was deleted): testkey : testvalue, testkey2: testvalue2 is not removed from the column family.

So, as a workaround, I need to delete the entire line and then insert it again.

My insert code:

final EntityManager<T, String> entityManager = new DefaultEntityManager.Builder<T, String>() .withEntityType(clazz) .withKeyspace(getKeyspace()) .withColumnFamily(columnFamily) .build(); entityManager.put(entity); 

What am I missing? This is really inefficient, and I think the astyanax entity persister should take care of this on its own.

Any thoughts?

+6
source share
2 answers

You are missing nothing.

What happens: 1. Astyanax creates a list of ColumnMappers, one for each field of the object under serialization. 2. Then, ColumnMappers take turns filling in the batch of mutations. 3. For maps, MapColumnMapper is used. If you look at its code, you will see that it simply adds key: value pairs to the batch of mutations. 4. When data is placed in a row in cassandra, new columns from the package are added, existing columns are overwritten, old ones, unfortunately, remain the same .

One solution here would be to write your own serializer for your map and save it in one field.

+2
source

See https://github.com/deanhiller/playorm its orm mapper for cassandra, hbase and several other nosql databases. It removes items from collections when saved. It is also easier to use then astyanax.

+1
source

Source: https://habr.com/ru/post/945507/


All Articles