Skip to content

Commit 1b6116f

Browse files
authored
deprecate getBlobentryFirst -> getfirstBlobentry, fix blobId bugs, update folderstore, and remove some exports (#1144)
* deprecate getBlobentryFirst -> getfirstBlobentry, fix blobId bugs, update folderstore, and remove some exports * fix mergeVairableState! bug
1 parent 993e9b6 commit 1b6116f

16 files changed

+95
-85
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ Listing news on any major breaking changes in DFG. For regular changes, see int
1919
- Deprecate listVariableSolverData -> listVariableStates
2020
- Deprecate getVariableSolverDataAll -> getVariableStates
2121
- Deprecate getSolverData -> getVariableState/getFactorState
22+
- Deprecate getBlobentryFirst -> getfirstBlobentry, see #1114
23+
- OrderedDict is no longer exported
24+
- FolderStore path now includes the store label.
2225

2326
# v0.26
2427
- Graph structure plotting now uses GraphMakie.jl instead of GraphPlot.jl. Update by replacing `using GraphPlot` with `using GraphMakie`.

Project.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
2121
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
2222
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
2323
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
24-
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
2524
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
2625
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
2726
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
@@ -64,7 +63,6 @@ Pkg = "1.4, 1.5"
6463
ProgressMeter = "1"
6564
Random = "1.10"
6665
RecursiveArrayTools = "2, 3"
67-
Reexport = "1"
6866
SHA = "0.7, 1"
6967
SparseArrays = "1.10"
7068
StaticArrays = "1"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
Click on badges to follow links:
44

5-
| Release v0.25 | Dev | Coverage | Documentation |
5+
| Release v0.26 | Dev | Coverage | Documentation |
66
|---------------|-----|----------|---------------|
77
| [![CI][dfg-ci-stb-img]][dfg-ci-stb-url] | [![CI][dfg-ci-dev-img]][dfg-ci-dev-url] <br> [![Average time to resolve an issue](https://isitmaintained.com/badge/resolution/JuliaRobotics/DistributedFactorGraphs.jl.svg)](https://github.com/JuliaRobotics/DistributedFactorGraphs.jl/issues) | [![codecov.io][dfg-cov-img]][dfg-cov-url] <br> [![Percentage of issues still open](https://isitmaintained.com/badge/open/JuliaRobotics/DistributedFactorGraphs.jl.svg)](https://github.com/JuliaRobotics/DistributedFactorGraphs.jl/issues) | [![docs](https://img.shields.io/badge/DFGDocs-latest-blue.svg)](http://juliarobotics.github.io/DistributedFactorGraphs.jl/latest/) <br> [![docs](https://img.shields.io/badge/CaesarDocs-latest-blue.svg)](http://juliarobotics.github.io/Caesar.jl/latest/)
88

99
[dfg-ci-dev-img]: https://github.com/JuliaRobotics/DistributedFactorGraphs.jl/actions/workflows/ci.yml/badge.svg
1010
[dfg-ci-dev-url]: https://github.com/JuliaRobotics/DistributedFactorGraphs.jl/actions/workflows/ci.yml
11-
[dfg-ci-stb-img]: https://github.com/JuliaRobotics/DistributedFactorGraphs.jl/actions/workflows/ci.yml/badge.svg?branch=release%2Fv0.25
11+
[dfg-ci-stb-img]: https://github.com/JuliaRobotics/DistributedFactorGraphs.jl/actions/workflows/ci.yml/badge.svg?branch=release%2Fv0.26
1212
[dfg-ci-stb-url]: https://github.com/JuliaRobotics/DistributedFactorGraphs.jl/actions/workflows/ci.yml
1313
[dfg-cov-img]: https://codecov.io/github/JuliaRobotics/DistributedFactorGraphs.jl/coverage.svg?branch=develop
1414
[dfg-cov-url]: https://codecov.io/github/JuliaRobotics/DistributedFactorGraphs.jl?branch=develop

src/DataBlobs/entities/BlobEntry.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Base.@kwdef struct Blobentry
1717
id::Union{UUID, Nothing} = nothing
1818
""" Machine friendly and globally unique identifier of the 'Blob', usually assigned from a common point in the system. This can be used to guarantee unique retrieval of the large data blob. """
1919
blobId::Union{UUID, Nothing} = uuid4() #Deprecated in v0.25 TODO remove union, blobId is mandatory
20-
""" Machine friendly and locally assigned identifier of the 'Blob'. `.originId`s are mandatory upon first creation at the origin regardless of network access. Separate from `.blobId` since some architectures do not allow edge processes to assign a uuid4 to data store elements. """
20+
""" TBD if Deprecated. Machine friendly and locally assigned identifier of the 'Blob'."""
2121
originId::Union{UUID, Nothing} = blobId #Deprecated in v0.25 TODO remove union or remove originId completely
2222
""" 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. """
2323
label::Symbol

src/DataBlobs/services/BlobEntry.jl

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ function Base.show(io::IO, ::MIME"text/plain", entry::Blobentry)
4444
println(io, "Blobentry {")
4545
println(io, " id: ", entry.id)
4646
println(io, " blobId: ", entry.blobId)
47-
println(io, " originId: ", entry.originId)
4847
println(io, " label: ", entry.label)
4948
println(io, " blobstore: ", entry.blobstore)
5049
println(io, " hash: ", entry.hash)
@@ -84,23 +83,26 @@ function getBlobentry(var::VariableDFG, key::Symbol)
8483
return var.blobEntries[findfirst(x -> x.label == key, var.blobEntries)]
8584
end
8685

87-
#TODO maybe rename to getBlobentryFirst
88-
function getBlobentry(var::AbstractDFGVariable, blobId::UUID)
86+
"""
87+
$(SIGNATURES)
88+
Finds and returns the first blob entry that matches the filter.
89+
90+
Also see: [`getBlobentry`](@ref)
91+
"""
92+
function getfirstBlobentry(var::AbstractDFGVariable, blobId::UUID)
8993
for (k, v) in var.dataDict
90-
if blobId in [v.originId, v.blobId]
94+
if blobId == v.blobId
9195
return v
9296
end
9397
end
9498
throw(KeyError("No blobEntry with blobId $(blobId) found in variable $(getLabel(var))"))
9599
end
96100

97-
"""
98-
$(SIGNATURES)
99-
Finds and returns the first blob entry that matches the regex.
101+
function getfirstBlobentry(dfg::AbstractDFG, label::Symbol, blobId::UUID)
102+
return getfirstBlobentry(getVariable(dfg, label), blobId)
103+
end
100104

101-
Also see: [`getBlobentry`](@ref)
102-
"""
103-
function getBlobentryFirst(var::AbstractDFGVariable, key::Regex)
105+
function getfirstBlobentry(var::AbstractDFGVariable, key::Regex)
104106
for (k, v) in var.dataDict
105107
if occursin(key, string(v.label))
106108
return v
@@ -113,15 +115,15 @@ function getBlobentryFirst(var::AbstractDFGVariable, key::Regex)
113115
)
114116
end
115117

116-
function getBlobentryFirst(var::VariableDFG, key::Regex)
118+
function getfirstBlobentry(var::VariableDFG, key::Regex)
117119
firstIdx = findfirst(x -> contains(string(x.label), key), var.blobEntries)
118120
if isnothing(firstIdx)
119121
throw(KeyError("$key"))
120122
end
121123
return var.blobEntries[firstIdx]
122124
end
123125

124-
function getBlobentryFirst(dfg::AbstractDFG, label::Symbol, key::Regex)
126+
function getfirstBlobentry(dfg::AbstractDFG, label::Symbol, key::Regex)
125127
els = listBlobentries(dfg, label)
126128
firstIdx = findfirst(contains(key), string.(els))
127129
isnothing(firstIdx) && throw(
@@ -136,13 +138,13 @@ end
136138
# verbNoun(dfg::VariableCompute, label::Symbol, args...; kwargs...) = verbNoun(getVariable(dfg, label), args...; kwargs...)
137139
# with something like:
138140
# getvariablemethod = [
139-
# :getBlobentryFirst,
141+
# :getfirstBlobentry,
140142
# ]
141143
# for met in methodstooverload
142144
# @eval DistributedFactorGraphs $met(dfg::AbstractDFG, label::Symbol, args...; kwargs...) = $met(getVariable(dfg, label), args...; kwargs...)
143145
# end
144146

145-
function getBlobentry(dfg::AbstractDFG, label::Symbol, key::Union{Symbol, UUID})
147+
function getBlobentry(dfg::AbstractDFG, label::Symbol, key::Symbol)
146148
return getBlobentry(getVariable(dfg, label), key)
147149
end
148150
# getBlobentry(dfg::AbstractDFG, label::Symbol, key::Symbol) = getBlobentry(getVariable(dfg, label), key)

src/DataBlobs/services/BlobStores.jl

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ end
8181
##==============================================================================
8282
## AbstractBlobstore derived CRUD for Blob
8383
##==============================================================================
84-
84+
#TODO looking in all the blobstores does not make sense since since there is a chance that the blobId is not unique across blobstores.
85+
# using the cached blobstore is the right way to go here.
8586
function getBlob(dfg::AbstractDFG, entry::Blobentry)
8687
stores = getBlobstores(dfg)
8788
storekeys = collect(keys(stores))
@@ -111,8 +112,7 @@ function getBlob(dfg::AbstractDFG, entry::Blobentry)
111112
end
112113

113114
function getBlob(store::AbstractBlobstore, entry::Blobentry)
114-
blobId = isnothing(entry.blobId) ? entry.originId : entry.blobId
115-
return getBlob(store, blobId)
115+
return getBlob(store, entry.blobId)
116116
end
117117

118118
#add
@@ -121,11 +121,10 @@ function addBlob!(dfg::AbstractDFG, entry::Blobentry, data)
121121
end
122122

123123
function addBlob!(store::AbstractBlobstore{T}, entry::Blobentry, data::T) where {T}
124-
blobId = isnothing(entry.blobId) ? entry.originId : entry.blobId
125-
return addBlob!(store, blobId, data)
124+
return addBlob!(store, entry.blobId, data)
126125
end
127126

128-
# also creates an originId as uuid4
127+
# also creates an blobId as uuid4
129128
addBlob!(store::AbstractBlobstore, data) = addBlob!(store, uuid4(), data)
130129

131130
#update
@@ -142,13 +141,15 @@ function deleteBlob!(dfg::AbstractDFG, entry::Blobentry)
142141
end
143142

144143
function deleteBlob!(store::AbstractBlobstore, entry::Blobentry)
145-
blobId = isnothing(entry.blobId) ? entry.originId : entry.blobId
146-
return deleteBlob!(store, blobId)
144+
return deleteBlob!(store, entry.blobId)
147145
end
148146

149147
#has
148+
function hasBlob(store::AbstractBlobstore, entry::Blobentry)
149+
return hasBlob(store, entry.blobId)
150+
end
150151
function hasBlob(dfg::AbstractDFG, entry::Blobentry)
151-
return hasBlob(getBlobstore(dfg, entry.blobstore), entry.originId)
152+
return hasBlob(getBlobstore(dfg, entry.blobstore), entry.blobId)
152153
end
153154

154155
#TODO
@@ -182,19 +183,22 @@ end
182183
#TODO added in v0.25 to avoid a breaking change in deserialization old DFGs, remove.
183184
StructTypes.StructType(::Type{<:FolderStore}) = StructTypes.OrderedStruct()
184185

185-
function FolderStore(foldername::String; label = :default_folder_store, createfolder = true)
186-
if createfolder && !isdir(foldername)
187-
@info "Folder '$foldername' doesn't exist - creating."
186+
function FolderStore(foldername::String; label::Symbol = :default, createfolder = true)
187+
storepath = joinpath(foldername, string(label))
188+
if createfolder && !isdir(storepath)
189+
@info "Folder '$storepath' doesn't exist - creating."
188190
# create new folder
189-
mkpath(foldername)
191+
mkpath(storepath)
190192
end
191193
return FolderStore{Vector{UInt8}}(label, foldername)
192194
end
193195

194-
blobfilename(store::FolderStore, blobId::UUID) = joinpath(store.folder, string(blobId))
196+
function blobfilename(store::FolderStore, blobId::UUID)
197+
return joinpath(store.folder, string(store.label), string(blobId))
198+
end
195199

196200
function getBlob(store::FolderStore{T}, blobId::UUID) where {T}
197-
blobfilename = joinpath(store.folder, string(blobId))
201+
blobfilename = joinpath(store.folder, string(store.label), string(blobId))
198202
if isfile(blobfilename)
199203
open(blobfilename) do f
200204
return read(f)
@@ -205,7 +209,7 @@ function getBlob(store::FolderStore{T}, blobId::UUID) where {T}
205209
end
206210

207211
function addBlob!(store::FolderStore{T}, blobId::UUID, data::T) where {T}
208-
blobfilename = joinpath(store.folder, string(blobId))
212+
blobfilename = joinpath(store.folder, string(store.label), string(blobId))
209213
if isfile(blobfilename)
210214
throw(KeyError("Key '$blobId' blob already exists."))
211215
else
@@ -218,7 +222,7 @@ function addBlob!(store::FolderStore{T}, blobId::UUID, data::T) where {T}
218222
end
219223

220224
function updateBlob!(store::FolderStore{T}, blobId::UUID, data::T) where {T}
221-
blobfilename = joinpath(store.folder, string(blobId))
225+
blobfilename = joinpath(store.folder, string(store.label), string(blobId))
222226
if !isfile(blobfilename)
223227
@warn "Key '$blobId' doesn't exist."
224228
else
@@ -230,18 +234,18 @@ function updateBlob!(store::FolderStore{T}, blobId::UUID, data::T) where {T}
230234
end
231235

232236
function deleteBlob!(store::FolderStore{T}, blobId::UUID) where {T}
233-
blobfilename = joinpath(store.folder, string(blobId))
237+
blobfilename = joinpath(store.folder, string(store.label), string(blobId))
234238
rm(blobfilename)
235239
return 1
236240
end
237241

238242
#hasBlob or existsBlob?
239243
function hasBlob(store::FolderStore, blobId::UUID)
240-
blobfilename = joinpath(store.folder, string(blobId))
244+
blobfilename = joinpath(store.folder, string(store.label), string(blobId))
241245
return isfile(blobfilename)
242246
end
243247

244-
hasBlob(store::FolderStore, entry::Blobentry) = hasBlob(store, entry.originId)
248+
hasBlob(store::FolderStore, entry::Blobentry) = hasBlob(store, entry.blobId)
245249

246250
listBlobs(store::FolderStore) = readdir(store.folder)
247251
##==============================================================================
@@ -319,7 +323,7 @@ function getBlob(store::LinkStore, blobId::UUID)
319323
end
320324

321325
function addBlob!(store::LinkStore, entry::Blobentry, linkfile::String)
322-
return addBlob!(store, entry.originId, nothing, linkfile::String)
326+
return addBlob!(store, entry.blobId, nothing, linkfile::String)
323327
end
324328

325329
function addBlob!(store::LinkStore, blobId::UUID, blob::Any, linkfile::String)

src/DataBlobs/services/HelpersDataWrapEntryBlob.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function getData(
8787
getlast::Bool = true,
8888
)
8989
_getblobentr(g, v, k) = getBlobentries(g, v, k)
90-
_getblobentr(g, v, k::UUID) = [getBlobentry(g, v, k);]
90+
_getblobentr(g, v, k::UUID) = [getfirstBlobentry(g, v, k);]
9191
de_ = _getblobentr(dfg, vlabel, key)
9292
lbls = (s -> s.label).(de_)
9393
idx = sortperm(lbls; rev = getlast)
@@ -181,8 +181,8 @@ function addData!(
181181
metadata = "",
182182
mimeType::String = "application/octet-stream",
183183
id::Union{UUID, Nothing} = nothing,
184-
blobId::Union{UUID, Nothing} = nothing, #only assign if blobstore issued you an id
185-
originId::UUID = uuid4(),
184+
blobId::UUID = uuid4(),
185+
originId::UUID = blobId,
186186
hashfunction = sha256,
187187
)
188188
#

src/Deprecated.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ const VariableNodeData = VariableState
6262
@deprecate listAgentBlobEntries(args...; kwargs...) listAgentBlobentries(args...; kwargs...)
6363
@deprecate hasBlobEntry(args...; kwargs...) hasBlobentry(args...; kwargs...)
6464
@deprecate getBlobEntry(args...; kwargs...) getBlobentry(args...; kwargs...)
65-
@deprecate getBlobEntryFirst(args...; kwargs...) getBlobentryFirst(args...; kwargs...)
65+
@deprecate getBlobEntryFirst(args...; kwargs...) getfirstBlobentry(args...; kwargs...)
66+
@deprecate getBlobentry(var::AbstractDFGVariable, blobId::UUID) getfirstBlobentry(
67+
var::AbstractDFGVariable,
68+
blobId::UUID,
69+
)
6670
@deprecate addBlobEntry!(args...; kwargs...) addBlobentry!(args...; kwargs...)
6771
@deprecate addBlobEntries!(args...; kwargs...) addBlobentries!(args...; kwargs...)
6872
@deprecate mergeBlobEntry!(args...; kwargs...) mergeBlobentry!(args...; kwargs...)

0 commit comments

Comments
 (0)