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

SQLAlchemy: Polyfill for transparently synchronizing data with REFRESH TABLE #83

Open
amotl opened this issue Sep 16, 2023 · 1 comment
Labels
question Further information is requested

Comments

@amotl
Copy link
Member

amotl commented Sep 16, 2023

About

Because CrateDB does not immediately flush data to disk, applications relying on that behavior will fail. This becomes immediately appearant when running the test suites of typical SQLAlchemy applications.

Recently, we started working on unlocking MLflow and LangChain, and needed to patch SQLAlchemy, adding a bit of compensation to satisfy their test cases.

Proposal

Provide corresponding functionality through a dialect parameter like crate_refresh_after_dml or crate_synchronize_all, or find a different solution to the same problem.

def polyfill_refresh_after_dml(base_model):
    """
    Run `REFRESH TABLE <tablename>` after each INSERT, UPDATE, and DELETE operation.

    CrateDB is eventually consistent, i.e. write operations are not flushed to
    disk immediately, so readers may see stale data. In a traditional OLTP-like
    application, this is not applicable.

    This SQLAlchemy extension makes sure that data is synchronized after each
    operation manipulating data.

    TODO: Submit patch to `crate-python`, to be enabled by a
          dialect parameter `crate_dml_refresh` or such.
    """
    for mapper in base_model.registry.mappers:
        listen(mapper.class_, "after_insert", do_refresh)
        listen(mapper.class_, "after_update", do_refresh)
        listen(mapper.class_, "after_delete", do_refresh)

References

@amotl amotl added the question Further information is requested label Oct 6, 2023
@amotl amotl transferred this issue from crate/crate-python Jun 16, 2024
@amotl
Copy link
Member Author

amotl commented Jun 22, 2024

There is a patch now, which includes the corresponding improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant