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

[Enhancement] Support Async delete files from Recycle Bin in shared data mode #50636

Closed
wants to merge 1 commit into from

Conversation

srlch
Copy link
Contributor

@srlch srlch commented Sep 3, 2024

Support Async delete files from Recycle Bin in shared data mode to avoid acquire lock for a long time.

Fixes #issue

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 3.3
    • 3.2
    • 3.1
    • 3.0
    • 2.5

@srlch srlch requested review from a team as code owners September 3, 2024 10:59
}, LakeTableHelper.ASYNC_REMOVE_PARTITION_EXECUTOR));
}
}

public static boolean isSharedPartitionDirectory(PhysicalPartition partition, long warehouseId) throws StarClientException {
ShardInfo shardInfo = getAssociatedShardInfo(partition, warehouseId).orElse(null);
if (shardInfo == null) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most risky bug in this code is:
Concurrency issue with RUNNING_DELETE_TABLE map.

You can modify the code like this:

static boolean submitAndCheckAsyncDeleteTableFromRecycleBin(long dbId, OlapTable table) {
    Preconditions.checkState(table.isCloudNativeTableOrMaterializedView());
    table.removeTableBinds(false);

    RUNNING_DELETE_TABLE.computeIfAbsent(table, key -> new LakeTableCleaner(table, Lists.newArrayList()));
    LakeTableCleaner cleaner = RUNNING_DELETE_TABLE.get(table);

    // return false if submit failed or some of the deletion task has been failed.
    boolean succ = cleaner.submitAndCheckAsyncCleanTable();
    if (succ) {
        table.removeTabletsFromInvertedIndex();
    }
    return succ;
}

}
});
return allSuccessed;
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most risky bug in this code is:
In the checkAllAsyncDeleteSuccessed method, clearing asyncDeleteReturn within the stream operation can cause a ConcurrentModificationException.

You can modify the code like this:

protected static boolean checkAllAsyncDeleteSuccessed(List<CompletableFuture<Boolean>> asyncDeleteReturn) {
    boolean allSuccessed = false;
    List<CompletableFuture<Boolean>> toBeRetried = new ArrayList<>();
    
    allSuccessed = asyncDeleteReturn.stream().allMatch(future -> {
        try {
            return future != null && future.isDone() && future.get();
        } catch (Exception e) {
            // add to list for retrying later if any exception is thrown
            toBeRetried.add(future);
            return false;
        }
    });

    asyncDeleteReturn.clear();
    asyncDeleteReturn.addAll(toBeRetried);

    return allSuccessed;
}

}
}

return checkAllAsyncDeleteSuccessed();
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most risky bug in this code is:
Potential non-thread-safe access to asyncDeleteReturn

You can modify the code like this:

private final List<CompletableFuture<Boolean>> asyncDeleteReturn = Collections.synchronizedList(new ArrayList<>());

// And make sure other accesses to asyncDeleteReturn are synchronized properly.
    
// This method ensures thread-safe access when checking if all async deletions succeeded
private boolean checkAllAsyncDeleteSuccessed() {
    synchronized (asyncDeleteReturn) {
        return asyncDeleteReturn.stream().allMatch(future -> {
            try {
                return future != null && future.isDone() && future.get();
            } catch (Exception e) {
                // re-submit in the future if any exception is thrown
                asyncDeleteReturn.clear();
                return false;
            }
        });
    }
}

@mergify mergify bot assigned srlch Sep 3, 2024
@github-actions github-actions bot added the 3.3 label Sep 3, 2024
@srlch srlch force-pushed the enhance_remove_lock_recycle branch 5 times, most recently from e07bb9f to 01eef89 Compare September 9, 2024 03:10
Copy link

sonarcloud bot commented Sep 9, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
14.9% Duplication on New Code (required ≤ 3%)
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

…ata mode

Support Async delete files from Recycle Bin in shared data mode to avoid acquire
lock for a long time.

Signed-off-by: srlch <[email protected]>
Copy link

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link

[FE Incremental Coverage Report]

fail : 8 / 27 (29.63%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/catalog/CatalogRecycleBin.java 1 18 05.56% [499, 507, 529, 546, 558, 913, 914, 915, 916, 918, 921, 922, 923, 924, 925, 1004, 1005]
🔵 com/starrocks/catalog/Table.java 2 4 50.00% [687, 691]
🔵 com/starrocks/lake/LakeMaterializedView.java 3 3 100.00% []
🔵 com/starrocks/lake/LakeTable.java 2 2 100.00% []

Copy link

[BE Incremental Coverage Report]

pass : 0 / 0 (0%)

@srlch srlch closed this Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant