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 old bundle data before new activation #4944

Merged
merged 2 commits into from Jul 29, 2022

Conversation

ashutosh-narkar
Copy link
Member

If OPA has an activated bundle that owns all roots
and a new bundle with empty roots is to be activated, the
old bundle's data should first be erased from the store.
Currently both the old and new data is kept in the store.

This commit attempts to fix this by providing an indication to
the truncate call about the scenario in which the root is to be
overwritten.

Fixes: #4940

Signed-off-by: Ashutosh Narkar anarkar4387@gmail.com

}
}

params.RootOverwrite = rootOverwrite
Copy link
Member Author

Choose a reason for hiding this comment

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

Other idea was to pass this in the context's value but did not seem right.

Comment on lines 266 to 281
if params.RootOverwrite {
newPath, ok := storage.ParsePathEscaped("/" + "")
if !ok {
return fmt.Errorf("storage path invalid: %v", newPath)
}

sTxn, err := db.doTruncateData(ctx, underlyingTxn, newDB, params, newPath, map[string]interface{}{})
if err != nil {
return wrapError(err)
}

if sTxn != nil {
underlyingTxn = sTxn
}
}

Copy link
Member Author

Choose a reason for hiding this comment

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

This part I'm not sure if it wipes out everything. The tests seem to indicate that is not the case.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this still an open issue with that change?

@srenatus
Copy link
Contributor

If OPA has an activated bundle that owns all roots
and a new bundle with empty roots is to be activated, the
old bundle's data should first be erased from the store.

Isn't the same true when the roots differ? I.e. when the old roots are different from the new roots, does the old data get deleted properly?

@ashutosh-narkar
Copy link
Member Author

If OPA has an activated bundle that owns all roots
and a new bundle with empty roots is to be activated, the
old bundle's data should first be erased from the store.

Isn't the same true when the roots differ? I.e. when the old roots are different from the new roots, does the old data get deleted properly?

When the roots are specified in the manifest we delete the contents before calling the truncate call. https://github.com/open-policy-agent/opa/blob/main/bundle/store.go#L622. The issue comes up when no roots are defined.

Copy link
Contributor

@srenatus srenatus left a comment

Choose a reason for hiding this comment

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

Sorry just skimmed it. Nothing raising eye brows but I'm also tired

@@ -263,6 +263,22 @@ func (db *Store) Truncate(ctx context.Context, txn storage.Transaction, params s
xid := atomic.AddUint64(&db.xid, uint64(1))
underlyingTxn := newTransaction(xid, true, underlying, params.Context, db.pm, db.partitions, nil)

if params.RootOverwrite {
newPath, ok := storage.ParsePathEscaped("/" + "")
Copy link
Contributor

Choose a reason for hiding this comment

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

💭 "/" + "" is "/", isn't it?

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right. Updated.

If OPA has an activated bundle that owns all roots
and a new bundle with empty roots is to be activated, the
old bundle's data should first be erased from the store.
Currently both the old and new data is kept in the store.

This commit attempts to fix this by providing an indication to
the truncate call about the scenario in which the root is to be
overwritten.

Fixes: open-policy-agent#4940

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
@srenatus srenatus merged commit 8f63046 into open-policy-agent:main Jul 29, 2022
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.

Old bundles not properly cleaned up during activation
2 participants