Skip to content

Implement Drop Trait for Storage#32

Merged
jonasmartin merged 3 commits intodevfrom
implement-drop
Jan 20, 2026
Merged

Implement Drop Trait for Storage#32
jonasmartin merged 3 commits intodevfrom
implement-drop

Conversation

@TomasSzeSirk
Copy link
Copy Markdown
Contributor

No description provided.

Comment thread src/storage.rs
Some("test_value2".to_string())
);
assert_eq!(store.read("test3").unwrap(), None);
store.rollback_transaction(second_transaction_id).unwrap();
Copy link
Copy Markdown
Contributor

@Ignacio-87 Ignacio-87 Jan 20, 2026

Choose a reason for hiding this comment

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

This was wrong right, that is why you remove it ?

Copy link
Copy Markdown
Contributor Author

@TomasSzeSirk TomasSzeSirk Jan 20, 2026

Choose a reason for hiding this comment

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

The rollback wasn´t part of the test. It was used to solve a leaking memory issue with unclosed transactions when Storage went out of scope. This was fixed with the implementation of the Drop Trait

Comment thread src/storage.rs
impl Drop for Storage {
fn drop(&mut self) {
let mut map = self.transactions.borrow_mut();
map.clear();
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.

Should drop implement transaction/rollback?

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.

The intention for drop is remove transactions?

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.

Maybe we can call it transaction_drop

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.

It's is ok, when the object is removed, the transaction is automatically rolled back. The change is to make sure that on shutdown, even if there is a transaction open it does not crash.
But I would add a comment explaining why this is here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The Drop Trait was defined because if you left transactions unclosed when Storage went out of scope there was a leaking memory issue. I can´t change the name of the function, it's defined by the trait, but I can document the function explaining why it's needed.

Copy link
Copy Markdown
Contributor

@jonasmartin jonasmartin left a comment

Choose a reason for hiding this comment

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

lgtm

@jonasmartin jonasmartin merged commit 818b563 into dev Jan 20, 2026
1 check passed
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.

3 participants