Skip to content
Permalink
Browse files
Add global metadata lock to ensure thread safety of global metadata (#…
…183)

* Add global metadata lock to ensure thread safety of global metadata
store

Follow up to #90, based on discussions in that issue.

* fix
  • Loading branch information
quinnj committed Apr 24, 2021
1 parent 8fca1e0 commit 8de2d7d0f58f42880af1a3b2be2c8cebb27a6915
Showing 2 changed files with 6 additions and 2 deletions.
@@ -106,6 +106,7 @@ function __init__()
CodecLz4.TranscodingStreams.initialize(lz4)
push!(LZ4_FRAME_COMPRESSOR, lz4)
end
OBJ_METADATA_LOCK[] = ReentrantLock()
return
end

@@ -14,6 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

const OBJ_METADATA_LOCK = Ref{ReentrantLock}()
const OBJ_METADATA = IdDict{Any, Dict{String, String}}()

"""
@@ -24,7 +25,9 @@ Metadata attached to a table or column will be serialized when written
as a stream or file.
"""
function setmetadata!(x, meta::Dict{String, String})
OBJ_METADATA[x] = meta
lock(OBJ_METADATA_LOCK[]) do
OBJ_METADATA[x] = meta
end
return
end

@@ -42,7 +45,7 @@ Note that this function's return value directly aliases `x`'s attached metadata
this function should preserve this behavior so that downstream callers can rely
on this behavior in generic code.
"""
getmetadata(x, default=nothing) = get(OBJ_METADATA, x, default)
getmetadata(x, default=nothing) = lock(() -> get(OBJ_METADATA, x, default), OBJ_METADATA_LOCK[])

const DEFAULT_MAX_DEPTH = 6

0 comments on commit 8de2d7d

Please sign in to comment.