Add durable cellular mutation reservations
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m53s
Foundation / checks (checks) (push) Failing after 4m5s
Foundation / checks (tsan) (push) Canceled after 0s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (network) (push) Canceled after 3m44s
Foundation / checks (postgres) (push) Canceled after 1m44s
Foundation / checks (client) (push) Canceled after 5m49s
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m53s
Foundation / checks (checks) (push) Failing after 4m5s
Foundation / checks (tsan) (push) Canceled after 0s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (network) (push) Canceled after 3m44s
Foundation / checks (postgres) (push) Canceled after 1m44s
Foundation / checks (client) (push) Canceled after 5m49s
This commit is contained in:
@@ -858,6 +858,10 @@ LifeReservationFailure life_failure(const PgFailure& f) {
|
||||
kind = LifeReservationError::not_available;
|
||||
else if (state == "EVL05")
|
||||
kind = LifeReservationError::exhausted;
|
||||
else if (state == "EVL07")
|
||||
kind = LifeReservationError::identity_conflict;
|
||||
else if (state == "EVL18")
|
||||
kind = LifeReservationError::pending_mutation;
|
||||
return {kind, f};
|
||||
}
|
||||
} // namespace
|
||||
@@ -1252,4 +1256,79 @@ overdue_probe_transfers(Postgres& db, RegionKey key, const LeaseGrant& lease,
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::expected<CellularMutationReservation, LifeReservationFailure> reserve_cellular_mutation(
|
||||
Postgres& db, RegionKey key, const LeaseGrant& lease, const Uuid& account,
|
||||
std::uint64_t generation, std::uint64_t action_id,
|
||||
const std::array<std::uint8_t, cellular_mutation_reservation_input_bytes>& input,
|
||||
milliseconds timeout) {
|
||||
const auto target_tick = little(input, 0, 8);
|
||||
if (account == Uuid{} || action_id == 0 || generation == 0 || target_tick == 0 ||
|
||||
little(input, 8, 8) == 0 || little(input, 16, 8) == 0 || little(input, 24, 8) == 0 ||
|
||||
target_tick <= little(input, 24, 8) || little(input, 32, 2) == 0)
|
||||
return std::unexpected{LifeReservationFailure{LifeReservationError::invalid, {}}};
|
||||
const auto base = control_parameters(key, lease, account, generation);
|
||||
const std::array<std::string, 9> p{base[0],
|
||||
base[1],
|
||||
base[2],
|
||||
base[3],
|
||||
base[4],
|
||||
base[5],
|
||||
std::to_string(action_id),
|
||||
std::to_string(target_tick),
|
||||
"\\x" + hex(input)};
|
||||
auto rows = db.query("SELECT * FROM evolution.reserve_cellular_mutation($1::evolution.u64, "
|
||||
"$2::evolution.u64, $3::uuid, $4::evolution.u64, $5::uuid, "
|
||||
"$6::evolution.u64, $7::evolution.u64, $8::evolution.u64, $9::bytea)",
|
||||
p, timeout);
|
||||
if (!rows)
|
||||
return std::unexpected{life_failure(rows.error())};
|
||||
if (rows->size() != 1 || (*rows)[0].size() != 2)
|
||||
return std::unexpected{LifeReservationFailure{LifeReservationError::unknown, {}}};
|
||||
const auto identity = parse_integer<std::uint64_t>((*rows)[0][0]);
|
||||
const auto region = parse_integer<std::uint64_t>((*rows)[0][1]);
|
||||
if (!identity || *identity == 0 || !region || *region == 0)
|
||||
return std::unexpected{LifeReservationFailure{LifeReservationError::unknown, {}}};
|
||||
return CellularMutationReservation{account, action_id, *region, generation,
|
||||
target_tick, *identity, input};
|
||||
}
|
||||
|
||||
std::expected<std::vector<CellularMutationReservation>, LifeReservationFailure>
|
||||
load_pending_cellular_mutations(Postgres& db, RegionKey key, const LeaseGrant& lease,
|
||||
milliseconds timeout) {
|
||||
const std::array<std::string, 4> p{std::to_string(key.world), std::to_string(key.region),
|
||||
uuid_text(lease.holder), std::to_string(lease.epoch)};
|
||||
auto rows = db.query("SELECT account_id::text, action_id::text, generation::text, "
|
||||
"target_tick::text, successor_identity::text, "
|
||||
"encode(input_bytes, 'hex') FROM "
|
||||
"evolution.load_pending_cellular_mutations($1::evolution.u64, "
|
||||
"$2::evolution.u64, $3::uuid, $4::evolution.u64)",
|
||||
p, timeout);
|
||||
if (!rows)
|
||||
return std::unexpected{life_failure(rows.error())};
|
||||
if (rows->size() > 256)
|
||||
return std::unexpected{LifeReservationFailure{LifeReservationError::store, {}}};
|
||||
std::vector<CellularMutationReservation> out;
|
||||
out.reserve(rows->size());
|
||||
for (const auto& row : *rows) {
|
||||
if (row.size() != 6)
|
||||
return std::unexpected{LifeReservationFailure{LifeReservationError::store, {}}};
|
||||
const auto account = parse_uuid(row[0]);
|
||||
const auto action = parse_integer<std::uint64_t>(row[1]);
|
||||
const auto generation = parse_integer<std::uint64_t>(row[2]);
|
||||
const auto target_tick = parse_integer<std::uint64_t>(row[3]);
|
||||
const auto successor = parse_integer<std::uint64_t>(row[4]);
|
||||
const auto input =
|
||||
row[5] ? unhex<cellular_mutation_reservation_input_bytes>(*row[5]) : std::nullopt;
|
||||
if (!account || *account == Uuid{} || !action || *action == 0 || !generation ||
|
||||
*generation == 0 || !target_tick || *target_tick == 0 || !successor ||
|
||||
*successor == 0 || !input || little(*input, 0, 8) != *target_tick ||
|
||||
little(*input, 8, 8) == 0 || little(*input, 16, 8) == 0 || little(*input, 24, 8) == 0 ||
|
||||
*target_tick <= little(*input, 24, 8) || little(*input, 32, 2) == 0)
|
||||
return std::unexpected{LifeReservationFailure{LifeReservationError::store, {}}};
|
||||
out.push_back(
|
||||
{*account, *action, key.region, *generation, *target_tick, *successor, *input});
|
||||
}
|
||||
return out;
|
||||
}
|
||||
} // namespace evo::persistence
|
||||
|
||||
Reference in New Issue
Block a user