Skip to content

Commit 6695b84

Browse files
authored
feat(spill): introduce external sort buffer and writer memory manager (#257)
1 parent 9108ac7 commit 6695b84

20 files changed

Lines changed: 1493 additions & 251 deletions

include/paimon/defs.h

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,27 @@ struct PAIMON_EXPORT Options {
178178
/// on-disk file. The default value is 256 mb
179179
static const char WRITE_BUFFER_SIZE[];
180180

181+
/// "write-buffer-spillable" - Whether the write buffer can be spillable. Default value is true.
182+
static const char WRITE_BUFFER_SPILLABLE[];
183+
184+
/// "write-buffer-spill.max-disk-size" - The max disk to use for write buffer spill. This only
185+
/// works when the write buffer spill is enabled. Default value is unlimited.
186+
static const char WRITE_BUFFER_SPILL_MAX_DISK_SIZE[];
187+
188+
/// "local-sort.max-num-file-handles" - The maximal fan-in for external merge sort. It limits
189+
/// the number of file handles. If it is too small, may cause intermediate merging. But if it is
190+
/// too large, it will cause too many files opened at the same time, consume memory and lead to
191+
/// random reading. Default value is 128.
192+
static const char LOCAL_SORT_MAX_NUM_FILE_HANDLES[];
193+
194+
/// "spill-compression" - Compression for spill. Default value is zstd.
195+
static const char SPILL_COMPRESSION[];
196+
197+
/// "spill-compression.zstd-level" - Default spill compression zstd level. For higher
198+
/// compression rates, it can be configured to 9, but the read and write speed will
199+
/// significantly decrease. Default value is 1.
200+
static const char SPILL_COMPRESSION_ZSTD_LEVEL[];
201+
181202
/// "snapshot.num-retained.min" - The minimum number of completed snapshots to retain. Should be
182203
/// greater than or equal to 1. Default value is 10
183204
static const char SNAPSHOT_NUM_RETAINED_MIN[];
@@ -417,10 +438,6 @@ struct PAIMON_EXPORT Options {
417438
/// lz4 are supported. Default value is zstd.
418439
/// Noted that java paimon also supports lzo which paimon-cpp does not support for now.
419440
static const char LOOKUP_CACHE_SPILL_COMPRESSION[];
420-
/// "spill-compression.zstd-level" - Default spill compression zstd level. For higher
421-
/// compression rates, it can be configured to 9, but the read and write speed will
422-
/// significantly decrease. Default value is 1.
423-
static const char SPILL_COMPRESSION_ZSTD_LEVEL[];
424441
/// "cache-page-size" - Memory page size for caching. Default value is 64 kb.
425442
static const char CACHE_PAGE_SIZE[];
426443
/// "file.format.per.level" - Define different file format for different level, you can add the

src/paimon/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ set(PAIMON_CORE_SRCS
234234
core/manifest/manifest_list.cpp
235235
core/manifest/partition_entry.cpp
236236
core/manifest/index_manifest_file_handler.cpp
237+
core/memory/writer_memory_manager.cpp
237238
core/mergetree/compact/universal_compaction.cpp
238239
core/mergetree/compact/early_full_compaction.cpp
239240
core/mergetree/compact/aggregate/aggregate_merge_function.cpp
@@ -251,6 +252,7 @@ set(PAIMON_CORE_SRCS
251252
core/mergetree/compact/changelog_merge_tree_rewriter.cpp
252253
core/mergetree/merge_tree_writer.cpp
253254
core/mergetree/in_memory_sort_buffer.cpp
255+
core/mergetree/external_sort_buffer.cpp
254256
core/mergetree/write_buffer.cpp
255257
core/mergetree/levels.cpp
256258
core/mergetree/lookup_file.cpp
@@ -594,6 +596,7 @@ if(PAIMON_BUILD_TESTS)
594596
core/manifest/file_entry_test.cpp
595597
core/manifest/index_manifest_entry_serializer_test.cpp
596598
core/manifest/index_manifest_file_handler_test.cpp
599+
core/memory/writer_memory_manager_test.cpp
597600
core/mergetree/levels_test.cpp
598601
core/mergetree/lookup_file_test.cpp
599602
core/mergetree/lookup_levels_test.cpp
@@ -633,6 +636,7 @@ if(PAIMON_BUILD_TESTS)
633636
core/mergetree/drop_delete_reader_test.cpp
634637
core/mergetree/merge_tree_writer_test.cpp
635638
core/mergetree/write_buffer_test.cpp
639+
core/mergetree/sort_buffer_test.cpp
636640
core/mergetree/sorted_run_test.cpp
637641
core/mergetree/spill_channel_manager_test.cpp
638642
core/mergetree/spill_reader_writer_test.cpp

src/paimon/common/defs.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ const char Options::SCAN_MODE[] = "scan.mode";
5050
const char Options::READ_BATCH_SIZE[] = "read.batch-size";
5151
const char Options::WRITE_BATCH_SIZE[] = "write.batch-size";
5252
const char Options::WRITE_BUFFER_SIZE[] = "write-buffer-size";
53+
const char Options::WRITE_BUFFER_SPILLABLE[] = "write-buffer-spillable";
54+
const char Options::WRITE_BUFFER_SPILL_MAX_DISK_SIZE[] = "write-buffer-spill.max-disk-size";
55+
const char Options::LOCAL_SORT_MAX_NUM_FILE_HANDLES[] = "local-sort.max-num-file-handles";
56+
const char Options::SPILL_COMPRESSION[] = "spill-compression";
57+
const char Options::SPILL_COMPRESSION_ZSTD_LEVEL[] = "spill-compression.zstd-level";
5358
const char Options::SNAPSHOT_NUM_RETAINED_MIN[] = "snapshot.num-retained.min";
5459
const char Options::SNAPSHOT_NUM_RETAINED_MAX[] = "snapshot.num-retained.max";
5560
const char Options::SNAPSHOT_TIME_RETAINED[] = "snapshot.time-retained";
@@ -106,7 +111,6 @@ const char Options::LOOKUP_CACHE_BLOOM_FILTER_FPP[] = "lookup.cache.bloom.filter
106111
const char Options::LOOKUP_REMOTE_FILE_ENABLED[] = "lookup.remote-file.enabled";
107112
const char Options::LOOKUP_REMOTE_LEVEL_THRESHOLD[] = "lookup.remote-file.level-threshold";
108113
const char Options::LOOKUP_CACHE_SPILL_COMPRESSION[] = "lookup.cache-spill-compression";
109-
const char Options::SPILL_COMPRESSION_ZSTD_LEVEL[] = "spill-compression.zstd-level";
110114
const char Options::CACHE_PAGE_SIZE[] = "cache-page-size";
111115
const char Options::FILE_FORMAT_PER_LEVEL[] = "file.format.per.level";
112116
const char Options::FILE_COMPRESSION_PER_LEVEL[] = "file.compression.per.level";

src/paimon/common/utils/string_utils_test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,12 @@ TEST_F(StringUtilsTest, TestSplit) {
327327
StringUtils::Split("key1=value1//key3=value3", std::string("/"), std::string("="));
328328
ASSERT_EQ(expect, result);
329329
}
330+
{
331+
std::vector<std::vector<std::string>> expect = {};
332+
std::vector<std::vector<std::string>> result =
333+
StringUtils::Split("", std::string("/"), std::string("="));
334+
ASSERT_EQ(expect, result);
335+
}
330336
}
331337

332338
TEST_F(StringUtilsTest, TestStringToValueSimple) {

0 commit comments

Comments
 (0)