lxy-9602 commented on code in PR #588:
URL: https://github.com/apache/paimon-cpp/pull/588#discussion_r4675015096
##########
src/paimon/core/snapshot.cpp:
##########
@@ -323,11 +332,42 @@ void Snapshot::FromJson(const rapidjson::Value& obj)
noexcept(false) {
RapidJsonUtil::DeserializeKeyValue<std::optional<int64_t>>(obj,
FIELD_NEXT_ROW_ID);
}
-Result<Snapshot> Snapshot::FromPath(const std::shared_ptr<FileSystem>& fs,
- const std::string& path) {
- std::string json_str;
- PAIMON_RETURN_NOT_OK(fs->ReadFile(path, &json_str));
- PAIMON_ASSIGN_OR_RAISE(Snapshot snapshot,
Snapshot::FromJsonString(json_str));
+Result<Snapshot> Snapshot::FromPath(const std::shared_ptr<FileSystem>& fs,
const std::string& path,
+ MemoryPool* pool) {
+ if (pool == nullptr || pool == GetDefaultPool().get()) {
+ std::string json_str;
+ PAIMON_RETURN_NOT_OK(fs->ReadFile(path, &json_str));
+ return Snapshot::FromJsonString(json_str);
+ }
+
+ Bytes json;
+ {
+ PAIMON_ASSIGN_OR_RAISE(std::unique_ptr<InputStream> input,
fs->Open(path));
+ if (input == nullptr) {
+ return Status::Invalid("input stream is not suppose to be a null
pointer, path: ",
+ path);
+ }
+ ScopeGuard close([&input]() { (void)input->Close(); });
+ PAIMON_ASSIGN_OR_RAISE(int64_t length, input->Length());
+ PAIMON_RETURN_NOT_OK(ValidateValueNonNegative(length, "read length"));
+ const uint64_t allocation_size = static_cast<uint64_t>(length) + 1;
+ PAIMON_RETURN_NOT_OK(ValidateValueInRange<size_t>(allocation_size,
"snapshot buffer size"));
+ try {
+ json = Bytes(static_cast<size_t>(allocation_size), pool);
+ } catch (const std::bad_alloc&) {
+ return Status::OutOfMemory("cannot allocate ", allocation_size, "
bytes for snapshot ",
+ path);
+ }
+ PAIMON_ASSIGN_OR_RAISE(int64_t read_length, input->Read(json.data(),
length));
+ if (read_length != length) {
+ return Status::IOError(fmt::format("path {}, expect read len {},
actual read len {}",
+ path, length, read_length));
+ }
+ json.data()[length] = '\0';
+ }
+ Snapshot snapshot;
+ PAIMON_RETURN_NOT_OK(RapidJsonUtil::FromNullTerminatedJson(
+ std::string_view(json.data(), json.size() - 1), &snapshot, path));
return snapshot;
Review Comment:
After internal discussion, our understanding is that both #588 and #592 aim
to make memory usage during scan planning more tightly bounded. Although 256
KiB is a stress-test quota rather than a production requirement, manifest
limits and accounting for JSON buffers alone would still leave many allocations
outside the budget. Fully enforcing such a limit across the planning path could
require intrusive changes and create a substantial maintenance burden.
We suggest either exploring a scan-limit design aligned with Java Paimon to
mitigate planning memory pressure, or maintaining downstream patches for your
integration’s stricter requirements. Based on the workload evidence shared so
far, it is not yet clear that precise memory-budget enforcement is a broadly
applicable requirement that justifies the added code complexity and maintenance
burden.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]