fix: propagate transaction hooks into nested managed recovery
Co-authored-by: GPT-6 <gpt-6@openai.com>
This commit is contained in:
1 parent
b4e1e1e9ca
commit
18038e4112
2 files changed
+65
-11
No files matched your search
@@ -227,17 +227,6 @@ func recoverManagedTarget(ctx context.Context, d managedRecoveryDeps) (result ma
|
|||||||
if err := ctx.Err(); err != nil {
|
if err := ctx.Err(); err != nil {
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
if d.service {
|
|
||||||
_, healthErr := d.health(ctx)
|
|
||||||
var fatal *managedRecoveryFatal
|
|
||||||
if ctx.Err() != nil || errors.As(healthErr, &fatal) || errors.Is(healthErr, context.Canceled) || errors.Is(healthErr, context.DeadlineExceeded) {
|
|
||||||
return result, managedRecoveryContextError(ctx, healthErr)
|
|
||||||
}
|
|
||||||
var failure *managedResourceFailure
|
|
||||||
if errors.As(healthErr, &failure) && assetEndpoint(failure.Host) {
|
|
||||||
return result, repairManagedAssets(ctx, d, failure.Host)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m := *d.transaction
|
m := *d.transaction
|
||||||
// Rollback must restart even after job cancellation; independently bounded.
|
// Rollback must restart even after job cancellation; independently bounded.
|
||||||
var cleanupCtx context.Context
|
var cleanupCtx context.Context
|
||||||
@@ -272,6 +261,20 @@ func recoverManagedTarget(ctx context.Context, d managedRecoveryDeps) (result ma
|
|||||||
}
|
}
|
||||||
return status, err
|
return status, err
|
||||||
}
|
}
|
||||||
|
// Nested asset/GGC recovery reads the same transaction before binding its
|
||||||
|
// apply-specific hooks. Production adapters start with path-only transactions.
|
||||||
|
d.transaction = &m
|
||||||
|
if d.service {
|
||||||
|
_, healthErr := d.health(ctx)
|
||||||
|
var fatal *managedRecoveryFatal
|
||||||
|
if ctx.Err() != nil || errors.As(healthErr, &fatal) || errors.Is(healthErr, context.Canceled) || errors.Is(healthErr, context.DeadlineExceeded) {
|
||||||
|
return result, managedRecoveryContextError(ctx, healthErr)
|
||||||
|
}
|
||||||
|
var failure *managedResourceFailure
|
||||||
|
if errors.As(healthErr, &failure) && assetEndpoint(failure.Host) {
|
||||||
|
return result, repairManagedAssets(ctx, d, failure.Host)
|
||||||
|
}
|
||||||
|
}
|
||||||
ids, err := m.ActiveCandidates(d.db)
|
ids, err := m.ActiveCandidates(d.db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, &managedRecoveryFatal{Err: err}
|
return result, &managedRecoveryFatal{Err: err}
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
"errors"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestManagedRecoveryProductionTransactionHooks(t *testing.T) {
|
||||||
|
d, front, _ := recoveryFixture(t, false)
|
||||||
|
if path := os.Getenv("RC_PRIVATE_DB"); path != "" {
|
||||||
|
db, err := sql.Open("sqlite", "file:"+path+"?mode=ro")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal("private snapshot open failed")
|
||||||
|
}
|
||||||
|
defer db.Close()
|
||||||
|
ids, err := qualifiedCandidateIDs(db, "frontend")
|
||||||
|
if err != nil || len(ids) != 1 {
|
||||||
|
t.Fatal("private qualification unavailable")
|
||||||
|
}
|
||||||
|
if err := d.transaction.Apply(db, ids); err != nil {
|
||||||
|
t.Fatal("private offline apply failed")
|
||||||
|
}
|
||||||
|
d.db, front = db, ids[0]
|
||||||
|
} else {
|
||||||
|
front = managedCandidateFixture(t, d.db, "frontend", "youtube.com", "--lua-desync=fake", true)
|
||||||
|
if err := d.transaction.Apply(d.db, []int64{front}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Production adapters supply only the target path; recovery binds hooks.
|
||||||
|
d.transaction = &managedTransaction{Dir: d.transaction.Dir, Name: "config"}
|
||||||
|
d.service, d.adaptive = true, true
|
||||||
|
d.frontHealth = d.health
|
||||||
|
d.mediaSamples = func(context.Context) ([]mediaResource, error) {
|
||||||
|
t.Fatal("asset qualification must precede private media discovery")
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
d.verifyGooglevideo = func(context.Context, storedCandidate, []mediaResource) (GooglevideoQualificationProof, error) {
|
||||||
|
t.Fatal("unexpected verification")
|
||||||
|
return GooglevideoQualificationProof{}, nil
|
||||||
|
}
|
||||||
|
result, err := recoverManagedTarget(context.Background(), d)
|
||||||
|
var failure *managedResourceFailure
|
||||||
|
if err != nil || result.FrontendID != front || !errors.As(result.GGCError, &failure) {
|
||||||
|
// Never expose private DB contents or error causes.
|
||||||
|
t.Fatalf("frontend_preserved=%t recovery_error_type=%T ggc_error_type=%T", result.FrontendID == front, err, result.GGCError)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user