Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add global metadata lock to ensure thread safety of global metadata #183

Merged
merged 2 commits into from
Apr 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Arrow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ function __init__()
CodecLz4.TranscodingStreams.initialize(lz4)
push!(LZ4_FRAME_COMPRESSOR, lz4)
end
OBJ_METADATA_LOCK[] = ReentrantLock()
return
end

Expand Down
7 changes: 5 additions & 2 deletions src/write.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}}()

"""
Expand All @@ -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

Expand All @@ -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

Expand Down