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

[kv] when table(partition) is deleted, drop corresponding snapshots #427

Merged
merged 8 commits into from
Feb 21, 2025

Conversation

zcoo
Copy link
Contributor

@zcoo zcoo commented Feb 19, 2025

Purpose

Linked issue: close #412

Currently, when kv table is deleted or table partition is expired, memory still persist its kv snapshot, which causes memory leak. This pr will fix it.

Tests

CompletedSnapshotStoreManagerTest::testRemoveCompletedSnapshotStoreFromManager

API and Format

Documentation

@luoyuxia luoyuxia self-requested a review February 20, 2025 06:05
Copy link
Collaborator

@luoyuxia luoyuxia left a comment

Choose a reason for hiding this comment

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

@zcoo Thanks for the pr.. I left some comments..
Also, we need to add test to verify when table/partition is dropped, the completeSnapshotStore will also be removed in CoordinatorEventProcessorTest.

@@ -96,6 +97,14 @@ public CompletedSnapshotStore getOrCreateCompletedSnapshotStore(TableBucket tabl
});
}

public void onRemoveCompletedSnapshotStoreByTableBuckets(Set<TableBucket> tableBuckets) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit:

Suggested change
public void onRemoveCompletedSnapshotStoreByTableBuckets(Set<TableBucket> tableBuckets) {
public void removeCompletedSnapshotStoreByTableBuckets(Set<TableBucket> tableBuckets) {

to make the naming style align with createCompletedSnapshotStore

@@ -96,6 +97,14 @@ public CompletedSnapshotStore getOrCreateCompletedSnapshotStore(TableBucket tabl
});
}

public void onRemoveCompletedSnapshotStoreByTableBuckets(Set<TableBucket> tableBuckets) {
// Remove CompletedSnapshotStore is all we need to do, as remote KV files have already
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can remove theres comments since it may not precise for the root directory of table snapshot will be drop in coordinator server.

@@ -499,6 +499,12 @@ private void processCreatePartition(CreatePartitionEvent createPartitionEvent) {
}

private void processDropTable(DropTableEvent dropTableEvent) {
// When drop a table, drop its snapshot store meanwhile.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Only when the table is a primary key table, do we need to remove snapshot store

// When drop a primary key table, drop its snapshot store meanwhile.
        if (coordinatorContext.getTableInfo(dropTableEvent.getTableId()).hasPrimaryKey()) {
            Set<TableBucket> deleteTableBuckets =
                    coordinatorContext.getAllBucketsForTable(dropTableEvent.getTableId());
            completedSnapshotStoreManager.onRemoveCompletedSnapshotStoreByTableBuckets(
                    deleteTableBuckets);
        }

You'll need to add a method getTableInfo in CoordinatorContext

@@ -510,6 +516,14 @@ private void processDropPartition(DropPartitionEvent dropPartitionEvent) {
TablePartition tablePartition =
new TablePartition(
dropPartitionEvent.getTableId(), dropPartitionEvent.getPartitionId());

// When drop a table partition, drop its snapshot store meanwhile.
Copy link
Collaborator

Choose a reason for hiding this comment

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

dito:
Only when the table is a primary key table, do we need to remove snapshot store

@zcoo
Copy link
Contributor Author

zcoo commented Feb 20, 2025

@luoyuxia thanks a lot for your opinion! I've tried to fix.

PTAL~

Copy link
Collaborator

@luoyuxia luoyuxia left a comment

Choose a reason for hiding this comment

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

@zcoo Thanks for updating.. Left minor comments. should be ready to be merged in next iteration.

@@ -149,6 +149,11 @@ public boolean hasPrimaryKey() {
return !primaryKeys.isEmpty();
}

/** Check if the table is a primary key table or a log table. */
public boolean isPrimaryKeyTable() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

if hasPrimaryKey return true, it means it's a primaryKeyTable. We don't need to introduce this method.

coordinatorContext.getAllBucketsForPartition(tableId, partition2Id);
int sizeofCompletedSnapshotStore4partition1 = 0;
int sizeofCompletedSnapshotStore4partition2 = 0;
for (TableBucket tableBucket : tableBuckets4partition1) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit:
We can just mock completedSnapshotStore for the partition1 which is to be drop to simlify the test

@zcoo
Copy link
Contributor Author

zcoo commented Feb 20, 2025

@luoyuxia I've simplify the code. Thanks for code review!

@zcoo zcoo reopened this Feb 21, 2025
@luoyuxia luoyuxia merged commit 2d27224 into alibaba:main Feb 21, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CompletedSnapshotStoreManager miss to remove the table buckets for dropped table
2 participants