mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-28 03:08:53 -06:00
Bug fix for global auto increment
This commit is contained in:
@@ -58,9 +58,9 @@ type WriteSessionFlusher interface {
|
||||
// Serves as coordination for SessionedTableEditors.
|
||||
type nomsWriteSession struct {
|
||||
workingSet *doltdb.WorkingSet
|
||||
tables map[string]*sessionedTableEditor
|
||||
tracker globalstate.AutoIncrementTracker
|
||||
mut *sync.RWMutex // This mutex is specifically for changes that affect the TES or all STEs
|
||||
tables map[string]*sessionedTableEditor
|
||||
aiTracker globalstate.AutoIncrementTracker
|
||||
mut *sync.RWMutex // This mutex is specifically for changes that affect the TES or all STEs
|
||||
opts editor.Options
|
||||
}
|
||||
|
||||
@@ -69,12 +69,12 @@ var _ WriteSession = &nomsWriteSession{}
|
||||
// NewWriteSession creates and returns a WriteSession. Inserting a nil root is not an error, as there are
|
||||
// locations that do not have a root at the time of this call. However, a root must be set through SetRoot before any
|
||||
// table editors are returned.
|
||||
func NewWriteSession(nbf *types.NomsBinFormat, ws *doltdb.WorkingSet, tracker globalstate.AutoIncrementTracker, opts editor.Options) WriteSession {
|
||||
func NewWriteSession(nbf *types.NomsBinFormat, ws *doltdb.WorkingSet, aiTracker globalstate.AutoIncrementTracker, opts editor.Options) WriteSession {
|
||||
if types.IsFormat_DOLT_1(nbf) {
|
||||
return &prollyWriteSession{
|
||||
workingSet: ws,
|
||||
tables: make(map[string]*prollyTableWriter),
|
||||
tracker: tracker,
|
||||
aiTracker: aiTracker,
|
||||
mut: &sync.RWMutex{},
|
||||
}
|
||||
}
|
||||
@@ -82,7 +82,7 @@ func NewWriteSession(nbf *types.NomsBinFormat, ws *doltdb.WorkingSet, tracker gl
|
||||
return &nomsWriteSession{
|
||||
workingSet: ws,
|
||||
tables: make(map[string]*sessionedTableEditor),
|
||||
tracker: tracker,
|
||||
aiTracker: aiTracker,
|
||||
mut: &sync.RWMutex{},
|
||||
opts: opts,
|
||||
}
|
||||
@@ -127,7 +127,7 @@ func (s *nomsWriteSession) GetTableWriter(ctx context.Context, table, db string,
|
||||
tableEditor: te,
|
||||
flusher: s,
|
||||
batched: batched,
|
||||
autoInc: s.tracker,
|
||||
autoInc: s.aiTracker,
|
||||
setter: setter,
|
||||
}, nil
|
||||
}
|
||||
@@ -186,7 +186,7 @@ func (s *nomsWriteSession) flush(ctx context.Context) (*doltdb.WorkingSet, error
|
||||
// Update the auto increment value for the table if a tracker was provided
|
||||
// TODO: the table probably needs an autoincrement tracker no matter what
|
||||
if schema.HasAutoIncrement(ed.Schema()) {
|
||||
v := s.tracker.Current(name)
|
||||
v := s.aiTracker.Current(name)
|
||||
tbl, err = tbl.SetAutoIncrementValue(ctx, v)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -264,10 +264,6 @@ func (s *nomsWriteSession) setWorkingSet(ctx context.Context, ws *doltdb.Working
|
||||
s.workingSet = ws
|
||||
|
||||
root := ws.WorkingRoot()
|
||||
if err := updateAutoIncrementSequences(ctx, root, s.tracker); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for tableName, localTableEditor := range s.tables {
|
||||
t, ok, err := root.GetTable(ctx, tableName)
|
||||
if err != nil {
|
||||
|
||||
@@ -31,9 +31,9 @@ import (
|
||||
// Serves as coordination for SessionedTableEditors.
|
||||
type prollyWriteSession struct {
|
||||
workingSet *doltdb.WorkingSet
|
||||
tables map[string]*prollyTableWriter
|
||||
tracker globalstate.AutoIncrementTracker
|
||||
mut *sync.RWMutex
|
||||
tables map[string]*prollyTableWriter
|
||||
aiTracker globalstate.AutoIncrementTracker
|
||||
mut *sync.RWMutex
|
||||
}
|
||||
|
||||
var _ WriteSession = &prollyWriteSession{}
|
||||
@@ -96,7 +96,7 @@ func (s *prollyWriteSession) GetTableWriter(ctx context.Context, table, db strin
|
||||
sch: sch,
|
||||
sqlSch: pkSch.Schema,
|
||||
aiCol: autoCol,
|
||||
aiTracker: s.tracker,
|
||||
aiTracker: s.aiTracker,
|
||||
flusher: s,
|
||||
setter: setter,
|
||||
batched: batched,
|
||||
@@ -146,7 +146,7 @@ func (s *prollyWriteSession) flush(ctx context.Context) (*doltdb.WorkingSet, err
|
||||
}
|
||||
|
||||
if schema.HasAutoIncrement(wr.sch) {
|
||||
t, err = t.SetAutoIncrementValue(ctx2, s.tracker.Current(name))
|
||||
t, err = t.SetAutoIncrementValue(ctx2, s.aiTracker.Current(name))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -179,10 +179,6 @@ func (s *prollyWriteSession) flush(ctx context.Context) (*doltdb.WorkingSet, err
|
||||
// setRoot is the inner implementation for SetRoot that does not acquire any locks
|
||||
func (s *prollyWriteSession) setWorkingSet(ctx context.Context, ws *doltdb.WorkingSet) error {
|
||||
root := ws.WorkingRoot()
|
||||
if err := updateAutoIncrementSequences(ctx, root, s.tracker); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for tableName, tableWriter := range s.tables {
|
||||
t, ok, err := root.GetTable(ctx, tableName)
|
||||
if err != nil {
|
||||
@@ -205,17 +201,3 @@ func (s *prollyWriteSession) setWorkingSet(ctx context.Context, ws *doltdb.Worki
|
||||
s.workingSet = ws
|
||||
return nil
|
||||
}
|
||||
|
||||
func updateAutoIncrementSequences(ctx context.Context, root *doltdb.RootValue, t globalstate.AutoIncrementTracker) error {
|
||||
return root.IterTables(ctx, func(name string, table *doltdb.Table, sch schema.Schema) (stop bool, err error) {
|
||||
if !schema.HasAutoIncrement(sch) {
|
||||
return
|
||||
}
|
||||
v, err := table.GetAutoIncrementValue(ctx)
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
t.Set(name, v)
|
||||
return
|
||||
})
|
||||
}
|
||||
|
||||
@@ -719,7 +719,7 @@ SQL
|
||||
[[ "$output" =~ "2,2" ]] || false
|
||||
|
||||
dolt checkout branch1
|
||||
dolt sql -q 'select * from test' -r csv
|
||||
run dolt sql -q 'select * from test' -r csv
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "3,3" ]] || false
|
||||
[[ "$output" =~ "4,4" ]] || false
|
||||
@@ -753,18 +753,18 @@ insert into t1 (c0) values (5), (6);
|
||||
call dolt_commit('-am', 'branch4 values');
|
||||
SQL
|
||||
|
||||
dolt sql -q 'select * from t1' -r csv
|
||||
run dolt sql -q 'select * from t1' -r csv
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "1,1" ]] || false
|
||||
[[ "$output" =~ "2,2" ]] || false
|
||||
|
||||
dolt checkout branch1
|
||||
dolt checkout branch3
|
||||
run dolt sql -q 'select * from t1' -r csv
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "3,3" ]] || false
|
||||
[[ "$output" =~ "4,4" ]] || false
|
||||
|
||||
dolt checkout branch2
|
||||
dolt checkout branch4
|
||||
run dolt sql -q 'select * from t1' -r csv
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "5,5" ]] || false
|
||||
|
||||
Reference in New Issue
Block a user