Jackie-Jiang commented on code in PR #20283:
URL: https://github.com/apache/pinot/pull/20283#discussion_r4607732280


##########
pinot-controller/src/test/java/org/apache/pinot/controller/helix/core/util/SegmentDeletionManagerTest.java:
##########
@@ -895,6 +898,104 @@ public void 
testSweeperTreatsSegmentNamedMetadataAsAgedFile()
         "Unable to verify that a segment named metadata is swept like any 
other aged file");
   }
 
+  @DataProvider(name = "archiveRoots")
+  public Object[][] archiveRoots() {
+    return new Object[][]{{SegmentDeletionManager.DELETED_SEGMENTS}, 
{METADATA_ROOT}};
+  }
+
+  private ZkHelixPropertyStore<ZNRecord> makePropertyStoreWithLiveTable(String 
rawTableName) {
+    ZkHelixPropertyStore<ZNRecord> propertyStore = makePropertyStore();
+    String offlineTableName = rawTableName + "_OFFLINE";
+    
when(propertyStore.get(eq(constructPropertyStorePathForResourceConfig(offlineTableName)),
 isNull(),
+        eq(AccessOption.PERSISTENT))).thenReturn(new 
ZNRecord(offlineTableName));
+    return propertyStore;
+  }
+
+  private FakeDeletionManager newSweeperWithObjectStoreFs(File dataDir,
+      ZkHelixPropertyStore<ZNRecord> propertyStore) {
+    PinotFSFactory.register(PinotFSFactory.LOCAL_PINOT_FS_SCHEME, 
ObjectStoreLikeFs.class.getName(), null);

Review Comment:
   Non-blocking cleanup: these tests replace the process-wide `file` filesystem 
registration, and restoring a new `LocalPinotFS` does not restore the previous 
registration/configuration. Consider an isolated test scheme or fixture that 
preserves and restores the original state. Also explicitly delete the temporary 
directory trees in teardown/finally: registering only a non-empty parent with 
`deleteOnExit()` leaves its contents behind.



##########
pinot-controller/src/test/java/org/apache/pinot/controller/helix/core/util/SegmentDeletionManagerTest.java:
##########
@@ -895,6 +898,104 @@ public void 
testSweeperTreatsSegmentNamedMetadataAsAgedFile()
         "Unable to verify that a segment named metadata is swept like any 
other aged file");
   }
 
+  @DataProvider(name = "archiveRoots")
+  public Object[][] archiveRoots() {
+    return new Object[][]{{SegmentDeletionManager.DELETED_SEGMENTS}, 
{METADATA_ROOT}};
+  }
+
+  private ZkHelixPropertyStore<ZNRecord> makePropertyStoreWithLiveTable(String 
rawTableName) {
+    ZkHelixPropertyStore<ZNRecord> propertyStore = makePropertyStore();
+    String offlineTableName = rawTableName + "_OFFLINE";
+    
when(propertyStore.get(eq(constructPropertyStorePathForResourceConfig(offlineTableName)),
 isNull(),
+        eq(AccessOption.PERSISTENT))).thenReturn(new 
ZNRecord(offlineTableName));
+    return propertyStore;
+  }
+
+  private FakeDeletionManager newSweeperWithObjectStoreFs(File dataDir,
+      ZkHelixPropertyStore<ZNRecord> propertyStore) {
+    PinotFSFactory.register(PinotFSFactory.LOCAL_PINOT_FS_SCHEME, 
ObjectStoreLikeFs.class.getName(), null);
+    return new FakeDeletionManager(dataDir.getAbsolutePath(), 
makeHelixAdmin(), propertyStore, 7);
+  }
+
+  private static void restoreLocalFs() {
+    PinotFSFactory.register(PinotFSFactory.LOCAL_PINOT_FS_SCHEME, 
LocalPinotFS.class.getName(), null);
+  }
+
+  // A raw table named like an archive root has that root as its own live 
deep-store directory, so the sweep must not
+  // treat the live segment files in it as archived files.
+  @Test(dataProvider = "archiveRoots")
+  public void 
testSweeperDoesNotDeleteSegmentsOfLiveTableNamedAsArchiveRoot(String root)
+      throws Exception {
+    File dataDir = Files.createTempDirectory("pinot-test-").toFile();
+    dataDir.deleteOnExit();
+    File liveTableDir = new File(dataDir, root);
+    liveTableDir.mkdirs();
+    File seg1 = new File(liveTableDir, "seg1");
+    File seg2 = new File(liveTableDir, "seg2");
+    // Old enough to be expired under the 7 day default retention if they were 
mistaken for archived files.
+    createTestFileWithAge(seg1.getAbsolutePath(), 30);
+    createTestFileWithAge(seg2.getAbsolutePath(), 30);
+    LeadControllerManager leadControllerManager = 
mock(LeadControllerManager.class);
+    when(leadControllerManager.isLeaderForTable(anyString())).thenReturn(true);
+
+    try {
+      newSweeperWithObjectStoreFs(dataDir, 
makePropertyStoreWithLiveTable(root)).removeAgedDeletedSegments(

Review Comment:
   Non-blocking test improvement: this test would still pass if the live-table 
ownership guard were removed, because the fixtures are plain files and the new 
`isDirectory` check independently protects them. Please add an assertion that 
an occupied archive root is never listed, or use directory-shaped contents that 
would otherwise be swept. Parameterizing both archive roots across OFFLINE and 
REALTIME, and covering a failed property-store lookup, would exercise the 
ownership guard independently.



##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/SegmentDeletionManager.java:
##########
@@ -521,6 +541,24 @@ private void removeAgedDeletedFiles(LeadControllerManager 
leadControllerManager,
     }
   }
 
+  /// Whether a live table's raw name equals `rootName`, which makes that 
archive root the table's own deep-store
+  /// directory. Assumes a collision when the table config cannot be read, so 
nothing is swept or archived on a guess.
+  private boolean isRootNameOfLiveTable(String rootName) {
+    try {
+      for (TableType tableType : TableType.values()) {
+        String tableNameWithType = 
TableNameBuilder.forType(tableType).tableNameWithType(rootName);
+        if 
(_propertyStore.get(ZKMetadataProvider.constructPropertyStorePathForResourceConfig(tableNameWithType),
 null,

Review Comment:
   Non-blocking hardening: this guard only needs to establish whether the 
table-config node exists. Could we use `_propertyStore.exists(...)` while 
retaining the conservative exception handling? With the current Helix 
serializer, an existing node with empty or malformed data can deserialize to 
`null`, so `get(...) != null` can treat an occupied namespace as absent. An 
existence check also avoids unnecessary deserialization. The test fixtures 
should stub table-config node existence separately from segment-node existence.



##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/SegmentDeletionManager.java:
##########
@@ -521,6 +541,24 @@ private void removeAgedDeletedFiles(LeadControllerManager 
leadControllerManager,
     }
   }
 
+  /// Whether a live table's raw name equals `rootName`, which makes that 
archive root the table's own deep-store
+  /// directory. Assumes a collision when the table config cannot be read, so 
nothing is swept or archived on a guess.
+  private boolean isRootNameOfLiveTable(String rootName) {
+    try {
+      for (TableType tableType : TableType.values()) {
+        String tableNameWithType = 
TableNameBuilder.forType(tableType).tableNameWithType(rootName);
+        if 
(_propertyStore.get(ZKMetadataProvider.constructPropertyStorePathForResourceConfig(tableNameWithType),
 null,
+            AccessOption.PERSISTENT) != null) {
+          return true;
+        }
+      }
+      return false;
+    } catch (Exception e) {
+      LOGGER.warn("Failed to check whether a live table is named {}, assuming 
it is", rootName, e);

Review Comment:
   Non-blocking diagnostics/coverage: returning `true` for a lookup failure is 
conservative for namespace safety, but callers then log that a live table is 
named after the root even when ownership is unknown. Could we distinguish a 
confirmed collision from a failed lookup in the diagnostics? Please also test 
the preservation fallback on lookup failure: the full segment is archived as 
usual, metadata preservation is disabled, and the sidecar is deleted rather 
than archived.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to