test(library): P1 用只读可用性投影核对恢复后业务准入
为什么:POST /api/v1/library/restores 是"新建恢复作业"的入口,恢复后重复 POST 会制造第二次恢复;原任务的"同一受保护入口 409→200"应映射到零写副作用的 GET /library/restore-availability:held 时报维护原因且 allowed=false,恢复后 维护原因消失。不重复 POST,也不放宽权限。
This commit is contained in:
@@ -1365,6 +1365,21 @@ UPDATE knowledge_bases SET embedding_model_id='r38-model',vector_store_id='r38-v
|
|||||||
t.Fatalf("entry while held => %d %v, want 409 library_target_in_maintenance", code, blocked)
|
t.Fatalf("entry while held => %d %v, want 409 library_target_in_maintenance", code, blocked)
|
||||||
}
|
}
|
||||||
save("16-entry-409.json", map[string]any{"http": code, "body": blocked})
|
save("16-entry-409.json", map[string]any{"http": code, "body": blocked})
|
||||||
|
// POST /library/restores 是"新建恢复作业"的入口:恢复后再 POST 会创建新作业,
|
||||||
|
// 不能为凑 409→200 而制造第二次恢复。同一业务准入改用零写副作用的
|
||||||
|
// GET /library/restore-availability(页面判断"这份快照现在能不能恢复"的投影)。
|
||||||
|
availabilityPath := "/api/v1/library/restore-availability?scope=internal&snapshot_id=" + backupID
|
||||||
|
code, availabilityHeld := api.do(t, http.MethodGet, availabilityPath, nil)
|
||||||
|
if code != http.StatusOK {
|
||||||
|
t.Fatalf("restore availability while held => %d %v", code, availabilityHeld)
|
||||||
|
}
|
||||||
|
heldReasons, _ := availabilityHeld["reasons"].([]any)
|
||||||
|
heldMaintenanceReason := r38HasReason(heldReasons, "维护")
|
||||||
|
if availabilityHeld["allowed"] != false || !heldMaintenanceReason {
|
||||||
|
t.Fatalf("availability while held = %v", availabilityHeld)
|
||||||
|
}
|
||||||
|
save("16a-availability-held.json", map[string]any{"http": code, "body": availabilityHeld,
|
||||||
|
"maintenance_reason": heldMaintenanceReason})
|
||||||
code, mismatch := api.do(t, http.MethodPost, "/api/v1/library/maintenance/recover",
|
code, mismatch := api.do(t, http.MethodPost, "/api/v1/library/maintenance/recover",
|
||||||
map[string]any{"scope": "internal", "window_job_id": "some-other-window"})
|
map[string]any{"scope": "internal", "window_job_id": "some-other-window"})
|
||||||
if code != http.StatusConflict || mismatch["code"] != "library_window_mismatch" {
|
if code != http.StatusConflict || mismatch["code"] != "library_window_mismatch" {
|
||||||
@@ -1493,6 +1508,17 @@ FROM library_index_restore_dispatch WHERE index_name=$1 AND document_id='chunk-t
|
|||||||
}
|
}
|
||||||
save("21-ingress.json", map[string]any{"ingress": os.Getenv("KG_R38_INGRESS"), "http": 200, "open": true,
|
save("21-ingress.json", map[string]any{"ingress": os.Getenv("KG_R38_INGRESS"), "http": 200, "open": true,
|
||||||
"maintenance_http": openMaintenance})
|
"maintenance_http": openMaintenance})
|
||||||
|
code, availabilityRecovered := api.do(t, http.MethodGet, availabilityPath, nil)
|
||||||
|
if code != http.StatusOK {
|
||||||
|
t.Fatalf("restore availability after recovery => %d %v", code, availabilityRecovered)
|
||||||
|
}
|
||||||
|
recoveredReasons, _ := availabilityRecovered["reasons"].([]any)
|
||||||
|
recoveredMaintenanceReason := r38HasReason(recoveredReasons, "维护")
|
||||||
|
if recoveredMaintenanceReason {
|
||||||
|
t.Fatalf("availability still reports maintenance after recovery: %v", availabilityRecovered)
|
||||||
|
}
|
||||||
|
save("21a-availability-recovered.json", map[string]any{"http": code, "body": availabilityRecovered,
|
||||||
|
"maintenance_reason": recoveredMaintenanceReason, "post_entry": "not repeated: POST /restores creates a new job"})
|
||||||
|
|
||||||
// ---------- 5) 三个真实存储的全量恢复 ----------
|
// ---------- 5) 三个真实存储的全量恢复 ----------
|
||||||
afterPG := universeDump(t, fx.pool)
|
afterPG := universeDump(t, fx.pool)
|
||||||
@@ -1855,11 +1881,13 @@ FROM library_index_restore_dispatch WHERE index_name=$1 AND document_id='chunk-t
|
|||||||
"pg_restore_branch": pgBranch, "pg_early_restore_branch": earlyBranch,
|
"pg_restore_branch": pgBranch, "pg_early_restore_branch": earlyBranch,
|
||||||
"window_job": job.ID, "publish_queue": queueID,
|
"window_job": job.ID, "publish_queue": queueID,
|
||||||
"recovery_queue": recoveryQueueID, "backup": backupID, "scope": "internal", "instance": cfg.LibraryTargetInstance,
|
"recovery_queue": recoveryQueueID, "backup": backupID, "scope": "internal", "instance": cfg.LibraryTargetInstance,
|
||||||
"held": map[string]any{"journal": "held/restore_blocked", "maintenance": "needs_restore", "entry_http": 409},
|
"held": map[string]any{"journal": "held/restore_blocked", "maintenance": "needs_restore", "entry_http": 409,
|
||||||
|
"availability_maintenance_reason": true},
|
||||||
"recovered": map[string]any{"journal": "recovered", "maintenance_released": true, "entry_http": 200,
|
"recovered": map[string]any{"journal": "recovered", "maintenance_released": true, "entry_http": 200,
|
||||||
"pg_rows_restored": true, "object_versions_restored": true, "es_source_restored": true,
|
"pg_rows_restored": true, "object_versions_restored": true, "es_source_restored": true,
|
||||||
"receipts": len(receipts), "deliveries": len(deliveries), "recover_operations": recoverOps,
|
"receipts": len(receipts), "deliveries": len(deliveries), "recover_operations": recoverOps,
|
||||||
"object_delete_markers_equal": true},
|
"object_delete_markers_equal": true, "availability_maintenance_reason": recoveredMaintenanceReason,
|
||||||
|
"availability_allowed": availabilityRecovered["allowed"], "availability_reasons": recoveredReasons},
|
||||||
"es_refusals": refused, "object_refusals": objectRefused, "object_forwarded_mutations": objectForwarded,
|
"es_refusals": refused, "object_refusals": objectRefused, "object_forwarded_mutations": objectForwarded,
|
||||||
"publish_entry": "store.CreateLibraryDispatch (publish API entry not proven)",
|
"publish_entry": "store.CreateLibraryDispatch (publish API entry not proven)",
|
||||||
"object_wire_events_after": len(objectEventsAfter),
|
"object_wire_events_after": len(objectEventsAfter),
|
||||||
@@ -1877,6 +1905,15 @@ FROM library_index_restore_dispatch WHERE index_name=$1 AND document_id='chunk-t
|
|||||||
|
|
||||||
// ---------- 观察辅助 ----------
|
// ---------- 观察辅助 ----------
|
||||||
|
|
||||||
|
func r38HasReason(reasons []any, needle string) bool {
|
||||||
|
for _, reason := range reasons {
|
||||||
|
if text, ok := reason.(string); ok && strings.Contains(text, needle) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func objectInventoryR38(t *testing.T, ctx context.Context, fx *writeSetFixture) *s3.ListObjectVersionsOutput {
|
func objectInventoryR38(t *testing.T, ctx context.Context, fx *writeSetFixture) *s3.ListObjectVersionsOutput {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
out := &s3.ListObjectVersionsOutput{}
|
out := &s3.ListObjectVersionsOutput{}
|
||||||
|
|||||||
Reference in New Issue
Block a user