xaRecover method
xa_recover: list every XID currently in the XaState.prepared
state on the resource manager. Used after process restart to
discover branches awaiting a Phase 2 decision.
Resume each XID with xaResumePrepared and call XaTransactionHandle.commitPrepared / XaTransactionHandle.rollbackPrepared per the Transaction Manager's recovery decision.
Returns an empty list when no prepared XIDs exist; returns
null on FFI failure (call getStructuredErrorForConnection).
Implementation
List<Xid>? xaRecover(int connectionId) {
final count = _native.xaRecoverCount(connectionId);
if (count < 0) return null;
final out = <Xid>[];
for (var i = 0; i < count; i++) {
final entry = _native.xaRecoverGet(i);
if (entry == null) continue;
// Xid() throws ArgumentError on length violations. We *want* to
// catch that and skip the entry — those XIDs belong to a
// different client that violated the X/Open length limits, and
// we don't want recovery to abort over an unrelated bad
// neighbour.
try {
out.add(
Xid(
formatId: entry.formatId,
gtrid: entry.gtrid,
bqual: entry.bqual,
),
);
// Catching `Error` is unidiomatic in general, but here the
// error path is data-driven (a bad neighbour client wrote a
// malformed prepared XID) and we explicitly want to skip,
// not crash recovery.
// ignore: avoid_catching_errors
} on ArgumentError {
// intentionally silent — see comment above
}
}
return out;
}