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

[BugFix] cleanup in-memory partition state if check fail when creating multiple-partitions #45772

Merged
merged 1 commit into from
May 20, 2024

Conversation

mofeiatwork
Copy link
Contributor

@mofeiatwork mofeiatwork commented May 17, 2024

Why I'm doing:

What I'm doing:

Fixes SR-26924

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

Signed-off-by: Murphy <mofei@starrocks.com>
@mofeiatwork mofeiatwork requested a review from a team as a code owner May 17, 2024 00:55
idToRange.remove(partitionId);
}
}

public void moveRangeFromTempToFormal(long tempPartitionId) {
Range<PartitionKey> range = idToTempRange.remove(tempPartitionId);
if (range != 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:
Inconsistent handling of exceptions for partially processed partition entries leading to potential data inconsistency or resource leak.

You can modify the code like this:

@@ -253,25 +253,38 @@ public void createAutomaticShadowPartition(long partitionId, String replicateNum
 public void handleNewRangePartitionDescs(List<Pair<Partition, PartitionDesc>> partitionList,
                                          Set<String> existPartitionNameSet,
                                          boolean isTemp) throws DdlException {
+    List<Long> successfullyProcessedPartitions = new ArrayList<>();
     try {
         for (Pair<Partition, PartitionDesc> entry : partitionList) {
             Partition partition = entry.first;
             if (!existPartitionNameSet.contains(partition.getName())) {
                 long partitionId = partition.getId();
                 SingleRangePartitionDesc desc = (SingleRangePartitionDesc) entry.second;
                 Preconditions.checkArgument(desc.isAnalyzed());
                 Range<PartitionKey> range;
                 try {
                     range = checkAndCreateRange((SingleRangePartitionDesc) entry.second, isTemp);
                     setRangeInternal(partitionId, isTemp, range);
+                    successfullyProcessedPartitions.add(partitionId); // Add ID to list after successful processing
                 } catch (IllegalArgumentException e) {
                     // Range.closedOpen may throw this if (lower > upper)
                     throw new DdlException("Invalid key range: " + e.getMessage());
                 }
                 idToDataProperty.put(partitionId, desc.getPartitionDataProperty());
                 idToReplicationNum.put(partitionId, desc.getReplicationNum());
                 idToInMemory.put(partitionId, desc.isInMemory());
                 idToStorageCacheInfo.put(partitionId, desc.getDataCacheInfo());
             }
         }
     } catch (Exception e) {
         // cleanup only for processed partitions
-        partitionList.forEach(entry -> {
+        successfullyProcessedPartitions.forEach(partitionId -> {
             removeRangeInternal(partitionId, isTemp);
             idToDataProperty.remove(partitionId);
             idToReplicationNum.remove(partitionId);
             idToInMemory.remove(partitionId);
             idToStorageCacheInfo.remove(partitionId);
         });
         throw e;
     }
 }

This modification ensures that the cleanup process applies only to those partitions that were successfully processed before an exception occurred, thus preventing removal or alteration of entries that weren't affected by the current operation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it doesn't matter, bc the remove is safe even for non-existent partitions

Copy link

sonarcloud bot commented May 17, 2024

Copy link

[FE Incremental Coverage Report]

fail : 13 / 29 (44.83%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/catalog/RangePartitionInfo.java 13 29 44.83% [267, 269, 277, 279, 280, 281, 282, 283, 284, 285, 286, 287, 417, 418, 420, 422]

Copy link

[BE Incremental Coverage Report]

pass : 0 / 0 (0%)

@mofeiatwork mofeiatwork enabled auto-merge (squash) May 20, 2024 01:51
@imay imay merged commit a10e9f3 into StarRocks:main May 20, 2024
66 of 68 checks passed
Copy link

@Mergifyio backport branch-3.3

@github-actions github-actions bot removed the 3.3 label May 20, 2024
Copy link

@Mergifyio backport branch-3.2

@github-actions github-actions bot removed the 3.2 label May 20, 2024
Copy link
Contributor

mergify bot commented May 20, 2024

backport branch-3.3

✅ Backports have been created

Copy link
Contributor

mergify bot commented May 20, 2024

backport branch-3.2

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request May 20, 2024
mergify bot pushed a commit that referenced this pull request May 20, 2024
node pushed a commit to vivo/starrocks that referenced this pull request May 20, 2024
wanpengfei-git pushed a commit that referenced this pull request May 20, 2024
…g multiple-partitions (backport #45772) (#45868)

Co-authored-by: Murphy <96611012+mofeiatwork@users.noreply.github.com>
wanpengfei-git pushed a commit that referenced this pull request May 20, 2024
…g multiple-partitions (backport #45772) (#45869)

Co-authored-by: Murphy <96611012+mofeiatwork@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants