From 762e8daf0c0532c2b61c85477a3a6e12dfe46a55 Mon Sep 17 00:00:00 2001 From: James Cor Date: Fri, 23 Aug 2024 14:13:13 -0700 Subject: [PATCH] working? --- .../doltcore/sqle/dolt_ci_tables_creator.go | 51 ++++++++++------- .../sqle/dolt_ci_workflow_events_table.go | 40 +++----------- .../doltcore/sqle/dolt_ci_workflows_table.go | 55 +++---------------- 3 files changed, 46 insertions(+), 100 deletions(-) diff --git a/go/libraries/doltcore/sqle/dolt_ci_tables_creator.go b/go/libraries/doltcore/sqle/dolt_ci_tables_creator.go index fa0c72bf3c6..4bfc93f9675 100644 --- a/go/libraries/doltcore/sqle/dolt_ci_tables_creator.go +++ b/go/libraries/doltcore/sqle/dolt_ci_tables_creator.go @@ -15,8 +15,10 @@ package sqle import ( - "github.com/dolthub/dolt/go/libraries/doltcore/branch_control" - "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" + "fmt" +"github.com/dolthub/dolt/go/libraries/doltcore/branch_control" + "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" +"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" "github.com/dolthub/go-mysql-server/sql" ) @@ -45,31 +47,38 @@ func (d doltCITablesCreator) CreateTables(ctx *sql.Context) error { return err } - //dbName := ctx.GetCurrentDatabase() - //dSess := dsess.DSessFromSess(ctx.Session) - - //dbState, ok, err := dSess.LookupDbState(ctx, dbName) - //if err != nil { - // return err - //} - // - //if !ok { - // return fmt.Errorf("database %s not found in database state", dbName) - //} + // TOD0: maybe CreateTable(...) should take in old RootVal and return new RootVal? + err := d.workflowsTC.CreateTable(ctx) + if err != nil { + return err + } - //originalWorkingSetHash, err := dbState.WorkingSet().HashOf() - //if err != nil { - // return err - //} - // - //fmt.Fprintf(color.Output, "original working set hash: %s\n", originalWorkingSetHash) + err = d.workflowEventsTC.CreateTable(ctx) + if err != nil { + return err + } - err := d.workflowsTC.CreateTable(ctx) + // update doltdb workingset exactly once + dbName := ctx.GetCurrentDatabase() + dSess := dsess.DSessFromSess(ctx.Session) + ws, err := dSess.WorkingSet(ctx, dbName) + if err != nil { + return err + } + wsHash, err := ws.HashOf() // TODO: setting the WorkingRoot of WorkingSet has no impact on hash + if err != nil { + return err + } + ddb, exists := dSess.GetDoltDB(ctx, dbName) + if !exists { + return fmt.Errorf("database not found in database %s", dbName) + } + err = ddb.UpdateWorkingSet(ctx, ws.Ref(), ws, wsHash, doltdb.TodoWorkingSetMeta(), nil) if err != nil { return err } - return d.workflowEventsTC.CreateTable(ctx) + return nil } var _ DoltCITablesCreator = &doltCITablesCreator{} diff --git a/go/libraries/doltcore/sqle/dolt_ci_workflow_events_table.go b/go/libraries/doltcore/sqle/dolt_ci_workflow_events_table.go index c8fdedb251b..eb7aaf6ebb6 100644 --- a/go/libraries/doltcore/sqle/dolt_ci_workflow_events_table.go +++ b/go/libraries/doltcore/sqle/dolt_ci_workflow_events_table.go @@ -39,22 +39,19 @@ func NewDoltCIWorkflowEventsTableCreator() *doltCIWorkflowEventsTableCreator { func (d *doltCIWorkflowEventsTableCreator) CreateTable(ctx *sql.Context) error { dbName := ctx.GetCurrentDatabase() dSess := dsess.DSessFromSess(ctx.Session) - ws, err := dSess.WorkingSet(ctx, dbName) if err != nil { return err } - startHash, err := ws.HashOf() + root := ws.WorkingRoot() + startHash, err := root.HashOf() if err != nil { return err } + fmt.Fprintf(color.Output, "workflow events WorkingSet.WorkingRoot.HashOf() start: %s\n", startHash) - fmt.Fprintf(color.Output, "workflow events working set hash at start: %s\n", startHash) - - roots, _ := dSess.GetRoots(ctx, dbName) - - found, err := roots.Working.HasTable(ctx, doltdb.TableName{Name: doltdb.WorkflowEventsTableName}) + found, err := root.HasTable(ctx, doltdb.TableName{Name: doltdb.WorkflowEventsTableName}) if err != nil { return err } @@ -104,7 +101,7 @@ func (d *doltCIWorkflowEventsTableCreator) CreateTable(ctx *sql.Context) error { } // underlying table doesn't exist. Record this, then create the table. - nrv, err := doltdb.CreateEmptyTable(ctx, roots.Working, doltdb.TableName{Name: doltdb.WorkflowEventsTableName}, sch) + nrv, err := doltdb.CreateEmptyTable(ctx, root, doltdb.TableName{Name: doltdb.WorkflowEventsTableName}, sch) if err != nil { return err } @@ -187,38 +184,17 @@ func (d *doltCIWorkflowEventsTableCreator) CreateTable(ctx *sql.Context) error { return err } - //newWorkingSetRef := newWorkingSet.Ref() - //ddb, exists := dSess.GetDoltDB(ctx, dbName) - //if !exists { - // return fmt.Errorf("database not found in database %s", dbName) - //} - - ////oldHash, err := newWorkingSet.HashOf() - ////if err != nil { - //// return err - ////} - // - //oldHash, err := dbState.WorkingSet().HashOf() - //if err != nil { - // return err - //} - - //err = ddb.UpdateWorkingSet(ctx, newWorkingSetRef, newWorkingSet, startHash, doltdb.TodoWorkingSetMeta(), nil) - //if err != nil { - // return err - //} - nws, err := dSess.WorkingSet(ctx, dbName) if err != nil { return err } - endHash, err := nws.HashOf() + newRoot := nws.WorkingRoot() + endHash, err := newRoot.HashOf() if err != nil { return err } - fmt.Fprintf(color.Output, "workflow events working set hash at end: %s\n", endHash) + fmt.Fprintf(color.Output, "workflow events WorkingSet.WorkingRoot.HashOf() end: %s\n", endHash) return nil - } diff --git a/go/libraries/doltcore/sqle/dolt_ci_workflows_table.go b/go/libraries/doltcore/sqle/dolt_ci_workflows_table.go index a4340ec47eb..c3c12e7322d 100644 --- a/go/libraries/doltcore/sqle/dolt_ci_workflows_table.go +++ b/go/libraries/doltcore/sqle/dolt_ci_workflows_table.go @@ -36,31 +36,19 @@ func NewDoltCIWorkflowsTableCreator() *doltCIWorkflowsTableCreator { func (d *doltCIWorkflowsTableCreator) CreateTable(ctx *sql.Context) error { dbName := ctx.GetCurrentDatabase() dSess := dsess.DSessFromSess(ctx.Session) - ws, err := dSess.WorkingSet(ctx, dbName) if err != nil { return err } - startHash, err := ws.HashOf() + root := ws.WorkingRoot() + startHash, err := root.HashOf() if err != nil { return err } + fmt.Fprintf(color.Output, "workflow WorkingSet.WorkingRoot.HashOf() start: %s\n", startHash) - fmt.Fprintf(color.Output, "workflow working set hash at start: %s\n", startHash) - - //dbState, ok, err := dSess.LookupDbState(ctx, dbName) - //if err != nil { - // return err - //} - - //if !ok { - // return fmt.Errorf("no root value found in session") - //} - - roots, _ := dSess.GetRoots(ctx, dbName) - - found, err := roots.Working.HasTable(ctx, doltdb.TableName{Name: doltdb.WorkflowsTableName}) + found, err := root.HasTable(ctx, doltdb.TableName{Name: doltdb.WorkflowsTableName}) if err != nil { return err } @@ -111,14 +99,7 @@ func (d *doltCIWorkflowsTableCreator) CreateTable(ctx *sql.Context) error { } // underlying table doesn't exist. Record this, then create the table. - nrv, err := doltdb.CreateEmptyTable(ctx, roots.Working, doltdb.TableName{Name: doltdb.WorkflowsTableName}, newSchema) - if err != nil { - return err - } - - newWorkingSet := ws.WithWorkingRoot(nrv) - //newWorkingSet := dbState.WorkingSet().WithWorkingRoot(nrv) - err = dSess.SetWorkingSet(ctx, dbName, newWorkingSet) + nrv, err := doltdb.CreateEmptyTable(ctx, root, doltdb.TableName{Name: doltdb.WorkflowsTableName}, newSchema) if err != nil { return err } @@ -128,37 +109,17 @@ func (d *doltCIWorkflowsTableCreator) CreateTable(ctx *sql.Context) error { return err } - newWorkingSetRef := newWorkingSet.Ref() - ddb, exists := dSess.GetDoltDB(ctx, dbName) - if !exists { - return fmt.Errorf("database not found in database %s", dbName) - } - - //oldHash, err := newWorkingSet.HashOf() - //if err != nil { - // return err - //} - // - //oldHash, err := dbState.WorkingSet().HashOf() - //if err != nil { - // return err - //} - - err = ddb.UpdateWorkingSet(ctx, newWorkingSetRef, newWorkingSet, startHash, doltdb.TodoWorkingSetMeta(), nil) - if err != nil { - return err - } - nws, err := dSess.WorkingSet(ctx, dbName) if err != nil { return err } - endHash, err := nws.HashOf() + newRoot := nws.WorkingRoot() + endHash, err := newRoot.HashOf() if err != nil { return err } - fmt.Fprintf(color.Output, "workflow working set hash at end: %s\n", endHash) + fmt.Fprintf(color.Output, "workflow WorkingSet.WorkingRoot.HashOf() end: %s\n", endHash) return nil }