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

[Bug] saving cl_audit records is not idempotent #152

Closed
kespinola opened this issue Dec 21, 2023 · 1 comment
Closed

[Bug] saving cl_audit records is not idempotent #152

kespinola opened this issue Dec 21, 2023 · 1 comment

Comments

@kespinola
Copy link
Collaborator

Issue

The current implementation lacks an on_conflict clause during the insertion of cl_audit records. This omission leads to the possibility of inserting duplicate cl_audit records when a transaction is reprocessed, even if it has already been indexed. The relevant code snippet is as follows:

// Insert the audit item after the insert into cl_items have been completed
if let Some(audit_item) = audit_item {
cl_audits::Entity::insert(audit_item).exec(txn).await?;
}

This behavior is problematic as the ingester is expected to handle reprocessing of transactions seamlessly, without altering the current state of the active index snapshot or introducing redundant data. Duplicate entries can lead to skewed query results and contribute to index bloat, which is a concern given the substantial size of the index.

Proposed Fix

To address this issue, an on_conflict clause should be added to the insertion operation. This clause will ensure that the insertion does nothing if a uniqueness constraint (specifically on the combination of tree, node_id, and seq) is violated. Implementing this change requires the addition of the said constraint.

However, it is important to note that if teams have been using cl_audits for a significant period, there may already be a considerable number of duplicate cl_audit records. These records will need to be deduplicated before the proposed patch can be applied effectively.

@kespinola kespinola changed the title [Bug] saving cl_audit records are not idempotent [Bug] saving cl_audit records is not idempotent Dec 21, 2023
@kespinola
Copy link
Collaborator Author

Fixed by cl_audits_v2 which drops this v1 implementation.

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

No branches or pull requests

1 participant