realAaronWu commented on code in PR #588:
URL: https://github.com/apache/paimon-cpp/pull/588#discussion_r4667236065
##########
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:
I measured the 372 numbered snapshot fixtures on the target base. The median
is 572 B, p95 is 651 B, and the maximum is 716 B. The motivating case is one
embedded database scan with a capped pool. In the controlled reproduction,
padding the snapshot to 270,337 B with JSON whitespace let a 270,338 B input
allocation bypass the 256 KiB pool on the old path. I don’t have production
size or concurrency measurements, or evidence of meaningful RSS savings for
ordinary snapshots. The case demonstrates an admission gap for this buffer.
Would you prefer to keep this narrowly scoped to the data-scan path, or defer
it to the broader planning controls?
[Reproduction](https://github.com/apache/paimon-cpp/issues/587)
--
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]