|
|
|
|
@ -2296,6 +2296,232 @@ CREATE TABLE cloud_maintenance_notice_recipients (
|
|
|
|
|
ON DELETE CASCADE ON UPDATE RESTRICT
|
|
|
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
|
|
|
|
|
|
-- One administrator service-compensation request freezes an affected scope and
|
|
|
|
|
-- its exact per-instance evidence. The batch is retained as aggregate audit
|
|
|
|
|
-- after tenant PII in item and recipient rows is removed during account
|
|
|
|
|
-- deletion.
|
|
|
|
|
CREATE TABLE cloud_service_compensations (
|
|
|
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
|
|
|
compensation_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
|
|
|
incident_key VARCHAR(128) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
|
|
|
requested_by_user_id BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
request_idempotency_key VARCHAR(128) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
|
|
|
request_fingerprint CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
|
|
|
scope_type VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
|
|
|
scope_id BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
scope_snapshot_json LONGTEXT NOT NULL,
|
|
|
|
|
reason_text VARCHAR(500) NOT NULL,
|
|
|
|
|
incident_starts_at BIGINT UNSIGNED DEFAULT NULL,
|
|
|
|
|
incident_ends_at BIGINT UNSIGNED DEFAULT NULL,
|
|
|
|
|
compensation_seconds BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
notify_users TINYINT(1) NOT NULL DEFAULT 1,
|
|
|
|
|
audience_digest CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
|
|
|
instance_count INT UNSIGNED NOT NULL,
|
|
|
|
|
recipient_count INT UNSIGNED NOT NULL DEFAULT 0,
|
|
|
|
|
applied_count INT UNSIGNED NOT NULL DEFAULT 0,
|
|
|
|
|
deferred_count INT UNSIGNED NOT NULL DEFAULT 0,
|
|
|
|
|
rejected_count INT UNSIGNED NOT NULL DEFAULT 0,
|
|
|
|
|
attention_count INT UNSIGNED NOT NULL DEFAULT 0,
|
|
|
|
|
state VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'pending',
|
|
|
|
|
last_error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
|
|
|
terminal_at BIGINT UNSIGNED DEFAULT NULL,
|
|
|
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
UNIQUE KEY cloud_service_compensation_key (compensation_key),
|
|
|
|
|
UNIQUE KEY cloud_service_compensation_request (
|
|
|
|
|
requested_by_user_id, request_idempotency_key
|
|
|
|
|
),
|
|
|
|
|
UNIQUE KEY cloud_service_compensation_incident_identity (id, incident_key),
|
|
|
|
|
KEY cloud_service_compensation_incident (incident_key, id),
|
|
|
|
|
KEY cloud_service_compensation_scope (scope_type, scope_id, created_at, id),
|
|
|
|
|
KEY cloud_service_compensation_state (state, created_at, id),
|
|
|
|
|
CONSTRAINT chk_cloud_service_compensation_scope CHECK (
|
|
|
|
|
scope_type IN ('instance','host','public_ip_pool') AND scope_id > 0
|
|
|
|
|
),
|
|
|
|
|
CONSTRAINT chk_cloud_service_compensation_request CHECK (
|
|
|
|
|
CHAR_LENGTH(request_idempotency_key) BETWEEN 16 AND 128
|
|
|
|
|
AND CHAR_LENGTH(request_fingerprint) = 64
|
|
|
|
|
AND CHAR_LENGTH(incident_key) BETWEEN 1 AND 128
|
|
|
|
|
AND CHAR_LENGTH(audience_digest) = 64
|
|
|
|
|
AND CHAR_LENGTH(reason_text) BETWEEN 1 AND 500
|
|
|
|
|
),
|
|
|
|
|
CONSTRAINT chk_cloud_service_compensation_window CHECK (
|
|
|
|
|
compensation_seconds BETWEEN 1 AND 31622400
|
|
|
|
|
AND (
|
|
|
|
|
(incident_starts_at IS NULL AND incident_ends_at IS NULL)
|
|
|
|
|
OR (incident_starts_at IS NOT NULL AND incident_ends_at IS NOT NULL
|
|
|
|
|
AND incident_ends_at > incident_starts_at)
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
CONSTRAINT chk_cloud_service_compensation_counts CHECK (
|
|
|
|
|
notify_users IN (0,1)
|
|
|
|
|
AND instance_count > 0
|
|
|
|
|
AND recipient_count <= instance_count
|
|
|
|
|
AND applied_count + deferred_count + rejected_count + attention_count
|
|
|
|
|
<= instance_count
|
|
|
|
|
),
|
|
|
|
|
CONSTRAINT chk_cloud_service_compensation_state CHECK (
|
|
|
|
|
state IN ('pending','applying','completed','partial','attention')
|
|
|
|
|
),
|
|
|
|
|
CONSTRAINT chk_cloud_service_compensation_terminal CHECK (
|
|
|
|
|
(state IN ('pending','applying') AND terminal_at IS NULL)
|
|
|
|
|
OR (state IN ('completed','partial','attention') AND terminal_at IS NOT NULL)
|
|
|
|
|
)
|
|
|
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
|
|
|
|
|
|
-- Per-instance rows are both the durable work queue and the immutable before /
|
|
|
|
|
-- after audit. The incident key is repeated under a composite foreign key so
|
|
|
|
|
-- an item can never be attached to a batch for another incident.
|
|
|
|
|
CREATE TABLE cloud_service_compensation_items (
|
|
|
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
|
|
|
item_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
|
|
|
batch_id BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
incident_key VARCHAR(128) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
|
|
|
instance_id BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
host_id BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
instance_name VARCHAR(63) NOT NULL,
|
|
|
|
|
requested_seconds BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
service_period_id BIGINT UNSIGNED DEFAULT NULL,
|
|
|
|
|
traffic_entitlement_id BIGINT UNSIGNED DEFAULT NULL,
|
|
|
|
|
backup_entitlement_id BIGINT UNSIGNED DEFAULT NULL,
|
|
|
|
|
source_invoice_id BIGINT UNSIGNED DEFAULT NULL,
|
|
|
|
|
replacement_invoice_id BIGINT UNSIGNED DEFAULT NULL,
|
|
|
|
|
audit_job_id BIGINT UNSIGNED DEFAULT NULL,
|
|
|
|
|
before_expires_at BIGINT UNSIGNED DEFAULT NULL,
|
|
|
|
|
after_expires_at BIGINT UNSIGNED DEFAULT NULL,
|
|
|
|
|
before_period_ends_at BIGINT UNSIGNED DEFAULT NULL,
|
|
|
|
|
after_period_ends_at BIGINT UNSIGNED DEFAULT NULL,
|
|
|
|
|
before_traffic_ends_at BIGINT UNSIGNED DEFAULT NULL,
|
|
|
|
|
after_traffic_ends_at BIGINT UNSIGNED DEFAULT NULL,
|
|
|
|
|
before_backup_ends_at BIGINT UNSIGNED DEFAULT NULL,
|
|
|
|
|
after_backup_ends_at BIGINT UNSIGNED DEFAULT NULL,
|
|
|
|
|
before_snapshot_json LONGTEXT NOT NULL,
|
|
|
|
|
after_snapshot_json LONGTEXT DEFAULT NULL,
|
|
|
|
|
state VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'pending',
|
|
|
|
|
attempts INT UNSIGNED NOT NULL DEFAULT 0,
|
|
|
|
|
available_at BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
lease_token CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
|
|
|
lease_until BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
|
|
|
applied_at BIGINT UNSIGNED DEFAULT NULL,
|
|
|
|
|
terminal_at BIGINT UNSIGNED DEFAULT NULL,
|
|
|
|
|
last_error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
|
|
|
last_error VARCHAR(500) NOT NULL DEFAULT '',
|
|
|
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
UNIQUE KEY cloud_service_compensation_item_key (item_key),
|
|
|
|
|
UNIQUE KEY cloud_service_compensation_item_instance (batch_id, instance_id),
|
|
|
|
|
UNIQUE KEY cloud_service_compensation_item_incident (incident_key, instance_id),
|
|
|
|
|
KEY cloud_service_compensation_item_batch_state (batch_id, state, id),
|
|
|
|
|
KEY cloud_service_compensation_item_due (state, available_at, id),
|
|
|
|
|
KEY cloud_service_compensation_item_lease (state, lease_until, id),
|
|
|
|
|
KEY cloud_service_compensation_item_owner (user_id, created_at, id),
|
|
|
|
|
KEY cloud_service_compensation_item_instance_history (instance_id, created_at, id),
|
|
|
|
|
KEY cloud_service_compensation_item_audit_job (audit_job_id, id),
|
|
|
|
|
CONSTRAINT chk_cloud_service_compensation_item_state CHECK (
|
|
|
|
|
state IN (
|
|
|
|
|
'pending','applying','deferred','applied',
|
|
|
|
|
'rejected','attention','cancelled'
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
CONSTRAINT chk_cloud_service_compensation_item_window CHECK (
|
|
|
|
|
requested_seconds BETWEEN 1 AND 31622400 AND available_at > 0
|
|
|
|
|
),
|
|
|
|
|
CONSTRAINT chk_cloud_service_compensation_item_lease CHECK (
|
|
|
|
|
(state = 'applying' AND attempts > 0
|
|
|
|
|
AND lease_token IS NOT NULL AND lease_until > 0)
|
|
|
|
|
OR (state <> 'applying' AND lease_token IS NULL AND lease_until = 0)
|
|
|
|
|
),
|
|
|
|
|
CONSTRAINT chk_cloud_service_compensation_item_terminal CHECK (
|
|
|
|
|
(state IN ('pending','applying','deferred') AND terminal_at IS NULL)
|
|
|
|
|
OR (state IN ('applied','rejected','attention','cancelled')
|
|
|
|
|
AND terminal_at IS NOT NULL)
|
|
|
|
|
),
|
|
|
|
|
CONSTRAINT chk_cloud_service_compensation_item_applied CHECK (
|
|
|
|
|
state <> 'applied'
|
|
|
|
|
OR (
|
|
|
|
|
applied_at IS NOT NULL
|
|
|
|
|
AND before_expires_at IS NOT NULL AND after_expires_at IS NOT NULL
|
|
|
|
|
AND after_expires_at = before_expires_at + requested_seconds
|
|
|
|
|
AND before_period_ends_at IS NOT NULL
|
|
|
|
|
AND after_period_ends_at = before_period_ends_at + requested_seconds
|
|
|
|
|
AND (
|
|
|
|
|
(before_traffic_ends_at IS NULL AND after_traffic_ends_at IS NULL)
|
|
|
|
|
OR (before_traffic_ends_at IS NOT NULL
|
|
|
|
|
AND after_traffic_ends_at = before_traffic_ends_at + requested_seconds)
|
|
|
|
|
)
|
|
|
|
|
AND (
|
|
|
|
|
(before_backup_ends_at IS NULL AND after_backup_ends_at IS NULL)
|
|
|
|
|
OR (before_backup_ends_at IS NOT NULL
|
|
|
|
|
AND after_backup_ends_at = before_backup_ends_at + requested_seconds)
|
|
|
|
|
)
|
|
|
|
|
AND after_snapshot_json IS NOT NULL
|
|
|
|
|
AND last_error_code = '' AND last_error = ''
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
CONSTRAINT chk_cloud_service_compensation_item_error CHECK (
|
|
|
|
|
state NOT IN ('deferred','rejected','attention','cancelled')
|
|
|
|
|
OR last_error_code <> ''
|
|
|
|
|
),
|
|
|
|
|
CONSTRAINT fk_cloud_service_compensation_item_batch
|
|
|
|
|
FOREIGN KEY (batch_id, incident_key)
|
|
|
|
|
REFERENCES cloud_service_compensations (id, incident_key)
|
|
|
|
|
ON DELETE CASCADE ON UPDATE RESTRICT
|
|
|
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
|
|
|
|
|
|
-- Compensation mail uses the same no-blind-replay lease contract as maintenance
|
|
|
|
|
-- notices. The exact payload is frozen so an unknown SMTP effect can be
|
|
|
|
|
-- inspected without recomposing changed instance data.
|
|
|
|
|
CREATE TABLE cloud_service_compensation_recipients (
|
|
|
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
|
|
|
batch_id BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
email_snapshot VARCHAR(254) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
|
|
|
instance_count INT UNSIGNED NOT NULL,
|
|
|
|
|
payload_json LONGTEXT NOT NULL,
|
|
|
|
|
payload_sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
|
|
|
status VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'pending',
|
|
|
|
|
attempts INT UNSIGNED NOT NULL DEFAULT 0,
|
|
|
|
|
available_at BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
lease_token CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
|
|
|
lease_until BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
|
|
|
sent_at BIGINT UNSIGNED DEFAULT NULL,
|
|
|
|
|
last_error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
|
|
|
last_error VARCHAR(500) NOT NULL DEFAULT '',
|
|
|
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
UNIQUE KEY cloud_service_compensation_recipient (batch_id, user_id),
|
|
|
|
|
KEY cloud_service_compensation_recipient_due (status, available_at, id),
|
|
|
|
|
KEY cloud_service_compensation_recipient_lease (status, lease_until, id),
|
|
|
|
|
KEY cloud_service_compensation_recipient_owner (user_id, created_at, id),
|
|
|
|
|
CONSTRAINT chk_cloud_service_compensation_recipient_status CHECK (
|
|
|
|
|
status IN (
|
|
|
|
|
'pending','sending','sent','failed','unknown','skipped','cancelled'
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
CONSTRAINT chk_cloud_service_compensation_recipient_payload CHECK (
|
|
|
|
|
instance_count > 0 AND CHAR_LENGTH(payload_sha256) = 64
|
|
|
|
|
),
|
|
|
|
|
CONSTRAINT chk_cloud_service_compensation_recipient_shape CHECK (
|
|
|
|
|
available_at > 0
|
|
|
|
|
AND (
|
|
|
|
|
(status = 'pending' AND lease_token IS NULL AND lease_until = 0
|
|
|
|
|
AND sent_at IS NULL AND last_error_code = '' AND last_error = '')
|
|
|
|
|
OR (status = 'sending' AND attempts > 0
|
|
|
|
|
AND lease_token IS NOT NULL AND lease_until > 0 AND sent_at IS NULL)
|
|
|
|
|
OR (status = 'sent' AND lease_token IS NULL AND lease_until = 0
|
|
|
|
|
AND sent_at IS NOT NULL AND last_error_code = '' AND last_error = '')
|
|
|
|
|
OR (status IN ('failed','unknown') AND lease_token IS NULL
|
|
|
|
|
AND lease_until = 0 AND sent_at IS NULL AND last_error_code <> '')
|
|
|
|
|
OR (status IN ('skipped','cancelled') AND lease_token IS NULL
|
|
|
|
|
AND lease_until = 0 AND sent_at IS NULL AND last_error_code <> '')
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
CONSTRAINT fk_cloud_service_compensation_recipient_batch
|
|
|
|
|
FOREIGN KEY (batch_id) REFERENCES cloud_service_compensations (id)
|
|
|
|
|
ON DELETE CASCADE ON UPDATE RESTRICT
|
|
|
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
|
|
|
|
|
|
CREATE TABLE cloud_jobs (
|
|
|
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
|
|
|
operation_id CHAR(32) NOT NULL,
|
|
|
|
|
|