Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up more zk parent nodes for stale requests #2243

Merged
merged 1 commit into from
Nov 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1655,18 +1655,59 @@ public SingularityDeleteResult deleteTaskHistory(SingularityTaskId taskId) {
}

public void purgeStaleRequests(List<String> activeRequestIds, long deleteBeforeTime) {
final List<String> requestIds = getChildren(HISTORY_PATH_ROOT);
for (String requestId : requestIds) {
if (!activeRequestIds.contains(requestId)) {
String path = getRequestPath(requestId);
Optional<Stat> maybeStat = checkExists(path);
if (
maybeStat.isPresent() &&
maybeStat.get().getMtime() < deleteBeforeTime &&
getChildren(path).size() == 0
) {
delete(path);
}
getChildren(HISTORY_PATH_ROOT)
.forEach(
(
requestId ->
purgePathForRequest(
activeRequestIds,
deleteBeforeTime,
HISTORY_PATH_ROOT,
requestId
)
)
);
getChildren(LAST_ACTIVE_TASK_STATUSES_PATH_ROOT)
.forEach(
(
requestId ->
purgePathForRequest(
activeRequestIds,
deleteBeforeTime,
LAST_ACTIVE_TASK_STATUSES_PATH_ROOT,
requestId
)
)
);
getChildren(PENDING_PATH_ROOT)
.forEach(
(
requestId ->
purgePathForRequest(
activeRequestIds,
deleteBeforeTime,
PENDING_PATH_ROOT,
requestId
)
)
);
}

private void purgePathForRequest(
List<String> activeRequestIds,
long deleteBeforeTime,
String parentPath,
String requestId
) {
if (!activeRequestIds.contains(requestId)) {
String path = ZKPaths.makePath(parentPath, requestId);
Optional<Stat> maybeStat = checkExists(path);
if (
maybeStat.isPresent() &&
maybeStat.get().getMtime() < deleteBeforeTime &&
getChildren(path).size() == 0
) {
delete(path);
}
}
}
Expand Down