Skip to content
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
6 changes: 3 additions & 3 deletions docs/source/user_guide/clean.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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-<name>``, is not supported: branches share the table's data
files, so expiration returns ``NotImplemented`` before deleting anything.
Expand Down
11 changes: 8 additions & 3 deletions include/paimon/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 for full-text, scalar and vector index search modes.
/// Accepts "fast", "full" or "detail". Families default to "fast" when neither option is set.
static const char GLOBAL_INDEX_SEARCH_MODE[];
Expand Down
1 change: 1 addition & 0 deletions src/paimon/common/defs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
46 changes: 33 additions & 13 deletions src/paimon/core/catalog/file_system_catalog_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -1249,8 +1249,9 @@ 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
ASSERT_OK_AND_ASSIGN(auto fs, FileSystemFactory::Get("local", dir->Str(), {}));
// Create a file in each external directory to simulate global index data.
ASSERT_OK_AND_ASSIGN(std::shared_ptr<FileSystem> 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");
Expand All @@ -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 table with global index external path on 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()),
Expand All @@ -1270,12 +1271,26 @@ TEST(FileSystemCatalogTest, TestDropTableWithGlobalIndexExternalPathsOnMainBranc
ASSERT_TRUE(arrow::ExportSchema(typed_schema, &schema).ok());

std::map<std::string, std::string> table_options = options;
table_options[Options::GLOBAL_INDEX_EXTERNAL_PATH] =
global_index_path + "," + second_index_path;
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));

// 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<TableSchema> 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")));
Expand All @@ -1290,18 +1305,22 @@ 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 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));
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.
// branch-rt schema-1 to include a GLOBAL_INDEX_EXTERNAL_PATHS option.
// DropTable should discover and clean up that external path.
std::map<std::string, std::string> options;
options[Options::FILE_SYSTEM] = "local";
Expand All @@ -1325,7 +1344,7 @@ TEST(FileSystemCatalogTest, TestDropTableWithGlobalIndexExternalPathsOnBranch) {
ASSERT_OK(fs->WriteFile(PathUtil::JoinPath(branch_external_path, "index.bin"),
"branch global index data", /*overwrite=*/true));

// Patch branch-rt/schema/schema-1: add GLOBAL_INDEX_EXTERNAL_PATH to 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;
Expand All @@ -1334,10 +1353,10 @@ TEST(FileSystemCatalogTest, TestDropTableWithGlobalIndexExternalPathsOnBranch) {
// Insert the global index external path option into the JSON options block.
// Original: "file.format" : "orc"
// Patched: "file.format" : "orc",
// "global-index.external-path" : "<branch_external_path>"
// "global-index.external-paths" : "<branch_external_path>"
std::string search_str = R"("file.format" : "orc")";
std::string replace_str = R"("file.format" : "orc",
"global-index.external-path" : ")" +
"global-index.external-paths" : ")" +
branch_external_path + R"(")";
auto pos = schema_content.rfind(search_str);
ASSERT_NE(pos, std::string::npos);
Expand Down Expand Up @@ -1554,15 +1573,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" : "<branch_external_path>"
std::string search_str = R"("file.format" : "orc")";
std::string replace_str = R"("file.format" : "orc",
Expand Down
30 changes: 27 additions & 3 deletions src/paimon/core/core_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ struct CoreOptions::Impl {
std::optional<std::string> data_file_external_paths;
std::optional<std::string> data_file_external_paths_weights;
std::optional<std::string> changelog_file_compression;
std::optional<std::string> global_index_external_path;
std::optional<std::string> global_index_external_paths;
std::optional<std::string> scan_tag_name;
CompressOptions lookup_compress_options{"zstd", 1};
Expand Down Expand Up @@ -952,9 +953,12 @@ struct CoreOptions::Impl {
// Parse global-index.filter.refine-from-data, default false
PAIMON_RETURN_NOT_OK(parser.Parse<bool>(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();
}

Expand Down Expand Up @@ -1989,10 +1993,30 @@ std::optional<std::string> CoreOptions::GetGlobalIndexExternalPaths() const {
return impl_->global_index_external_paths;
}

Result<std::optional<std::string>> CoreOptions::CreateGlobalIndexExternalPath() const {
if (!impl_->global_index_external_path || impl_->global_index_external_path->empty()) {
return std::optional<std::string>();
}
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<std::string>(path.ToString());
}

Result<std::vector<std::string>> CoreOptions::CreateGlobalIndexExternalPaths() const {
std::vector<std::string> external_paths;
std::optional<std::string> 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<std::string> 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(), ",")) {
Expand Down
1 change: 1 addition & 0 deletions src/paimon/core/core_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ class PAIMON_EXPORT CoreOptions {
std::string FormatTableFileCompression() const;

bool GlobalIndexEnabled() const;
Result<std::optional<std::string>> CreateGlobalIndexExternalPath() const;
Result<std::vector<std::string>> CreateGlobalIndexExternalPaths() const;

std::optional<std::string> GetScanTagName() const;
Expand Down
Loading
Loading