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

System should work even if two batches of updates happened within the same millisecond #3

Closed
simonw opened this issue Sep 15, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@simonw
Copy link
Owner

simonw commented Sep 15, 2023

tricky problem has emerged while testing: SQLite is fast. My tests are trying to find everything that changed since an operation that took place within the same millisecond, which is failing because of:

        sql = textwrap.dedent(
            f"""
            SELECT {select_clause}
            FROM "_chronicle_{table_name}" chronicle
            LEFT JOIN "{table_name}" t ON {join_on}
            WHERE chronicle.updated_ms > ?
            ORDER BY chronicle.updated_ms
            LIMIT {batch_size}
            """
        )
        rows = cursor.execute(sql, (since,)).fetchall()

Going for WHERE chronicle.updated_ms > ? misses events which happened within > the same ms - which is clearly something that needs to be accounted for!

Originally posted by @simonw in #2 (comment)

@simonw simonw added bug Something isn't working good first issue Good for newcomers and removed good first issue Good for newcomers labels Sep 15, 2023
@simonw
Copy link
Owner Author

simonw commented Sep 15, 2023

The solution is to use a version column which increments every time, using max(version) + 1 - with an index to make both this increment and the lookups of rows that have changed since version X as fast as possible.

@simonw simonw closed this as completed in 3ffdc5f Sep 15, 2023
simonw added a commit that referenced this issue Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant