Skip to content

Commit c695311

Browse files
authored
Refactor DFG single agent to multiple agents and rename blobstore->storelabel and :default -> :primary (#1216)
1 parent eda3350 commit c695311

23 files changed

+431
-248
lines changed

src/DataBlobs/entities/BlobEntry.jl

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ A `Blobentry` is a small about of structured data that holds reference informati
88
can exist on different graph nodes spanning Agents and Factor Graphs which can all reference the same `Blob`.
99
1010
Notes:
11-
- `blobid`s should be unique within a blobstore and are immutable.
11+
- `blobid`s should be unique within a Blobstore and are immutable.
1212
"""
1313
StructUtils.@kwarg struct Blobentry
1414
""" Human friendly label of the `Blob` and also used as unique identifier per node on which a `Blobentry` is added. E.g. do "LEFTCAM_1", "LEFTCAM_2", ... of you need to repeat a label on the same variable. """
1515
label::Symbol
16-
""" The label of the `Blobstore` in which the `Blob` is stored. Default is `:default`."""
17-
blobstore::Symbol = :default
16+
""" The label of the `Blobstore` in which the `Blob` is stored. Default is `:primary`."""
17+
storelabel::Symbol = :primary
1818
""" Machine friendly and unique within a `Blobstore` identifier of the 'Blob'."""
1919
blobid::UUID = uuid4() # was blobId
2020
""" (Optional) crc32c hash value to ensure data consistency which must correspond to the stored hash upon retrieval."""
@@ -52,21 +52,21 @@ version(::Type{Blobentry}) = v"0.1.0"
5252

5353
function Blobentry(
5454
label::Symbol,
55-
blobstore = :default;
55+
storelabel = :primary;
5656
metadata::Union{JSONText, AbstractDict, NamedTuple} = JSONText("{}"),
5757
kwargs...,
5858
)
5959
if !(metadata isa JSONText)
6060
metadata = JSONText(JSON.json(metadata))
6161
end
62-
return Blobentry(; label, blobstore, metadata, kwargs...)
62+
return Blobentry(; label, storelabel, metadata, kwargs...)
6363
end
6464
# construction helper from existing Blobentry for user overriding via kwargs
6565
function Blobentry(
6666
entry::Blobentry;
6767
blobid::UUID = entry.blobid,
6868
label::Symbol = entry.label,
69-
blobstore::Symbol = entry.blobstore,
69+
storelabel::Symbol = entry.storelabel,
7070
crchash = entry.crchash,
7171
shahash = entry.shahash,
7272
size::Int64 = entry.size,
@@ -76,10 +76,15 @@ function Blobentry(
7676
metadata::JSONText = entry.metadata,
7777
timestamp::TimeDateZone = entry.timestamp,
7878
version = entry.version,
79+
blobstore = nothing, # TODO note deprecated in v0.29
7980
)
81+
!isnothing(blobstore) && Base.depwarn(
82+
"The `blobstore` keyword argument has been renamed to `storelabel`",
83+
:Blobentry,
84+
)
8085
return Blobentry(;
8186
label,
82-
blobstore,
87+
storelabel,
8388
blobid,
8489
crchash,
8590
shahash,

src/DataBlobs/entities/BlobStores.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
AbstractBlobstore{T}
33
4-
Abstract supertype for all blobstore implementations.
4+
Abstract supertype for all Blobstore implementations.
55
66
# Usage
77
@@ -16,9 +16,9 @@ The parameter `T` represents the type of blobs stored (e.g., `Vector{UInt8}` or
1616
See concrete implementations for details.
1717
1818
Design Notes
19-
- `blobid` is not considered unique across blobstores with different labels only within a single blobstore.
20-
- We cannot guarantee that `blobid` is unique across different blobstores with the same label and this is up to the end user.
21-
- Within a single blobstore `addBlob!` will fail if there is a UUID collision.
19+
- `blobid` is not considered unique across Blobstores with different labels only within a single Blobstore.
20+
- We cannot guarantee that `blobid` is unique across different Blobstores with the same label and this is up to the end user.
21+
- Within a single Blobstore `addBlob!` will fail if there is a UUID collision.
2222
- TODO: We should consider using uuid7 for `blobid`s (requires jl v1.12).
2323
- `Blobstrores`are identified by a `label::Symbol`, which allows for multiple blobstores to coexist in the same system.
2424

src/DataBlobs/services/BlobEntry.jl

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function Base.show(io::IO, ::MIME"text/plain", entry::Blobentry)
111111
println(io, "Blobentry {")
112112
println(io, " blobid: ", entry.blobid)
113113
println(io, " label: ", entry.label)
114-
println(io, " blobstore: ", entry.blobstore)
114+
println(io, " storelabel: ", entry.storelabel)
115115
println(io, " origin: ", entry.origin)
116116
println(io, " description: ", entry.description)
117117
println(io, " mimetype: ", entry.mimetype)
@@ -255,8 +255,12 @@ function addFactorBlobentries!(dfg::AbstractDFG, fLbl::Symbol, entries::Vector{B
255255
return entries
256256
end
257257

258-
function addAgentBlobentries!(dfg::AbstractDFG, entries::Vector{Blobentry})
259-
addAgentBlobentry!.(dfg, entries)
258+
function addAgentBlobentries!(
259+
dfg::AbstractDFG,
260+
agentlabel::Symbol,
261+
entries::Vector{Blobentry},
262+
)
263+
addAgentBlobentry!.(dfg, agentlabel, entries)
260264
return entries
261265
end
262266

@@ -277,8 +281,12 @@ function mergeFactorBlobentries!(dfg::AbstractDFG, fLbl::Symbol, entries::Vector
277281
mergeFactorBlobentry!.(dfg, fLbl, entries)
278282
return length(entries)
279283
end
280-
function mergeAgentBlobentries!(dfg::AbstractDFG, entries::Vector{Blobentry})
281-
mergeAgentBlobentry!.(dfg, entries)
284+
function mergeAgentBlobentries!(
285+
dfg::AbstractDFG,
286+
agentlabel::Symbol,
287+
entries::Vector{Blobentry},
288+
)
289+
mergeAgentBlobentry!.(dfg, agentlabel, entries)
282290
return length(entries)
283291
end
284292
function mergeGraphBlobentries!(dfg::AbstractDFG, entries::Vector{Blobentry})
@@ -308,9 +316,13 @@ function deleteFactorBlobentries!(
308316
return sum(cnts)
309317
end
310318

311-
function deleteAgentBlobentries!(dfg::AbstractDFG, labels::Vector{Symbol})
319+
function deleteAgentBlobentries!(
320+
dfg::AbstractDFG,
321+
agentlabel::Symbol,
322+
labels::Vector{Symbol},
323+
)
312324
cnts = map(labels) do label
313-
return deleteAgentBlobentry!(dfg, label)
325+
return deleteAgentBlobentry!(dfg, agentlabel, label)
314326
end
315327
return sum(cnts)
316328
end

src/DataBlobs/services/BlobStores.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
##==============================================================================
44

55
"""
6-
Get the data blob for the specified blobstore or dfg.
6+
Get the data blob for the specified Blobstore or DFG.
77
88
Related
99
[`getBlobentry`](@ref)
@@ -15,7 +15,7 @@ $(METHODLIST)
1515
function getBlob end
1616

1717
"""
18-
Adds a blob to the blob store or dfg with the blobid.
18+
Adds a blob to the Blobstore with the blobid.
1919
2020
Related
2121
[`addBlobentry!`](@ref)
@@ -53,9 +53,9 @@ function hasBlob end
5353
##==============================================================================
5454
## AbstractBlobstore derived CRUD for Blob
5555
##==============================================================================
56-
#TODO maybe we should generalize and move the cached blobstore to DFG.
56+
#TODO maybe we should generalize and move the cached Blobstore to DFG.
5757
function getBlob(dfg::AbstractDFG, entry::Blobentry)
58-
storeLabel = entry.blobstore
58+
storeLabel = entry.storelabel
5959
store = getBlobstore(dfg, storeLabel)
6060
return getBlob(store, entry.blobid)
6161
end
@@ -66,7 +66,7 @@ end
6666

6767
#add
6868
function addBlob!(dfg::AbstractDFG, entry::Blobentry, data)
69-
return addBlob!(getBlobstore(dfg, entry.blobstore), entry, data)
69+
return addBlob!(getBlobstore(dfg, entry.storelabel), entry, data)
7070
end
7171

7272
function addBlob!(store::AbstractBlobstore{T}, entry::Blobentry, data::T) where {T}
@@ -78,7 +78,7 @@ addBlob!(store::AbstractBlobstore, data) = addBlob!(store, uuid4(), data)
7878

7979
#delete
8080
function deleteBlob!(dfg::AbstractDFG, entry::Blobentry)
81-
return deleteBlob!(getBlobstore(dfg, entry.blobstore), entry)
81+
return deleteBlob!(getBlobstore(dfg, entry.storelabel), entry)
8282
end
8383

8484
function deleteBlob!(store::AbstractBlobstore, entry::Blobentry)
@@ -90,7 +90,7 @@ function hasBlob(store::AbstractBlobstore, entry::Blobentry)
9090
return hasBlob(store, entry.blobid)
9191
end
9292
function hasBlob(dfg::AbstractDFG, entry::Blobentry)
93-
return hasBlob(getBlobstore(dfg, entry.blobstore), entry.blobid)
93+
return hasBlob(getBlobstore(dfg, entry.storelabel), entry.blobid)
9494
end
9595

9696
#TODO
@@ -123,7 +123,7 @@ end
123123

124124
FolderStore(label::Symbol, folder::String) = FolderStore{Vector{UInt8}}(label, folder)
125125

126-
function FolderStore(foldername::String; label::Symbol = :default, createfolder = true)
126+
function FolderStore(foldername::String; label::Symbol = :primary, createfolder = true)
127127
storepath = expanduser(joinpath(foldername, string(label)))
128128
if createfolder && !isdir(storepath)
129129
@info "Folder '$storepath' doesn't exist - creating."
@@ -212,7 +212,7 @@ end
212212
function InMemoryBlobstore{T}(storeKey::Symbol) where {T}
213213
return InMemoryBlobstore{T}(storeKey, Dict{UUID, T}())
214214
end
215-
function InMemoryBlobstore(storeKey::Symbol = :default_inmemory_store)
215+
function InMemoryBlobstore(storeKey::Symbol = :primary)
216216
return InMemoryBlobstore{Vector{UInt8}}(storeKey)
217217
end
218218

src/DataBlobs/services/BlobWrappers.jl

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ function saveBlob_Variable!(
113113
variable_label::Symbol,
114114
blob::Vector{UInt8},
115115
entry_label::Symbol,
116-
blobstore::Symbol = :default;
116+
storelabel::Symbol = :primary;
117117
blobentry_kwargs...,
118118
)
119-
entry = Blobentry(entry_label, blobstore; blobentry_kwargs...)
119+
entry = Blobentry(entry_label, storelabel; blobentry_kwargs...)
120120
return saveBlob_Variable!(dfg, variable_label, blob, entry)
121121
end
122122

@@ -143,10 +143,10 @@ function saveBlob_Graph!(
143143
dfg::AbstractDFG,
144144
blob::Vector{UInt8},
145145
entry_label::Symbol,
146-
blobstore::Symbol = :default;
146+
storelabel::Symbol = :primary;
147147
blobentry_kwargs...,
148148
)
149-
entry = Blobentry(entry_label, blobstore; blobentry_kwargs...)
149+
entry = Blobentry(entry_label, storelabel; blobentry_kwargs...)
150150
return saveBlob_Graph!(dfg, blob, entry)
151151
end
152152

@@ -157,32 +157,38 @@ function deleteBlob_Graph!(dfg::AbstractDFG, entry_label::Symbol)
157157
return 2
158158
end
159159

160-
function loadBlob_Agent(dfg::AbstractDFG, entry_label::Symbol;)
161-
entry = getAgentBlobentry(dfg, entry_label)
160+
function loadBlob_Agent(dfg::AbstractDFG, agentlabel::Symbol, entry_label::Symbol;)
161+
entry = getAgentBlobentry(dfg, agentlabel, entry_label)
162162
blob = getBlob(dfg, entry)
163163
return entry, blob
164164
end
165165

166-
function saveBlob_Agent!(dfg::AbstractDFG, blob::Vector{UInt8}, entry::Blobentry)
167-
addAgentBlobentry!(dfg, entry)
166+
function saveBlob_Agent!(
167+
dfg::AbstractDFG,
168+
agentlabel::Symbol,
169+
blob::Vector{UInt8},
170+
entry::Blobentry,
171+
)
172+
addAgentBlobentry!(dfg, agentlabel, entry)
168173
addBlob!(dfg, entry, blob)
169174
return entry
170175
end
171176

172177
function saveBlob_Agent!(
173178
dfg::AbstractDFG,
179+
agentlabel::Symbol,
174180
blob::Vector{UInt8},
175181
entry_label::Symbol,
176-
blobstore::Symbol = :default;
182+
storelabel::Symbol = :primary;
177183
blobentry_kwargs...,
178184
)
179-
entry = Blobentry(entry_label, blobstore; blobentry_kwargs...)
180-
return saveBlob_Agent!(dfg, blob, entry)
185+
entry = Blobentry(entry_label, storelabel; blobentry_kwargs...)
186+
return saveBlob_Agent!(dfg, agentlabel, blob, entry)
181187
end
182188

183-
function deleteBlob_Agent!(dfg::AbstractDFG, entry_label::Symbol)
184-
entry = getAgentBlobentry(dfg, entry_label)
185-
deleteAgentBlobentry!(dfg, entry_label)
189+
function deleteBlob_Agent!(dfg::AbstractDFG, agentlabel::Symbol, entry_label::Symbol)
190+
entry = getAgentBlobentry(dfg, agentlabel, entry_label)
191+
deleteAgentBlobentry!(dfg, agentlabel, entry_label)
186192
deleteBlob!(dfg, entry)
187193
return 2
188194
end
@@ -209,10 +215,10 @@ function saveBlob_Factor!(
209215
factor_label::Symbol,
210216
blob::Vector{UInt8},
211217
entry_label::Symbol,
212-
blobstore::Symbol = :default;
218+
storelabel::Symbol = :primary;
213219
blobentry_kwargs...,
214220
)
215-
entry = Blobentry(entry_label, blobstore; blobentry_kwargs...)
221+
entry = Blobentry(entry_label, storelabel; blobentry_kwargs...)
216222
return saveBlob_Factor!(dfg, factor_label, blob, entry)
217223
end
218224

@@ -228,7 +234,7 @@ function saveImage_Variable!(
228234
variable_label::Symbol,
229235
img::AbstractMatrix,
230236
entry_label::Symbol,
231-
blobstore::Symbol = :default;
237+
storelabel::Symbol = :primary;
232238
entry_kwargs...,
233239
)
234240
mimetype = get(entry_kwargs, :mimeType, MIME("image/png"))
@@ -239,7 +245,7 @@ function saveImage_Variable!(
239245

240246
entry = Blobentry(
241247
entry_label,
242-
blobstore;
248+
storelabel;
243249
blobid = uuid4(),
244250
entry_kwargs...,
245251
size = length(blob),

src/Deprecated.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ function _getDuplicatedEmptyDFG(
117117
) where {P <: AbstractDFGParams, V <: AbstractGraphVariable, F <: AbstractGraphFactor}
118118
Base.depwarn("_getDuplicatedEmptyDFG is deprecated.", :_getDuplicatedEmptyDFG)
119119
newDfg = GraphsDFG{P, V, F}(;
120-
agentLabel = getAgentLabel(dfg),
120+
agents = deepcopy(dfg.agents),
121121
graphLabel = getGraphLabel(dfg),
122122
solverParams = deepcopy(dfg.solverParams),
123123
)
@@ -184,7 +184,9 @@ end
184184
# Function to generate source string - agentLabel|graphLabel|varLabel
185185
# """
186186
function buildSourceString(dfg::AbstractDFG, label::Symbol)
187-
return "$(getAgentLabel(dfg))|$(getGraphLabel(dfg))|$label"
187+
return error(
188+
"buildSourceString is deprecated. Use agents with `listAgents(dfg)` and `getAgent(dfg, agentlabel)` instead.",
189+
)
188190
end
189191

190192
getAgentMetadata(args...) = error("getAgentMetadata is obsolete, use Bloblets instead.")
@@ -572,7 +574,7 @@ function deepcopyGraph(
572574
destDFG = T(;
573575
solverParams = getSolverParams(sourceDFG),
574576
graph = sourceDFG.graph,
575-
agent = sourceDFG.agent,
577+
agents = deepcopy(sourceDFG.agents),
576578
graphLabel,
577579
)
578580
copyGraph!(

src/DistributedFactorGraphs.jl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -392,11 +392,16 @@ export loadDFG
392392
## Other utility functions
393393
##------------------------------------------------------------------------------
394394

395+
## Agent CRUD (now in AbstractDFG services)
396+
export addAgent!
397+
export deleteAgent!
398+
export listAgents
399+
export getAgent
400+
export hasAgent
401+
# export mergeAgent!
402+
# public refAgents
403+
395404
## TODO maybe move to DFG from SDK
396-
# addAgent!
397-
# deleteAgent!
398-
# listAgents
399-
# getAgents
400405
# addGraph!
401406
# deleteGraph!
402407
# listGraphs
@@ -445,7 +450,6 @@ const unstable_functions::Vector{Symbol} = [
445450
:findVariablesNearTimestamp,
446451
:findShortestPathDijkstra,
447452
:findFactorsBetweenNaive, # TODO not really used
448-
:getAgentLabel, #TODO check and mark as public
449453
:getGraphLabel, #TODO check and mark as public
450454
:getDescription,
451455
:getSolverParams,

0 commit comments

Comments
 (0)