From 250060a8e00a36a3f8ca24c4488e182404b38dc1 Mon Sep 17 00:00:00 2001 From: "lisizhuo.lsz" Date: Thu, 3 Dec 2026 16:45:13 +0800 Subject: [PATCH 1/2] feat(global-index): align global index external path options with Java --- docs/source/user_guide/clean.rst | 6 +- include/paimon/defs.h | 11 ++- src/paimon/common/defs.cpp | 1 + .../core/catalog/file_system_catalog.cpp | 5 ++ .../core/catalog/file_system_catalog_test.cpp | 48 +++++++++---- src/paimon/core/core_options.cpp | 30 +++++++- src/paimon/core/core_options.h | 1 + src/paimon/core/core_options_test.cpp | 72 +++++++++++++++++-- .../global_index_file_manager_test.cpp | 6 +- 9 files changed, 146 insertions(+), 34 deletions(-) diff --git a/docs/source/user_guide/clean.rst b/docs/source/user_guide/clean.rst index 5715c4b84..920b14d6d 100644 --- a/docs/source/user_guide/clean.rst +++ b/docs/source/user_guide/clean.rst @@ -41,8 +41,8 @@ Description - It runs as an independent task: construct a ``CleanContext`` and launch an ``OrphanFilesCleaner``. - It covers table-local index manifests and payloads as well as data files, - preserving files referenced by retained snapshots. It does not enumerate a - potentially shared ``global-index.external-path``. + preserving files referenced by retained snapshots. It does not enumerate + potentially shared ``global-index.external-path`` or ``global-index.external-paths`` roots. - Tables with tags or branches, or snapshots with a changelog manifest list, are rejected with ``NotImplemented``. Tag retention during snapshot expiration is supported separately, as described below. @@ -127,7 +127,7 @@ Description - Data files, index manifests and index payloads referenced by retained snapshots or current-branch tags are preserved. Retired index payloads are deleted before their index manifests, including payloads stored under - ``global-index.external-path``. + ``global-index.external-path`` or ``global-index.external-paths``. - Expiration on a branch other than main, or on a table with such a branch under ``branch/branch-``, is not supported: branches share the table's data files, so expiration returns ``NotImplemented`` before deleting anything. diff --git a/include/paimon/defs.h b/include/paimon/defs.h index 9b96d7220..887ec0348 100644 --- a/include/paimon/defs.h +++ b/include/paimon/defs.h @@ -633,10 +633,15 @@ struct PAIMON_EXPORT Options { /// "global-index.thread-num" - The maximum number of concurrent scanner for global index. No /// default value. By default is the number of processors available to the machine. static const char GLOBAL_INDEX_THREAD_NUM[]; - /// "global-index.external-path" - Comma-separated global index root directories. New files - /// and checkpoints use independent round robin. If not set, the global index - /// files will be stored under the index directory. + /// "global-index.external-path" - A single global index root URI, including literal commas. + /// Used when "global-index.external-paths" is absent. If neither option is set, global index + /// files are stored under the table index directory. static const char GLOBAL_INDEX_EXTERNAL_PATH[]; + /// "global-index.external-paths" - Comma-separated global index root directories. New files + /// and checkpoints use independent round robin. Takes precedence over + /// "global-index.external-path", including when empty; an empty value uses the table index + /// directory. + static const char GLOBAL_INDEX_EXTERNAL_PATHS[]; /// "global-index.search-mode" - Fallback search mode for global index queries, used when the /// search mode of the index family is not set: "fast", "full" or "detail". No default value. /// Paimon C++ reads it only for full-text search so far. diff --git a/src/paimon/common/defs.cpp b/src/paimon/common/defs.cpp index 9fef4fe1c..17f9f65d1 100644 --- a/src/paimon/common/defs.cpp +++ b/src/paimon/common/defs.cpp @@ -165,6 +165,7 @@ const char Options::BLOB_WRITE_NULL_ON_FETCH_FAILURE[] = "blob-write-null-on-fet const char Options::GLOBAL_INDEX_ENABLED[] = "global-index.enabled"; const char Options::GLOBAL_INDEX_THREAD_NUM[] = "global-index.thread-num"; const char Options::GLOBAL_INDEX_EXTERNAL_PATH[] = "global-index.external-path"; +const char Options::GLOBAL_INDEX_EXTERNAL_PATHS[] = "global-index.external-paths"; const char Options::GLOBAL_INDEX_SEARCH_MODE[] = "global-index.search-mode"; const char Options::FULL_TEXT_INDEX_SEARCH_MODE[] = "full-text-index.search-mode"; const char Options::SCALAR_INDEX_SEARCH_MODE[] = "scalar-index.search-mode"; diff --git a/src/paimon/core/catalog/file_system_catalog.cpp b/src/paimon/core/catalog/file_system_catalog.cpp index bb91ca88f..287acbd0d 100644 --- a/src/paimon/core/catalog/file_system_catalog.cpp +++ b/src/paimon/core/catalog/file_system_catalog.cpp @@ -461,6 +461,11 @@ Result> FileSystemCatalog::GetSchemaExternalPaths( for (const auto& path : index_external_paths) { external_paths_set.insert(path); } + PAIMON_ASSIGN_OR_RAISE(std::optional legacy_index_path, + core_options.CreateGlobalIndexExternalPath()); + if (legacy_index_path) { + external_paths_set.insert(legacy_index_path.value()); + } } return std::vector(external_paths_set.begin(), external_paths_set.end()); } diff --git a/src/paimon/core/catalog/file_system_catalog_test.cpp b/src/paimon/core/catalog/file_system_catalog_test.cpp index 10dd814dd..0046a6fed 100644 --- a/src/paimon/core/catalog/file_system_catalog_test.cpp +++ b/src/paimon/core/catalog/file_system_catalog_test.cpp @@ -1240,7 +1240,7 @@ TEST(FileSystemCatalogTest, TestDropTableWithGlobalIndexExternalPathsOnMainBranc FileSystemCatalog catalog(core_options.GetFileSystem(), dir->Str(), options); ASSERT_OK(catalog.CreateDatabase("test_db", options, /*ignore_if_exists=*/false)); - // Create external path directory for global index + // Create external directories for the global index path list. auto global_index_dir = UniqueTestDirectory::Create(); ASSERT_TRUE(global_index_dir); std::string global_index_path = global_index_dir->Str(); @@ -1249,7 +1249,7 @@ TEST(FileSystemCatalogTest, TestDropTableWithGlobalIndexExternalPathsOnMainBranc ASSERT_TRUE(second_index_dir); std::string second_index_path = "FILE://" + second_index_dir->Str(); - // Create a file in external path to simulate global index data + // Create a file in each external directory to simulate global index data. ASSERT_OK_AND_ASSIGN(auto fs, FileSystemFactory::Get("local", dir->Str(), {})); std::string index_file = PathUtil::JoinPath(global_index_path, "index-file.bin"); ASSERT_OK(fs->WriteFile(index_file, "index data", /*overwrite=*/true)); @@ -1260,7 +1260,7 @@ TEST(FileSystemCatalogTest, TestDropTableWithGlobalIndexExternalPathsOnMainBranc ASSERT_OK_AND_ASSIGN(bool index_file_exists, fs->Exists(index_file)); ASSERT_TRUE(index_file_exists); - // Create table with global index external path on main branch + // Create a table with both global index external path options on the main branch. arrow::FieldVector fields = { arrow::field("f0", arrow::int32()), arrow::field("f1", arrow::utf8()), @@ -1270,8 +1270,14 @@ TEST(FileSystemCatalogTest, TestDropTableWithGlobalIndexExternalPathsOnMainBranc ASSERT_TRUE(arrow::ExportSchema(typed_schema, &schema).ok()); std::map table_options = options; - table_options[Options::GLOBAL_INDEX_EXTERNAL_PATH] = + table_options[Options::GLOBAL_INDEX_EXTERNAL_PATHS] = global_index_path + "," + second_index_path; + // A legacy writer may have used the single root even with the newer list in the schema. + std::string legacy_path = PathUtil::JoinPath("FILE://" + dir->Str(), "legacy,index"); + std::string unrelated_path = PathUtil::JoinPath("FILE://" + dir->Str(), "legacy"); + ASSERT_OK(fs->WriteFile(PathUtil::JoinPath(legacy_path, "index.bin"), "legacy", false)); + ASSERT_OK(fs->WriteFile(PathUtil::JoinPath(unrelated_path, "keep.bin"), "keep", false)); + table_options[Options::GLOBAL_INDEX_EXTERNAL_PATH] = legacy_path; ASSERT_OK(catalog.CreateTable(Identifier("test_db", "tbl_global_index"), &schema, {}, {}, table_options, false)); @@ -1290,19 +1296,23 @@ TEST(FileSystemCatalogTest, TestDropTableWithGlobalIndexExternalPathsOnMainBranc catalog.TableExists(Identifier("test_db", "tbl_global_index"))); ASSERT_FALSE(table_exists); - // Verify global index external path is also cleaned up + // Verify all configured roots are removed and the unrelated directory is preserved. ASSERT_OK_AND_ASSIGN(bool global_index_exists, fs->Exists(global_index_path)); ASSERT_FALSE(global_index_exists); ASSERT_OK_AND_ASSIGN(global_index_exists, fs->Exists(second_index_path)); ASSERT_FALSE(global_index_exists); + ASSERT_OK_AND_ASSIGN(global_index_exists, fs->Exists(legacy_path)); + ASSERT_FALSE(global_index_exists); + ASSERT_OK_AND_ASSIGN(global_index_exists, fs->Exists(unrelated_path)); + ASSERT_TRUE(global_index_exists); ArrowSchemaRelease(&schema); } TEST(FileSystemCatalogTest, TestDropTableWithGlobalIndexExternalPathsOnBranch) { // Copy the real append_table_with_rt_branch.db test data, then patch the - // branch-rt schema-1 to include a GLOBAL_INDEX_EXTERNAL_PATH option. - // DropTable should discover and clean up that external path. + // branch-rt schema-1 to include both external index options. + // DropTable should discover and clean up all external paths. std::map options; options[Options::FILE_SYSTEM] = "local"; options[Options::FILE_FORMAT] = "orc"; @@ -1315,7 +1325,7 @@ TEST(FileSystemCatalogTest, TestDropTableWithGlobalIndexExternalPathsOnBranch) { std::string db_path = dir->Str() + "/test_db.db"; ASSERT_TRUE(TestUtil::CopyDirectory(test_data_path, db_path)); - // Create a temporary external directory that represents branch global index data + // Create external directories for the legacy root and the list root on the branch. auto branch_external_dir = UniqueTestDirectory::Create(); ASSERT_TRUE(branch_external_dir); std::string branch_external_path = branch_external_dir->Str(); @@ -1324,21 +1334,26 @@ TEST(FileSystemCatalogTest, TestDropTableWithGlobalIndexExternalPathsOnBranch) { ASSERT_OK_AND_ASSIGN(auto fs, FileSystemFactory::Get("local", dir->Str(), {})); ASSERT_OK(fs->WriteFile(PathUtil::JoinPath(branch_external_path, "index.bin"), "branch global index data", /*overwrite=*/true)); + std::string branch_list_path = "FILE://" + PathUtil::JoinPath(dir->Str(), "branch-list"); + ASSERT_OK(fs->WriteFile(PathUtil::JoinPath(branch_list_path, "index.bin"), + "branch list index data", /*overwrite=*/true)); - // Patch branch-rt/schema/schema-1: add GLOBAL_INDEX_EXTERNAL_PATH to options + // Patch branch-rt/schema/schema-1 with both global index external path options. std::string branch_schema_path = PathUtil::JoinPath(db_path, "append_table_with_rt_branch/branch/branch-rt/schema/schema-1"); std::string schema_content; ASSERT_OK(fs->ReadFile(branch_schema_path, &schema_content)); - // Insert the global index external path option into the JSON options block. + // Insert both global index external path options into the JSON options block. // Original: "file.format" : "orc" // Patched: "file.format" : "orc", - // "global-index.external-path" : "" + // "global-index.external-path" : "", + // "global-index.external-paths" : "" std::string search_str = R"("file.format" : "orc")"; std::string replace_str = R"("file.format" : "orc", "global-index.external-path" : ")" + - branch_external_path + R"(")"; + branch_external_path + R"(", "global-index.external-paths" : ")" + + branch_list_path + R"(")"; auto pos = schema_content.rfind(search_str); ASSERT_NE(pos, std::string::npos); schema_content.replace(pos, search_str.length(), replace_str); @@ -1360,9 +1375,11 @@ TEST(FileSystemCatalogTest, TestDropTableWithGlobalIndexExternalPathsOnBranch) { ASSERT_OK_AND_ASSIGN(table_exists, catalog.TableExists(identifier)); ASSERT_FALSE(table_exists); - // Verify the branch global index external path is cleaned up by DropTable + // Verify both branch global index external directories are cleaned up by DropTable. ASSERT_OK_AND_ASSIGN(external_exists, fs->Exists(branch_external_path)); ASSERT_FALSE(external_exists); + ASSERT_OK_AND_ASSIGN(external_exists, fs->Exists(branch_list_path)); + ASSERT_FALSE(external_exists); } TEST(FileSystemCatalogTest, TestListSnapshots) { @@ -1554,15 +1571,16 @@ TEST(FileSystemCatalogTest, TestDropTableWithBranchExternalPaths) { ASSERT_OK(fs->WriteFile(PathUtil::JoinPath(branch_external_path, "data.orc"), "branch external data", /*overwrite=*/true)); - // Patch branch-rt/schema/schema-1: add DATA_FILE_EXTERNAL_PATHS to options + // Patch branch-rt/schema/schema-1 with the external data path and its write strategy. std::string branch_schema_path = PathUtil::JoinPath(db_path, "append_table_with_rt_branch/branch/branch-rt/schema/schema-1"); std::string schema_content; ASSERT_OK(fs->ReadFile(branch_schema_path, &schema_content)); - // Insert the external path option into the JSON options block. + // Insert the external path and strategy options into the JSON options block. // Original: "file.format" : "orc" // Patched: "file.format" : "orc", + // "data-file.external-paths.strategy" : "round-robin", // "data-file.external-paths" : "" std::string search_str = R"("file.format" : "orc")"; std::string replace_str = R"("file.format" : "orc", diff --git a/src/paimon/core/core_options.cpp b/src/paimon/core/core_options.cpp index 3a87f6616..db87e1d26 100644 --- a/src/paimon/core/core_options.cpp +++ b/src/paimon/core/core_options.cpp @@ -407,6 +407,7 @@ struct CoreOptions::Impl { std::optional data_file_external_paths; std::optional data_file_external_paths_weights; std::optional changelog_file_compression; + std::optional global_index_external_path; std::optional global_index_external_paths; std::optional scan_tag_name; CompressOptions lookup_compress_options{"zstd", 1}; @@ -951,9 +952,12 @@ struct CoreOptions::Impl { // Parse global-index.filter.refine-from-data, default false PAIMON_RETURN_NOT_OK(parser.Parse(Options::GLOBAL_INDEX_FILTER_REFINE_FROM_DATA, &global_index_filter_refine_from_data)); - // Parse global-index.external-path - global index root directories + // Parse global-index.external-path, the legacy single external global index root directory PAIMON_RETURN_NOT_OK( - parser.Parse(Options::GLOBAL_INDEX_EXTERNAL_PATH, &global_index_external_paths)); + parser.Parse(Options::GLOBAL_INDEX_EXTERNAL_PATH, &global_index_external_path)); + // Parse global-index.external-paths, external global index root directories + PAIMON_RETURN_NOT_OK( + parser.Parse(Options::GLOBAL_INDEX_EXTERNAL_PATHS, &global_index_external_paths)); return Status::OK(); } @@ -1984,10 +1988,30 @@ std::optional CoreOptions::GetGlobalIndexExternalPaths() const { return impl_->global_index_external_paths; } +Result> CoreOptions::CreateGlobalIndexExternalPath() const { + if (!impl_->global_index_external_path || impl_->global_index_external_path->empty()) { + return std::optional(); + } + std::string value = impl_->global_index_external_path.value(); + StringUtils::Trim(&value); + PAIMON_ASSIGN_OR_RAISE(Path path, PathUtil::ToPath(value)); + if (path.scheme.empty()) { + return Status::Invalid(fmt::format("scheme is null, path is {}", value)); + } + return std::optional(path.ToString()); +} + Result> CoreOptions::CreateGlobalIndexExternalPaths() const { std::vector external_paths; std::optional global_index_external_paths = GetGlobalIndexExternalPaths(); - if (!global_index_external_paths || global_index_external_paths->empty()) { + if (!global_index_external_paths) { + PAIMON_ASSIGN_OR_RAISE(std::optional path, CreateGlobalIndexExternalPath()); + if (path) { + external_paths.push_back(path.value()); + } + return external_paths; + } + if (global_index_external_paths->empty()) { return external_paths; } for (auto tmp_path : StringUtils::Split(global_index_external_paths.value(), ",")) { diff --git a/src/paimon/core/core_options.h b/src/paimon/core/core_options.h index c478b2c1c..864e69419 100644 --- a/src/paimon/core/core_options.h +++ b/src/paimon/core/core_options.h @@ -278,6 +278,7 @@ class PAIMON_EXPORT CoreOptions { std::string FormatTableFileCompression() const; bool GlobalIndexEnabled() const; + Result> CreateGlobalIndexExternalPath() const; Result> CreateGlobalIndexExternalPaths() const; std::optional GetScanTagName() const; diff --git a/src/paimon/core/core_options_test.cpp b/src/paimon/core/core_options_test.cpp index c3b78a696..236c06674 100644 --- a/src/paimon/core/core_options_test.cpp +++ b/src/paimon/core/core_options_test.cpp @@ -497,8 +497,9 @@ TEST(CoreOptionsTest, TestFromMap) { ASSERT_FALSE(core_options.GlobalIndexEnabled()); ASSERT_TRUE(core_options.GlobalIndexFilterRefineFromData()); ASSERT_EQ(core_options.GetGlobalIndexThreadNum(), 4); - ASSERT_TRUE(core_options.GetGlobalIndexExternalPaths()); - ASSERT_EQ(core_options.GetGlobalIndexExternalPaths().value(), "FILE:///tmp/global_index/"); + ASSERT_OK_AND_ASSIGN(std::optional global_index_path, + core_options.CreateGlobalIndexExternalPath()); + ASSERT_EQ(global_index_path, "FILE:/tmp/global_index"); ASSERT_EQ("test-tag", core_options.GetScanTagName().value()); ASSERT_EQ(StartupMode::FromSnapshotFull(), core_options.GetStartupMode()); ASSERT_EQ(375809637, core_options.GetCompactionFileSize(/*has_primary_key=*/true)); @@ -900,27 +901,84 @@ TEST(CoreOptionsTest, TestCreateGlobalIndexExternalPaths) { } TEST(CoreOptionsTest, GlobalIndexExternalPathsList) { - for (const std::string value : {"FILE:///a, FILE:///b", ",FILE:///a,,FILE:///b,"}) { + for (const std::string value : + {"FILE:///a, FILE:///b", " FILE:///a/ , FILE:///b/ ", "FILE:///a,FILE:///b,", + "FILE:///a,FILE:///b,,", ",FILE:///a,FILE:///b", "FILE:///a,,FILE:///b", + ",FILE:///a,,FILE:///b,"}) { ASSERT_OK_AND_ASSIGN(CoreOptions options, - CoreOptions::FromMap({{Options::GLOBAL_INDEX_EXTERNAL_PATH, value}})); + CoreOptions::FromMap({{Options::GLOBAL_INDEX_EXTERNAL_PATHS, value}})); ASSERT_OK_AND_ASSIGN(std::vector paths, options.CreateGlobalIndexExternalPaths()); ASSERT_EQ(paths, std::vector({"FILE:/a", "FILE:/b"})); } - for (const std::string value : {",", " ", "FILE:///a,/b", "FILE:///a, ,FILE:///b"}) { + for (const std::string value : + {"FILE:///a", " FILE:///a/ ", ",FILE:///a", "FILE:///a,", ",,FILE:///a,,"}) { ASSERT_OK_AND_ASSIGN(CoreOptions options, - CoreOptions::FromMap({{Options::GLOBAL_INDEX_EXTERNAL_PATH, value}})); + CoreOptions::FromMap({{Options::GLOBAL_INDEX_EXTERNAL_PATHS, value}})); + ASSERT_OK_AND_ASSIGN(std::vector paths, + options.CreateGlobalIndexExternalPaths()); + ASSERT_EQ(paths, std::vector({"FILE:/a"})); + } + for (const std::string value : {",", ",,", " ", "a", " ,FILE:///a", "FILE:///a, ", + "FILE:///a,/b", "FILE:///a, ,FILE:///b"}) { + ASSERT_OK_AND_ASSIGN(CoreOptions options, + CoreOptions::FromMap({{Options::GLOBAL_INDEX_EXTERNAL_PATHS, value}})); ASSERT_NOK(options.CreateGlobalIndexExternalPaths()); } ASSERT_OK_AND_ASSIGN(CoreOptions options, CoreOptions::FromMap({})); ASSERT_OK_AND_ASSIGN(std::vector paths, options.CreateGlobalIndexExternalPaths()); ASSERT_TRUE(paths.empty()); ASSERT_OK_AND_ASSIGN(options, - CoreOptions::FromMap({{Options::GLOBAL_INDEX_EXTERNAL_PATH, ""}})); + CoreOptions::FromMap({{Options::GLOBAL_INDEX_EXTERNAL_PATHS, ""}})); ASSERT_OK_AND_ASSIGN(paths, options.CreateGlobalIndexExternalPaths()); ASSERT_TRUE(paths.empty()); } +TEST(CoreOptionsTest, LegacyGlobalIndexExternalPath) { + for (const auto& [value, expected] : + std::map{{"FILE:///a", "FILE:/a"}, + {" FILE:///a/ ", "FILE:/a"}, + {"FILE:///index,archive", "FILE:/index,archive"}, + {"FILE:///a,", "FILE:/a,"}, + {"FILE:///a,,", "FILE:/a,,"}}) { + ASSERT_OK_AND_ASSIGN(CoreOptions options, + CoreOptions::FromMap({{Options::GLOBAL_INDEX_EXTERNAL_PATH, value}})); + ASSERT_OK_AND_ASSIGN(std::optional path, + options.CreateGlobalIndexExternalPath()); + ASSERT_EQ(path, expected); + ASSERT_OK_AND_ASSIGN(std::vector paths, + options.CreateGlobalIndexExternalPaths()); + ASSERT_EQ(paths, std::vector({expected})); + } + for (const std::string value : {" ", "a", "/index", ",", ",,"}) { + ASSERT_OK_AND_ASSIGN(CoreOptions options, + CoreOptions::FromMap({{Options::GLOBAL_INDEX_EXTERNAL_PATH, value}})); + ASSERT_NOK(options.CreateGlobalIndexExternalPath()); + ASSERT_NOK(options.CreateGlobalIndexExternalPaths()); + } +} + +TEST(CoreOptionsTest, GlobalIndexExternalPathsPrecedence) { + for (const std::string legacy : {"FILE:///index,archive", "/invalid-legacy-root"}) { + std::map raw_options = { + {Options::GLOBAL_INDEX_EXTERNAL_PATH, legacy}, + {Options::GLOBAL_INDEX_EXTERNAL_PATHS, "FILE:///a,FILE:///b"}, + {Options::DATA_FILE_EXTERNAL_PATHS_STRATEGY, "round-robin"}, + {Options::DATA_FILE_EXTERNAL_PATHS_WEIGHTS, "1,99"}}; + ASSERT_OK_AND_ASSIGN(CoreOptions options, CoreOptions::FromMap(raw_options)); + ASSERT_OK_AND_ASSIGN(std::vector paths, + options.CreateGlobalIndexExternalPaths()); + ASSERT_EQ(paths, std::vector({"FILE:/a", "FILE:/b"})); + raw_options[Options::GLOBAL_INDEX_EXTERNAL_PATHS] = ""; + ASSERT_OK_AND_ASSIGN(options, CoreOptions::FromMap(raw_options)); + ASSERT_OK_AND_ASSIGN(paths, options.CreateGlobalIndexExternalPaths()); + ASSERT_TRUE(paths.empty()); + raw_options[Options::GLOBAL_INDEX_EXTERNAL_PATHS] = "FILE:///a,/b"; + ASSERT_OK_AND_ASSIGN(options, CoreOptions::FromMap(raw_options)); + ASSERT_NOK(options.CreateGlobalIndexExternalPaths()); + } +} + TEST(CoreOptionsTest, ExternalPathWeights) { for (const std::string value : {"1, 3", "1,3,", "+1,3,,", "1,,3", ",1,3", "1,,3,"}) { ASSERT_OK_AND_ASSIGN( diff --git a/src/paimon/core/global_index/global_index_file_manager_test.cpp b/src/paimon/core/global_index/global_index_file_manager_test.cpp index e40028cbf..3d1343123 100644 --- a/src/paimon/core/global_index/global_index_file_manager_test.cpp +++ b/src/paimon/core/global_index/global_index_file_manager_test.cpp @@ -345,7 +345,7 @@ TEST_F(GlobalIndexFileManagerTest, LatestCheckpointIgnoresDuplicateOlderIds) { TEST_F(GlobalIndexFileManagerTest, TaskCleanupVisitsAllRootsAfterAnError) { std::string root_a = "file:" + PathUtil::JoinPath(dir_->Str(), "a"); std::string root_b = "file:" + PathUtil::JoinPath(dir_->Str(), "b"); - ASSERT_OK(CreateSchema({{Options::GLOBAL_INDEX_EXTERNAL_PATH, root_a + "," + root_b}})); + ASSERT_OK(CreateSchema({{Options::GLOBAL_INDEX_EXTERNAL_PATHS, root_a + "," + root_b}})); std::string directory_a = PathUtil::JoinPath(root_a, "checkpoint/task-1"); std::string directory_b = PathUtil::JoinPath(root_b, "checkpoint/task-1"); ASSERT_OK(fs_->WriteFile(PathUtil::JoinPath(directory_a, "unfinished"), "x", false)); @@ -540,7 +540,7 @@ TEST_F(GlobalIndexFileManagerTest, TestDeleteExternalTaskCheckpointFromSchemaAnd ASSERT_OK(fs_->WriteFile(path, "retained", /*overwrite=*/false)); } std::map overrides = { - {Options::GLOBAL_INDEX_EXTERNAL_PATH, " " + override_path + "/ "}}; + {Options::GLOBAL_INDEX_EXTERNAL_PATHS, " " + override_path + "/ "}}; ASSERT_OK(GlobalIndexWriteTask::DeleteCheckpoint(dir_->Str(), "task-1", overrides, fs_)); ASSERT_OK_AND_ASSIGN(bool exists, fs_->Exists(override_directory)); ASSERT_FALSE(exists); @@ -563,7 +563,7 @@ TEST_F(GlobalIndexFileManagerTest, TestDeleteExternalTaskCheckpointFromSchemaAnd } ASSERT_OK(GlobalIndexWriteTask::DeleteCheckpoint( - dir_->Str(), "task-1", {{Options::GLOBAL_INDEX_EXTERNAL_PATH, ""}}, fs_)); + dir_->Str(), "task-1", {{Options::GLOBAL_INDEX_EXTERNAL_PATHS, ""}}, fs_)); ASSERT_OK_AND_ASSIGN(exists, fs_->Exists(local_directory)); ASSERT_FALSE(exists); } From 0d9bc5a44c07053427199e1e7031838fa88de25f Mon Sep 17 00:00:00 2001 From: "lisizhuo.lsz" Date: Fri, 4 Dec 2026 14:26:56 +0800 Subject: [PATCH 2/2] fix comment --- .../core/catalog/file_system_catalog.cpp | 5 -- .../core/catalog/file_system_catalog_test.cpp | 46 ++++++++++--------- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/paimon/core/catalog/file_system_catalog.cpp b/src/paimon/core/catalog/file_system_catalog.cpp index 287acbd0d..bb91ca88f 100644 --- a/src/paimon/core/catalog/file_system_catalog.cpp +++ b/src/paimon/core/catalog/file_system_catalog.cpp @@ -461,11 +461,6 @@ Result> FileSystemCatalog::GetSchemaExternalPaths( for (const auto& path : index_external_paths) { external_paths_set.insert(path); } - PAIMON_ASSIGN_OR_RAISE(std::optional legacy_index_path, - core_options.CreateGlobalIndexExternalPath()); - if (legacy_index_path) { - external_paths_set.insert(legacy_index_path.value()); - } } return std::vector(external_paths_set.begin(), external_paths_set.end()); } diff --git a/src/paimon/core/catalog/file_system_catalog_test.cpp b/src/paimon/core/catalog/file_system_catalog_test.cpp index 0046a6fed..ebe00acbf 100644 --- a/src/paimon/core/catalog/file_system_catalog_test.cpp +++ b/src/paimon/core/catalog/file_system_catalog_test.cpp @@ -1250,7 +1250,8 @@ TEST(FileSystemCatalogTest, TestDropTableWithGlobalIndexExternalPathsOnMainBranc std::string second_index_path = "FILE://" + second_index_dir->Str(); // Create a file in each external directory to simulate global index data. - ASSERT_OK_AND_ASSIGN(auto fs, FileSystemFactory::Get("local", dir->Str(), {})); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, + FileSystemFactory::Get("local", dir->Str(), {})); std::string index_file = PathUtil::JoinPath(global_index_path, "index-file.bin"); ASSERT_OK(fs->WriteFile(index_file, "index data", /*overwrite=*/true)); std::string second_index_file = PathUtil::JoinPath(second_index_path, "index-file.bin"); @@ -1260,7 +1261,7 @@ TEST(FileSystemCatalogTest, TestDropTableWithGlobalIndexExternalPathsOnMainBranc ASSERT_OK_AND_ASSIGN(bool index_file_exists, fs->Exists(index_file)); ASSERT_TRUE(index_file_exists); - // Create a table with both global index external path options on the main branch. + // Create the initial schema with the legacy global index root. arrow::FieldVector fields = { arrow::field("f0", arrow::int32()), arrow::field("f1", arrow::utf8()), @@ -1270,9 +1271,6 @@ TEST(FileSystemCatalogTest, TestDropTableWithGlobalIndexExternalPathsOnMainBranc ASSERT_TRUE(arrow::ExportSchema(typed_schema, &schema).ok()); std::map table_options = options; - table_options[Options::GLOBAL_INDEX_EXTERNAL_PATHS] = - global_index_path + "," + second_index_path; - // A legacy writer may have used the single root even with the newer list in the schema. std::string legacy_path = PathUtil::JoinPath("FILE://" + dir->Str(), "legacy,index"); std::string unrelated_path = PathUtil::JoinPath("FILE://" + dir->Str(), "legacy"); ASSERT_OK(fs->WriteFile(PathUtil::JoinPath(legacy_path, "index.bin"), "legacy", false)); @@ -1282,6 +1280,17 @@ TEST(FileSystemCatalogTest, TestDropTableWithGlobalIndexExternalPathsOnMainBranc ASSERT_OK(catalog.CreateTable(Identifier("test_db", "tbl_global_index"), &schema, {}, {}, table_options, false)); + // The new schema uses the list while retaining the overridden legacy option. + table_options[Options::GLOBAL_INDEX_EXTERNAL_PATHS] = + global_index_path + "," + second_index_path; + ASSERT_OK_AND_ASSIGN(std::string table_path, + catalog.GetTableLocation(Identifier("test_db", "tbl_global_index"))); + SchemaManager schema_manager(fs, table_path); + ASSERT_OK_AND_ASSIGN(std::unique_ptr new_schema, + TableSchema::Create(1, arrow::schema(fields), {}, {}, table_options)); + ASSERT_OK_AND_ASSIGN(std::string schema_json, new_schema->ToJsonString()); + ASSERT_OK(fs->AtomicStore(schema_manager.ToSchemaPath(1), schema_json)); + // Verify table exists ASSERT_OK_AND_ASSIGN(bool table_exists, catalog.TableExists(Identifier("test_db", "tbl_global_index"))); @@ -1296,7 +1305,7 @@ TEST(FileSystemCatalogTest, TestDropTableWithGlobalIndexExternalPathsOnMainBranc catalog.TableExists(Identifier("test_db", "tbl_global_index"))); ASSERT_FALSE(table_exists); - // Verify all configured roots are removed and the unrelated directory is preserved. + // Verify roots from both schema versions are removed and the unrelated directory is preserved. ASSERT_OK_AND_ASSIGN(bool global_index_exists, fs->Exists(global_index_path)); ASSERT_FALSE(global_index_exists); ASSERT_OK_AND_ASSIGN(global_index_exists, fs->Exists(second_index_path)); @@ -1311,8 +1320,8 @@ TEST(FileSystemCatalogTest, TestDropTableWithGlobalIndexExternalPathsOnMainBranc TEST(FileSystemCatalogTest, TestDropTableWithGlobalIndexExternalPathsOnBranch) { // Copy the real append_table_with_rt_branch.db test data, then patch the - // branch-rt schema-1 to include both external index options. - // DropTable should discover and clean up all external paths. + // branch-rt schema-1 to include a GLOBAL_INDEX_EXTERNAL_PATHS option. + // DropTable should discover and clean up that external path. std::map options; options[Options::FILE_SYSTEM] = "local"; options[Options::FILE_FORMAT] = "orc"; @@ -1325,7 +1334,7 @@ TEST(FileSystemCatalogTest, TestDropTableWithGlobalIndexExternalPathsOnBranch) { std::string db_path = dir->Str() + "/test_db.db"; ASSERT_TRUE(TestUtil::CopyDirectory(test_data_path, db_path)); - // Create external directories for the legacy root and the list root on the branch. + // Create a temporary external directory that represents branch global index data auto branch_external_dir = UniqueTestDirectory::Create(); ASSERT_TRUE(branch_external_dir); std::string branch_external_path = branch_external_dir->Str(); @@ -1334,26 +1343,21 @@ TEST(FileSystemCatalogTest, TestDropTableWithGlobalIndexExternalPathsOnBranch) { ASSERT_OK_AND_ASSIGN(auto fs, FileSystemFactory::Get("local", dir->Str(), {})); ASSERT_OK(fs->WriteFile(PathUtil::JoinPath(branch_external_path, "index.bin"), "branch global index data", /*overwrite=*/true)); - std::string branch_list_path = "FILE://" + PathUtil::JoinPath(dir->Str(), "branch-list"); - ASSERT_OK(fs->WriteFile(PathUtil::JoinPath(branch_list_path, "index.bin"), - "branch list index data", /*overwrite=*/true)); - // Patch branch-rt/schema/schema-1 with both global index external path options. + // Patch branch-rt/schema/schema-1: add GLOBAL_INDEX_EXTERNAL_PATHS to options std::string branch_schema_path = PathUtil::JoinPath(db_path, "append_table_with_rt_branch/branch/branch-rt/schema/schema-1"); std::string schema_content; ASSERT_OK(fs->ReadFile(branch_schema_path, &schema_content)); - // Insert both global index external path options into the JSON options block. + // Insert the global index external path option into the JSON options block. // Original: "file.format" : "orc" // Patched: "file.format" : "orc", - // "global-index.external-path" : "", - // "global-index.external-paths" : "" + // "global-index.external-paths" : "" std::string search_str = R"("file.format" : "orc")"; std::string replace_str = R"("file.format" : "orc", - "global-index.external-path" : ")" + - branch_external_path + R"(", "global-index.external-paths" : ")" + - branch_list_path + R"(")"; + "global-index.external-paths" : ")" + + branch_external_path + R"(")"; auto pos = schema_content.rfind(search_str); ASSERT_NE(pos, std::string::npos); schema_content.replace(pos, search_str.length(), replace_str); @@ -1375,11 +1379,9 @@ TEST(FileSystemCatalogTest, TestDropTableWithGlobalIndexExternalPathsOnBranch) { ASSERT_OK_AND_ASSIGN(table_exists, catalog.TableExists(identifier)); ASSERT_FALSE(table_exists); - // Verify both branch global index external directories are cleaned up by DropTable. + // Verify the branch global index external path is cleaned up by DropTable ASSERT_OK_AND_ASSIGN(external_exists, fs->Exists(branch_external_path)); ASSERT_FALSE(external_exists); - ASSERT_OK_AND_ASSIGN(external_exists, fs->Exists(branch_list_path)); - ASSERT_FALSE(external_exists); } TEST(FileSystemCatalogTest, TestListSnapshots) {