Skip to content

fix(snapshot): Refactor the big_value_mu_ mutex #4327

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

Conversation

BagritsevichStepan
Copy link
Contributor

fixes #4152

@BagritsevichStepan BagritsevichStepan self-assigned this Dec 17, 2024
@BagritsevichStepan BagritsevichStepan force-pushed the big-values-serialization/fix-mutex branch 5 times, most recently from f53ae1c to e784dff Compare December 17, 2024 12:51
@BagritsevichStepan BagritsevichStepan force-pushed the big-values-serialization/fix-mutex branch 2 times, most recently from 3933526 to 2c4e79d Compare December 25, 2024 09:33
fixes dragonflydb#4152

Signed-off-by: Stepan Bagritsevich <stefan@dragonflydb.io>
@BagritsevichStepan BagritsevichStepan force-pushed the big-values-serialization/fix-mutex branch from 2c4e79d to dc55962 Compare December 25, 2024 13:36
// If A.id = 5, and then B.id = 6, and both are blocked here, it means that last_pushed_id_ < 4.
// Once last_pushed_id_ = 4, A will be unblocked, while B will wait until A finishes pushing and
// update last_pushed_id_ to 5.
seq_cond_.wait(lk, [&] { return id == this->last_pushed_id_ + 1; });
Copy link
Contributor Author

@BagritsevichStepan BagritsevichStepan Dec 25, 2024

Choose a reason for hiding this comment

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

I think we don't need this because FlushSerialized is called when big_value_mu_ is locked

Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe you are right here, but this is not the change I wanted by this PR.
I wanted the mutex to protect the serializer and only it.
So we will have a getter for the serializer when trying to access it and once done we release the mutex.
So in this point the mutex will not be taken

CHECK(res);
++type_freq_map_[*res];
}
}

size_t SliceSnapshot::FlushSerialized(SerializerBase::FlushState flush_state) {
io::StringFile sfile;

// FlushSerialized is already under lock
Copy link
Collaborator

Choose a reason for hiding this comment

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

The changes is not good
This is exactly what I wanted to simplify. I dont want us to think or review different flows to understand if the lock is already taken but instead have the getter protect us.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I suggest revert now all this changes that are for the CallSerializerUnderLock
we can keep the other small changes that you did that does not impact the mutex.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The issue is that FlushSerialized can be invoked from the flush_fn callback passed to the RdbSerializer, which can be called during the serializer->SaveEntry method (where the mutex is already locked).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok therefore I suggest reverting the changes as they do not simplify the code.
I will revisit this later and see if we can improve this

@BagritsevichStepan BagritsevichStepan deleted the big-values-serialization/fix-mutex branch December 26, 2024 15:20
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.

Lock the snapshot::big_value_mu_ within serializer for big values
2 participants