Skip to content

Commit 337811e

Browse files
committed
fix
1 parent b07ebda commit 337811e

3 files changed

Lines changed: 30 additions & 62 deletions

File tree

‎src/paimon/core/catalog/snapshot_commit.cpp‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,44 @@
2020

2121
#include <memory>
2222
#include <optional>
23+
#include <string>
2324

25+
#include "fmt/format.h"
2426
#include "paimon/core/catalog/catalog_snapshot_commit.h"
2527
#include "paimon/core/catalog/renaming_snapshot_commit.h"
2628
#include "paimon/core/catalog/version_managed_catalog.h"
29+
#include "paimon/core/core_options.h"
30+
#include "paimon/defs.h"
2731
#include "paimon/result.h"
2832
#include "paimon/status.h"
2933

3034
namespace paimon {
3135

3236
Result<std::shared_ptr<SnapshotCommit>> SnapshotCommit::Create(
3337
const std::shared_ptr<Catalog>& catalog, const std::optional<Identifier>& catalog_identifier,
34-
const std::optional<std::string>& table_id, bool use_rest_catalog_commit,
38+
const CoreOptions& options, const std::optional<std::string>& table_id,
39+
const std::string& commit_user, bool use_rest_catalog_commit,
3540
const std::shared_ptr<FileSystem>& file_system,
3641
const std::shared_ptr<SnapshotManager>& snapshot_manager) {
3742
if (AsVersionManaged(catalog) != nullptr) {
3843
if (!catalog_identifier) {
3944
return Status::Invalid("a catalog commit requires a table identifier");
4045
}
41-
return std::shared_ptr<SnapshotCommit>(
42-
std::make_shared<CatalogSnapshotCommit>(catalog, catalog_identifier.value(), table_id));
46+
PAIMON_ASSIGN_OR_RAISE(
47+
std::unique_ptr<CommitLock> lock,
48+
AsVersionManaged(catalog)
49+
->CreateCommitLock(catalog_identifier.value(), table_id, commit_user, options));
50+
// Reuse the caller's UUID so table recreation cannot redirect this commit.
51+
return std::shared_ptr<SnapshotCommit>(std::make_shared<CatalogSnapshotCommit>(
52+
catalog, catalog_identifier.value(), table_id, std::move(lock)));
4353
}
4454
if (use_rest_catalog_commit) {
55+
if (options.RestCommitAcquireLock()) {
56+
return Status::Invalid(fmt::format(
57+
"'{}' needs a commit through a REST catalog with WithCatalog(); a commit table "
58+
"request built for the caller to send cannot hold a commit lease",
59+
Options::REST_COMMIT_ACQUIRE_LOCK));
60+
}
4561
return std::shared_ptr<SnapshotCommit>(std::make_shared<CatalogSnapshotCommit>(table_id));
4662
}
4763
if (table_id && catalog == nullptr) {

‎src/paimon/core/catalog/snapshot_commit.h‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
namespace paimon {
3232

3333
class Catalog;
34+
class CoreOptions;
3435
class FileSystem;
3536
class SnapshotManager;
3637

@@ -54,17 +55,19 @@ class SnapshotCommit {
5455
/// @param catalog The catalog the commit was handed, or null for one that has none.
5556
/// @param catalog_identifier The identifier the catalog knows the table by, on the branch the
5657
/// commit commits to. A version-managing catalog needs one and is refused without it.
58+
/// @param options Table options merged with the writer's dynamic options.
5759
/// @param table_id The catalog's UUID for the table, captured before the changes were
5860
/// prepared; null when there is none.
61+
/// @param commit_user The commit user of the snapshots published under a commit lock.
5962
/// @param use_rest_catalog_commit Whether the caller asks for the request rather than for the
6063
/// catalog to send it.
6164
/// @param file_system The file system the snapshot file is renamed through.
6265
/// @param snapshot_manager The manager that names the snapshot file renamed.
6366
static Result<std::shared_ptr<SnapshotCommit>> Create(
6467
const std::shared_ptr<Catalog>& catalog,
65-
const std::optional<Identifier>& catalog_identifier,
66-
const std::optional<std::string>& table_id, bool use_rest_catalog_commit,
67-
const std::shared_ptr<FileSystem>& file_system,
68+
const std::optional<Identifier>& catalog_identifier, const CoreOptions& options,
69+
const std::optional<std::string>& table_id, const std::string& commit_user,
70+
bool use_rest_catalog_commit, const std::shared_ptr<FileSystem>& file_system,
6871
const std::shared_ptr<SnapshotManager>& snapshot_manager);
6972

7073
/// @param base_snapshot_uuid Base snapshot UUID; null for an absent or legacy snapshot.

‎src/paimon/core/table/file_store_table.cpp‎

Lines changed: 5 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737
#include "paimon/common/utils/sensitive_config_utils.h"
3838
#include "paimon/common/utils/string_utils.h"
3939
#include "paimon/core/catalog/catalog_utils.h"
40-
#include "paimon/core/catalog/commit_lock.h"
41-
#include "paimon/core/catalog/renaming_snapshot_commit.h"
4240
#include "paimon/core/catalog/snapshot_commit.h"
4341
#include "paimon/core/catalog/version_managed_catalog.h"
4442
#include "paimon/core/core_options.h"
@@ -505,56 +503,6 @@ Result<std::unique_ptr<TableRead>> FileStoreTable::NewRead(
505503
std::move(fallback_table_read), arrow_pool);
506504
}
507505

508-
Result<std::unique_ptr<TableRead>> TableRead::Create(std::unique_ptr<ReadContext> ctx) {
509-
PAIMON_RETURN_NOT_OK(ContextUtils::CheckOperatorContext(ctx, "read"));
510-
PAIMON_ASSIGN_OR_RAISE(std::shared_ptr<Table> table, FileStoreTableFactory::Create(*ctx));
511-
return table->NewRead(std::move(ctx));
512-
}
513-
514-
namespace {
515-
516-
bool IsCatalogCommit(const CommitContext& ctx) {
517-
return AsVersionManaged(ctx.GetCatalog()) != nullptr;
518-
}
519-
520-
Result<std::shared_ptr<SnapshotCommit>> NewSnapshotCommit(
521-
const CommitContext& ctx, const std::optional<Identifier>& catalog_identifier,
522-
const CoreOptions& options, const std::shared_ptr<SnapshotManager>& snapshot_manager) {
523-
if (IsCatalogCommit(ctx)) {
524-
if (!catalog_identifier) {
525-
return Status::Invalid("a catalog commit requires a table identifier");
526-
}
527-
PAIMON_ASSIGN_OR_RAISE(std::unique_ptr<CommitLock> lock,
528-
AsVersionManaged(ctx.GetCatalog())
529-
->CreateCommitLock(catalog_identifier.value(), ctx.GetTableId(),
530-
ctx.GetCommitUser(), options));
531-
// Reuse the caller's UUID so table recreation cannot redirect this commit.
532-
return std::shared_ptr<SnapshotCommit>(std::make_shared<CatalogSnapshotCommit>(
533-
ctx.GetCatalog(), catalog_identifier.value(), ctx.GetTableId(), std::move(lock)));
534-
}
535-
if (ctx.UseRESTCatalogCommit()) {
536-
if (options.RestCommitAcquireLock()) {
537-
return Status::Invalid(fmt::format(
538-
"'{}' needs a commit through a REST catalog with WithCatalog(); a commit table "
539-
"request built for the caller to send cannot hold a commit lease",
540-
Options::REST_COMMIT_ACQUIRE_LOCK));
541-
}
542-
return std::shared_ptr<SnapshotCommit>(
543-
std::make_shared<CatalogSnapshotCommit>(ctx.GetTableId()));
544-
}
545-
// Catalogs without version management may still supply a table ID.
546-
if (ctx.GetTableId() && ctx.GetCatalog() == nullptr) {
547-
return Status::Invalid(
548-
"a commit which publishes the snapshot by writing it to the table directory sends no "
549-
"commit table request, so there is nowhere to put a table id; commit through a "
550-
"catalog with WithCatalog() or ask for the request with UseRESTCatalogCommit()");
551-
}
552-
return std::shared_ptr<SnapshotCommit>(
553-
std::make_shared<RenamingSnapshotCommit>(options.GetFileSystem(), snapshot_manager));
554-
}
555-
556-
} // namespace
557-
558506
Result<std::unique_ptr<FileStoreCommit>> FileStoreTable::NewCommit(
559507
std::unique_ptr<CommitContext> ctx) const {
560508
PAIMON_RETURN_NOT_OK(ContextUtils::CheckOperatorContext(ctx, "commit"));
@@ -642,10 +590,11 @@ Result<std::unique_ptr<FileStoreCommit>> FileStoreTable::NewCommit(
642590
NewCommitScanSupplier(snapshot_manager, manifest_list, manifest_file, arrow_schema, options,
643591
ctx->GetExecutor(), ctx->GetMemoryPool());
644592

645-
PAIMON_ASSIGN_OR_RAISE(std::shared_ptr<SnapshotCommit> snapshot_commit,
646-
SnapshotCommit::Create(ctx->GetCatalog(), catalog_identifier, options,
647-
ctx->GetTableId(), ctx->UseRESTCatalogCommit(),
648-
options.GetFileSystem(), snapshot_manager));
593+
PAIMON_ASSIGN_OR_RAISE(
594+
std::shared_ptr<SnapshotCommit> snapshot_commit,
595+
SnapshotCommit::Create(ctx->GetCatalog(), catalog_identifier, options, ctx->GetTableId(),
596+
ctx->GetCommitUser(), ctx->UseRESTCatalogCommit(),
597+
options.GetFileSystem(), snapshot_manager));
649598

650599
return std::make_unique<FileStoreCommitImpl>(
651600
ctx->GetMemoryPool(), ctx->GetExecutor(), arrow_schema, root_path_, ctx->GetCommitUser(),

0 commit comments

Comments
 (0)