Skip to content

Commit da85eb3

Browse files
authored
Standardise to Blobstore label (#1113)
Co-authored-by: Johannes Terblanche <[email protected]>
1 parent b45339a commit da85eb3

File tree

9 files changed

+29
-33
lines changed

9 files changed

+29
-33
lines changed

src/DataBlobs/services/BlobEntry.jl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,7 @@ end
7979

8080
function getBlobEntry(var::VariableDFG, key::Symbol)
8181
if !hasBlobEntry(var, key)
82-
throw(
83-
KeyError(
84-
"No dataEntry label $(key) found in variable $(getLabel(var)). Available keys: $(keys(var.dataDict))",
85-
),
86-
)
82+
throw(KeyError(key))
8783
end
8884
return var.blobEntries[findfirst(x -> x.label == key, var.blobEntries)]
8985
end

src/DataBlobs/services/BlobStores.jl

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function getBlob(dfg::AbstractDFG, entry::BlobEntry)
9797
end
9898
throw(
9999
KeyError(
100-
"could not find $(entry.label), uuid $(entry.blobId) in any of the listed blobstores:\n $([s->getKey(s) for (s,v) in stores]))",
100+
"could not find $(entry.label), uuid $(entry.blobId) in any of the listed blobstores:\n $([s->getLabel(s) for (s,v) in stores]))",
101101
),
102102
)
103103
end
@@ -177,13 +177,10 @@ end
177177
## FolderStore
178178
##==============================================================================
179179
struct FolderStore{T} <: AbstractBlobStore{T}
180-
key::Symbol
180+
label::Symbol
181181
folder::String
182182
end
183183

184-
#TODO rename key to label for consistency
185-
getLabel(store::FolderStore) = store.key
186-
187184
function FolderStore(foldername::String; label = :default_folder_store, createfolder = true)
188185
if createfolder && !isdir(foldername)
189186
@info "Folder '$foldername' doesn't exist - creating."
@@ -247,12 +244,13 @@ end
247244

248245
hasBlob(store::FolderStore, entry::BlobEntry) = hasBlob(store, entry.originId)
249246

247+
listBlobs(store::FolderStore) = readdir(store.folder)
250248
##==============================================================================
251249
## InMemoryBlobStore
252250
##==============================================================================
253251

254252
struct InMemoryBlobStore{T} <: AbstractBlobStore{T}
255-
key::Symbol
253+
label::Symbol
256254
blobs::Dict{UUID, T}
257255
end
258256

@@ -295,22 +293,22 @@ listBlobs(store::InMemoryBlobStore) = collect(keys(store.blobs))
295293
##==============================================================================
296294

297295
struct LinkStore <: AbstractBlobStore{String}
298-
key::Symbol
296+
label::Symbol
299297
csvfile::String
300298
cache::Dict{UUID, String}
301299

302-
function LinkStore(key, csvfile)
300+
function LinkStore(label, csvfile)
303301
if !isfile(csvfile)
304302
@info "File '$csvfile' doesn't exist - creating."
305303
# create new folder
306304
open(csvfile, "w") do io
307305
return println(io, "blobid,path")
308306
end
309-
return new(key, csvfile, Dict{UUID, String}())
307+
return new(label, csvfile, Dict{UUID, String}())
310308
else
311309
file = CSV.File(csvfile)
312310
cache = Dict(UUID.(file.blobid) .=> file.path)
313-
return new(key, csvfile, cache)
311+
return new(label, csvfile, cache)
314312
end
315313
end
316314
end
@@ -373,7 +371,7 @@ end
373371
## RowBlobStore
374372

375373
struct RowBlobStore{T} <: AbstractBlobStore{T}
376-
key::Symbol
374+
label::Symbol
377375
blobs::OrderedDict{UUID, RowBlob{T}}
378376
end
379377

src/DataBlobs/services/HelpersDataWrapEntryBlob.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ function addData!(
191191
blobId,
192192
originId,
193193
label = bLbl,
194-
blobstore = blobstore.key,
194+
blobstore = getLabel(blobstore),
195195
hash = string(bytes2hex(hashfunction(blob))),
196196
origin = buildSourceString(dfg, vLbl),
197197
description,
@@ -224,7 +224,7 @@ function addData!(
224224
blobId,
225225
originId = blobId,
226226
label = blobLabel,
227-
blobstore = blobstore.key,
227+
blobstore = getLabel(blobstore),
228228
# hash = string(bytes2hex(hashfunction(blob))),
229229
hash = "",
230230
origin,
@@ -264,7 +264,7 @@ function updateData!(
264264
# order of operations with unknown new blobId not tested
265265
newEntry = BlobEntry(
266266
entry; # and kwargs to override new values
267-
blobstore = blobstore.key,
267+
blobstore = getLabel(blobstore),
268268
hash = string(bytes2hex(hashfunction(blob))),
269269
origin = buildSourceString(dfg, label),
270270
_version = string(_getDFGVersion()),

src/Deprecated.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export DFGSummary
3939
DFGSummary(args) = error("DFGSummary is deprecated")
4040
@deprecate getSummary(dfg::AbstractDFG) getSummaryGraph(dfg)
4141

42+
@deprecate getKey(store::AbstractBlobStore) getLabel(store)
43+
4244
##------------------------------------------------------------------------------
4345
## smallData
4446
##------------------------------------------------------------------------------

src/GraphsDFG/services/GraphsDFGSerialization.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ function packDFGMetadata(fg::GraphsDFG)
5353
blobStores = Dict{Symbol, FolderStore{Vector{UInt8}}}()
5454
foreach(values(fg.blobStores)) do store
5555
if store isa FolderStore{Vector{UInt8}}
56-
blobStores[store.key] = store
56+
blobStores[getLabel(store)] = store
5757
else
58-
@warn "BlobStore $(store.key) of type $(typeof(store)) is not supported yet and will not be saved"
58+
@warn "BlobStore $(getLabel(store)) of type $(typeof(store)) is not supported yet and will not be saved"
5959
end
6060
end
6161

src/services/AbstractDFG.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,16 +253,15 @@ function listModelBlobEntries end
253253
##==============================================================================
254254
## AbstractBlobStore CRUD
255255
##==============================================================================
256-
# AbstractBlobStore should have key or overwrite getKey
257-
getKey(store::AbstractBlobStore) = store.key
256+
# AbstractBlobStore should have label or overwrite getLabel
258257

259258
getBlobStores(dfg::AbstractDFG) = dfg.blobStores
260259
getBlobStore(dfg::AbstractDFG, key::Symbol) = dfg.blobStores[key]
261260
function addBlobStore!(dfg::AbstractDFG, bs::AbstractBlobStore)
262-
return push!(dfg.blobStores, getKey(bs) => bs)
261+
return push!(dfg.blobStores, getLabel(bs) => bs)
263262
end
264263
function updateBlobStore!(dfg::AbstractDFG, bs::AbstractBlobStore)
265-
return push!(dfg.blobStores, getKey(bs) => bs)
264+
return push!(dfg.blobStores, getLabel(bs) => bs)
266265
end
267266
deleteBlobStore!(dfg::AbstractDFG, key::Symbol) = pop!(dfg.blobStores, key)
268267
emptyBlobStore!(dfg::AbstractDFG) = empty!(dfg.blobStores)

src/services/DFGFactor.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Notes
3030
"""
3131
getFactorType(data::GenericFunctionNodeData) = data.fnc.usrfnc!
3232
getFactorType(fct::FactorCompute) = getFactorType(getSolverData(fct))
33+
getFactorType(f::FactorDFG) = getTypeFromSerializationModule(f.fnctype)() # TODO find a better way to do this that does not rely on empty constructor
3334
getFactorType(dfg::AbstractDFG, lbl::Symbol) = getFactorType(getFactor(dfg, lbl))
3435

3536
"""
@@ -150,7 +151,7 @@ getVariableOrder(dfg::AbstractDFG, fct::Symbol) = getVariableOrder(getFactor(dfg
150151
151152
Retrieve solver data structure stored in a factor.
152153
"""
153-
function getSolverData(f::F) where {F <: FactorCompute}
154+
function getSolverData(f::FactorCompute)
154155
return f.solverData
155156
end
156157

test/consol_DataEntryBlobTests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ deleteData!(dfg, :x2, :random)
122122
#test default folder store
123123
dfs = FolderStore("/tmp/defaultfolderstore")
124124
@test dfs.folder == "/tmp/defaultfolderstore"
125-
@test dfs.key == :default_folder_store
125+
@test getLabel(dfs) == :default_folder_store
126126
@test dfs isa FolderStore{Vector{UInt8}}
127127

128128
##==============================================================================

test/testBlocks.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,14 +1115,14 @@ function blobsStoresTestBlock!(fg)
11151115
# Adding
11161116
addBlobStore!(fg, fs)
11171117
# Listing
1118-
@test listBlobStores(fg) == [fs.key]
1118+
@test listBlobStores(fg) == [fs.label]
11191119
# Getting
1120-
@test getBlobStore(fg, fs.key) == fs
1120+
@test getBlobStore(fg, fs.label) == fs
11211121
# Deleting
1122-
@test deleteBlobStore!(fg, fs.key) == fs
1122+
@test deleteBlobStore!(fg, fs.label) == fs
11231123
# Updating
11241124
updateBlobStore!(fg, fs)
1125-
@test listBlobStores(fg) == [fs.key]
1125+
@test listBlobStores(fg) == [fs.label]
11261126
# Emptying
11271127
emptyBlobStore!(fg)
11281128
@test listBlobStores(fg) == []
@@ -1132,7 +1132,7 @@ function blobsStoresTestBlock!(fg)
11321132
# Data functions
11331133
testData = rand(UInt8, 50)
11341134
# Adding
1135-
newData = addData!(fg, fs.key, :a, :testing, testData) # convenience wrapper over addBlob!
1135+
newData = addData!(fg, fs.label, :a, :testing, testData) # convenience wrapper over addBlob!
11361136
# Listing
11371137
@test :testing in listBlobEntries(fg, :a)
11381138
# Getting
@@ -1154,7 +1154,7 @@ function blobsStoresTestBlock!(fg)
11541154
@test updateData[1].hash != data[1].hash
11551155
@test updateData[2] != data[2]
11561156
@show bllb = DistributedFactorGraphs.incrDataLabelSuffix(fg, :a, :testing)
1157-
newData2 = addData!(fg, fs.key, :a, bllb, testData) # convenience wrapper over addBlob!
1157+
newData2 = addData!(fg, fs.label, :a, bllb, testData) # convenience wrapper over addBlob!
11581158
nbe = listBlobEntries(fg, :a)
11591159
filter!(s -> occursin(r"testing", string(s)), nbe)
11601160
@test 2 == length(nbe)

0 commit comments

Comments
 (0)