Skip to content

Immutable Folderstore id=>blob pair #1160

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

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 29 additions & 14 deletions src/DataBlobs/services/BlobStores.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ end

function getBlob(store::FolderStore{T}, blobId::UUID) where {T}
blobfilename = joinpath(store.folder, string(store.label), string(blobId))
if isfile(blobfilename)
tombstonefile = blobfilename * ".deleted"
if isfile(tombstonefile)
throw(IdNotFoundError("Blob (deleted)", blobId))
elseif isfile(blobfilename)
open(blobfilename) do f
return read(f)
end
Expand All @@ -198,24 +201,28 @@ function addBlob!(store::FolderStore{T}, blobId::UUID, data::T) where {T}
end

function updateBlob!(store::FolderStore{T}, blobId::UUID, data::T) where {T}
blobfilename = joinpath(store.folder, string(store.label), string(blobId))
if !isfile(blobfilename)
@warn "Key '$blobId' doesn't exist."
else
open(blobfilename, "w") do f
return write(f, data)
end
return data
end
return error("updateBlob! is obsolete as blobsId=>Blob pairs are immutable.")
end

function deleteBlob!(store::FolderStore{T}, blobId::UUID) where {T}
# Tombstone pattern: instead of deleting the file, create a tombstone marker file
blobfilename = joinpath(store.folder, string(store.label), string(blobId))
if !isfile(blobfilename)
tombstonefile = blobfilename * ".deleted"
if isfile(blobfilename)
# Remove the actual blob file
rm(blobfilename)
# Create a tombstone marker
open(tombstonefile, "w") do f
return write(f, "deleted")
end
return 1
elseif isfile(tombstonefile)
# Already deleted
return 0
else
# Not found
throw(IdNotFoundError("Blob", blobId))
end
rm(blobfilename)
return 1
end

function hasBlob(store::FolderStore, blobId::UUID)
Expand All @@ -225,7 +232,15 @@ end

hasBlob(store::FolderStore, entry::Blobentry) = hasBlob(store, entry.blobId)

listBlobs(store::FolderStore) = readdir(store.folder)
function listBlobs(store::FolderStore)
folder = joinpath(store.folder, string(store.label))
# Parse folder to only include UUIDs automatically excluding tombstone files this way.
blobIds = map(readdir(folder)) do filename
return tryparse(UUID, filename)
end
return filter(!isnothing, blobIds)
end

##==============================================================================
## InMemoryBlobstore
##==============================================================================
Expand Down
Loading