-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
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.
- Have a secondary index (
LocPieceIndex
that maps location -> piece) that I want to updatePiece.MovePiece
moves the chess pieces, and when capturing a piece, callsPiece.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, andPiece.MovePiece
then adding the new piece to that location. - Workaround: b/c
Piece.Remove
's update is temporary and immediately overwritten, madePiece.MovePiece
for the update. IntroducedPiece.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.
- 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.
- due to Transaction must abort - Transaction cannot commit if child transaction aborts #28, would require that it returns boolean state as to whether or not the rook can castle