Skip to content

Commit 001d5d6

Browse files
authored
feat: support external path for global index (alibaba#52)
1 parent 9ea8e48 commit 001d5d6

45 files changed

Lines changed: 424 additions & 141 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

include/paimon/defs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ struct PAIMON_EXPORT Options {
284284
static const char BLOB_AS_DESCRIPTOR[];
285285
/// "global-index.enabled" - Whether to enable global index for scan. Default value is "true".
286286
static const char GLOBAL_INDEX_ENABLED[];
287+
/// "global-index.external-path" - Global index root directory, if not set, the global index
288+
/// files will be stored under the index directory.
289+
static const char GLOBAL_INDEX_EXTERNAL_PATH[];
287290
};
288291

289292
static constexpr int64_t BATCH_WRITE_COMMIT_IDENTIFIER = std::numeric_limits<int64_t>::max();

include/paimon/global_index/global_index_io_meta.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
namespace paimon {
2626
/// Metadata describing a single file entry in a global index.
2727
struct PAIMON_EXPORT GlobalIndexIOMeta {
28-
GlobalIndexIOMeta(const std::string& _file_name, int64_t _file_size, int64_t _range_end,
28+
GlobalIndexIOMeta(const std::string& _file_path, int64_t _file_size, int64_t _range_end,
2929
const std::shared_ptr<Bytes>& _metadata)
30-
: file_name(_file_name),
30+
: file_path(_file_path),
3131
file_size(_file_size),
3232
range_end(_range_end),
3333
metadata(_metadata) {}
3434

35-
std::string file_name;
35+
std::string file_path;
3636
int64_t file_size;
3737
/// The inclusive range end covered by this file (i.e., the last local row id).
3838
int64_t range_end;

include/paimon/global_index/io/global_index_file_writer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ class PAIMON_EXPORT GlobalIndexFileWriter {
3636

3737
/// Get the file size of input file name.
3838
virtual Result<int64_t> GetFileSize(const std::string& file_name) const = 0;
39+
40+
/// Get the index file path of input file name.
41+
virtual std::string ToPath(const std::string& file_name) const = 0;
3942
};
4043

4144
} // namespace paimon

src/paimon/common/defs.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,5 @@ const char Options::DATA_EVOLUTION_ENABLED[] = "data-evolution.enabled";
8080
const char Options::PARTITION_GENERATE_LEGACY_NAME[] = "partition.legacy-name";
8181
const char Options::BLOB_AS_DESCRIPTOR[] = "blob-as-descriptor";
8282
const char Options::GLOBAL_INDEX_ENABLED[] = "global-index.enabled";
83+
const char Options::GLOBAL_INDEX_EXTERNAL_PATH[] = "global-index.external-path";
8384
} // namespace paimon

src/paimon/common/global_index/bitmap/bitmap_global_index.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Result<std::shared_ptr<GlobalIndexReader>> BitmapGlobalIndex::CreateReader(
4141
}
4242
const auto& meta = files[0];
4343
PAIMON_ASSIGN_OR_RAISE(std::shared_ptr<InputStream> in,
44-
file_reader->GetInputStream(meta.file_name));
44+
file_reader->GetInputStream(meta.file_path));
4545
PAIMON_ASSIGN_OR_RAISE(
4646
std::shared_ptr<FileIndexReader> reader,
4747
index_->CreateReader(arrow_schema, /*start=*/0, meta.file_size, in, pool));

src/paimon/common/global_index/bitmap/bitmap_global_index_test.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,9 @@ class BitmapGlobalIndexTest : public ::testing::Test {
100100
PAIMON_ASSIGN_OR_RAISE(auto result_metas, global_writer->Finish());
101101
// check meta
102102
EXPECT_EQ(result_metas.size(), 1);
103-
EXPECT_TRUE(StringUtils::StartsWith(result_metas[0].file_name, "bitmap-global-index-"));
104-
EXPECT_TRUE(StringUtils::EndsWith(result_metas[0].file_name, ".index"));
103+
auto file_name = PathUtil::GetName(result_metas[0].file_path);
104+
EXPECT_TRUE(StringUtils::StartsWith(file_name, "bitmap-global-index-"));
105+
EXPECT_TRUE(StringUtils::EndsWith(file_name, ".index"));
105106
EXPECT_EQ(result_metas[0].range_end, expected_range.to);
106107
EXPECT_FALSE(result_metas[0].metadata);
107108
return result_metas[0];

src/paimon/common/global_index/wrap/file_index_writer_wrapper.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ class FileIndexWriterWrapper : public GlobalIndexWriter {
7272
}
7373
PAIMON_RETURN_NOT_OK(out->Flush());
7474
PAIMON_RETURN_NOT_OK(out->Close());
75-
GlobalIndexIOMeta meta(file_name, /*file_size=*/bytes->size(), /*range_end=*/count_ - 1,
75+
GlobalIndexIOMeta meta(file_manager_->ToPath(file_name), /*file_size=*/bytes->size(),
76+
/*range_end=*/count_ - 1,
7677
/*metadata=*/nullptr);
7778
return std::vector<GlobalIndexIOMeta>({meta});
7879
}

src/paimon/core/core_options.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ struct CoreOptions::Impl {
303303
bool data_evolution_enabled = false;
304304
bool legacy_partition_name_enabled = true;
305305
bool global_index_enabled = true;
306+
std::optional<std::string> global_index_external_path;
306307
};
307308

308309
// Parse configurations from a map and return a populated CoreOptions object
@@ -470,6 +471,15 @@ Result<CoreOptions> CoreOptions::FromMap(
470471
// Parse global-index.enabled
471472
PAIMON_RETURN_NOT_OK(
472473
parser.Parse<bool>(Options::GLOBAL_INDEX_ENABLED, &impl->global_index_enabled));
474+
475+
// Parse global_index.external-path
476+
std::string global_index_external_path;
477+
PAIMON_RETURN_NOT_OK(
478+
parser.ParseString(Options::GLOBAL_INDEX_EXTERNAL_PATH, &global_index_external_path));
479+
if (!global_index_external_path.empty()) {
480+
impl->global_index_external_path = global_index_external_path;
481+
}
482+
473483
return options;
474484
}
475485

@@ -746,4 +756,23 @@ bool CoreOptions::LegacyPartitionNameEnabled() const {
746756
bool CoreOptions::GlobalIndexEnabled() const {
747757
return impl_->global_index_enabled;
748758
}
759+
760+
std::optional<std::string> CoreOptions::GetGlobalIndexExternalPath() const {
761+
return impl_->global_index_external_path;
762+
}
763+
764+
Result<std::optional<std::string>> CoreOptions::CreateGlobalIndexExternalPath() const {
765+
std::optional<std::string> global_index_external_path = GetGlobalIndexExternalPath();
766+
if (global_index_external_path == std::nullopt) {
767+
return global_index_external_path;
768+
}
769+
std::string tmp_path = global_index_external_path.value();
770+
StringUtils::Trim(&tmp_path);
771+
PAIMON_ASSIGN_OR_RAISE(Path path, PathUtil::ToPath(tmp_path));
772+
if (path.scheme.empty()) {
773+
return Status::Invalid(fmt::format("scheme is null, path is {}", tmp_path));
774+
}
775+
return std::optional<std::string>(path.ToString());
776+
}
777+
749778
} // namespace paimon

src/paimon/core/core_options.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ class PAIMON_EXPORT CoreOptions {
102102
std::optional<std::string> GetScanFallbackBranch() const;
103103
std::string GetBranch() const;
104104

105-
std::optional<std::string> GetDataFileExternalPaths() const;
106105
ExternalPathStrategy GetExternalPathStrategy() const;
107106
Result<std::vector<std::string>> CreateExternalPaths() const;
108107
bool EnableAdaptivePrefetchStrategy() const;
@@ -117,8 +116,14 @@ class PAIMON_EXPORT CoreOptions {
117116
bool LegacyPartitionNameEnabled() const;
118117

119118
bool GlobalIndexEnabled() const;
119+
Result<std::optional<std::string>> CreateGlobalIndexExternalPath() const;
120+
120121
const std::map<std::string, std::string>& ToMap() const;
121122

123+
private:
124+
std::optional<std::string> GetDataFileExternalPaths() const;
125+
std::optional<std::string> GetGlobalIndexExternalPath() const;
126+
122127
private:
123128
struct Impl;
124129

src/paimon/core/core_options_test.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ TEST(CoreOptionsTest, TestDefaultValue) {
8787
ASSERT_FALSE(core_options.DataEvolutionEnabled());
8888
ASSERT_TRUE(core_options.LegacyPartitionNameEnabled());
8989
ASSERT_TRUE(core_options.GlobalIndexEnabled());
90+
ASSERT_FALSE(core_options.GetGlobalIndexExternalPath());
9091
}
9192

9293
TEST(CoreOptionsTest, TestFromMap) {
@@ -144,6 +145,7 @@ TEST(CoreOptionsTest, TestFromMap) {
144145
{Options::DATA_EVOLUTION_ENABLED, "true"},
145146
{Options::PARTITION_GENERATE_LEGACY_NAME, "false"},
146147
{Options::GLOBAL_INDEX_ENABLED, "false"},
148+
{Options::GLOBAL_INDEX_EXTERNAL_PATH, "FILE:///tmp/global_index/"},
147149
};
148150

149151
ASSERT_OK_AND_ASSIGN(CoreOptions core_options, CoreOptions::FromMap(options));
@@ -212,6 +214,8 @@ TEST(CoreOptionsTest, TestFromMap) {
212214
ASSERT_TRUE(core_options.DataEvolutionEnabled());
213215
ASSERT_FALSE(core_options.LegacyPartitionNameEnabled());
214216
ASSERT_FALSE(core_options.GlobalIndexEnabled());
217+
ASSERT_TRUE(core_options.GetGlobalIndexExternalPath());
218+
ASSERT_EQ(core_options.GetGlobalIndexExternalPath().value(), "FILE:///tmp/global_index/");
215219
}
216220

217221
TEST(CoreOptionsTest, TestInvalidCase) {
@@ -273,6 +277,25 @@ TEST(CoreOptionsTest, TestInvalidCreateExternalPath) {
273277
}
274278
}
275279

280+
TEST(CoreOptionsTest, TestCreateGlobalIndexExternalPath) {
281+
std::map<std::string, std::string> options = {
282+
{Options::GLOBAL_INDEX_EXTERNAL_PATH, " FILE:///tmp/index1"},
283+
};
284+
ASSERT_OK_AND_ASSIGN(CoreOptions core_options, CoreOptions::FromMap(options));
285+
ASSERT_OK_AND_ASSIGN(std::optional<std::string> external_path,
286+
core_options.CreateGlobalIndexExternalPath());
287+
ASSERT_EQ("FILE:/tmp/index1", external_path.value());
288+
}
289+
290+
TEST(CoreOptionsTest, TestInvalidCreateGlobalIndexExternalPath) {
291+
std::map<std::string, std::string> options = {
292+
{Options::GLOBAL_INDEX_EXTERNAL_PATH, "/tmp/index1"},
293+
};
294+
ASSERT_OK_AND_ASSIGN(CoreOptions core_options, CoreOptions::FromMap(options));
295+
ASSERT_NOK_WITH_MSG(core_options.CreateGlobalIndexExternalPath(),
296+
"scheme is null, path is /tmp/index1");
297+
}
298+
276299
TEST(CoreOptionsTest, TestFileSystem) {
277300
{
278301
auto mock_fs = std::make_shared<MockFileSystem>();

0 commit comments

Comments
 (0)