lxy-9602 commented on code in PR #285:
URL: https://github.com/apache/paimon-cpp/pull/285#discussion_r3949816565


##########
src/paimon/core/utils/snapshot_manager_test.cpp:
##########
@@ -139,6 +141,51 @@ TEST(SnapshotManagerTest, TestPathNotExist) {
     ASSERT_EQ(snapshot, std::nullopt);
 }
 
+TEST(SnapshotManagerTest, 
LatestHintAvoidsDirectoryProbeAndStillFindsNewSnapshots) {
+    class TrackingFileSystem : public LocalFileSystem {
+     public:
+        Result<bool> Exists(const std::string& path) const override {
+            exists_paths.push_back(path);
+            return LocalFileSystem::Exists(path);
+        }
+        mutable std::vector<std::string> exists_paths;
+    };
+    auto dir = UniqueTestDirectory::Create();
+    ASSERT_TRUE(dir);
+    auto fs = std::make_shared<TrackingFileSystem>();
+    SnapshotManager mgr(fs, dir->Str());
+    ASSERT_OK(fs->Mkdirs(mgr.SnapshotDirectory()));
+    ASSERT_OK(fs->WriteFile(mgr.SnapshotPath(1), "{}", true));
+    ASSERT_OK(mgr.CommitLatestHint(1));
+    fs->exists_paths.clear();
+
+    ASSERT_OK_AND_ASSIGN(std::optional<int64_t> latest, 
mgr.LatestSnapshotId());
+    ASSERT_EQ(latest, 1);
+    ASSERT_EQ(std::count(fs->exists_paths.begin(), fs->exists_paths.end(), 
mgr.SnapshotDirectory()),
+              0);
+    ASSERT_EQ(std::count(fs->exists_paths.begin(), fs->exists_paths.end(), 
mgr.SnapshotPath(2)), 1);
+
+    // A commit can publish its snapshot before updating the hint.
+    ASSERT_OK(fs->WriteFile(mgr.SnapshotPath(2), "{}", true));
+    fs->exists_paths.clear();
+    ASSERT_OK_AND_ASSIGN(latest, mgr.LatestSnapshotId());
+    ASSERT_EQ(latest, 2);
+    ASSERT_EQ(std::count(fs->exists_paths.begin(), fs->exists_paths.end(), 
mgr.SnapshotDirectory()),
+              1);
+
+    const std::string hint_path = PathUtil::JoinPath(mgr.SnapshotDirectory(), 
"LATEST");
+    ASSERT_OK(fs->Delete(hint_path));
+    fs->exists_paths.clear();
+    ASSERT_OK_AND_ASSIGN(latest, mgr.LatestSnapshotId());
+    ASSERT_EQ(latest, 2);
+    ASSERT_EQ(std::count(fs->exists_paths.begin(), fs->exists_paths.end(), 
mgr.SnapshotDirectory()),
+              1);
+
+    ASSERT_OK(fs->WriteFile(hint_path, "invalid", true));
+    ASSERT_OK_AND_ASSIGN(latest, mgr.LatestSnapshotId());
+    ASSERT_EQ(latest, 2);

Review Comment:
   I’m not sure this test is necessary. It is tightly coupled to the current 
implementation flow, so it may easily become a false alarm if `FindLatest` is 
refactored later.



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