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

Transaction commit #51

Open
dbluhm opened this issue Jun 5, 2022 · 0 comments
Open

Transaction commit #51

dbluhm opened this issue Jun 5, 2022 · 0 comments

Comments

@dbluhm
Copy link
Contributor

dbluhm commented Jun 5, 2022

I had a question come up as I've been working with the Askar Python wrapper.

Consider these lines from the demo script:

    async with store.transaction() as txn:
        # ^ should be faster within a transaction
        for idx in range(PERF_ROWS):
            await txn.insert(
                "txn",
                f"name-{idx}",
                b"value",
                {"~plaintag": "a", "enctag": "b"},
            )
        await txn.commit()

My question pertains to the await txn.commit() on the final line. As I understand it, after commit has been called, the handle is closed. In other words, it is impossible to do something like:

    async with store.transaction() as txn:
        # ^ should be faster within a transaction
        for idx in range(PERF_ROWS):
            await txn.insert(
                "txn",
                f"name-{idx}",
                b"value",
                {"~plaintag": "a", "enctag": "b"},
            )
        await txn.commit()
        await txn.insert(
            "txn",
            f"name-one-more",
            b"value",
            {"~plaintag": "a", "enctag": "b"},
        )
        await txn.commit()

Therefore, calling commit should essentially terminate every async with store.transaction() block and can occur only once within the block. My question: why not call commit on exit of the with block (within the context manager itself)? This seems like an ideal case for using this pattern, in fact, from my perspective at least.

Curious to hear your rationale. Thanks!

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