Skip to content

Commit

Permalink
go: sqle: auto_gc.go: Make sure the safepoint controller works on the…
Browse files Browse the repository at this point in the history
… same database as the auto GC work.
  • Loading branch information
reltuk committed Feb 12, 2025
1 parent 62e5032 commit f509d98
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion go/libraries/doltcore/sqle/auto_gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (c *AutoGCController) doWork(ctx context.Context, work autoGCWork, ctxF fun
defer sql.SessionEnd(sqlCtx.Session)
sql.SessionCommandBegin(sqlCtx.Session)
defer sql.SessionCommandEnd(sqlCtx.Session)
err = dprocedures.RunDoltGC(sqlCtx, work.db, types.GCModeDefault)
err = dprocedures.RunDoltGC(sqlCtx, work.db, types.GCModeDefault, work.name)
if err != nil {
c.lgr.Warnf("sqle/auto_gc: Attempt to auto GC database %s failed with error: %v", work.name, err)
return
Expand Down
21 changes: 11 additions & 10 deletions go/libraries/doltcore/sqle/dprocedures/dolt_gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,25 +154,25 @@ func (sc killConnectionsSafepointController) CancelSafepoint() {
}

type sessionAwareSafepointController struct {
controller *dsess.GCSafepointController
callCtx *sql.Context
controller *dsess.GCSafepointController
dbname string
callSession *dsess.DoltSession

waiter *dsess.GCSafepointWaiter
keeper func(hash.Hash) bool
}

func (sc *sessionAwareSafepointController) visit(ctx context.Context, sess *dsess.DoltSession) error {
return sess.VisitGCRoots(ctx, sc.callCtx.GetCurrentDatabase(), sc.keeper)
return sess.VisitGCRoots(ctx, sc.dbname, sc.keeper)
}

func (sc *sessionAwareSafepointController) BeginGC(ctx context.Context, keeper func(hash.Hash) bool) error {
sc.keeper = keeper
thisSess := dsess.DSessFromSess(sc.callCtx.Session)
err := sc.visit(ctx, thisSess)
err := sc.visit(ctx, sc.callSession)
if err != nil {
return err
}
sc.waiter = sc.controller.Waiter(ctx, thisSess, sc.visit)
sc.waiter = sc.controller.Waiter(ctx, sc.callSession, sc.visit)
return nil
}

Expand Down Expand Up @@ -230,7 +230,7 @@ func doDoltGC(ctx *sql.Context, args []string) (int, error) {
mode = types.GCModeFull
}

err := RunDoltGC(ctx, ddb, mode)
err := RunDoltGC(ctx, ddb, mode, ctx.GetCurrentDatabase() )
if err != nil {
return cmdFailure, err
}
Expand All @@ -239,14 +239,15 @@ func doDoltGC(ctx *sql.Context, args []string) (int, error) {
return cmdSuccess, nil
}

func RunDoltGC(ctx *sql.Context, ddb *doltdb.DoltDB, mode types.GCMode) error {
func RunDoltGC(ctx *sql.Context, ddb *doltdb.DoltDB, mode types.GCMode, dbname string) error {
var sc types.GCSafepointController
if UseSessionAwareSafepointController {
dSess := dsess.DSessFromSess(ctx.Session)
gcSafepointController := dSess.GCSafepointController()
sc = &sessionAwareSafepointController{
callCtx: ctx,
controller: gcSafepointController,
callSession: dSess,
dbname: dbname,
controller: gcSafepointController,
}
} else {
// Legacy safepoint controller behavior was to not
Expand Down

0 comments on commit f509d98

Please sign in to comment.