Skip to content

Optimize RocksDB buffered wrapper with single Mutex - #5915

Merged
agourlay merged 2 commits into
devfrom
optimize-rocksdb-buffered-wrapper
Feb 10, 2025
Merged

agourlay merged 2 commits into
devfrom
optimize-rocksdb-buffered-wrapper

Conversation

@agourlay

@agourlay agourlay commented Jan 30, 2025 •

Copy link
Copy Markdown
Member

The two mutexes are always acquired together so they can be merged.

@agourlay
agourlay marked this pull request as ready for review January 30, 2025 14:25
@agourlay
agourlay requested review from coszio and timvisee January 30, 2025 14:26

@timvisee timvisee left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice! This is better!

Comment on lines +62 to +63
let ids_to_insert = pending_operations.inserted;
let ids_to_delete = pending_operations.deleted;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: how about struct destructing here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

very good point, it will please Andrey :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

TIL. Thanks!

let PendingOperations { deleted, inserted } =
            mem::take(&mut *self.pending_operations.lock());

timvisee

This comment was marked as duplicate.

timvisee

This comment was marked as duplicate.

timvisee

This comment was marked as duplicate.

timvisee

This comment was marked as duplicate.

timvisee

This comment was marked as duplicate.

timvisee

This comment was marked as duplicate.

Comment on lines +22 to +25
#[derive(Debug, Default)]
struct PendingOperations {
deleted: HashSet<Vec<u8>>,
inserted: HashMap<Vec<u8>, Vec<u8>>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do we even need parallel structures here? Wouldn't it be easier to represent as hashmap of enum?

@KShivendu KShivendu Jan 31, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you mean something like this? 🤔

enum Operation {
    Inserted(Vec<u8>),
    Deleted,
}

type PendingOperations = HashMap<Vec<u8>, Operation>;

But then we also have this situation. It will change behaviour if we override

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes.

Insertions have priority over deletions, so a delete entry can just be replaced. If we really want we can add the same debug assertion in a different place.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'd prefer just tackling the Mutex refactoring in the current PR.
Using a single data structure is a different transformation that should be done in isolation.

@agourlay
agourlay merged commit 9c00903 into dev Feb 10, 2025
@agourlay
agourlay deleted the optimize-rocksdb-buffered-wrapper branch February 10, 2025 14:10
timvisee pushed a commit that referenced this pull request Feb 11, 2025
* Optimize RocksDB buffered wrapper with single Mutex

* deconstruct struct to not foget field later
@timvisee timvisee mentioned this pull request Feb 11, 2025
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.

4 participants