warning cross-shard-tx
Транзакция с разными ключами шардирования или cross_shard: true.
What it means#
In the built-in store a transaction MUST touch one shard key (§11.2). atomic(db, cross_shard: true) asks for a two-phase commit, which this implementation does not provide (determined by the implementation, D-7790): the flag is accepted with this warning and the transaction runs as an ordinary single-shard one; at run time it fails with CrossShardTx when its rows live on different shards. The analyzer also reports a body whose Db.find / Db.deleteById of a sharded table use different literal keys.
Example#
use std.orm { Db }
@table("accounts")
data Account {
@pk id: i64
balance: i64
}
fn transfer(db: Db, a: Account, b: Account) db {
atomic(db, cross_shard: true) { // <- cross-shard-tx
db.update(a)
db.update(b)
}
}error
cross-shard-tx
How to fix#
Keep one shard key per transaction: route the work to the shard of the key, or use a saga for several shards.
use std.orm { Db }
@table("accounts")
data Account {
@pk id: i64
balance: i64
}
fn debit(db: Db, a: Account) db {
atomic(db) {
db.update(a)
}
}