Skip to content

✨ Add WriteLog replay #2783

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

Merged
merged 13 commits into from
May 27, 2025
Merged

✨ Add WriteLog replay #2783

merged 13 commits into from
May 27, 2025

Conversation

alexras
Copy link
Collaborator

@alexras alexras commented May 21, 2025

This diff implements a "write log replayer" that can apply individual write log records (specified as WriteLog model instances) to the current instance's database. As a side-effect of this change, I had to make more of the system aware of individual columns' types, and I've moved a couple things shared by both the trigger installer and write log replayer into utility functions.

@alexras alexras force-pushed the alexras/write-log-replay branch from 63e1d66 to 93aa6f6 Compare May 23, 2025 02:38
Base automatically changed from alexras/history-backfill to main May 23, 2025 17:16
@alexras alexras force-pushed the alexras/write-log-replay branch from 93aa6f6 to f2e4087 Compare May 23, 2025 23:00
@alexras alexras changed the title Alexras/write log replay ✨ Add write log replay May 23, 2025
@alexras alexras marked this pull request as ready for review May 23, 2025 23:09
@alexras alexras requested a review from falexwolf May 26, 2025 17:13
alexras added 10 commits May 26, 2025 10:14

Verified

This commit was signed with the committer’s verified signature.
alexras Alex Rasmussen

Verified

This commit was signed with the committer’s verified signature.
alexras Alex Rasmussen

Verified

This commit was signed with the committer’s verified signature.
alexras Alex Rasmussen

Verified

This commit was signed with the committer’s verified signature.
alexras Alex Rasmussen

Verified

This commit was signed with the committer’s verified signature.
alexras Alex Rasmussen

Verified

This commit was signed with the committer’s verified signature.
alexras Alex Rasmussen

Verified

This commit was signed with the committer’s verified signature.
alexras Alex Rasmussen

Verified

This commit was signed with the committer’s verified signature.
alexras Alex Rasmussen

Verified

This commit was signed with the committer’s verified signature.
alexras Alex Rasmussen

Verified

This commit was signed with the committer’s verified signature.
alexras Alex Rasmussen
@alexras alexras force-pushed the alexras/write-log-replay branch from f2e4087 to 1511b62 Compare May 26, 2025 17:14

Verified

This commit was signed with the committer’s verified signature.
alexras Alex Rasmussen
@alexras alexras marked this pull request as draft May 26, 2025 17:19
@alexras alexras marked this pull request as ready for review May 26, 2025 21:59
@@ -52,8 +52,7 @@ class WriteLog(models.Model):
created_by_uid = models.CharField(max_length=8, default=DEFAULT_CREATED_BY_UID)
branch_code = models.IntegerField(default=DEFAULT_BRANCH_CODE)
run_uid = models.CharField(max_length=16, default=DEFAULT_RUN_UID)
# Many-to-many tables don't have row UIDs, so this needs to be nullable.
record_uid = models.JSONField(null=True)
record_uid = models.JSONField()
Copy link
Member

Choose a reason for hiding this comment

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

I'm only seeing this now, but I think this should likely be a CharField rather than a JSONField, should it?

Copy link
Member

Choose a reason for hiding this comment

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

Can change in the next PR.

Copy link
Member

Choose a reason for hiding this comment

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

I tried this in the next PR and it seems there is a good reason for that this is a JSON field. Many tests break if turning it into CHARField. I think this is because you're modeling multiple uids as a list within the JSON field.

#2798

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The write log record's UID takes one of two forms:

  • For tables that are many to many, it's a list of 3-tuples specifying the table's foreign-key relationships by UID
  • For all other tables, it's an ordered list of values of the table's UID fields.

Because of that it's easier if those fields are JSONFields rather than CharFields.

@falexwolf falexwolf changed the title ✨ Add write log replay ✨ Add WriteLog replay May 27, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
key_constraint=None,
)
]
elif table == "lamindb_param":
Copy link
Member

Choose a reason for hiding this comment

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

This table does no longer exist. I consciously removed it. So, no need to add it back. ☺️

Copy link
Member

Choose a reason for hiding this comment

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

Can be removed in the next PR.

Copy link

codecov bot commented May 27, 2025

Codecov Report

Attention: Patch coverage is 81.51815% with 56 lines in your changes missing coverage. Please review.

Project coverage is 91.80%. Comparing base (c081cbd) to head (4aeff47).
Report is 37 commits behind head on main.

Files with missing lines Patch % Lines
lamindb/core/writelog/_replayer.py 74.68% 40 Missing ⚠️
lamindb/core/writelog/_db_metadata_wrapper.py 82.92% 14 Missing ⚠️
lamindb/core/writelog/_utils.py 93.93% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2783      +/-   ##
==========================================
- Coverage   91.94%   91.80%   -0.15%     
==========================================
  Files          70       74       +4     
  Lines       10717     9871     -846     
==========================================
- Hits         9854     9062     -792     
+ Misses        863      809      -54     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

Deployment URL: https://b475b581.lamindb.pages.dev

@falexwolf falexwolf merged commit 262ab0a into main May 27, 2025
18 of 19 checks passed
@falexwolf falexwolf deleted the alexras/write-log-replay branch May 27, 2025 08:28
@falexwolf falexwolf restored the alexras/write-log-replay branch May 27, 2025 08:30
@falexwolf
Copy link
Member

This branch can be deleted as soon as @alexras changes the base of his other open PR.

@falexwolf falexwolf deleted the alexras/write-log-replay branch May 27, 2025 09:55
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.

None yet

2 participants