File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2020#include " iceberg/inspect/files_table.h"
2121
2222#include < memory>
23+ #include < mutex>
2324#include < utility>
2425
2526#include " iceberg/inspect/metadata_scan_util_internal.h"
@@ -37,7 +38,10 @@ FilesTable::FilesTable(std::shared_ptr<const Table> table)
3738
3839FilesTable::~FilesTable () = default ;
3940
40- std::shared_ptr<Schema> FilesTable::schema () const { return schema_.load (); }
41+ std::shared_ptr<Schema> FilesTable::schema () const {
42+ std::lock_guard lock (schema_mutex_);
43+ return schema_;
44+ }
4145
4246Result<std::unique_ptr<FilesTable>> FilesTable::Make (std::shared_ptr<const Table> table) {
4347 ICEBERG_PRECHECK (table != nullptr , " Table cannot be null" );
@@ -52,7 +56,10 @@ Result<std::shared_ptr<Schema>> FilesTable::SchemaForScan(
5256 ICEBERG_ASSIGN_OR_RAISE (auto partition_type, internal::UnifiedPartitionType (metadata));
5357 ICEBERG_ASSIGN_OR_RAISE (auto schema,
5458 internal::FilesTableSchema (*table_schema, partition_type));
55- schema_.store (schema);
59+ {
60+ std::lock_guard lock (schema_mutex_);
61+ schema_ = schema;
62+ }
5663 return schema;
5764}
5865
Original file line number Diff line number Diff line change 2222// / \file iceberg/inspect/files_table.h
2323// / \brief Define the files metadata table.
2424
25- #include < atomic>
2625#include < memory>
26+ #include < mutex>
2727
2828#include " iceberg/arrow_c_data.h"
2929#include " iceberg/iceberg_export.h"
@@ -62,7 +62,8 @@ class ICEBERG_EXPORT FilesTable : public MetadataTable {
6262
6363 explicit FilesTable (std::shared_ptr<const Table> table);
6464
65- mutable std::atomic<std::shared_ptr<Schema>> schema_;
65+ mutable std::mutex schema_mutex_;
66+ mutable std::shared_ptr<Schema> schema_;
6667};
6768
6869} // namespace iceberg
Original file line number Diff line number Diff line change 2424#include < cstddef>
2525#include < cstdint>
2626#include < memory>
27+ #include < mutex>
2728#include < optional>
2829#include < ranges>
2930#include < unordered_map>
@@ -213,7 +214,10 @@ PartitionsTable::PartitionsTable(std::shared_ptr<const Table> table)
213214
214215PartitionsTable::~PartitionsTable () = default ;
215216
216- std::shared_ptr<Schema> PartitionsTable::schema () const { return schema_.load (); }
217+ std::shared_ptr<Schema> PartitionsTable::schema () const {
218+ std::lock_guard lock (schema_mutex_);
219+ return schema_;
220+ }
217221
218222Result<std::unique_ptr<PartitionsTable>> PartitionsTable::Make (
219223 std::shared_ptr<const Table> table) {
@@ -254,7 +258,10 @@ Result<std::shared_ptr<Schema>> PartitionsTable::SchemaForScan(
254258 " last_updated_snapshot_id" , int64 ()));
255259
256260 auto schema = std::make_shared<Schema>(std::move (fields));
257- schema_.store (schema);
261+ {
262+ std::lock_guard lock (schema_mutex_);
263+ schema_ = schema;
264+ }
258265 return schema;
259266}
260267
@@ -303,7 +310,7 @@ Result<ArrowArrayStream> PartitionsTable::ReadRows(
303310 auto file_snapshot = context.table_metadata ->SnapshotById (*live_file.snapshot_id );
304311 if (!file_snapshot.has_value () &&
305312 file_snapshot.error ().kind != ErrorKind::kNotFound ) {
306- return std:: unexpected<Error>(file_snapshot.error ());
313+ return unexpected<Error>(file_snapshot.error ());
307314 }
308315 snapshot_iter =
309316 snapshots.emplace (*live_file.snapshot_id , file_snapshot.value_or (nullptr ))
Original file line number Diff line number Diff line change 2222// / \file iceberg/inspect/partitions_table.h
2323// / \brief Define the partitions metadata table.
2424
25- #include < atomic>
2625#include < memory>
26+ #include < mutex>
2727
2828#include " iceberg/arrow_c_data.h"
2929#include " iceberg/iceberg_export.h"
@@ -63,7 +63,8 @@ class ICEBERG_EXPORT PartitionsTable : public MetadataTable {
6363
6464 explicit PartitionsTable (std::shared_ptr<const Table> table);
6565
66- mutable std::atomic<std::shared_ptr<Schema>> schema_;
66+ mutable std::mutex schema_mutex_;
67+ mutable std::shared_ptr<Schema> schema_;
6768};
6869
6970} // namespace iceberg
You can’t perform that action at this time.
0 commit comments