mirror of
https://github.com/dolthub/dolt.git
synced 2026-02-09 10:38:10 -06:00
move globalstate to sqle.Database
This commit is contained in:
@@ -51,7 +51,6 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dfunctions"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dtables"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/globalstate"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/argparser"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/filesys"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/iohelp"
|
||||
@@ -1490,11 +1489,10 @@ func getDbState(ctx context.Context, db dsqle.Database, mrEnv env.MultiRepoEnv)
|
||||
}
|
||||
|
||||
return dsess.InitialDbState{
|
||||
Db: db,
|
||||
HeadCommit: headCommit,
|
||||
WorkingSet: ws,
|
||||
DbData: dEnv.DbData(),
|
||||
GlobalState: globalstate.NewGlobalStateStore(),
|
||||
Db: db,
|
||||
HeadCommit: headCommit,
|
||||
WorkingSet: ws,
|
||||
DbData: dEnv.DbData(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,6 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dfunctions"
|
||||
_ "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dfunctions"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/globalstate"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/tracing"
|
||||
)
|
||||
|
||||
@@ -277,8 +276,6 @@ func getDbStates(ctx context.Context, mrEnv env.MultiRepoEnv, dbs []dsqle.Databa
|
||||
HeadCommit: headCommit,
|
||||
WorkingSet: ws,
|
||||
DbData: dEnv.DbData(),
|
||||
// TODO: The placement of this may change when multiple Dolt Databases can be represented in one commit log.
|
||||
GlobalState: globalstate.NewGlobalStateStore(),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema/alterschema"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dtables"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/globalstate"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/sqlfmt"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/sqlutil"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/table/editor"
|
||||
@@ -58,6 +59,11 @@ type Database struct {
|
||||
rsr env.RepoStateReader
|
||||
rsw env.RepoStateWriter
|
||||
drw env.DocsReadWriter
|
||||
|
||||
// todo: needs a major refactor to
|
||||
// correctly handle persisted sequences
|
||||
// that must be coordinated across txs
|
||||
gs globalstate.GlobalState
|
||||
}
|
||||
|
||||
var _ sql.Database = Database{}
|
||||
@@ -123,6 +129,7 @@ func NewDatabase(name string, dbData env.DbData) Database {
|
||||
rsr: dbData.Rsr,
|
||||
rsw: dbData.Rsw,
|
||||
drw: dbData.Drw,
|
||||
gs: globalstate.NewGlobalStateStore(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -200,6 +200,7 @@ func dbRevisionForBranch(ctx context.Context, srcDb Database, revSpec string) (D
|
||||
rsw: static,
|
||||
rsr: static,
|
||||
drw: static,
|
||||
gs: srcDb.gs,
|
||||
}
|
||||
init := dsess.InitialDbState{
|
||||
Db: db,
|
||||
@@ -234,6 +235,7 @@ func dbRevisionForCommit(ctx context.Context, srcDb Database, revSpec string) (R
|
||||
rsw: srcDb.rsw,
|
||||
rsr: srcDb.rsr,
|
||||
drw: srcDb.drw,
|
||||
gs: nil,
|
||||
}}
|
||||
init := dsess.InitialDbState{
|
||||
Db: db,
|
||||
|
||||
@@ -26,7 +26,6 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/env"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/env/actions"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/ref"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/globalstate"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/table/editor"
|
||||
"github.com/dolthub/dolt/go/store/hash"
|
||||
)
|
||||
@@ -143,7 +142,6 @@ type DatabaseSessionState struct {
|
||||
dirty bool
|
||||
TempTableRoot *doltdb.RootValue
|
||||
TempTableEditSession *editor.TableEditSession
|
||||
GlobalState globalstate.GlobalState
|
||||
}
|
||||
|
||||
func (d DatabaseSessionState) GetRoots() doltdb.Roots {
|
||||
@@ -182,7 +180,6 @@ type InitialDbState struct {
|
||||
ReadOnly bool
|
||||
WorkingSet *doltdb.WorkingSet
|
||||
DbData env.DbData
|
||||
GlobalState globalstate.GlobalState
|
||||
}
|
||||
|
||||
// NewSession creates a Session object from a standard sql.Session and 0 or more Database objects.
|
||||
@@ -597,26 +594,6 @@ func (sess *Session) GetDoltDB(ctx *sql.Context, dbName string) (*doltdb.DoltDB,
|
||||
return dbState.dbData.Ddb, true
|
||||
}
|
||||
|
||||
func (sess *Session) GetDoltDbAutoIncrementTracker(ctx *sql.Context, dbName string) (globalstate.AutoIncrementTracker, bool) {
|
||||
dbState, ok, err := sess.LookupDbState(ctx, dbName)
|
||||
if err != nil {
|
||||
return nil, false
|
||||
}
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
wsref := dbState.WorkingSet.Ref()
|
||||
|
||||
if dbState.GlobalState == nil {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
tracker := dbState.GlobalState.GetAutoIncrementTracker(wsref)
|
||||
|
||||
return tracker, true
|
||||
}
|
||||
|
||||
func (sess *Session) GetDbData(ctx *sql.Context, dbName string) (env.DbData, bool) {
|
||||
dbState, ok, err := sess.LookupDbState(ctx, dbName)
|
||||
if err != nil {
|
||||
@@ -1058,7 +1035,6 @@ func (sess *Session) AddDB(ctx *sql.Context, dbState InitialDbState) error {
|
||||
adapter := NewSessionStateAdapter(sess, db.Name())
|
||||
sessionState.dbData.Rsr = adapter
|
||||
sessionState.dbData.Rsw = adapter
|
||||
sessionState.GlobalState = dbState.GlobalState
|
||||
sessionState.readOnly, sessionState.detachedHead = dbState.ReadOnly, dbState.DetachedHead
|
||||
|
||||
sessionState.EditSession = editor.CreateTableEditSession(nil, editor.TableEditSessionProps{})
|
||||
|
||||
@@ -203,7 +203,6 @@ func getDbState(t *testing.T, db sqle.Database, dEnv *env.DoltEnv, globalState g
|
||||
HeadCommit: headCommit,
|
||||
WorkingSet: ws,
|
||||
DbData: dEnv.DbData(),
|
||||
GlobalState: globalState,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
package sqle
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
@@ -67,8 +69,13 @@ func newSqlTableEditor(ctx *sql.Context, t *WritableDoltTable) (*sqlTableEditor,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
doltSession := dsess.DSessFromSess(ctx.Session)
|
||||
ait, _ := doltSession.GetDoltDbAutoIncrementTracker(ctx, t.db.Name())
|
||||
err = fmt.Errorf("could not create auto_increment tracker for table %s", t.tableName)
|
||||
ds := dsess.DSessFromSess(ctx.Session)
|
||||
ws, err := ds.WorkingSet(ctx, t.db.name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ait := t.db.gs.GetAutoIncrementTracker(ws.Ref())
|
||||
|
||||
conv := NewKVToSqlRowConverterForCols(t.nbf, t.sch.GetAllCols().GetColumns())
|
||||
return &sqlTableEditor{
|
||||
|
||||
Reference in New Issue
Block a user