aries-askar icon indicating copy to clipboard operation
aries-askar copied to clipboard

Transaction commit

Open dbluhm opened this issue 3 years ago • 0 comments

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!

dbluhm avatar Jun 05 '22 02:06 dbluhm