From be6a441edea5fd4e2aab0710c9f65bbd005b9338 Mon Sep 17 00:00:00 2001 From: Zach Musgrave Date: Mon, 20 Sep 2021 10:12:24 -0700 Subject: [PATCH] Rebase on transaction start --- go/libraries/doltcore/doltdb/doltdb.go | 6 ++++++ go/libraries/doltcore/sqle/dsess/session.go | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/go/libraries/doltcore/doltdb/doltdb.go b/go/libraries/doltcore/doltdb/doltdb.go index 567e1de626..32f24a3f08 100644 --- a/go/libraries/doltcore/doltdb/doltdb.go +++ b/go/libraries/doltcore/doltdb/doltdb.go @@ -1129,6 +1129,12 @@ func (ddb *DoltDB) DeleteWorkspace(ctx context.Context, workRef ref.DoltRef) err return err } +// Rebase rebases the underlying db from disk, re-loading the manifest. Useful when another process might have made +// changes to the database we need to read. +func (ddb *DoltDB) Rebase(ctx context.Context) error { + return ddb.db.Rebase(ctx) +} + // GC performs garbage collection on this ddb. Values passed in |uncommitedVals| will be temporarily saved during gc. func (ddb *DoltDB) GC(ctx context.Context, uncommitedVals ...hash.Hash) error { collector, ok := ddb.db.(datas.GarbageCollector) diff --git a/go/libraries/doltcore/sqle/dsess/session.go b/go/libraries/doltcore/sqle/dsess/session.go index 09a752c11e..ab399c3bad 100644 --- a/go/libraries/doltcore/sqle/dsess/session.go +++ b/go/libraries/doltcore/sqle/dsess/session.go @@ -281,8 +281,14 @@ func (sess *Session) StartTransaction(ctx *sql.Context, dbName string) (sql.Tran return DisabledTransaction{}, nil } + err = sessionState.dbData.Ddb.Rebase(ctx) + if err != nil { + return nil, err + } + wsRef := sessionState.WorkingSet.Ref() ws, err := sessionState.dbData.Ddb.ResolveWorkingSet(ctx, wsRef) + // TODO: every HEAD needs a working set created when it is. We can get rid of this in a 1.0 release when this is fixed if err == doltdb.ErrWorkingSetNotFound { ws, err = sess.newWorkingSetForHead(ctx, wsRef, dbName) if err != nil {