Skip to content

Commit 82fabc1

Browse files
committed
wip integrate linkstore
1 parent a5d43e8 commit 82fabc1

File tree

3 files changed

+72
-12
lines changed

3 files changed

+72
-12
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ version = "0.20.2"
44

55
[deps]
66
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
7+
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
78
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
89
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
910
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"

src/DataBlobs/services/BlobStores.jl

Lines changed: 70 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,36 +103,43 @@ function getBlob(dfg::AbstractDFG, entry::BlobEntry)
103103
)
104104
end
105105

106-
getBlob(store::AbstractBlobStore, entry::BlobEntry) =
107-
getBlob(store, entry.originId)
106+
function getBlob(store::AbstractBlobStore, entry::BlobEntry)
107+
blobId = isnothing(entry.blobId) ? entry.originId : entry.blobId
108+
getBlob(store, blobId)
109+
end
108110

109111
#add
110112
addBlob!(dfg::AbstractDFG, entry::BlobEntry, data) =
111113
addBlob!(getBlobStore(dfg, entry.blobstore), entry, data)
112114

113-
addBlob!(store::AbstractBlobStore, entry::BlobEntry, data) =
114-
addBlob!(store, entry.originId, data)
115-
115+
function addBlob!(store::AbstractBlobStore, entry::BlobEntry, data)
116+
blobId = isnothing(entry.blobId) ? entry.originId : entry.blobId
117+
addBlob!(store, blobId, data)
118+
end
119+
116120
addBlob!(store::AbstractBlobStore, data) =
117121
addBlob!(store, uuid4(), data)
118122

119123
#fallback as not all blobStores use filename
120-
addBlob!(store::AbstractBlobStore, blobId::UUID, data, ::String) =
124+
addBlob!(store::AbstractBlobStore, blobId::UUID, data, ::String) =
121125
addBlob!(store, blobId, data)
122126

123127
#update
124128
updateBlob!(dfg::AbstractDFG, entry::BlobEntry, data::T) where {T} =
125129
updateBlob!(getBlobStore(dfg, entry.blobstore), entry, data)
126130

127-
updateBlob!(store::AbstractBlobStore, entry::BlobEntry, data) =
128-
updateBlob!(store, entry.originId, data)
129-
131+
function updateBlob!(store::AbstractBlobStore, entry::BlobEntry, data)
132+
blobId = isnothing(entry.blobId) ? entry.originId : entry.blobId
133+
updateBlob!(store, blobId, data)
134+
end
130135
#delete
131136
deleteBlob!(dfg::AbstractDFG, entry::BlobEntry) =
132137
deleteBlob!(getBlobStore(dfg, entry.blobstore), entry)
133138

134-
deleteBlob!(store::AbstractBlobStore, entry::BlobEntry) =
135-
deleteBlob!(store, entry.originId)
139+
function deleteBlob!(store::AbstractBlobStore, entry::BlobEntry)
140+
blobId = isnothing(entry.blobId) ? entry.originId : entry.blobId
141+
deleteBlob!(store, blobId)
142+
end
136143

137144

138145
#has
@@ -250,7 +257,7 @@ function getBlob(store::InMemoryBlobStore, blobId::UUID)
250257
end
251258

252259
function addBlob!(store::InMemoryBlobStore{T}, blobId::UUID, data::T) where {T}
253-
if haskey(store.blobs, entry.originId)
260+
if haskey(store.blobs, blobId)
254261
error("Key '$blobId' blob already exists.")
255262
end
256263
store.blobs[blobId] = data
@@ -269,3 +276,54 @@ function deleteBlob!(store::InMemoryBlobStore, blobId::UUID)
269276
end
270277

271278
hasBlob(store::InMemoryBlobStore, blobId::UUID) = haskey(store.blobs, blobId)
279+
280+
281+
##==============================================================================
282+
## LinkStore Link blobId to a existing local folder
283+
##==============================================================================
284+
285+
struct LinkStore <: AbstractBlobStore{String}
286+
key::Symbol
287+
csvfile::String
288+
cache::Dict{UUID, String}
289+
290+
function LinkStore(key, csvfile)
291+
if !isfile(csvfile)
292+
@info "File '$csvfile' doesn't exist - creating."
293+
# create new folder
294+
open(csvfile, "w") do io
295+
println(io, "blobid,path")
296+
end
297+
return new(key, csvfile, Dict{UUID, String}())
298+
else
299+
file = CSV.File(csvfile)
300+
cache = Dict(UUID.(file.blobid) .=> file.path)
301+
return new(key, csvfile, cache)
302+
end
303+
end
304+
end
305+
306+
function getBlob(store::LinkStore, blobId::UUID)
307+
fname = get(store.cache, blobId, nothing)
308+
read(fname)
309+
end
310+
311+
function addBlob!(store::LinkStore, entry::BlobEntry, linkfile::String)
312+
addBlob!(store, entry.originId, nothing, linkfile::String)
313+
end
314+
315+
function addBlob!(store::LinkStore, blobId::UUID, blob::Any, linkfile::String)
316+
if haskey(store.cache, blobId)
317+
error("blobId $blobId already exists in the store")
318+
end
319+
push!(store.cache, blobId=>linkfile)
320+
open(store.csvfile, "a") do f
321+
println(f, blobId,",",linkfile)
322+
end
323+
getBlob(store, blobId)
324+
end
325+
326+
function deleteBlob!(store::LinkStore, args...)
327+
error("deleteDataBlob(::LinkStore) not supported")
328+
end
329+

src/DistributedFactorGraphs.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ using TensorCast
3232
using ProgressMeter
3333
using SHA
3434

35+
using CSV
3536

3637
# used for @defVariable
3738
import ManifoldsBase

0 commit comments

Comments
 (0)