Skip to content

fix(storage): reset size_written only after successful clear - #20

Open
kevetka wants to merge 1 commit into
Piletskii-Oleg:mainfrom
kevetka:work_storage_clear
Open

fix(storage): reset size_written only after successful clear#20
kevetka wants to merge 1 commit into
Piletskii-Oleg:mainfrom
kevetka:work_storage_clear

Conversation

@kevetka

@kevetka kevetka commented Jul 13, 2026

Copy link
Copy Markdown

Problem:
In both clear_database and clear_database_full methods of ChunkStorage, the size_written counter was being reset to 0 before calling the fallible database.clear(). If clear() returns an Err, the method propagates the error to the caller, but size_written has already been zeroed. This leaves the storage in an inconsistent state: the database still contains all data, yet the byte counter indicates that nothing has been written.

Fix:
Reordered the operations so that size_written is updated only after all fallible operations have succeeded:

  • clear_database: database.clear()? → size_written = 0 → Ok(())
  • clear_database_full: database.clear()? → target_map.clear()? → size_written = 0 → Ok(())
    With this fix, if clear() fails, the state remains consistent: the database is untouched and size_written still reflects the actual amount of stored data.

@Vlm326 Vlm326 left a comment

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.

Ok👌

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