Skip to content

Commit

Permalink
v4 rewrite ~80% + some tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
josePereiro committed Nov 27, 2024
1 parent 0164cdc commit c9c8fd8
Show file tree
Hide file tree
Showing 15 changed files with 347 additions and 326 deletions.
1 change: 0 additions & 1 deletion _DEPRECATED/v4/src/0.Base/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ function _quoted_join(col, sep)
return join(strs, sep)
end


function _canonical_bytes(bytes)
bytes < 1024 && return (bytes, "bytes")
bytes /= 1024
Expand Down
44 changes: 10 additions & 34 deletions src/2.BloberiaBase/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,6 @@ Base.copy(B::Bloberia) = Bloberia(B.root)
# obj struct interface
bloberia(bo::Bloberia) = bo

# ## --.--. - .-. .- .--.-.- .- .---- ... . .-.-.-.-
# import Base.show
# function Base.show(io::IO, B::Bloberia)
# print(io, "Bloberia")
# _isdir = isdir(B.root)
# _pretty_print_pairs(io,
# "\n filesys",
# hasfilesys(B) ? B.root : ""
# )
# _pretty_print_pairs(io,
# "\n batch(es)",
# _isdir ? batchcount(B) : 0
# )
# _pretty_print_pairs(io,
# "\n blob(s)",
# _isdir ? vblobcount(B) : 0
# )
# val, unit = _isdir ? _canonical_bytes(filesize(B)) : (0.0, "bytes")
# _pretty_print_pairs(io,
# "\n disk usage",
# _isdir ? string(round(val; digits = 3), " ", unit) : 0.0
# )
# end

# ## --.--. - .-. .- .--.-.- .- .---- ... . .-.-.-.-
# # import Base.getindex
# # # uuid indexing
Expand All @@ -59,14 +35,14 @@ bloberia(bo::Bloberia) = bo
# # Base.getindex(B::Bloberia) = blob!(B, BLOBERIA_DEFAULT_RABLOB_ID) # random access blob!


# ## --.--. - .-. .- .--.-.- .- .---- ... . .-.-.-.-
# # Use, uuids
# function vblobcount(B::Bloberia, bbid_pt = nothing)
# count = 0
# bbs = eachbatch(B, bbid_pt)
# for bb in bbs
# count += vblobcount(bb)
# end
# return count
# end
## --.--. - .-. .- .--.-.- .- .---- ... . .-.-.-.-
# Use, uuids
function vblobcount(B::Bloberia, bbid_pt = nothing)
count = 0
bbs = eachbatch(B, bbid_pt)
for bb in bbs
count += vblobcount(bb)
end
return count
end

23 changes: 23 additions & 0 deletions src/2.BloberiaBase/show.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## --.--. - .-. .- .--.-.- .- .---- ... . .-.-.-.-
import Base.show
function Base.show(io::IO, B::Bloberia)
print(io, "Bloberia")
_isdir = isdir(B.root)
_pretty_print_pairs(io,
"\n filesys",
hasfilesys(B) ? B.root : ""
)
_pretty_print_pairs(io,
"\n batch(es)",
_isdir ? batchcount(B) : 0
)
_pretty_print_pairs(io,
"\n blob(s)",
_isdir ? vblobcount(B) : 0
)
val, unit = _isdir ? _canonical_bytes(filesize(B)) : (0.0, "bytes")
_pretty_print_pairs(io,
"\n disk usage",
_isdir ? string(round(val; digits = 3), " ", unit) : 0.0
)
end
111 changes: 27 additions & 84 deletions src/3.BlobBatchBase/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,96 +34,39 @@ function close!(bb::BlobBatch)
setindex!(getmeta(bb), false, "bb.isopen")
end

# ## --.--. - .-. .- .--.-.- .- .---- ... . .-.-.-.-
# function _bb_show_file_sortby(ph)
# name = basename(ph)
# name == "uuid.blobs.jls" && return "."
# name == "meta.jls" && return ".."
# return name
# end

