Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: delete all but last #847

Merged
merged 8 commits into from
Aug 1, 2024
Merged

Conversation

octonato
Copy link
Member

First delete all event but the last and then mark the last as delete.

Comment on lines 72 to 75
def markAsDeleted(persistenceId: String, highestMarkedSequenceNr: Long) =
JournalTable
.filter(_.persistenceId === persistenceId)
.filter(_.sequenceNumber <= maxSequenceNr)
.filter(_.sequenceNumber === highestMarkedSequenceNr)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

being more explicitly and only marking a single message as delete.

Only used when deleted events though and what we want is to delete the latest.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this will probably not work as expected. Looking further in the code.

@octonato octonato force-pushed the octonato/fix-ordering-of-event-deletion branch from bbfb7ed to 39684aa Compare July 31, 2024 14:42
Comment on lines +57 to +73
// note: the passed toSequenceNr will be Long.MaxValue when doing a 'full' journal clean-up
// see JournalSpec's test: 'not reset highestSequenceNr after journal cleanup'
val actions: DBIOAction[Unit, NoStream, Effect.Write with Effect.Read] =
highestSequenceNrAction(persistenceId)
.flatMap {
// are we trying to delete the highest or even higher seqNr ?
case highestSeqNr if highestSeqNr <= toSequenceNr =>
// if so, we delete up to the before last and
// mark the last as logically deleted preserving highestSeqNr
queries
.delete(persistenceId, highestSeqNr - 1)
.flatMap(_ => queries.markAsDeleted(persistenceId, highestSeqNr))
case _ =>
// if not, we delete up to the requested seqNr
queries.delete(persistenceId, toSequenceNr)
}
.map(_ => ())
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests for h2 are passing now locally. Should pass for the the other databases as well. All failures were comping from the akka journal specs.

Comment on lines -53 to -55
_ <- queries.markJournalMessagesAsDeleted(persistenceId, maxSequenceNr)
highestMarkedSequenceNr <- highestMarkedSequenceNr(persistenceId)
_ <- queries.delete(persistenceId, highestMarkedSequenceNr.getOrElse(0L) - 1)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was indeed not efficient and there was also a little bug here.

For a journal with events: 1, 2, 3, 4, 5

Deleting up to 3, would first:
logically delete: 1, 2, 3
collect the highest logically deleted nr, thus 3
delete everything until 3, so delete 1 and 2.

The journal remains with: 3, 4, 5 while 3 is invisible because logically deleted.

There is no reason to keep 3, because it's not the highest anyway.

@octonato octonato force-pushed the octonato/fix-ordering-of-event-deletion branch from e1abbc6 to 01d5d32 Compare August 1, 2024 10:59
Copy link
Member

@johanandren johanandren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but two questions

@octonato
Copy link
Member Author

octonato commented Aug 1, 2024

We are having issues with mysql tests. Container not starting. 3 days ago it passed. Might be a intermittent issue.

@octonato octonato merged commit 736bc34 into main Aug 1, 2024
10 checks passed
@octonato octonato deleted the octonato/fix-ordering-of-event-deletion branch August 1, 2024 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants