luoluoyuyu commented on code in PR #19314:
URL: https://github.com/apache/iotdb/pull/19314#discussion_r4610305878
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/consensus/deletion/DeletionResourceManager.java:
##########
@@ -308,6 +296,42 @@ public static DeletionResourceManager getInstance(int
groupId) {
});
}
+ /**
+ * Returns the manager of the given data region without creating one.
Deleting a data region must
+ * not create a manager just to close it, which would allocate a deletion
buffer and start a
+ * persist thread only to shut it down immediately.
+ */
+ public static DeletionResourceManager getInstanceIfPresent(int groupId) {
+ return DeletionResourceManagerHolder.CONSENSUS_GROUP_ID_2_INSTANCE_MAP ==
null
+ ? null
+ :
DeletionResourceManagerHolder.CONSENSUS_GROUP_ID_2_INSTANCE_MAP.get(groupId);
+ }
+
+ /** Closes the manager of the data region if it exists, then removes its DAL
folder. */
+ public static void closeAndRemoveDAL(int dataRegionId) {
+ DeletionResourceManager manager = getInstanceIfPresent(dataRegionId);
Review Comment:
Thanks, good catch. Fixed in b70691e:
- Manager creation and teardown are now serialized per data region with a
striped lifecycle lock, and a deleted region id is added to a closed set.
`getInstance()` checks that set under the same lock and returns `null`, so
after the teardown it can no longer create a manager (and recreate its DAL
folder). `closeAndRemoveDAL()` removes the manager and deletes the DAL folder
inside the lock, so a concurrent `getInstance()` either creates a manager that
is closed in the same teardown, or observes the closed region and returns
`null`.
- `PipeHistoricalDataRegionTsFileAndDeletionSource.start()` now checks
`dataRegion.isDeleted()` under the write lock, so a caller queued behind
`markDeleted()` does not extract from a deleted region.
- Data region ids are allocated monotonically by ConfigNode
(`PartitionInfo.generateNextRegionGroupId()`, persisted across restarts) and
are never reused, so keeping the closed ids for the process lifetime is safe.
- `shutdownNow()` is kept in `PageCacheDeletionBuffer.close()`; the
resulting interrupt is logged at DEBUG only when the buffer is closed and all
deletions are flushed, so a genuine interruption still logs WARN.
New tests in `DeletionResourceManagerTest`:
`testDeletedRegionCannotRecreateManager` and
`testConcurrentGetInstanceDuringTeardownLeavesNoManager` (8 concurrent
`getInstance()` callers race the teardown; afterwards there is no manager, no
DAL folder and no persist thread). Both fail on the previous implementation.
Regression run: deletion/buffer/pipe-source tests 44 passed,
`DataRegionTest`/`StorageEngineTest` 56 passed.
--
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]