# import Base.show
# function Base.show(io::IO, bb::BlobBatch)
# print(io, "BlobBatch(", repr(bb.uuid), ")")
# hasfilesys(bb) || return
# _pretty_print_pairs(io,
# "\n filesys",
# basename(batchpath(bb))
# )
# _pretty_print_pairs(io,
# "\n blob(s)",
# vblobcount(bb)
# )
# if !isempty(bb.frames)
# print(io, "\nRam frames: ")
# for (frame, _bb_frame) in bb.frames
# isempty(_bb_frame) && continue
# kT_pairs = Set()
# for (_, _b_frame) in _bb_frame
# for (key, val) in _b_frame
# push!(kT_pairs, string(key) => typeof(val))
# end
# end
# print(io, "\n \"", frame, "\" ")
# _kv_print_type(io, kT_pairs; _typeof = identity)
# end
# end

# if isdir(bb)
# _bb_filesize = 0.0
# print(io, "\nDisk frames: ")
# b_files = readdir(batchpath(bb); join = true)
# sort!(b_files; by = _bb_show_file_sortby)
# for path in b_files
# endswith(path, ".frame.jls") || continue
# _filesize = filesize(path)
# val, unit = _canonical_bytes(_filesize)
# print(io, "\n \"", basename(path), "\" ")
# print(io, "[")
# printstyled(io, string(round(val; digits = 3), " ", unit);
# color = :blue
# )
# print(io, "]")
# _bb_filesize += _filesize
# end
# val, unit = _canonical_bytes(_bb_filesize)
# print(io, "\ndisk usage: ")
# printstyled(io, string(round(val; digits = 3), " ", unit);
# color = :blue
# )
# end

# end

# ## --.--. - .-. .- .--.-.- .- .---- ... . .-.-.-.-
# # getindex

# import Base.getindex
# Base.getindex(bb::BlobBatch, uuid::UInt128) = blob(bb, uuid)
# Base.getindex(bb::BlobBatch, i::Int) = blob(bb, i)

# # isempty
# function Base.isempty(bb::BlobBatch)
# ondemand_loadvuuids!(bb)
# return isempty(bb.vuuids)
# end

# # isempty
# import Base.empty!
# function Base.empty!(bb::BlobBatch)
# empty!(bb.meta)
# empty!(bb.vuuids)
# empty!(bb.temp)
# empty!(bb.frames)
# return nothing
# end
# isempty (ram only)
function Base.isempty(bb::BlobBatch)
isempty(bb.vuuids) || return false
isempty(bb.dframes) || return false
isempty(bb.vframes) || return false
return true
end

# ## --.--. - .-. .- .--.-.- .- .---- ... . .-.-.-.-
# # Set the batch limit
# isempty (ram only)
import Base.empty!
function Base.empty!(bb::BlobBatch)
empty!(bb.meta)
empty!(bb.vuuids)
empty!(bb.temp)
empty!(bb.dframes)
empty!(bb.vframes)
return nothing
end

# function isfullbatch(bb::BlobBatch)
# B_lim = getmeta(bb.B, "batches.blobs.lim", typemax(Int))::Int
# bb_lim = getmeta(bb, "blobs.lim", typemax(Int))::Int
# lim = min(B_lim, bb_lim)
# return vblobcount(bb) >= lim
# end
## --.--. - .-. .- .--.-.- .- .---- ... . .-.-.-.-
# Set the batch vframes limit
function isfullbatch(bb::BlobBatch)
B_meta = getmeta(bb.B)
B_lim = get(B_meta, "config.batches.vblobs.lim", typemax(Int))::Int
bb_meta = getmeta(bb)
bb_lim = get(bb_meta, "config.vblobs.lim", typemax(Int))::Int
lim = min(B_lim, bb_lim)
return vblobcount(bb) >= lim
end
20 changes: 3 additions & 17 deletions src/3.BlobBatchBase/dblob.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
# # random blobs
# random blobs

# # return blob if exist in DISK
# function blob(B::Bloberia, id::String)
# rb = dBlob(B, id)
# path = rablobpath(rb)
# isdir(path) || error("dBlob(\"", id, "\") not found.")
# return rb
# end
# blob(B::Bloberia) = blob(B, BLOBERIA_DEFAULT_RABLOB_ID)

# # existing or new blob
# # in practice an unchecked blob
# function blob!(B::Bloberia, id::String)
# rb = dBlob(B, id)
# return rb
# end
# blob!(B::Bloberia) = blob!(B, BLOBERIA_DEFAULT_RABLOB_ID)
# return the only dblob
dblob(bb::BlobBatch) = dBlob(bb)
44 changes: 24 additions & 20 deletions src/3.BlobBatchBase/getframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,29 @@ function getdframe!(bb::BlobBatch, framekey::AbstractString)
return get!(OrderedDict, bb.dframes, framekey)
end

