Skip to content

Commit 32bc14f

Browse files
committed
fix helpers addData! and entry.originId
1 parent 5b25536 commit 32bc14f

File tree

6 files changed

+79
-59
lines changed

6 files changed

+79
-59
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ Listing news on any major breaking changes in DFG. For regular changes, see int
22

33
# v0.20
44

5+
- Change return type on `addData!` convenience wrappers to only return new `BlobEntry`.
6+
- Fix `addBlob!` calls for `FolderStore` and `InMemoryBlobStore` to use `BlobEntry.originId` and not previous bug `entry.id`.
57
- Close long running serialization redo (#590) using only JSON3.jl and StructTypes.jl going forward.
68
- Standardize BlobEntry=>Blob naming of functions, and keeping convenience wrappers `{get,add,update,delete}Data[!]`.
79
- Consolidate to only one `BlobEntry` definition, dropping use of `AbstractBlobEntry`.

attic/DataBlobs/FileDataEntryBlob.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ function addBlob!(dfg::AbstractDFG, entry::BlobEntry, data::Vector{UInt8})
4242
open(entryfilename(entry), "w") do f
4343
JSON.print(f, entry)
4444
end
45-
return getBlob(dfg, entry)::Vector{UInt8}
45+
# FIXME update for entry.blobId vs entry.originId
46+
return UUID(entry.id)
47+
# return getBlob(dfg, entry)::Vector{UInt8}
4648
end
4749
end
4850

@@ -72,7 +74,8 @@ end
7274
function addData!(::Type{BlobEntry}, dfg::AbstractDFG, label::Symbol, key::Symbol, folder::String, blob::Vector{UInt8}, timestamp=now(localzone());
7375
id::UUID = uuid4(), hashfunction = sha256)
7476
fde = BlobEntry(key, id, folder, bytes2hex(hashfunction(blob)), timestamp)
75-
de = addBlobEntry!(dfg, label, fde)
76-
db = addBlob!(dfg, fde, blob)
77-
return de=>db
77+
blobId = addBlob!(dfg, fde, blob) |> UUID
78+
newEntry = BlobEntry(fde; id=blobId, blobId)
79+
de = addBlobEntry!(dfg, label, newEntry)
80+
return de # de=>db
7881
end

src/DataBlobs/services/BlobStores.jl

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -165,30 +165,32 @@ function getBlob(store::FolderStore{T}, entry::BlobEntry) where T
165165
end
166166

167167
function addBlob!(store::FolderStore{T}, entry::BlobEntry, data::T) where T
168-
blobfilename = joinpath(store.folder,"$(entry.id).dat")
169-
entryfilename = joinpath(store.folder,"$(entry.id).json")
168+
blobfilename = joinpath(store.folder,"$(entry.originId).dat")
169+
entryfilename = joinpath(store.folder,"$(entry.originId).json")
170170
if isfile(blobfilename)
171-
error("Key '$(entry.id)' blob already exists.")
171+
error("Key '$(entry.originId)' blob already exists.")
172172
elseif isfile(entryfilename)
173-
error("Key '$(entry.id)' entry already exists, but no blob.")
173+
error("Key '$(entry.originId)' entry already exists, but no blob.")
174174
else
175175
open(blobfilename, "w") do f
176176
write(f, data)
177177
end
178178
open(entryfilename, "w") do f
179179
JSON3.write(f, entry)
180180
end
181-
return data
181+
# return data
182+
# FIXME update for entry.blobId vs. entry.originId
183+
return UUID(entry.originId)
182184
end
183185
end
184186

185187
function updateBlob!(store::FolderStore{T}, entry::BlobEntry, data::T) where T
186-
blobfilename = joinpath(store.folder,"$(entry.id).dat")
187-
entryfilename = joinpath(store.folder,"$(entry.id).json")
188+
blobfilename = joinpath(store.folder,"$(entry.originId).dat")
189+
entryfilename = joinpath(store.folder,"$(entry.originId).json")
188190
if !isfile(blobfilename)
189-
@warn "Key '$(entry.id)' doesn't exist."
191+
@warn "Key '$(entry.originId)' doesn't exist."
190192
elseif !isfile(entryfilename)
191-
@warn "Key '$(entry.id)' doesn't exist."
193+
@warn "Key '$(entry.originId)' doesn't exist."
192194
else
193195
open(blobfilename, "w") do f
194196
write(f, data)
@@ -228,19 +230,21 @@ function getBlob(store::InMemoryBlobStore{T}, entry::BlobEntry) where T
228230
end
229231

230232
function addBlob!(store::InMemoryBlobStore{T}, entry::BlobEntry, data::T) where T
231-
if haskey(store.blobs, entry.id)
232-
error("Key '$(entry.id)' blob already exists.")
233+
if haskey(store.blobs, entry.originId)
234+
error("Key '$(entry.originId)' blob already exists.")
233235
end
234-
return store.blobs[entry.id] = data
236+
# FIXME update for entry.originId vs .blobId
237+
store.blobs[entry.originId] = data
238+
return UUID(entry.originId)
235239
end
236240

237241
function updateBlob!(store::InMemoryBlobStore{T}, entry::BlobEntry, data::T) where T
238-
if haskey(store.blobs, entry.id)
239-
@warn "Key '$(entry.id)' doesn't exist."
242+
if haskey(store.blobs, entry.originId)
243+
@warn "Key '$(entry.originId)' doesn't exist."
240244
end
241-
return store.blobs[entry.id] = data
245+
return store.blobs[entry.originId] = data
242246
end
243247

244248
function deleteBlob!(store::InMemoryBlobStore{T}, entry::BlobEntry) where T
245-
return pop!(store.blobs, entry.id)
249+
return pop!(store.blobs, entry.originId)
246250
end

src/DataBlobs/services/HelpersDataWrapEntryBlob.jl

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -114,35 +114,43 @@ function addData!(
114114
entry::BlobEntry,
115115
blob::Vector{UInt8};
116116
hashfunction = sha256,
117-
checkhash::Bool=true
117+
checkhash::Bool=false
118118
)
119119
checkhash && assertHash(entry, blob, hashfunction=hashfunction)
120-
de = addBlobEntry!(dfg, label, entry)
121-
db = addBlob!(dfg, de, blob)
122-
return de=>db
120+
blobId = addBlob!(dfg, entry, blob) |> UUID
121+
newEntry = BlobEntry(entry; id=blobId, blobId) #, size=length(blob))
122+
addBlobEntry!(dfg, label, newEntry)
123123
end
124124

125-
function addData!(dfg::AbstractDFG, blobstore::AbstractBlobStore, label::Symbol, entry::BlobEntry, blob::Vector{UInt8}; hashfunction = sha256)
126-
assertHash(entry, blob; hashfunction)
127-
de = addBlobEntry!(dfg, label, entry)
128-
db = addBlob!(blobstore, de, blob)
129-
return de=>db
125+
function addData!(
126+
dfg::AbstractDFG,
127+
blobstore::AbstractBlobStore,
128+
label::Symbol,
129+
entry::BlobEntry,
130+
blob::Vector{UInt8};
131+
hashfunction = sha256,
132+
checkhash::Bool=false,
133+
)
134+
checkhash && assertHash(entry, blob; hashfunction)
135+
blobId = addBlob!(blobstore, entry, blob) |> UUID
136+
newEntry = BlobEntry(entry; id=blobId, blobId) #, size=length(blob))
137+
addBlobEntry!(dfg, label, newEntry)
130138
end
131139

132140

133141
addData!(
134142
dfg::AbstractDFG,
135143
blobstorekey::Symbol,
136-
label::Symbol,
137-
key::Symbol,
144+
vLbl::Symbol,
145+
bLbl::Symbol,
138146
blob::Vector{UInt8},
139147
timestamp=now(localzone());
140148
kwargs...
141149
) = addData!(
142150
dfg,
143151
getBlobStore(dfg, blobstorekey),
144-
label,
145-
key,
152+
vLbl,
153+
bLbl,
146154
blob,
147155
timestamp;
148156
kwargs...
@@ -151,31 +159,32 @@ addData!(
151159
function addData!(
152160
dfg::AbstractDFG,
153161
blobstore::AbstractBlobStore,
154-
label::Symbol,
155-
key::Symbol,
156-
blob::AbstractVector{UInt8},
162+
vLbl::Symbol,
163+
bLbl::Symbol,
164+
blob::Vector{UInt8},
157165
timestamp=now(localzone());
158166
description="",
159167
metadata = "",
160-
mimeType = "application/octet-stream",
161-
id::UUID = uuid4(),
168+
mimeType::String = "application/octet-stream",
169+
id::Union{UUID,Nothing} = nothing, #only assign if blobstore issued you an id
170+
originId::UUID = uuid4(),
162171
hashfunction = sha256
163172
)
164173
#
165-
@warn "ID's and origin IDs should be reconciled here."
174+
@warn "ID's and origin IDs should be reconciled here in DFG.addData!." maxlog=50
166175
entry = BlobEntry(;
167-
id = id,
168-
originId = id,
169-
label = key,
176+
id,
177+
originId,
178+
label = bLbl,
170179
blobstore = blobstore.key,
171-
hash = bytes2hex(hashfunction(blob)),
172-
origin = buildSourceString(dfg, label),
180+
hash = string(bytes2hex(hashfunction(blob))),
181+
origin = buildSourceString(dfg, vLbl),
173182
description = description,
174-
mimeType = mimeType,
183+
mimeType,
175184
metadata,
176-
timestamp = timestamp)
185+
timestamp)
177186

178-
addData!(dfg, blobstore, label, entry, blob; hashfunction)
187+
addData!(dfg, blobstore, vLbl, entry, blob; hashfunction)
179188
end
180189

181190

@@ -188,6 +197,7 @@ function updateData!(
188197
checkhash::Bool=true
189198
)
190199
checkhash && assertHash(entry, blob; hashfunction)
200+
# order of ops with unknown new blobId not tested
191201
de = updateBlobEntry!(dfg, label, entry)
192202
db = updateBlob!(dfg, de, blob)
193203
return de=>db
@@ -203,6 +213,7 @@ function updateData!(
203213
hashfunction = sha256
204214
)
205215
# Recalculate the hash - NOTE Assuming that this is going to be a BlobEntry. TBD.
216+
# order of operations with unknown new blobId not tested
206217
newEntry = BlobEntry(
207218
entry; # and kwargs to override new values
208219
blobstore = blobstore.key,

test/consol_DataEntryBlobTests.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ dataset2 = rand(UInt8, 1000)
9191
ds = FolderStore{Vector{UInt8}}(:filestore, "/tmp/dfgFolderStore")
9292
addBlobStore!(dfg, ds)
9393

94-
ade,adb = addData!(dfg, :filestore, :x1, :random, dataset1)
95-
_,_ = addData!(dfg, :filestore, :x1, :another_1, dataset1)
94+
ade = addData!(dfg, :filestore, :x1, :random, dataset1)
95+
_ = addData!(dfg, :filestore, :x1, :another_1, dataset1)
9696
_,_ = getData(dfg, :x1, "random")
9797
_,_ = getData(dfg, :x1, r"rando")
9898
gde,gdb = getData(dfg, :x1, :random)
@@ -108,13 +108,13 @@ dde,ddb = deleteData!(dfg, :x1, :random)
108108
_,_ = deleteData!(dfg, :x1, :another_1)
109109

110110
@test ade == gde == dde
111-
@test adb == gdb == ddb
111+
@test dataset1 == gdb == ddb
112112

113-
ade2,adb2 = addData!(dfg, :x2, deepcopy(ade), dataset1)
113+
ade2 = addData!(dfg, :x2, deepcopy(ade), dataset1)
114114
# ade3,adb3 = updateBlob!(dfg, :x2, deepcopy(ade), dataset1)
115115

116116
@test ade == ade2# == ade3
117-
@test adb == adb2# == adb3
117+
# @test adb == adb2# == adb3
118118

119119
deleteData!(dfg, :x2, :random)
120120

@@ -132,18 +132,18 @@ dfs = FolderStore("/tmp/defaultfolderstore")
132132
ds = InMemoryBlobStore()
133133
addBlobStore!(dfg, ds)
134134

135-
ade,adb = addData!(dfg, :default_inmemory_store, :x1, :random, dataset1)
135+
ade = addData!(dfg, :default_inmemory_store, :x1, :random, dataset1)
136136
gde,gdb = getData(dfg, :x1, :random)
137137
dde,ddb = deleteData!(dfg, :x1, :random)
138138

139139
@test ade == gde == dde
140-
@test adb == gdb == ddb
140+
@test dataset1 == gdb == ddb
141141

142-
ade2,adb2 = addData!(dfg, :x2, deepcopy(ade), dataset1)
142+
ade2 = addData!(dfg, :x2, deepcopy(ade), dataset1)
143143
# ade3,adb3 = updateBlob!(dfg, :x2, deepcopy(ade), dataset1)
144144

145145
@test ade == ade2# == ade3
146-
@test adb == adb2# == adb3
146+
# @test adb == adb2# == adb3
147147

148148
deleteData!(dfg, :x2, :random)
149149

test/testBlocks.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,10 +1050,10 @@ function blobsStoresTestBlock!(fg)
10501050
@test :testing in listBlobEntries(fg, :a)
10511051
# Getting
10521052
data = getData(fg, fs, :a, :testing) # convenience wrapper over getBlob
1053-
@test data[1].hash == newData[1].hash
1054-
@test data[2] == newData[2]
1053+
@test data[1].hash == newData.hash #[1]
1054+
# @test data[2] == newData[2]
10551055
# Updating
1056-
updateData = updateData!(fg, fs, :a, newData[1], rand(UInt8, 50)) # convenience wrapper around updateBlob!
1056+
updateData = updateData!(fg, fs, :a, newData, rand(UInt8, 50)) # convenience wrapper around updateBlob!
10571057
@test updateData[1].hash != data[1].hash
10581058
@test updateData[2] != data[2]
10591059
# Deleting

0 commit comments

Comments
 (0)