You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by "9aman (via GitHub)" <gi...@apache.org> on 2025/02/27 07:56:36 UTC
[PR] Add support for orphan segment cleanup [pinot]
9aman opened a new pull request, #15142:
URL: https://github.com/apache/pinot/pull/15142
Instructions:
1. The PR has to be tagged with at least one of the following labels (*):
1. `feature`
2. `bugfix`
3. `performance`
4. `ui`
5. `backward-incompat`
6. `release-notes` (**)
2. Remove these instructions before publishing the PR.
(*) Other labels to consider:
- `testing`
- `dependencies`
- `docker`
- `kubernetes`
- `observability`
- `security`
- `code-style`
- `extension-point`
- `refactor`
- `cleanup`
(**) Use `release-notes` label for scenarios like:
- New configuration options
- Deprecation of configurations
- Signature changes to public methods/interfaces
- New plugins added or old plugins removed
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add support for orphan segment cleanup [pinot]
Posted by "9aman (via GitHub)" <gi...@apache.org>.
9aman commented on code in PR #15142:
URL: https://github.com/apache/pinot/pull/15142#discussion_r1991322274
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/RetentionManager.java:
##########
@@ -189,6 +219,110 @@ private boolean shouldDeleteInProgressLLCSegment(String segmentName, IdealState
}
}
+ private List<String> getSegmentsToDeleteFromDeepstore(String tableNameWithType, RetentionStrategy retentionStrategy,
+ List<SegmentZKMetadata> segmentZKMetadataList, int untrackedSegmentsDeletionBatchSize) {
+ List<String> segmentsToDelete = new ArrayList<>();
+
+ if (untrackedSegmentsDeletionBatchSize <= 0) {
+ // return an empty list in case untracked segment deletion is not configured
+ LOGGER.info(
+ "Not scanning deep store for untracked segments for table: {} as untrackedSegmentsDeletionBatchSize is set "
+ + "to: {}",
+ tableNameWithType, untrackedSegmentsDeletionBatchSize);
+ return segmentsToDelete;
+ }
+
+ List<String> segmentsPresentInZK =
+ segmentZKMetadataList.stream().map(SegmentZKMetadata::getSegmentName).collect(Collectors.toList());
+ try {
+ LOGGER.info("Fetch segments present in deep store that are beyond retention period for table: {}",
+ tableNameWithType);
+ segmentsToDelete =
+ findUntrackedSegmentsToDeleteFromDeepstore(tableNameWithType, retentionStrategy, segmentsPresentInZK);
+ _controllerMetrics.setValueOfTableGauge(tableNameWithType, ControllerGauge.UNTRACKED_SEGMENTS_COUNT,
+ segmentsToDelete.size());
+
+ if (segmentsToDelete.size() > untrackedSegmentsDeletionBatchSize) {
Review Comment:
Added the logic to pick as per the configured batch size.
cc: @swaminathanmanish @klsince
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add support for orphan segment cleanup [pinot]
Posted by "klsince (via GitHub)" <gi...@apache.org>.
klsince commented on code in PR #15142:
URL: https://github.com/apache/pinot/pull/15142#discussion_r1999439274
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/RetentionManager.java:
##########
@@ -189,6 +219,110 @@ private boolean shouldDeleteInProgressLLCSegment(String segmentName, IdealState
}
}
+ private List<String> getSegmentsToDeleteFromDeepstore(String tableNameWithType, RetentionStrategy retentionStrategy,
+ List<SegmentZKMetadata> segmentZKMetadataList, int untrackedSegmentsDeletionBatchSize) {
+ List<String> segmentsToDelete = new ArrayList<>();
+
+ if (untrackedSegmentsDeletionBatchSize <= 0) {
+ // return an empty list in case untracked segment deletion is not configured
+ LOGGER.info(
+ "Not scanning deep store for untracked segments for table: {} as untrackedSegmentsDeletionBatchSize is set "
+ + "to: {}",
+ tableNameWithType, untrackedSegmentsDeletionBatchSize);
+ return segmentsToDelete;
+ }
+
+ List<String> segmentsPresentInZK =
+ segmentZKMetadataList.stream().map(SegmentZKMetadata::getSegmentName).collect(Collectors.toList());
+ try {
+ LOGGER.info("Fetch segments present in deep store that are beyond retention period for table: {}",
+ tableNameWithType);
+ segmentsToDelete =
+ findUntrackedSegmentsToDeleteFromDeepstore(tableNameWithType, retentionStrategy, segmentsPresentInZK);
+ _controllerMetrics.setValueOfTableGauge(tableNameWithType, ControllerGauge.UNTRACKED_SEGMENTS_COUNT,
+ segmentsToDelete.size());
+
+ if (segmentsToDelete.size() > untrackedSegmentsDeletionBatchSize) {
Review Comment:
+1 to stop listing once batch size is reached, perhaps leave a TODO here
##########
pinot-common/src/main/java/org/apache/pinot/common/metrics/ControllerGauge.java:
##########
@@ -190,7 +190,11 @@ public enum ControllerGauge implements AbstractMetrics.Gauge {
REINGESTED_SEGMENT_UPLOADS_IN_PROGRESS("reingestedSegmentUploadsInProgress", true),
// Resource utilization is within limits or not for a table
- RESOURCE_UTILIZATION_LIMIT_EXCEEDED("ResourceUtilizationLimitExceeded", false);
+ RESOURCE_UTILIZATION_LIMIT_EXCEEDED("ResourceUtilizationLimitExceeded", false),
Review Comment:
nit: lower case the first letter `resourceUtilizationLimitExceeded` for consistency
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add support for orphan segment cleanup [pinot]
Posted by "9aman (via GitHub)" <gi...@apache.org>.
9aman commented on code in PR #15142:
URL: https://github.com/apache/pinot/pull/15142#discussion_r1984793317
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/RetentionManager.java:
##########
@@ -136,11 +164,86 @@ private void manageRetentionForOfflineTable(String offlineTableName, RetentionSt
}
}
+ /**
+ * Identifies segments in deepstore that are ready for deletion based on the retention strategy.
+ *
+ * This method finds segments that are beyond the retention period and are ready to be purged.
+ * It only considers segments that do not have entries in ZooKeeper metadata.
+ * The lastModified time of the file in deepstore is used to determine whether the segment
+ * should be retained or purged.
+ *
+ * @param tableNameWithType Name of the offline table
+ * @param retentionStrategy Strategy to determine if a segment should be purged
+ * @param segmentsToExclude List of segment names that should be excluded from deletion
+ * @return List of segment names that should be deleted from deepstore
+ * @throws IOException If there's an error accessing the filesystem
+ */
+ private List<String> getSegmentsToDeleteFromDeepstore(String tableNameWithType, RetentionStrategy retentionStrategy,
+ List<String> segmentsToExclude)
+ throws IOException {
+
+ List<String> segmentsToDelete = new ArrayList<>();
+ String rawTableName = TableNameBuilder.extractRawTableName(tableNameWithType);
+ URI tableDataUri = URIUtils.getUri(_pinotHelixResourceManager.getDataDir(), rawTableName);
+ PinotFS pinotFS = PinotFSFactory.create(tableDataUri.getScheme());
+
+ List<FileMetadata> deepstoreFiles = pinotFS.listFilesWithMetadata(tableDataUri, false);
+
+ for (FileMetadata fileMetadata : deepstoreFiles) {
+ if (fileMetadata.isDirectory()) {
+ continue;
+ }
+
+ String segmentName = extractSegmentName(fileMetadata.getFilePath());
+ if (Strings.isEmpty(segmentName) || segmentsToExclude.contains(segmentName)) {
+ continue;
+ }
+
+ // determine whether the segment should be perged or not based on the last modified time of the file
+ long lastModifiedTime = fileMetadata.getLastModifiedTime();
+
+ if (retentionStrategy.isPurgeable(segmentName, tableNameWithType, lastModifiedTime)) {
+ segmentsToDelete.add(segmentName);
+ }
+ }
+
Review Comment:
Done.
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add support for orphan segment cleanup [pinot]
Posted by "9aman (via GitHub)" <gi...@apache.org>.
9aman commented on code in PR #15142:
URL: https://github.com/apache/pinot/pull/15142#discussion_r1991325038
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/RetentionManager.java:
##########
@@ -189,6 +219,110 @@ private boolean shouldDeleteInProgressLLCSegment(String segmentName, IdealState
}
}
+ private List<String> getSegmentsToDeleteFromDeepstore(String tableNameWithType, RetentionStrategy retentionStrategy,
+ List<SegmentZKMetadata> segmentZKMetadataList, int untrackedSegmentsDeletionBatchSize) {
+ List<String> segmentsToDelete = new ArrayList<>();
+
+ if (untrackedSegmentsDeletionBatchSize <= 0) {
+ // return an empty list in case untracked segment deletion is not configured
+ LOGGER.info(
+ "Not scanning deep store for untracked segments for table: {} as untrackedSegmentsDeletionBatchSize is set "
+ + "to: {}",
+ tableNameWithType, untrackedSegmentsDeletionBatchSize);
+ return segmentsToDelete;
+ }
+
+ List<String> segmentsPresentInZK =
+ segmentZKMetadataList.stream().map(SegmentZKMetadata::getSegmentName).collect(Collectors.toList());
+ try {
+ LOGGER.info("Fetch segments present in deep store that are beyond retention period for table: {}",
+ tableNameWithType);
+ segmentsToDelete =
+ findUntrackedSegmentsToDeleteFromDeepstore(tableNameWithType, retentionStrategy, segmentsPresentInZK);
+ _controllerMetrics.setValueOfTableGauge(tableNameWithType, ControllerGauge.UNTRACKED_SEGMENTS_COUNT,
+ segmentsToDelete.size());
+
+ if (segmentsToDelete.size() > untrackedSegmentsDeletionBatchSize) {
Review Comment:
The ideal way would be to do pagination on the FS and bring only untrackedSegmentsDeletionBatchSize number of files/ segments from deepstore.
We can add this improvement 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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add support for orphan segment cleanup [pinot]
Posted by "9aman (via GitHub)" <gi...@apache.org>.
9aman commented on code in PR #15142:
URL: https://github.com/apache/pinot/pull/15142#discussion_r1974943911
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/RetentionManager.java:
##########
@@ -124,8 +138,19 @@ private void manageRetentionForTable(TableConfig tableConfig) {
}
private void manageRetentionForOfflineTable(String offlineTableName, RetentionStrategy retentionStrategy) {
+ List<SegmentZKMetadata> segmentZKMetadataList = _pinotHelixResourceManager.getSegmentsZKMetadata(offlineTableName);
Review Comment:
The deletion occurs based on the `endTime` present in the segmentZKMetadata. That's why the isPurgeable relies on segmentZKMetadata to decide whether we need to remove a segment or not.
Are you suggesting some other approach where we move away from endTime of the segment?
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add support for orphan segment cleanup [pinot]
Posted by "9aman (via GitHub)" <gi...@apache.org>.
9aman commented on code in PR #15142:
URL: https://github.com/apache/pinot/pull/15142#discussion_r1984776827
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/RetentionManager.java:
##########
@@ -124,8 +138,19 @@ private void manageRetentionForTable(TableConfig tableConfig) {
}
private void manageRetentionForOfflineTable(String offlineTableName, RetentionStrategy retentionStrategy) {
+ List<SegmentZKMetadata> segmentZKMetadataList = _pinotHelixResourceManager.getSegmentsZKMetadata(offlineTableName);
Review Comment:
If the deletion fails in the middle then the segment will be in ZK but not in IS.
Moreover, as per Xiang we have seen cases where the SegmentRefreshTask etc push segment in Deepstore and ZK but fail to update the IS.
In that case as well we have such segments.
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add support for orphan segment cleanup [pinot]
Posted by "swaminathanmanish (via GitHub)" <gi...@apache.org>.
swaminathanmanish commented on code in PR #15142:
URL: https://github.com/apache/pinot/pull/15142#discussion_r1993358381
##########
pinot-spi/src/main/java/org/apache/pinot/spi/config/table/SegmentsValidationAndRetentionConfig.java:
##########
@@ -55,6 +55,8 @@ public class SegmentsValidationAndRetentionConfig extends BaseJsonConfig {
// For more usage of this field, please refer to this design doc: https://tinyurl.com/f63ru4sb
private String _peerSegmentDownloadScheme;
+ private int _untrackedSegmentsDeletionBatchSize;
Review Comment:
Where do we set the default value for this ?
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add support for orphan segment cleanup [pinot]
Posted by "9aman (via GitHub)" <gi...@apache.org>.
9aman commented on code in PR #15142:
URL: https://github.com/apache/pinot/pull/15142#discussion_r1974942431
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/RetentionManager.java:
##########
@@ -124,8 +136,24 @@ private void manageRetentionForTable(TableConfig tableConfig) {
}
private void manageRetentionForOfflineTable(String offlineTableName, RetentionStrategy retentionStrategy) {
Review Comment:
The support is present for realtime tables as well.
It is there right: https://github.com/apache/pinot/pull/15142/files#diff-fc6f837f3641465c40ccf44fdded9bd37a3c7c9fb966d4710b2b034da5844759R225
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add support for orphan segment cleanup [pinot]
Posted by "9aman (via GitHub)" <gi...@apache.org>.
9aman commented on code in PR #15142:
URL: https://github.com/apache/pinot/pull/15142#discussion_r1974948571
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/RetentionManager.java:
##########
@@ -136,11 +164,86 @@ private void manageRetentionForOfflineTable(String offlineTableName, RetentionSt
}
}
+ /**
+ * Identifies segments in deepstore that are ready for deletion based on the retention strategy.
+ *
+ * This method finds segments that are beyond the retention period and are ready to be purged.
+ * It only considers segments that do not have entries in ZooKeeper metadata.
+ * The lastModified time of the file in deepstore is used to determine whether the segment
+ * should be retained or purged.
+ *
+ * @param tableNameWithType Name of the offline table
+ * @param retentionStrategy Strategy to determine if a segment should be purged
+ * @param segmentsToExclude List of segment names that should be excluded from deletion
+ * @return List of segment names that should be deleted from deepstore
+ * @throws IOException If there's an error accessing the filesystem
+ */
+ private List<String> getSegmentsToDeleteFromDeepstore(String tableNameWithType, RetentionStrategy retentionStrategy,
+ List<String> segmentsToExclude)
+ throws IOException {
+
+ List<String> segmentsToDelete = new ArrayList<>();
+ String rawTableName = TableNameBuilder.extractRawTableName(tableNameWithType);
+ URI tableDataUri = URIUtils.getUri(_pinotHelixResourceManager.getDataDir(), rawTableName);
+ PinotFS pinotFS = PinotFSFactory.create(tableDataUri.getScheme());
+
+ List<FileMetadata> deepstoreFiles = pinotFS.listFilesWithMetadata(tableDataUri, false);
+
+ for (FileMetadata fileMetadata : deepstoreFiles) {
+ if (fileMetadata.isDirectory()) {
+ continue;
+ }
+
+ String segmentName = extractSegmentName(fileMetadata.getFilePath());
+ if (Strings.isEmpty(segmentName) || segmentsToExclude.contains(segmentName)) {
+ continue;
+ }
+
+ // determine whether the segment should be perged or not based on the last modified time of the file
+ long lastModifiedTime = fileMetadata.getLastModifiedTime();
+
+ if (retentionStrategy.isPurgeable(segmentName, tableNameWithType, lastModifiedTime)) {
Review Comment:
But won't this happen in the current scenario as well.
```
try {
retentionStrategy = new TimeRetentionStrategy(TimeUnit.valueOf(retentionTimeUnit.toUpperCase()),
Long.parseLong(retentionTimeValue));
} catch (Exception e) {
LOGGER.warn("Invalid retention time: {} {} for table: {}, skip", retentionTimeUnit, retentionTimeValue,
tableNameWithType);
return;
}
```
The code will not proceed unless a valid retention is provided. I think the above scenario will only happen when someone puts it to 0.
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add support for orphan segment cleanup [pinot]
Posted by "9aman (via GitHub)" <gi...@apache.org>.
9aman commented on code in PR #15142:
URL: https://github.com/apache/pinot/pull/15142#discussion_r1984787547
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/SegmentDeletionManager.java:
##########
@@ -221,6 +221,7 @@ private void deleteSegmentMetadataFromStore(PinotFS pinotFS, URI segmentFileUri,
URI segmentMetadataUri = SegmentPushUtils.generateSegmentMetadataURI(segmentFileUri.toString(), segmentId);
if (pinotFS.exists(segmentMetadataUri)) {
LOGGER.info("Deleting segment metadata {} from {}", segmentId, segmentMetadataUri);
+ // TODO: check if the deletion was successful and add a warning here.
Review Comment:
Done.
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add support for orphan segment cleanup [pinot]
Posted by "9aman (via GitHub)" <gi...@apache.org>.
9aman commented on code in PR #15142:
URL: https://github.com/apache/pinot/pull/15142#discussion_r1997854881
##########
pinot-spi/src/main/java/org/apache/pinot/spi/config/table/SegmentsValidationAndRetentionConfig.java:
##########
@@ -55,6 +55,8 @@ public class SegmentsValidationAndRetentionConfig extends BaseJsonConfig {
// For more usage of this field, please refer to this design doc: https://tinyurl.com/f63ru4sb
private String _peerSegmentDownloadScheme;
+ private int _untrackedSegmentsDeletionBatchSize;
Review Comment:
It should be off by default, i.e. it picks the value 0. This is an expensive operation and for now I have kept it off by default.
The user has to update the tableConfig for this to work.
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add support for orphan segment cleanup [pinot]
Posted by "9aman (via GitHub)" <gi...@apache.org>.
9aman commented on code in PR #15142:
URL: https://github.com/apache/pinot/pull/15142#discussion_r2001093916
##########
pinot-spi/src/main/java/org/apache/pinot/spi/config/table/SegmentsValidationAndRetentionConfig.java:
##########
@@ -55,6 +55,8 @@ public class SegmentsValidationAndRetentionConfig extends BaseJsonConfig {
// For more usage of this field, please refer to this design doc: https://tinyurl.com/f63ru4sb
private String _peerSegmentDownloadScheme;
+ private int _untrackedSegmentsDeletionBatchSize;
Review Comment:
Have added a controller config to enable/ disable deletion of untracked segments.
It is `off` by default to keep in check the blast radius.
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add support for orphan segment cleanup [pinot]
Posted by "swaminathanmanish (via GitHub)" <gi...@apache.org>.
swaminathanmanish commented on code in PR #15142:
URL: https://github.com/apache/pinot/pull/15142#discussion_r1973913895
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/RetentionManager.java:
##########
@@ -136,11 +164,86 @@ private void manageRetentionForOfflineTable(String offlineTableName, RetentionSt
}
}
+ /**
+ * Identifies segments in deepstore that are ready for deletion based on the retention strategy.
+ *
+ * This method finds segments that are beyond the retention period and are ready to be purged.
+ * It only considers segments that do not have entries in ZooKeeper metadata.
+ * The lastModified time of the file in deepstore is used to determine whether the segment
+ * should be retained or purged.
+ *
+ * @param tableNameWithType Name of the offline table
+ * @param retentionStrategy Strategy to determine if a segment should be purged
+ * @param segmentsToExclude List of segment names that should be excluded from deletion
+ * @return List of segment names that should be deleted from deepstore
+ * @throws IOException If there's an error accessing the filesystem
+ */
+ private List<String> getSegmentsToDeleteFromDeepstore(String tableNameWithType, RetentionStrategy retentionStrategy,
+ List<String> segmentsToExclude)
+ throws IOException {
+
+ List<String> segmentsToDelete = new ArrayList<>();
+ String rawTableName = TableNameBuilder.extractRawTableName(tableNameWithType);
+ URI tableDataUri = URIUtils.getUri(_pinotHelixResourceManager.getDataDir(), rawTableName);
+ PinotFS pinotFS = PinotFSFactory.create(tableDataUri.getScheme());
+
+ List<FileMetadata> deepstoreFiles = pinotFS.listFilesWithMetadata(tableDataUri, false);
+
+ for (FileMetadata fileMetadata : deepstoreFiles) {
+ if (fileMetadata.isDirectory()) {
+ continue;
+ }
+
+ String segmentName = extractSegmentName(fileMetadata.getFilePath());
+ if (Strings.isEmpty(segmentName) || segmentsToExclude.contains(segmentName)) {
+ continue;
+ }
+
+ // determine whether the segment should be perged or not based on the last modified time of the file
+ long lastModifiedTime = fileMetadata.getLastModifiedTime();
+
+ if (retentionStrategy.isPurgeable(segmentName, tableNameWithType, lastModifiedTime)) {
+ segmentsToDelete.add(segmentName);
+ }
+ }
+
+ return segmentsToDelete;
+ }
+
+ @Nullable
+ private String extractSegmentName(@Nullable String filePath) {
+ if (Strings.isEmpty(filePath)) {
+ return null;
+ }
+ String segmentName = filePath.substring(filePath.lastIndexOf("/") + 1);
+ if (segmentName.endsWith(TarCompressionUtils.TAR_GZ_FILE_EXTENSION)) {
+ segmentName = segmentName.substring(0, segmentName.length() - TarCompressionUtils.TAR_GZ_FILE_EXTENSION.length());
+ }
+ return segmentName;
+ }
+
private void manageRetentionForRealtimeTable(String realtimeTableName, RetentionStrategy retentionStrategy) {
+ List<SegmentZKMetadata> segmentZKMetadataList = _pinotHelixResourceManager.getSegmentsZKMetadata(realtimeTableName);
Review Comment:
Can we use partitionSet from ideal state to get segment names instead? We really need only segment names and not Zk metadata.
```
/**
* Returns the segments for the given table from the ideal state.
*
* @param tableNameWithType Table name with type suffix
* @param shouldExcludeReplacedSegments whether to return the list of segments that doesn't contain replaced segments.
* @param startTimestamp start timestamp in milliseconds (inclusive)
* @param endTimestamp end timestamp in milliseconds (exclusive)
* @param excludeOverlapping whether to exclude the segments overlapping with the timestamps
* @return List of segment names
*/
public List<String> getSegmentsFor(String tableNameWithType, boolean shouldExcludeReplacedSegments,
long startTimestamp, long endTimestamp, boolean excludeOverlapping)
```
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add support for orphan segment cleanup [pinot]
Posted by "klsince (via GitHub)" <gi...@apache.org>.
klsince commented on code in PR #15142:
URL: https://github.com/apache/pinot/pull/15142#discussion_r1985496441
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/RetentionManager.java:
##########
@@ -136,11 +166,101 @@ private void manageRetentionForOfflineTable(String offlineTableName, RetentionSt
}
}
+ /**
+ * Identifies segments in deepstore that are ready for deletion based on the retention strategy.
+ *
+ * This method finds segments that are beyond the retention period and are ready to be purged.
+ * It only considers segments that do not have entries in ZooKeeper metadata.
+ * The lastModified time of the file in deepstore is used to determine whether the segment
+ * should be retained or purged.
+ *
+ * @param tableNameWithType Name of the offline table
+ * @param retentionStrategy Strategy to determine if a segment should be purged
+ * @param segmentsToExclude List of segment names that should be excluded from deletion
+ * @return List of segment names that should be deleted from deepstore
+ * @throws IOException If there's an error accessing the filesystem
+ */
+ private List<String> getSegmentsToDeleteFromDeepstore(String tableNameWithType, RetentionStrategy retentionStrategy,
+ List<String> segmentsToExclude)
+ throws IOException {
+
+ List<String> segmentsToDelete = new ArrayList<>();
+ String rawTableName = TableNameBuilder.extractRawTableName(tableNameWithType);
+ URI tableDataUri = URIUtils.getUri(_pinotHelixResourceManager.getDataDir(), rawTableName);
+ PinotFS pinotFS = PinotFSFactory.create(tableDataUri.getScheme());
+
+ long startTimeMs = System.currentTimeMillis();
+
+ List<FileMetadata> deepstoreFiles = pinotFS.listFilesWithMetadata(tableDataUri, false);
+ long listEndTimeMs = System.currentTimeMillis();
+ LOGGER.info("Found: {} segments in deepstore for table: {}. Time taken to list segments: {} ms",
Review Comment:
nit: `Found ... in {} ms` to be short
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/RetentionManager.java:
##########
@@ -136,11 +166,101 @@ private void manageRetentionForOfflineTable(String offlineTableName, RetentionSt
}
}
+ /**
+ * Identifies segments in deepstore that are ready for deletion based on the retention strategy.
+ *
+ * This method finds segments that are beyond the retention period and are ready to be purged.
+ * It only considers segments that do not have entries in ZooKeeper metadata.
+ * The lastModified time of the file in deepstore is used to determine whether the segment
+ * should be retained or purged.
+ *
+ * @param tableNameWithType Name of the offline table
+ * @param retentionStrategy Strategy to determine if a segment should be purged
+ * @param segmentsToExclude List of segment names that should be excluded from deletion
+ * @return List of segment names that should be deleted from deepstore
+ * @throws IOException If there's an error accessing the filesystem
+ */
+ private List<String> getSegmentsToDeleteFromDeepstore(String tableNameWithType, RetentionStrategy retentionStrategy,
+ List<String> segmentsToExclude)
+ throws IOException {
+
+ List<String> segmentsToDelete = new ArrayList<>();
+ String rawTableName = TableNameBuilder.extractRawTableName(tableNameWithType);
+ URI tableDataUri = URIUtils.getUri(_pinotHelixResourceManager.getDataDir(), rawTableName);
+ PinotFS pinotFS = PinotFSFactory.create(tableDataUri.getScheme());
+
+ long startTimeMs = System.currentTimeMillis();
+
+ List<FileMetadata> deepstoreFiles = pinotFS.listFilesWithMetadata(tableDataUri, false);
+ long listEndTimeMs = System.currentTimeMillis();
+ LOGGER.info("Found: {} segments in deepstore for table: {}. Time taken to list segments: {} ms",
+ deepstoreFiles.size(), tableNameWithType, listEndTimeMs - startTimeMs);
+
+ for (FileMetadata fileMetadata : deepstoreFiles) {
+ if (fileMetadata.isDirectory()) {
+ continue;
+ }
+
+ String segmentName = extractSegmentName(fileMetadata.getFilePath());
+ if (Strings.isEmpty(segmentName) || segmentsToExclude.contains(segmentName)) {
+ continue;
+ }
+
+ // determine whether the segment should be purged or not based on the last modified time of the file
+ long lastModifiedTime = fileMetadata.getLastModifiedTime();
+
+ if (retentionStrategy.isPurgeable(tableNameWithType, segmentName, lastModifiedTime)) {
+ segmentsToDelete.add(segmentName);
+ }
+ }
+ long endTimeMs = System.currentTimeMillis();
+ LOGGER.info(
Review Comment:
perhaps combine the two INFO together, as "Found {} segments ... have no corresponding ZK metadata, in {} msg"
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/RetentionManager.java:
##########
@@ -136,11 +166,101 @@ private void manageRetentionForOfflineTable(String offlineTableName, RetentionSt
}
}
+ /**
+ * Identifies segments in deepstore that are ready for deletion based on the retention strategy.
+ *
+ * This method finds segments that are beyond the retention period and are ready to be purged.
+ * It only considers segments that do not have entries in ZooKeeper metadata.
+ * The lastModified time of the file in deepstore is used to determine whether the segment
+ * should be retained or purged.
+ *
+ * @param tableNameWithType Name of the offline table
+ * @param retentionStrategy Strategy to determine if a segment should be purged
+ * @param segmentsToExclude List of segment names that should be excluded from deletion
+ * @return List of segment names that should be deleted from deepstore
+ * @throws IOException If there's an error accessing the filesystem
+ */
+ private List<String> getSegmentsToDeleteFromDeepstore(String tableNameWithType, RetentionStrategy retentionStrategy,
+ List<String> segmentsToExclude)
+ throws IOException {
+
+ List<String> segmentsToDelete = new ArrayList<>();
+ String rawTableName = TableNameBuilder.extractRawTableName(tableNameWithType);
+ URI tableDataUri = URIUtils.getUri(_pinotHelixResourceManager.getDataDir(), rawTableName);
+ PinotFS pinotFS = PinotFSFactory.create(tableDataUri.getScheme());
+
+ long startTimeMs = System.currentTimeMillis();
+
+ List<FileMetadata> deepstoreFiles = pinotFS.listFilesWithMetadata(tableDataUri, false);
+ long listEndTimeMs = System.currentTimeMillis();
+ LOGGER.info("Found: {} segments in deepstore for table: {}. Time taken to list segments: {} ms",
+ deepstoreFiles.size(), tableNameWithType, listEndTimeMs - startTimeMs);
+
+ for (FileMetadata fileMetadata : deepstoreFiles) {
+ if (fileMetadata.isDirectory()) {
+ continue;
+ }
+
+ String segmentName = extractSegmentName(fileMetadata.getFilePath());
+ if (Strings.isEmpty(segmentName) || segmentsToExclude.contains(segmentName)) {
+ continue;
+ }
+
+ // determine whether the segment should be purged or not based on the last modified time of the file
+ long lastModifiedTime = fileMetadata.getLastModifiedTime();
+
+ if (retentionStrategy.isPurgeable(tableNameWithType, segmentName, lastModifiedTime)) {
+ segmentsToDelete.add(segmentName);
+ }
+ }
+ long endTimeMs = System.currentTimeMillis();
+ LOGGER.info(
+ "Took: {} ms to filter segments to delete from deepstore for table: {} that don't have a corresponding entry "
+ + "in property store",
+ endTimeMs - startTimeMs, tableNameWithType);
+ LOGGER.info(
+ "Deleting: {} segments from deep store for table: {} as they have no corresponding entry in the property "
+ + "store.", segmentsToDelete.size(), tableNameWithType);
+
+ return segmentsToDelete;
+ }
+
+ @Nullable
+ private String extractSegmentName(@Nullable String filePath) {
+ if (Strings.isEmpty(filePath)) {
+ return null;
+ }
+ String segmentName = filePath.substring(filePath.lastIndexOf("/") + 1);
+ if (segmentName.endsWith(TarCompressionUtils.TAR_GZ_FILE_EXTENSION)) {
+ segmentName = segmentName.substring(0, segmentName.length() - TarCompressionUtils.TAR_GZ_FILE_EXTENSION.length());
+ }
+ return segmentName;
+ }
+
private void manageRetentionForRealtimeTable(String realtimeTableName, RetentionStrategy retentionStrategy) {
+ List<SegmentZKMetadata> segmentZKMetadataList = _pinotHelixResourceManager.getSegmentsZKMetadata(realtimeTableName);
+ List<String> segmentsPresentInZK =
+ segmentZKMetadataList.stream().map(SegmentZKMetadata::getSegmentName).collect(Collectors.toList());
+
List<String> segmentsToDelete = new ArrayList<>();
+
+ // fetch those segments that are beyond the retention period and don't have an entry in ZK i.e.
+ // SegmentZkMetadata is missing for those segments
+ try {
+ LOGGER.info("Fetch segments present in deep store that are beyond retention period for table: {}",
+ realtimeTableName);
+ segmentsToDelete = getSegmentsToDeleteFromDeepstore(realtimeTableName, retentionStrategy, segmentsPresentInZK);
+ _controllerMetrics.setValueOfTableGauge(realtimeTableName, ControllerGauge.UNTRACKED_SEGMENTS_COUNT,
+ segmentsToDelete.size());
+ } catch (IOException e) {
+ LOGGER.warn("Unable to fetch segments from deep store that are beyond retention period for table: {}",
+ realtimeTableName);
+ }
Review Comment:
make a helper method from L241-L258 and use it for both manageRetentionForOfflineTable and manageRetentionForREaltimeTable?
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add support for orphan segment cleanup [pinot]
Posted by "swaminathanmanish (via GitHub)" <gi...@apache.org>.
swaminathanmanish commented on code in PR #15142:
URL: https://github.com/apache/pinot/pull/15142#discussion_r1983669497
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/RetentionManager.java:
##########
@@ -136,11 +164,86 @@ private void manageRetentionForOfflineTable(String offlineTableName, RetentionSt
}
}
+ /**
+ * Identifies segments in deepstore that are ready for deletion based on the retention strategy.
+ *
+ * This method finds segments that are beyond the retention period and are ready to be purged.
+ * It only considers segments that do not have entries in ZooKeeper metadata.
+ * The lastModified time of the file in deepstore is used to determine whether the segment
+ * should be retained or purged.
+ *
+ * @param tableNameWithType Name of the offline table
+ * @param retentionStrategy Strategy to determine if a segment should be purged
+ * @param segmentsToExclude List of segment names that should be excluded from deletion
+ * @return List of segment names that should be deleted from deepstore
+ * @throws IOException If there's an error accessing the filesystem
+ */
+ private List<String> getSegmentsToDeleteFromDeepstore(String tableNameWithType, RetentionStrategy retentionStrategy,
+ List<String> segmentsToExclude)
+ throws IOException {
+
+ List<String> segmentsToDelete = new ArrayList<>();
+ String rawTableName = TableNameBuilder.extractRawTableName(tableNameWithType);
+ URI tableDataUri = URIUtils.getUri(_pinotHelixResourceManager.getDataDir(), rawTableName);
+ PinotFS pinotFS = PinotFSFactory.create(tableDataUri.getScheme());
+
+ List<FileMetadata> deepstoreFiles = pinotFS.listFilesWithMetadata(tableDataUri, false);
Review Comment:
Can we add a metric to get count of files that are in deep store but not in segmentZkMetadata ? This is to see how many dangling files are in the deep store
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/RetentionManager.java:
##########
@@ -136,11 +164,86 @@ private void manageRetentionForOfflineTable(String offlineTableName, RetentionSt
}
}
+ /**
+ * Identifies segments in deepstore that are ready for deletion based on the retention strategy.
+ *
+ * This method finds segments that are beyond the retention period and are ready to be purged.
+ * It only considers segments that do not have entries in ZooKeeper metadata.
+ * The lastModified time of the file in deepstore is used to determine whether the segment
+ * should be retained or purged.
+ *
+ * @param tableNameWithType Name of the offline table
+ * @param retentionStrategy Strategy to determine if a segment should be purged
+ * @param segmentsToExclude List of segment names that should be excluded from deletion
+ * @return List of segment names that should be deleted from deepstore
+ * @throws IOException If there's an error accessing the filesystem
+ */
+ private List<String> getSegmentsToDeleteFromDeepstore(String tableNameWithType, RetentionStrategy retentionStrategy,
+ List<String> segmentsToExclude)
+ throws IOException {
+
+ List<String> segmentsToDelete = new ArrayList<>();
+ String rawTableName = TableNameBuilder.extractRawTableName(tableNameWithType);
+ URI tableDataUri = URIUtils.getUri(_pinotHelixResourceManager.getDataDir(), rawTableName);
+ PinotFS pinotFS = PinotFSFactory.create(tableDataUri.getScheme());
+
+ List<FileMetadata> deepstoreFiles = pinotFS.listFilesWithMetadata(tableDataUri, false);
+
+ for (FileMetadata fileMetadata : deepstoreFiles) {
+ if (fileMetadata.isDirectory()) {
+ continue;
+ }
+
+ String segmentName = extractSegmentName(fileMetadata.getFilePath());
+ if (Strings.isEmpty(segmentName) || segmentsToExclude.contains(segmentName)) {
+ continue;
+ }
+
+ // determine whether the segment should be perged or not based on the last modified time of the file
+ long lastModifiedTime = fileMetadata.getLastModifiedTime();
+
+ if (retentionStrategy.isPurgeable(segmentName, tableNameWithType, lastModifiedTime)) {
Review Comment:
Sycned and learnt that default is 7 days of retention
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/RetentionManager.java:
##########
@@ -136,11 +164,86 @@ private void manageRetentionForOfflineTable(String offlineTableName, RetentionSt
}
}
+ /**
+ * Identifies segments in deepstore that are ready for deletion based on the retention strategy.
+ *
+ * This method finds segments that are beyond the retention period and are ready to be purged.
+ * It only considers segments that do not have entries in ZooKeeper metadata.
+ * The lastModified time of the file in deepstore is used to determine whether the segment
+ * should be retained or purged.
+ *
+ * @param tableNameWithType Name of the offline table
+ * @param retentionStrategy Strategy to determine if a segment should be purged
+ * @param segmentsToExclude List of segment names that should be excluded from deletion
+ * @return List of segment names that should be deleted from deepstore
+ * @throws IOException If there's an error accessing the filesystem
+ */
+ private List<String> getSegmentsToDeleteFromDeepstore(String tableNameWithType, RetentionStrategy retentionStrategy,
+ List<String> segmentsToExclude)
+ throws IOException {
+
+ List<String> segmentsToDelete = new ArrayList<>();
+ String rawTableName = TableNameBuilder.extractRawTableName(tableNameWithType);
+ URI tableDataUri = URIUtils.getUri(_pinotHelixResourceManager.getDataDir(), rawTableName);
+ PinotFS pinotFS = PinotFSFactory.create(tableDataUri.getScheme());
+
+ List<FileMetadata> deepstoreFiles = pinotFS.listFilesWithMetadata(tableDataUri, false);
+
+ for (FileMetadata fileMetadata : deepstoreFiles) {
+ if (fileMetadata.isDirectory()) {
+ continue;
+ }
+
+ String segmentName = extractSegmentName(fileMetadata.getFilePath());
+ if (Strings.isEmpty(segmentName) || segmentsToExclude.contains(segmentName)) {
+ continue;
+ }
+
+ // determine whether the segment should be perged or not based on the last modified time of the file
+ long lastModifiedTime = fileMetadata.getLastModifiedTime();
+
+ if (retentionStrategy.isPurgeable(segmentName, tableNameWithType, lastModifiedTime)) {
+ segmentsToDelete.add(segmentName);
+ }
+ }
+
+ return segmentsToDelete;
+ }
+
+ @Nullable
+ private String extractSegmentName(@Nullable String filePath) {
+ if (Strings.isEmpty(filePath)) {
+ return null;
+ }
+ String segmentName = filePath.substring(filePath.lastIndexOf("/") + 1);
+ if (segmentName.endsWith(TarCompressionUtils.TAR_GZ_FILE_EXTENSION)) {
+ segmentName = segmentName.substring(0, segmentName.length() - TarCompressionUtils.TAR_GZ_FILE_EXTENSION.length());
+ }
+ return segmentName;
+ }
+
private void manageRetentionForRealtimeTable(String realtimeTableName, RetentionStrategy retentionStrategy) {
+ List<SegmentZKMetadata> segmentZKMetadataList = _pinotHelixResourceManager.getSegmentsZKMetadata(realtimeTableName);
Review Comment:
Understood that we need segmentZkmetadata for endTime.
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/RetentionManager.java:
##########
@@ -124,8 +138,19 @@ private void manageRetentionForTable(TableConfig tableConfig) {
}
private void manageRetentionForOfflineTable(String offlineTableName, RetentionStrategy retentionStrategy) {
+ List<SegmentZKMetadata> segmentZKMetadataList = _pinotHelixResourceManager.getSegmentsZKMetadata(offlineTableName);
Review Comment:
I initially did not realize that we already loop through all of segmentZk metadata to check if segment is purge-able (retentionStrategy.isPurgeable).
Yes its possible for a segment to be Zk metadata but not in IS @klsince, but we want to handle that case as well right?
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add support for orphan segment cleanup [pinot]
Posted by "9aman (via GitHub)" <gi...@apache.org>.
9aman commented on code in PR #15142:
URL: https://github.com/apache/pinot/pull/15142#discussion_r2001098021
##########
pinot-spi/src/main/java/org/apache/pinot/spi/config/table/SegmentsValidationAndRetentionConfig.java:
##########
@@ -55,6 +55,8 @@ public class SegmentsValidationAndRetentionConfig extends BaseJsonConfig {
// For more usage of this field, please refer to this design doc: https://tinyurl.com/f63ru4sb
private String _peerSegmentDownloadScheme;
+ private int _untrackedSegmentsDeletionBatchSize;
Review Comment:
- It uses the default value of 100 in case it is enabled and no batch size is provided.
- The user can still stop the deletion, at a `table level`, by setting the batch size to `0`.
- Increasing/ decreasing batch size is still possible at table level.
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add support for orphan segment cleanup [pinot]
Posted by "swaminathanmanish (via GitHub)" <gi...@apache.org>.
swaminathanmanish commented on code in PR #15142:
URL: https://github.com/apache/pinot/pull/15142#discussion_r1973944323
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/RetentionManager.java:
##########
@@ -136,11 +164,86 @@ private void manageRetentionForOfflineTable(String offlineTableName, RetentionSt
}
}
+ /**
+ * Identifies segments in deepstore that are ready for deletion based on the retention strategy.
+ *
+ * This method finds segments that are beyond the retention period and are ready to be purged.
+ * It only considers segments that do not have entries in ZooKeeper metadata.
+ * The lastModified time of the file in deepstore is used to determine whether the segment
+ * should be retained or purged.
+ *
+ * @param tableNameWithType Name of the offline table
+ * @param retentionStrategy Strategy to determine if a segment should be purged
+ * @param segmentsToExclude List of segment names that should be excluded from deletion
+ * @return List of segment names that should be deleted from deepstore
+ * @throws IOException If there's an error accessing the filesystem
+ */
+ private List<String> getSegmentsToDeleteFromDeepstore(String tableNameWithType, RetentionStrategy retentionStrategy,
+ List<String> segmentsToExclude)
+ throws IOException {
+
+ List<String> segmentsToDelete = new ArrayList<>();
+ String rawTableName = TableNameBuilder.extractRawTableName(tableNameWithType);
+ URI tableDataUri = URIUtils.getUri(_pinotHelixResourceManager.getDataDir(), rawTableName);
+ PinotFS pinotFS = PinotFSFactory.create(tableDataUri.getScheme());
+
+ List<FileMetadata> deepstoreFiles = pinotFS.listFilesWithMetadata(tableDataUri, false);
+
+ for (FileMetadata fileMetadata : deepstoreFiles) {
+ if (fileMetadata.isDirectory()) {
+ continue;
+ }
+
+ String segmentName = extractSegmentName(fileMetadata.getFilePath());
+ if (Strings.isEmpty(segmentName) || segmentsToExclude.contains(segmentName)) {
+ continue;
+ }
+
+ // determine whether the segment should be perged or not based on the last modified time of the file
+ long lastModifiedTime = fileMetadata.getLastModifiedTime();
+
+ if (retentionStrategy.isPurgeable(segmentName, tableNameWithType, lastModifiedTime)) {
Review Comment:
Is there a default retention ? If its 0, we will end up removing the segment from Deep store, when minion might have just pushed it.
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/strategy/RetentionStrategy.java:
##########
@@ -34,4 +34,14 @@ public interface RetentionStrategy {
* @return Whether the segment should be purged
*/
boolean isPurgeable(String tableNameWithType, SegmentZKMetadata segmentZKMetadata);
-}
+
+ /**
+ * Returns whether the segment should be purged based on end time.
+ *
+ * @param segmentName The name of the segment to check
+ * @param tableNameWithType Table name with type
+ * @param endTimeMs The end time of the segment in milliseconds
+ * @return Whether the segment should be purged
+ */
+ boolean isPurgeable(String segmentName, String tableNameWithType, long endTimeMs);
Review Comment:
Suggest having this method local to SegmentDeletionManager since endTime is supplied from outside. It'll be confusing as to what needs to be passed in (file modification time/segment time etc..). The caller can get the retention time and do its own checks ?
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/RetentionManager.java:
##########
@@ -124,8 +138,19 @@ private void manageRetentionForTable(TableConfig tableConfig) {
}
private void manageRetentionForOfflineTable(String offlineTableName, RetentionStrategy retentionStrategy) {
+ List<SegmentZKMetadata> segmentZKMetadataList = _pinotHelixResourceManager.getSegmentsZKMetadata(offlineTableName);
Review Comment:
Can we not just rely on the ideal state as source of truth because that would avoid reading all of segment Zk ? We are going to check retention window as well prior to deletion (if the concern is deleting a new segment that just got added, which can happen even when the segment is not in Zk metadata but just in deep store).
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/RetentionManager.java:
##########
@@ -124,8 +136,24 @@ private void manageRetentionForTable(TableConfig tableConfig) {
}
private void manageRetentionForOfflineTable(String offlineTableName, RetentionStrategy retentionStrategy) {
Review Comment:
We need this for manageRetentionForRealtimeTable as well right? There can be tasks that work on realtime tables as well.
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add support for orphan segment cleanup [pinot]
Posted by "9aman (via GitHub)" <gi...@apache.org>.
9aman commented on code in PR #15142:
URL: https://github.com/apache/pinot/pull/15142#discussion_r1984788298
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/RetentionManager.java:
##########
@@ -77,6 +88,7 @@ protected void processTable(String tableNameWithType) {
return;
}
+ // Did not understand
Review Comment:
Done. Thanks for pointing it out.
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add support for orphan segment cleanup [pinot]
Posted by "9aman (via GitHub)" <gi...@apache.org>.
9aman commented on code in PR #15142:
URL: https://github.com/apache/pinot/pull/15142#discussion_r1991323173
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/RetentionManager.java:
##########
@@ -189,6 +219,110 @@ private boolean shouldDeleteInProgressLLCSegment(String segmentName, IdealState
}
}
+ private List<String> getSegmentsToDeleteFromDeepstore(String tableNameWithType, RetentionStrategy retentionStrategy,
+ List<SegmentZKMetadata> segmentZKMetadataList, int untrackedSegmentsDeletionBatchSize) {
+ List<String> segmentsToDelete = new ArrayList<>();
+
+ if (untrackedSegmentsDeletionBatchSize <= 0) {
Review Comment:
Logging and returning early in case it's set to zero to avoid listing all the files in the deepstore.
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add support for orphan segment cleanup [pinot]
Posted by "9aman (via GitHub)" <gi...@apache.org>.
9aman commented on code in PR #15142:
URL: https://github.com/apache/pinot/pull/15142#discussion_r2000870263
##########
pinot-common/src/main/java/org/apache/pinot/common/metrics/ControllerGauge.java:
##########
@@ -190,7 +190,11 @@ public enum ControllerGauge implements AbstractMetrics.Gauge {
REINGESTED_SEGMENT_UPLOADS_IN_PROGRESS("reingestedSegmentUploadsInProgress", true),
// Resource utilization is within limits or not for a table
- RESOURCE_UTILIZATION_LIMIT_EXCEEDED("ResourceUtilizationLimitExceeded", false);
+ RESOURCE_UTILIZATION_LIMIT_EXCEEDED("ResourceUtilizationLimitExceeded", false),
Review Comment:
The ControllerGauge has a mixed of formats used for naming.
Won't it introduce backwards compatibility issue as this will change the metric name in prometheus/ grafana ?
Also, I haven't added this metric and is not part of the PR. I am happy to change it though.
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add support for orphan segment cleanup [pinot]
Posted by "9aman (via GitHub)" <gi...@apache.org>.
9aman commented on code in PR #15142:
URL: https://github.com/apache/pinot/pull/15142#discussion_r1976538207
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/strategy/RetentionStrategy.java:
##########
@@ -34,4 +34,14 @@ public interface RetentionStrategy {
* @return Whether the segment should be purged
*/
boolean isPurgeable(String tableNameWithType, SegmentZKMetadata segmentZKMetadata);
-}
+
+ /**
+ * Returns whether the segment should be purged based on end time.
+ *
+ * @param segmentName The name of the segment to check
+ * @param tableNameWithType Table name with type
+ * @param endTimeMs The end time of the segment in milliseconds
+ * @return Whether the segment should be purged
+ */
+ boolean isPurgeable(String segmentName, String tableNameWithType, long endTimeMs);
Review Comment:
Yes, but I would still keep it as part of the `RetentionManager`. I feel that the `SegmentDeletionManager` should just have the job of deleting (moving to Deleted_Segments dir) and not know what segments needs to be deleted.
For our case, the RetentionManager can fetch the segments from deepstore and decide based on the file modification time whether they need to be deleted or not.
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/strategy/RetentionStrategy.java:
##########
@@ -34,4 +34,14 @@ public interface RetentionStrategy {
* @return Whether the segment should be purged
*/
boolean isPurgeable(String tableNameWithType, SegmentZKMetadata segmentZKMetadata);
-}
+
+ /**
+ * Returns whether the segment should be purged based on end time.
+ *
+ * @param segmentName The name of the segment to check
+ * @param tableNameWithType Table name with type
+ * @param endTimeMs The end time of the segment in milliseconds
+ * @return Whether the segment should be purged
+ */
+ boolean isPurgeable(String segmentName, String tableNameWithType, long endTimeMs);
Review Comment:
Yes, but I would still keep it as part of the `RetentionManager`. I feel that the `SegmentDeletionManager` should just have the job of deleting (moving to Deleted_Segments dir) and not know what segments needs to be deleted.
For our case, the `RetentionManager` can fetch the segments from deepstore and decide based on the file modification time whether they need to be deleted or not.
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add support for orphan segment cleanup [pinot]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #15142:
URL: https://github.com/apache/pinot/pull/15142#issuecomment-2687261957
## [Codecov](https://app.codecov.io/gh/apache/pinot/pull/15142?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 55.92%. Comparing base [(`59551e4`)](https://app.codecov.io/gh/apache/pinot/commit/59551e45224f1535c4863fd577622b37366ccc97?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`405afa0`)](https://app.codecov.io/gh/apache/pinot/commit/405afa0a53fdd03ea4e37d59998946aa63026ff1?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
> Report is 1768 commits behind head on master.
> :exclamation: There is a different number of reports uploaded between BASE (59551e4) and HEAD (405afa0). Click for more details.
>
> <details><summary>HEAD has 48 uploads less than BASE</summary>
>
>| Flag | BASE (59551e4) | HEAD (405afa0) |
>|------|------|------|
>|integration|7|0|
>|integration2|3|0|
>|temurin|12|2|
>|java-21|7|2|
>|skip-bytebuffers-true|3|1|
>|skip-bytebuffers-false|7|1|
>|unittests|5|2|
>|java-11|5|0|
>|unittests2|3|0|
>|integration1|2|0|
>|custom-integration1|2|0|
></details>
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## master #15142 +/- ##
============================================
- Coverage 61.75% 55.92% -5.83%
- Complexity 207 712 +505
============================================
Files 2436 2152 -284
Lines 133233 115772 -17461
Branches 20636 18587 -2049
============================================
- Hits 82274 64744 -17530
- Misses 44911 45709 +798
+ Partials 6048 5319 -729
```
| [Flag](https://app.codecov.io/gh/apache/pinot/pull/15142/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [custom-integration1](https://app.codecov.io/gh/apache/pinot/pull/15142/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [integration](https://app.codecov.io/gh/apache/pinot/pull/15142/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [integration1](https://app.codecov.io/gh/apache/pinot/pull/15142/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [integration2](https://app.codecov.io/gh/apache/pinot/pull/15142/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [java-11](https://app.codecov.io/gh/apache/pinot/pull/15142/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [java-21](https://app.codecov.io/gh/apache/pinot/pull/15142/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `55.92% <ø> (-5.71%)` | :arrow_down: |
| [skip-bytebuffers-false](https://app.codecov.io/gh/apache/pinot/pull/15142/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `55.90% <ø> (-5.85%)` | :arrow_down: |
| [skip-bytebuffers-true](https://app.codecov.io/gh/apache/pinot/pull/15142/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `55.86% <ø> (+28.13%)` | :arrow_up: |
| [temurin](https://app.codecov.io/gh/apache/pinot/pull/15142/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `55.92% <ø> (-5.83%)` | :arrow_down: |
| [unittests](https://app.codecov.io/gh/apache/pinot/pull/15142/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `55.92% <ø> (-5.83%)` | :arrow_down: |
| [unittests1](https://app.codecov.io/gh/apache/pinot/pull/15142/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `55.92% <ø> (+9.03%)` | :arrow_up: |
| [unittests2](https://app.codecov.io/gh/apache/pinot/pull/15142/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
</details>
[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/pinot/pull/15142?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add support for orphan segment cleanup [pinot]
Posted by "9aman (via GitHub)" <gi...@apache.org>.
9aman commented on code in PR #15142:
URL: https://github.com/apache/pinot/pull/15142#discussion_r1974945868
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/RetentionManager.java:
##########
@@ -136,11 +164,86 @@ private void manageRetentionForOfflineTable(String offlineTableName, RetentionSt
}
}
+ /**
+ * Identifies segments in deepstore that are ready for deletion based on the retention strategy.
+ *
+ * This method finds segments that are beyond the retention period and are ready to be purged.
+ * It only considers segments that do not have entries in ZooKeeper metadata.
+ * The lastModified time of the file in deepstore is used to determine whether the segment
+ * should be retained or purged.
+ *
+ * @param tableNameWithType Name of the offline table
+ * @param retentionStrategy Strategy to determine if a segment should be purged
+ * @param segmentsToExclude List of segment names that should be excluded from deletion
+ * @return List of segment names that should be deleted from deepstore
+ * @throws IOException If there's an error accessing the filesystem
+ */
+ private List<String> getSegmentsToDeleteFromDeepstore(String tableNameWithType, RetentionStrategy retentionStrategy,
+ List<String> segmentsToExclude)
+ throws IOException {
+
+ List<String> segmentsToDelete = new ArrayList<>();
+ String rawTableName = TableNameBuilder.extractRawTableName(tableNameWithType);
+ URI tableDataUri = URIUtils.getUri(_pinotHelixResourceManager.getDataDir(), rawTableName);
+ PinotFS pinotFS = PinotFSFactory.create(tableDataUri.getScheme());
+
+ List<FileMetadata> deepstoreFiles = pinotFS.listFilesWithMetadata(tableDataUri, false);
+
+ for (FileMetadata fileMetadata : deepstoreFiles) {
+ if (fileMetadata.isDirectory()) {
+ continue;
+ }
+
+ String segmentName = extractSegmentName(fileMetadata.getFilePath());
+ if (Strings.isEmpty(segmentName) || segmentsToExclude.contains(segmentName)) {
+ continue;
+ }
+
+ // determine whether the segment should be perged or not based on the last modified time of the file
+ long lastModifiedTime = fileMetadata.getLastModifiedTime();
+
+ if (retentionStrategy.isPurgeable(segmentName, tableNameWithType, lastModifiedTime)) {
+ segmentsToDelete.add(segmentName);
+ }
+ }
+
+ return segmentsToDelete;
+ }
+
+ @Nullable
+ private String extractSegmentName(@Nullable String filePath) {
+ if (Strings.isEmpty(filePath)) {
+ return null;
+ }
+ String segmentName = filePath.substring(filePath.lastIndexOf("/") + 1);
+ if (segmentName.endsWith(TarCompressionUtils.TAR_GZ_FILE_EXTENSION)) {
+ segmentName = segmentName.substring(0, segmentName.length() - TarCompressionUtils.TAR_GZ_FILE_EXTENSION.length());
+ }
+ return segmentName;
+ }
+
private void manageRetentionForRealtimeTable(String realtimeTableName, RetentionStrategy retentionStrategy) {
+ List<SegmentZKMetadata> segmentZKMetadataList = _pinotHelixResourceManager.getSegmentsZKMetadata(realtimeTableName);
Review Comment:
`Can we use partitionSet from ideal state to get segment names instead? We really need only segment names and not Zk metadata.`
We need the metadata to decide whether a segment should be purged or not. The existing code also relied on the metadata to perform the cleanup. I just reused it to get the segment name as well
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add support for orphan segment cleanup [pinot]
Posted by "9aman (via GitHub)" <gi...@apache.org>.
9aman commented on code in PR #15142:
URL: https://github.com/apache/pinot/pull/15142#discussion_r1984975628
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/RetentionManager.java:
##########
@@ -136,11 +164,86 @@ private void manageRetentionForOfflineTable(String offlineTableName, RetentionSt
}
}
+ /**
+ * Identifies segments in deepstore that are ready for deletion based on the retention strategy.
+ *
+ * This method finds segments that are beyond the retention period and are ready to be purged.
+ * It only considers segments that do not have entries in ZooKeeper metadata.
+ * The lastModified time of the file in deepstore is used to determine whether the segment
+ * should be retained or purged.
+ *
+ * @param tableNameWithType Name of the offline table
+ * @param retentionStrategy Strategy to determine if a segment should be purged
+ * @param segmentsToExclude List of segment names that should be excluded from deletion
+ * @return List of segment names that should be deleted from deepstore
+ * @throws IOException If there's an error accessing the filesystem
+ */
+ private List<String> getSegmentsToDeleteFromDeepstore(String tableNameWithType, RetentionStrategy retentionStrategy,
+ List<String> segmentsToExclude)
+ throws IOException {
+
+ List<String> segmentsToDelete = new ArrayList<>();
+ String rawTableName = TableNameBuilder.extractRawTableName(tableNameWithType);
+ URI tableDataUri = URIUtils.getUri(_pinotHelixResourceManager.getDataDir(), rawTableName);
+ PinotFS pinotFS = PinotFSFactory.create(tableDataUri.getScheme());
+
+ List<FileMetadata> deepstoreFiles = pinotFS.listFilesWithMetadata(tableDataUri, false);
Review Comment:
Done
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/strategy/TimeRetentionStrategy.java:
##########
@@ -50,4 +50,17 @@ public boolean isPurgeable(String tableNameWithType, SegmentZKMetadata segmentZK
return System.currentTimeMillis() - endTimeMs > _retentionMs;
}
+
+ @Override
+ public boolean isPurgeable(String segmentName, String tableNameWithType, long endTimeMs) {
Review Comment:
Done
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add support for orphan segment cleanup [pinot]
Posted by "swaminathanmanish (via GitHub)" <gi...@apache.org>.
swaminathanmanish merged PR #15142:
URL: https://github.com/apache/pinot/pull/15142
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add support for orphan segment cleanup [pinot]
Posted by "9aman (via GitHub)" <gi...@apache.org>.
9aman commented on code in PR #15142:
URL: https://github.com/apache/pinot/pull/15142#discussion_r2000894701
##########
pinot-spi/src/main/java/org/apache/pinot/spi/config/table/SegmentsValidationAndRetentionConfig.java:
##########
@@ -55,6 +55,8 @@ public class SegmentsValidationAndRetentionConfig extends BaseJsonConfig {
// For more usage of this field, please refer to this design doc: https://tinyurl.com/f63ru4sb
private String _peerSegmentDownloadScheme;
+ private int _untrackedSegmentsDeletionBatchSize;
Review Comment:
In case we but the default size as 100 segments, the time taken for the run for a table with 100 K segments will be:
- Time taken to list all the 100 K segments: ~ 20 seconds (it take 200 ms to list 1000 segments)
- All the segments will be listed irrespective of the batch size.
- Assuming each path listed if of 100 characters, the size will be 200 bytes. For 100 K it will be ~20 MB
- Time taken to delete 100 segments: ~25 seconds
Total time taken ~ 1 minute for each table.
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add support for orphan segment cleanup [pinot]
Posted by "9aman (via GitHub)" <gi...@apache.org>.
9aman commented on code in PR #15142:
URL: https://github.com/apache/pinot/pull/15142#discussion_r1973211227
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/RetentionManager.java:
##########
@@ -124,8 +138,19 @@ private void manageRetentionForTable(TableConfig tableConfig) {
}
private void manageRetentionForOfflineTable(String offlineTableName, RetentionStrategy retentionStrategy) {
+ List<SegmentZKMetadata> segmentZKMetadataList = _pinotHelixResourceManager.getSegmentsZKMetadata(offlineTableName);
Review Comment:
Segment metadata is added to ZK before it's added to IdealState
Segment metadata is removed from ZK after the segment has been removed from the ideal state.
The segment list from ZK will always be a super set of segments in Ideal State. Thus, I have not checked IS for filtering segments that are still in IS.
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add support for orphan segment cleanup [pinot]
Posted by "klsince (via GitHub)" <gi...@apache.org>.
klsince commented on code in PR #15142:
URL: https://github.com/apache/pinot/pull/15142#discussion_r1982294881
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/RetentionManager.java:
##########
@@ -77,6 +88,7 @@ protected void processTable(String tableNameWithType) {
return;
}
+ // Did not understand
Review Comment:
remove?
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/strategy/TimeRetentionStrategy.java:
##########
@@ -50,4 +50,17 @@ public boolean isPurgeable(String tableNameWithType, SegmentZKMetadata segmentZK
return System.currentTimeMillis() - endTimeMs > _retentionMs;
}
+
+ @Override
+ public boolean isPurgeable(String segmentName, String tableNameWithType, long endTimeMs) {
Review Comment:
1. better move tableNameWithType as the first param for consistency
2. can reuse this method to implement the method above
3. perhaps call endTimeMs segmentTimeMs to be generic? and leave a comment that segmentTimeMs can be endTime or mtime etc. to be decided by the caller
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/SegmentDeletionManager.java:
##########
@@ -221,6 +221,7 @@ private void deleteSegmentMetadataFromStore(PinotFS pinotFS, URI segmentFileUri,
URI segmentMetadataUri = SegmentPushUtils.generateSegmentMetadataURI(segmentFileUri.toString(), segmentId);
if (pinotFS.exists(segmentMetadataUri)) {
LOGGER.info("Deleting segment metadata {} from {}", segmentId, segmentMetadataUri);
+ // TODO: check if the deletion was successful and add a warning here.
Review Comment:
is this TODO supposed to check the return of the delete() method and log warning if false? if so, maybe we can just add it in this PR.
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/RetentionManager.java:
##########
@@ -136,11 +164,86 @@ private void manageRetentionForOfflineTable(String offlineTableName, RetentionSt
}
}
+ /**
+ * Identifies segments in deepstore that are ready for deletion based on the retention strategy.
+ *
+ * This method finds segments that are beyond the retention period and are ready to be purged.
+ * It only considers segments that do not have entries in ZooKeeper metadata.
+ * The lastModified time of the file in deepstore is used to determine whether the segment
+ * should be retained or purged.
+ *
+ * @param tableNameWithType Name of the offline table
+ * @param retentionStrategy Strategy to determine if a segment should be purged
+ * @param segmentsToExclude List of segment names that should be excluded from deletion
+ * @return List of segment names that should be deleted from deepstore
+ * @throws IOException If there's an error accessing the filesystem
+ */
+ private List<String> getSegmentsToDeleteFromDeepstore(String tableNameWithType, RetentionStrategy retentionStrategy,
+ List<String> segmentsToExclude)
+ throws IOException {
+
+ List<String> segmentsToDelete = new ArrayList<>();
+ String rawTableName = TableNameBuilder.extractRawTableName(tableNameWithType);
+ URI tableDataUri = URIUtils.getUri(_pinotHelixResourceManager.getDataDir(), rawTableName);
+ PinotFS pinotFS = PinotFSFactory.create(tableDataUri.getScheme());
+
+ List<FileMetadata> deepstoreFiles = pinotFS.listFilesWithMetadata(tableDataUri, false);
+
Review Comment:
maybe print a INFO log here about how many segments found, and the timestamp in the log, with another INFO log after the for-loop, can be used to calculate how long it'd take to figure out the files to delete.
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/RetentionManager.java:
##########
@@ -124,8 +138,19 @@ private void manageRetentionForTable(TableConfig tableConfig) {
}
private void manageRetentionForOfflineTable(String offlineTableName, RetentionStrategy retentionStrategy) {
+ List<SegmentZKMetadata> segmentZKMetadataList = _pinotHelixResourceManager.getSegmentsZKMetadata(offlineTableName);
Review Comment:
Would it happen that segment's ZKMetadata was still there in ZK but segment was not in IS any more?
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/RetentionManager.java:
##########
@@ -136,11 +164,86 @@ private void manageRetentionForOfflineTable(String offlineTableName, RetentionSt
}
}
+ /**
+ * Identifies segments in deepstore that are ready for deletion based on the retention strategy.
+ *
+ * This method finds segments that are beyond the retention period and are ready to be purged.
+ * It only considers segments that do not have entries in ZooKeeper metadata.
+ * The lastModified time of the file in deepstore is used to determine whether the segment
+ * should be retained or purged.
+ *
+ * @param tableNameWithType Name of the offline table
+ * @param retentionStrategy Strategy to determine if a segment should be purged
+ * @param segmentsToExclude List of segment names that should be excluded from deletion
+ * @return List of segment names that should be deleted from deepstore
+ * @throws IOException If there's an error accessing the filesystem
+ */
+ private List<String> getSegmentsToDeleteFromDeepstore(String tableNameWithType, RetentionStrategy retentionStrategy,
+ List<String> segmentsToExclude)
+ throws IOException {
+
+ List<String> segmentsToDelete = new ArrayList<>();
+ String rawTableName = TableNameBuilder.extractRawTableName(tableNameWithType);
+ URI tableDataUri = URIUtils.getUri(_pinotHelixResourceManager.getDataDir(), rawTableName);
+ PinotFS pinotFS = PinotFSFactory.create(tableDataUri.getScheme());
+
+ List<FileMetadata> deepstoreFiles = pinotFS.listFilesWithMetadata(tableDataUri, false);
+
+ for (FileMetadata fileMetadata : deepstoreFiles) {
+ if (fileMetadata.isDirectory()) {
+ continue;
+ }
+
+ String segmentName = extractSegmentName(fileMetadata.getFilePath());
+ if (Strings.isEmpty(segmentName) || segmentsToExclude.contains(segmentName)) {
+ continue;
+ }
+
+ // determine whether the segment should be perged or not based on the last modified time of the file
+ long lastModifiedTime = fileMetadata.getLastModifiedTime();
+
+ if (retentionStrategy.isPurgeable(segmentName, tableNameWithType, lastModifiedTime)) {
+ segmentsToDelete.add(segmentName);
+ }
+ }
+
Review Comment:
add an INFO log about how many segments to delete
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add support for orphan segment cleanup [pinot]
Posted by "9aman (via GitHub)" <gi...@apache.org>.
9aman commented on code in PR #15142:
URL: https://github.com/apache/pinot/pull/15142#discussion_r1984783168
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/strategy/RetentionStrategy.java:
##########
@@ -34,4 +34,14 @@ public interface RetentionStrategy {
* @return Whether the segment should be purged
*/
boolean isPurgeable(String tableNameWithType, SegmentZKMetadata segmentZKMetadata);
-}
+
+ /**
+ * Returns whether the segment should be purged based on end time.
+ *
+ * @param segmentName The name of the segment to check
+ * @param tableNameWithType Table name with type
+ * @param endTimeMs The end time of the segment in milliseconds
+ * @return Whether the segment should be purged
+ */
+ boolean isPurgeable(String segmentName, String tableNameWithType, long endTimeMs);
Review Comment:
On a second pass I think it's fine to have this.
One can pass the endTimeMs that needs to be compared to System.currentTimeMillis() - retentionMS i.e.
System.currentTimeMillis() - retentionMS > endTimeMs.
It's a more generic implementation of the
```
public boolean isPurgeable(String tableNameWithType, SegmentZKMetadata segmentZKMetadata)
```
Where one only needs to rely on endTime present in segmentZKMetadata
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add support for orphan segment cleanup [pinot]
Posted by "swaminathanmanish (via GitHub)" <gi...@apache.org>.
swaminathanmanish commented on code in PR #15142:
URL: https://github.com/apache/pinot/pull/15142#discussion_r1998227220
##########
pinot-spi/src/main/java/org/apache/pinot/spi/config/table/SegmentsValidationAndRetentionConfig.java:
##########
@@ -55,6 +55,8 @@ public class SegmentsValidationAndRetentionConfig extends BaseJsonConfig {
// For more usage of this field, please refer to this design doc: https://tinyurl.com/f63ru4sb
private String _peerSegmentDownloadScheme;
+ private int _untrackedSegmentsDeletionBatchSize;
Review Comment:
Thanks Aman. User has to provide the batchSize to enable deletion? Why dont we start with small default ( < 100) and enable it by default. User can either increase this or reduce if needed.
cc @klsince .
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add support for orphan segment cleanup [pinot]
Posted by "9aman (via GitHub)" <gi...@apache.org>.
9aman commented on code in PR #15142:
URL: https://github.com/apache/pinot/pull/15142#discussion_r1973212774
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/RetentionManager.java:
##########
@@ -136,6 +161,49 @@ private void manageRetentionForOfflineTable(String offlineTableName, RetentionSt
}
}
+ private List<String> getSegmentsToDeleteFromDeepstore(String offlineTableName, RetentionStrategy retentionStrategy,
+ List<String> segmentsToExclude)
+ throws IOException {
+
+ List<String> segmentsToDelete = new ArrayList<>();
+ String rawTableName = TableNameBuilder.extractRawTableName(offlineTableName);
+ URI tableDataUri = URIUtils.getUri(_pinotHelixResourceManager.getDataDir(), rawTableName);
+ PinotFS pinotFS = PinotFSFactory.create(tableDataUri.getScheme());
+
+ List<FileMetadata> deepstoreFiles = pinotFS.listFilesWithMetadata(tableDataUri, false);
+
+ for (FileMetadata fileMetadata : deepstoreFiles) {
+ if (fileMetadata.isDirectory()) {
+ continue;
+ }
+
+ String segmentName = extractSegmentName(fileMetadata.getFilePath());
+ if (segmentName == null || segmentsToExclude.contains(segmentName)) {
+ continue;
+ }
+
+ long lastModifiedTime = fileMetadata.getLastModifiedTime();
+
+ if (retentionStrategy.isPurgeable(segmentName, offlineTableName, lastModifiedTime)) {
Review Comment:
This ensures that a segment that has not entry in the ZK but has been uploaded to deepstore does not get deleted.
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add support for orphan segment cleanup [pinot]
Posted by "9aman (via GitHub)" <gi...@apache.org>.
9aman commented on code in PR #15142:
URL: https://github.com/apache/pinot/pull/15142#discussion_r1973214797
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/RetentionManager.java:
##########
@@ -136,6 +161,49 @@ private void manageRetentionForOfflineTable(String offlineTableName, RetentionSt
}
}
+ private List<String> getSegmentsToDeleteFromDeepstore(String offlineTableName, RetentionStrategy retentionStrategy,
+ List<String> segmentsToExclude)
+ throws IOException {
+
+ List<String> segmentsToDelete = new ArrayList<>();
+ String rawTableName = TableNameBuilder.extractRawTableName(offlineTableName);
+ URI tableDataUri = URIUtils.getUri(_pinotHelixResourceManager.getDataDir(), rawTableName);
+ PinotFS pinotFS = PinotFSFactory.create(tableDataUri.getScheme());
+
+ List<FileMetadata> deepstoreFiles = pinotFS.listFilesWithMetadata(tableDataUri, false);
+
+ for (FileMetadata fileMetadata : deepstoreFiles) {
+ if (fileMetadata.isDirectory()) {
+ continue;
+ }
+
+ String segmentName = extractSegmentName(fileMetadata.getFilePath());
+ if (segmentName == null || segmentsToExclude.contains(segmentName)) {
Review Comment:
Rely on endTime in ZK Metadata for retention in case the segment ZK metadata is present.
This function relies on file modification time to decide whether a segment should be purged or not.
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add support for orphan segment cleanup [pinot]
Posted by "9aman (via GitHub)" <gi...@apache.org>.
9aman commented on code in PR #15142:
URL: https://github.com/apache/pinot/pull/15142#discussion_r1986736997
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/RetentionManager.java:
##########
@@ -136,11 +166,101 @@ private void manageRetentionForOfflineTable(String offlineTableName, RetentionSt
}
}
+ /**
+ * Identifies segments in deepstore that are ready for deletion based on the retention strategy.
+ *
+ * This method finds segments that are beyond the retention period and are ready to be purged.
+ * It only considers segments that do not have entries in ZooKeeper metadata.
+ * The lastModified time of the file in deepstore is used to determine whether the segment
+ * should be retained or purged.
+ *
+ * @param tableNameWithType Name of the offline table
+ * @param retentionStrategy Strategy to determine if a segment should be purged
+ * @param segmentsToExclude List of segment names that should be excluded from deletion
+ * @return List of segment names that should be deleted from deepstore
+ * @throws IOException If there's an error accessing the filesystem
+ */
+ private List<String> getSegmentsToDeleteFromDeepstore(String tableNameWithType, RetentionStrategy retentionStrategy,
+ List<String> segmentsToExclude)
+ throws IOException {
+
+ List<String> segmentsToDelete = new ArrayList<>();
+ String rawTableName = TableNameBuilder.extractRawTableName(tableNameWithType);
+ URI tableDataUri = URIUtils.getUri(_pinotHelixResourceManager.getDataDir(), rawTableName);
+ PinotFS pinotFS = PinotFSFactory.create(tableDataUri.getScheme());
+
+ long startTimeMs = System.currentTimeMillis();
+
+ List<FileMetadata> deepstoreFiles = pinotFS.listFilesWithMetadata(tableDataUri, false);
+ long listEndTimeMs = System.currentTimeMillis();
+ LOGGER.info("Found: {} segments in deepstore for table: {}. Time taken to list segments: {} ms",
+ deepstoreFiles.size(), tableNameWithType, listEndTimeMs - startTimeMs);
+
+ for (FileMetadata fileMetadata : deepstoreFiles) {
+ if (fileMetadata.isDirectory()) {
+ continue;
+ }
+
+ String segmentName = extractSegmentName(fileMetadata.getFilePath());
+ if (Strings.isEmpty(segmentName) || segmentsToExclude.contains(segmentName)) {
+ continue;
+ }
+
+ // determine whether the segment should be purged or not based on the last modified time of the file
+ long lastModifiedTime = fileMetadata.getLastModifiedTime();
+
+ if (retentionStrategy.isPurgeable(tableNameWithType, segmentName, lastModifiedTime)) {
+ segmentsToDelete.add(segmentName);
+ }
+ }
+ long endTimeMs = System.currentTimeMillis();
+ LOGGER.info(
Review Comment:
Done
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/RetentionManager.java:
##########
@@ -136,11 +166,101 @@ private void manageRetentionForOfflineTable(String offlineTableName, RetentionSt
}
}
+ /**
+ * Identifies segments in deepstore that are ready for deletion based on the retention strategy.
+ *
+ * This method finds segments that are beyond the retention period and are ready to be purged.
+ * It only considers segments that do not have entries in ZooKeeper metadata.
+ * The lastModified time of the file in deepstore is used to determine whether the segment
+ * should be retained or purged.
+ *
+ * @param tableNameWithType Name of the offline table
+ * @param retentionStrategy Strategy to determine if a segment should be purged
+ * @param segmentsToExclude List of segment names that should be excluded from deletion
+ * @return List of segment names that should be deleted from deepstore
+ * @throws IOException If there's an error accessing the filesystem
+ */
+ private List<String> getSegmentsToDeleteFromDeepstore(String tableNameWithType, RetentionStrategy retentionStrategy,
+ List<String> segmentsToExclude)
+ throws IOException {
+
+ List<String> segmentsToDelete = new ArrayList<>();
+ String rawTableName = TableNameBuilder.extractRawTableName(tableNameWithType);
+ URI tableDataUri = URIUtils.getUri(_pinotHelixResourceManager.getDataDir(), rawTableName);
+ PinotFS pinotFS = PinotFSFactory.create(tableDataUri.getScheme());
+
+ long startTimeMs = System.currentTimeMillis();
+
+ List<FileMetadata> deepstoreFiles = pinotFS.listFilesWithMetadata(tableDataUri, false);
+ long listEndTimeMs = System.currentTimeMillis();
+ LOGGER.info("Found: {} segments in deepstore for table: {}. Time taken to list segments: {} ms",
+ deepstoreFiles.size(), tableNameWithType, listEndTimeMs - startTimeMs);
+
+ for (FileMetadata fileMetadata : deepstoreFiles) {
+ if (fileMetadata.isDirectory()) {
+ continue;
+ }
+
+ String segmentName = extractSegmentName(fileMetadata.getFilePath());
+ if (Strings.isEmpty(segmentName) || segmentsToExclude.contains(segmentName)) {
+ continue;
+ }
+
+ // determine whether the segment should be purged or not based on the last modified time of the file
+ long lastModifiedTime = fileMetadata.getLastModifiedTime();
+
+ if (retentionStrategy.isPurgeable(tableNameWithType, segmentName, lastModifiedTime)) {
+ segmentsToDelete.add(segmentName);
+ }
+ }
+ long endTimeMs = System.currentTimeMillis();
+ LOGGER.info(
+ "Took: {} ms to filter segments to delete from deepstore for table: {} that don't have a corresponding entry "
+ + "in property store",
+ endTimeMs - startTimeMs, tableNameWithType);
+ LOGGER.info(
+ "Deleting: {} segments from deep store for table: {} as they have no corresponding entry in the property "
+ + "store.", segmentsToDelete.size(), tableNameWithType);
+
+ return segmentsToDelete;
+ }
+
+ @Nullable
+ private String extractSegmentName(@Nullable String filePath) {
+ if (Strings.isEmpty(filePath)) {
+ return null;
+ }
+ String segmentName = filePath.substring(filePath.lastIndexOf("/") + 1);
+ if (segmentName.endsWith(TarCompressionUtils.TAR_GZ_FILE_EXTENSION)) {
+ segmentName = segmentName.substring(0, segmentName.length() - TarCompressionUtils.TAR_GZ_FILE_EXTENSION.length());
+ }
+ return segmentName;
+ }
+
private void manageRetentionForRealtimeTable(String realtimeTableName, RetentionStrategy retentionStrategy) {
+ List<SegmentZKMetadata> segmentZKMetadataList = _pinotHelixResourceManager.getSegmentsZKMetadata(realtimeTableName);
+ List<String> segmentsPresentInZK =
+ segmentZKMetadataList.stream().map(SegmentZKMetadata::getSegmentName).collect(Collectors.toList());
+
List<String> segmentsToDelete = new ArrayList<>();
+
+ // fetch those segments that are beyond the retention period and don't have an entry in ZK i.e.
+ // SegmentZkMetadata is missing for those segments
+ try {
+ LOGGER.info("Fetch segments present in deep store that are beyond retention period for table: {}",
+ realtimeTableName);
+ segmentsToDelete = getSegmentsToDeleteFromDeepstore(realtimeTableName, retentionStrategy, segmentsPresentInZK);
+ _controllerMetrics.setValueOfTableGauge(realtimeTableName, ControllerGauge.UNTRACKED_SEGMENTS_COUNT,
+ segmentsToDelete.size());
+ } catch (IOException e) {
+ LOGGER.warn("Unable to fetch segments from deep store that are beyond retention period for table: {}",
+ realtimeTableName);
+ }
Review Comment:
Done
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add support for orphan segment cleanup [pinot]
Posted by "9aman (via GitHub)" <gi...@apache.org>.
9aman commented on code in PR #15142:
URL: https://github.com/apache/pinot/pull/15142#discussion_r1984935551
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/RetentionManager.java:
##########
@@ -136,11 +164,86 @@ private void manageRetentionForOfflineTable(String offlineTableName, RetentionSt
}
}
+ /**
+ * Identifies segments in deepstore that are ready for deletion based on the retention strategy.
+ *
+ * This method finds segments that are beyond the retention period and are ready to be purged.
+ * It only considers segments that do not have entries in ZooKeeper metadata.
+ * The lastModified time of the file in deepstore is used to determine whether the segment
+ * should be retained or purged.
+ *
+ * @param tableNameWithType Name of the offline table
+ * @param retentionStrategy Strategy to determine if a segment should be purged
+ * @param segmentsToExclude List of segment names that should be excluded from deletion
+ * @return List of segment names that should be deleted from deepstore
+ * @throws IOException If there's an error accessing the filesystem
+ */
+ private List<String> getSegmentsToDeleteFromDeepstore(String tableNameWithType, RetentionStrategy retentionStrategy,
+ List<String> segmentsToExclude)
+ throws IOException {
+
+ List<String> segmentsToDelete = new ArrayList<>();
+ String rawTableName = TableNameBuilder.extractRawTableName(tableNameWithType);
+ URI tableDataUri = URIUtils.getUri(_pinotHelixResourceManager.getDataDir(), rawTableName);
+ PinotFS pinotFS = PinotFSFactory.create(tableDataUri.getScheme());
+
+ List<FileMetadata> deepstoreFiles = pinotFS.listFilesWithMetadata(tableDataUri, false);
+
Review Comment:
Done.
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add support for orphan segment cleanup [pinot]
Posted by "9aman (via GitHub)" <gi...@apache.org>.
9aman commented on code in PR #15142:
URL: https://github.com/apache/pinot/pull/15142#discussion_r1984976288
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/retention/strategy/RetentionStrategy.java:
##########
@@ -34,4 +34,14 @@ public interface RetentionStrategy {
* @return Whether the segment should be purged
*/
boolean isPurgeable(String tableNameWithType, SegmentZKMetadata segmentZKMetadata);
-}
+
+ /**
+ * Returns whether the segment should be purged based on end time.
+ *
+ * @param segmentName The name of the segment to check
+ * @param tableNameWithType Table name with type
+ * @param endTimeMs The end time of the segment in milliseconds
+ * @return Whether the segment should be purged
+ */
+ boolean isPurgeable(String segmentName, String tableNameWithType, long endTimeMs);
Review Comment:
Have changed as per @klsince suggestions.
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org