Skip to content

RuntimeError: Nested transactions must currently read/modify mutually exclusive state from their parent transactions #30

@katfang

Description

@katfang

What is the limitation?

If you try to read/write to the same location in nested transactions, you get the following error:

RuntimeError: Nested transactions must currently read/modify mutually exclusive state from their parent transactions

Opening ticket to track use cases.

Use Case & Workarounds

I have a chess app.

  1. Have a secondary index (LocPieceIndex that maps location -> piece) that I want to update
    • Piece.MovePiece moves the chess pieces, and when capturing a piece, calls Piece.Remove to remove the captured piece.
    • Ideally, each individual Piece method would do the required update.
    • This results in both Piece.Remove trying to remove the piece at the location, and Piece.MovePiece then adding the new piece to that location.
    • Workaround: b/c Piece.Remove's update is temporary and immediately overwritten, made Piece.MovePiece for the update. Introduced Piece.RemoveNoIndexUpdate to indicate that the caller is responsible for updating the secondary index.
    • Fine b/c capturing a chess piece necessarily has an associated piece moved in.
  2. When castling the king (move performed on the king) need to check rook hasn't moved and then also move the rook
    • B/c Rook is a different piece from King, requires that it get updated in a child method.
    • Again, would ideally have the Index update in the Piece method that actually makes the move
    • Workaround: have the parent transaction be responsible for updating the index.
    • Alternate workaround: make a special method for castling rook move which first checks if it has moved then moves it; making it so the parent txn doesn't need to read before writing.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions