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

feat: enable stale permission GC #223

Conversation

alexgao001
Copy link
Collaborator

Description

When resource bucket and object are deleted by user, its associated stale policies linked to personal accounts or groups need to be garbage collected. For resource group, its associated stale policy with personal accounts, and all group members meta will be garbage collected. these are done in each endblock auto execution.

Rationale

Get rid of useless stale permission data

Example

NA

Changes

Notable changes:

  • garbage collecting during endblock

@@ -102,6 +102,11 @@ service Query {
option (google.api.http).get = "/greenfield/storage/policy_for_group/{resource}/{principal_group_id}";
}

// Queries a policy by policy id
rpc QueryPolicyById(QueryPolicyByIdRequest) returns (QueryPolicyByIdResponse) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Currently enabe this api for e2e, might need to hide this api

x/permission/keeper/keeper.go Show resolved Hide resolved
x/storage/keeper/keeper.go Show resolved Hide resolved
k.permKeeper.ForceDeleteGroupPolicyForResource(ctx, resource.RESOURCE_TYPE_OBJECT, id)
deletedCount++
// reaches the deletion limit during current endblocker
if deletedCount > maxCleanup {
Copy link
Contributor

@fynnss fynnss Apr 27, 2023

Choose a reason for hiding this comment

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

I finally know why forget the limit count above. Actually, we should limit the kv count per block. not the resource count.

}

// the specified block height(iterator-key)'s stale resource permission metadata is purged
if deleteInfo.IsEmpty() {
Copy link
Contributor

@fynnss fynnss Apr 27, 2023

Choose a reason for hiding this comment

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

If the delete info is not empty, but some permission info associated with certain resources has already been deleted, it still needs update and persist.

@@ -13,6 +13,7 @@ func BeginBlocker(ctx sdk.Context, keeper k.Keeper) {
keeper.ClearDiscontinueObjectCount(ctx)
keeper.ClearDiscontinueBucketCount(ctx)
}
keeper.InitDeleteInfo(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why needs store this empty key if there is no deleted resource in this block.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah actually this is redundant, because when appending resource ids to deleteInfo, we are still checking the key existence.

// EventStalePolicyCleanup is emitted when specified block height's stale policies is garbage collected
message EventStalePolicyCleanup {
int64 blockNum = 1;
DeleteInfo delete_info =2;
Copy link
Contributor

Choose a reason for hiding this comment

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

It's important to note that the meta-service may require these events in order to delete its policy. cc @krish-nr @ruojunm

deleteStalePoliciesPrefixStore.Set(iterator.Key(), k.cdc.MustMarshal(deleteInfo))
return
}
k.permKeeper.ForceDeleteGroupMembers(ctx, id)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't group members has a maximum cleanup count limit?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added

@unclezoro unclezoro added the r4r label May 6, 2023

func (k Keeper) GarbageCollectResourcesStalePolicy(ctx sdk.Context) {
store := ctx.KVStore(k.storeKey)
deleteStalePoliciesPrefixStore := prefix.NewStore(store, types.DeleteStalePoliciesPrefix)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Too many duplicated code here, I think we can improve it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

refactored

if di == nil {
return true
}
if di.BucketIds == nil || (di.BucketIds != nil && len(di.BucketIds.Id) == 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

di.BucketIds != nil seems unnecessary.

Copy link
Collaborator Author

@alexgao001 alexgao001 May 6, 2023

Choose a reason for hiding this comment

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

removed

Choose a reason for hiding this comment

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

  • [ ]

x/storage/keeper/keeper.go Show resolved Hide resolved
@alexgao001 alexgao001 merged commit 44baf61 into bnb-chain:develop_v0.47_latest May 6, 2023
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.

4 participants