# ## --.--. - .-. .- .--.-.- .- .---- ... . .-.-.-.-
# # hasframe
# function hasframe_ram(bb::BlobBatch, frame)
# # check ram
# frame == "temp" && return true
# frame == "meta" && return true
# haskey(bb.frames, frame) && return true
# return false
# end
function getvuuids(bb::BlobBatch)
ondemand_loadvuuids!(bb)
return bb.vuuids
end

## --.--. - .-. .- .--.-.- .- .---- ... . .-.-.-.-
# hasframe
hasvframe_ram(bb::BlobBatch, frame) =
haskey(bb.vframes, frame)
hasdframe_ram(bb::BlobBatch, frame) =
haskey(bb.dframes, frame)
hasframe_ram(bb::BlobBatch, frame) =
hasvframe_ram(bb, frame) || hasdframe_ram(bb, frame)

# function hasframe_disk(bb::BlobBatch, frame)
# frame == "temp" && return false
# frame == "meta" && return isfile(meta_jlspath(bb))
# isfile(vframe_jlspath(bb, frame)) && return true
# return false
# end
hasvframe_disk(bb::BlobBatch, frame) =
isfile(vframe_jlspath(bb, frame))
hasdframe_disk(bb::BlobBatch, frame) =
isfile(dframe_jlspath(bb, frame))
hasframe_disk(bb::BlobBatch, frame) =
hasvframe_disk(bb, frame) || hasdframe_ram(bb, frame)

# function hasframe(bb::BlobBatch, frame)
# hasframe_ram(bb, frame) && return true
# hasframe_disk(bb, frame) && return true
# return false
# end
function hasframe(bb::BlobBatch, frame)
hasframe_ram(bb, frame) && return true
hasframe_disk(bb, frame) && return true
return false
end
66 changes: 34 additions & 32 deletions src/3.BlobBatchBase/iterator.jl
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
# ## --.--. - .-. .- .--.-.- .- .---- ... . .-.-.-.-
# function eachblob(bb::BlobBatch)
# return Channel{vBlob}(0) do _ch
# ondemand_loadvuuids!(bb)
# for uuid in bb.vuuids
# b = vBlob(bb, uuid) # I do not need to check if blob exist
# put!(_ch, b)
# end
# end
# end
# The blobbatch iterate accross the blobs

# ## --.--. - .-. .- .--.-.- .- .---- ... . .-.-.-.-
# # Iterator
# function _bb_iterate_next(ch::Channel, ch_next)
# isnothing(ch_next) && return nothing
# item, ch_state = ch_next
# bb_state = (ch, ch_state)
# return (item, bb_state)
# end
## --.--. - .-. .- .--.-.- .- .---- ... . .-.-.-.-
function eachblob(bb::BlobBatch)
return Channel{vBlob}(0) do _ch
vuuids = getvuuids(bb)
for uuid in vuuids
# I do not need to check if blob exist
b = vBlob(bb, uuid)
put!(_ch, b)
end
end
end

# import Base.iterate
# function Base.iterate(bb::BlobBatch)
# ch = eachblob(bb)
# ch_next = iterate(ch)
# return _bb_iterate_next(ch, ch_next)
# end
# --.--. - .-. .- .--.-.- .- .---- ... . .-.-.-.-
# Iterator
function _bb_iterate_next(ch::Channel, ch_next)
isnothing(ch_next) && return nothing
item, ch_state = ch_next
bb_state = (ch, ch_state)
return (item, bb_state)
end

# function Base.iterate(::BlobBatch, bb_state)
# isnothing(bb_state) && return nothing
# ch, ch_state = bb_state
# ch_next = iterate(ch, ch_state)
# return _bb_iterate_next(ch, ch_next)
# end
import Base.iterate
function Base.iterate(bb::BlobBatch)
ch = eachblob(bb)
ch_next = iterate(ch)
return _bb_iterate_next(ch, ch_next)
end

# import Base.length
# Base.length(bb::BlobBatch) = vblobcount(bb)
function Base.iterate(::BlobBatch, bb_state)
isnothing(bb_state) && return nothing
ch, ch_state = bb_state
ch_next = iterate(ch, ch_state)
return _bb_iterate_next(ch, ch_next)
end

import Base.length
Base.length(bb::BlobBatch) = vblobcount(bb)
Loading

0 comments on commit c9c8fd8

Please sign in to comment.