fix: delete the previous content when a file is replaced - #419
Open
justadityaraj wants to merge 1 commit into
Open
fix: delete the previous content when a file is replaced#419justadityaraj wants to merge 1 commit into
justadityaraj wants to merge 1 commit into
Conversation
ReplaceFile rewrites the metadata entry in place to point at the new content, which leaves the data the file used to hold with no entry referencing it. CleanUp walks metadata and only frees a source it can still reach from an entry, so that data is never reclaimed, with or without deleteNewFile. Capture the entry before it is rewritten and delete its source, unless another entry still shares the same SHA1. Closes Forceu#407
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Closes #407.
ReplaceFilerewrites the existing metadata entry in place, pointing it at the new content'sSHA1,AwsBucketand size. Whatever the file used to hold is then referenced by no entry at all.CleanUpfrees a source by walking metadata: for each entry it considers expired or missing it checks whether any other entry shares the sameSHA1, and only then removes the stored data. Since nothing points at the replaced content any more,CleanUpnever visits it, so it is never reclaimed. That is why the storage stays occupied whether or notdeleteNewFileis set:deleteNewFileonly expires the entry holding the new content.The fix keeps a copy of the entry before it is rewritten and deletes that source afterwards, unless another entry still shares the same
SHA1(a duplicate, or a replace with identical content).Type of Change
Technical Details
deleteSource, which already routes toaws.DeleteObjectfor non-local files and keeps the oldAwsBucketfrom the copied entry.ReplaceFile->CleanUppath and drafting the test. I confirmed the root cause against the code, decided the approach, and ran the suite myself.How Has This Been Tested?
TestReplaceFileDeletesPreviousContentwrites both sources to the data dir, replaces one with the other, and asserts the previous source is gone while the new one remains. It fails onmaster(Assertion failed, got: false, want: true) and passes with the change.TestReplaceFilestill passes.go test ./internal/storage/... --tags=test,awsmock.TestNewFile,TestGetFileByChunkId,TestLocalStorageDriver_InitandTestGetDataPath. They look like path-separator assumptions rather than anything related to this change.go vet --tags=test,awsmock ./internal/storage/andgofmt -lclean.Checklist