realAaronWu commented on code in PR #588:
URL: https://github.com/apache/paimon-cpp/pull/588#discussion_r4676806289


##########
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:
   Thanks for discussing the scope and maintenance cost. We tested a 
Sirius-side alternative with unmodified Paimon C++. Sirius checks the numbered 
snapshot size, manifest references, and Zstandard decoded block bounds before 
entering planning.
   
   For our fixed local append-only fixture, healthy reads and retry returned 
the expected rows. The oversized snapshot, decode amplification, manifest 
fanout, and unknown decoded-size cases were refused before the SDK ran.
   
   We will carry this forward on the Sirius side and close this PR. [Sirius 
validation draft](https://github.com/sirius-db/sirius/pull/2709)
   



-- 
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]

Reply via email to