Akka: Persistence data small leak for actors with finite lifetime

Created on 12 Aug 2016  路  3Comments  路  Source: akka/akka

At first, this question appeared in Akka.Net port and is moving here as it was considered the main design issue (https://github.com/akkadotnet/Akka.Persistence.Redis/issues/7).

I'll describe the case.
I have an actor (PersistentFSM) that represents an order. While an order is active - everything is ok, but as soon as order closed (in either way), the actor is removed from the system and will never come back (archived order is quite another story). So I want to remove everything from the persistence store.

But there is test/requirement in persistence TCK - "not reset highestSequenceNr after journal cleanup". And even if I remove everything from journal and snapshot stores, the record of highestSequenceNr will be left there forever.

Most helpful comment

Maybe it will be a good idea to introduce some new method to remove all (clean up)? For cases when persistent storage is definitely no more needed for the entity (so I am sure that seq nr will not be reused).

All 3 comments

Removal is not something you normally do in event sourced systems. Storage is considered cheap. If this is problem in Redis it could remove such a record after a few days. That should not cause any problems in practise, I think.

Sorry but this is not something we want to change in akka or the tck. Reusing seq nr can cause all kind of problems.

Maybe it will be a good idea to introduce some new method to remove all (clean up)? For cases when persistent storage is definitely no more needed for the entity (so I am sure that seq nr will not be reused).

Maybe it will be a good idea to introduce some new method to remove all (clean up)? For cases when persistent storage is definitely no more needed for the entity (so I am sure that seq nr will not be reused).

If you use akka-persistent-redis, you can use Lua script to clear terminated actor

redis-cli --eval akka-persistence-redis-clean.lua

akka-persistence-redis-clean.lua

local ids = redis.call('smembers','journal:persistenceIds');
local delkeys = {};
for k, v in pairs(ids) do
  local jpid = 'journal:persisted:' .. v;
  local jpidnr = 'journal:persisted:' .. v .. ':highestSequenceNr';
  local hasjpid  = redis.call('exists',jpid);
  if(hasjpid == 0)
  then
    local hasjpidnr  = redis.call('exists',jpidnr);
    if(hasjpidnr == 1)
    then
      redis.call('del',jpidnr);
      table.insert(delkeys,jpid);
    end
  end
end
return delkeys;
Was this page helpful?
0 / 5 - 0 ratings