removed RootValue.SetFeatureVersion(), set FeatureVersion on every DoltDb.WriteRootValue()

This commit is contained in:
Andy Arthur
2021-02-12 12:27:35 -08:00
parent bbd371e8d8
commit 5f0c96231d
7 changed files with 6 additions and 157 deletions
+6
View File
@@ -386,6 +386,12 @@ func (ddb *DoltDB) ResolveTag(ctx context.Context, tagRef ref.TagRef) (*Tag, err
// WriteRootValue will write a doltdb.RootValue instance to the database. This value will not be associated with a commit
// and can be committed by hash at a later time. Returns the hash of the value written.
func (ddb *DoltDB) WriteRootValue(ctx context.Context, rv *RootValue) (hash.Hash, error) {
var err error
rv.valueSt, err = rv.valueSt.Set(featureVersKey, types.Int(DoltFeatureVersion))
if err != nil {
return hash.Hash{}, err
}
valRef, err := ddb.db.WriteValue(ctx, rv.valueSt)
if err != nil {
@@ -129,44 +129,6 @@ func TestFeatureVersion(t *testing.T) {
},
expVer: newVersion,
},
{
name: "Commit does not update feature version",
setup: []fvCommand{
{OldClient, commands.SqlCmd{}, args{"-q", "CREATE TABLE test (pk int PRIMARY KEY);"}},
{NewClient, commands.CommitCmd{}, args{"-a", "-m", "created table"}},
},
expVer: oldVersion,
},
{
name: "Branch does not update feature version",
setup: []fvCommand{
{OldClient, commands.SqlCmd{}, args{"-q", "CREATE TABLE test (pk int PRIMARY KEY);"}},
{OldClient, commands.CommitCmd{}, args{"-a", "-m", "created table"}},
{NewClient, commands.BranchCmd{}, args{"other"}},
},
expVer: oldVersion,
},
{
name: "Checkout does not update feature version",
setup: []fvCommand{
{OldClient, commands.SqlCmd{}, args{"-q", "CREATE TABLE test (pk int PRIMARY KEY);"}},
{OldClient, commands.CommitCmd{}, args{"-a", "-m", "created table"}},
{OldClient, commands.BranchCmd{}, args{"other"}},
{NewClient, commands.CheckoutCmd{}, args{"other"}},
{NewClient, commands.CheckoutCmd{}, args{"master"}},
},
expVer: oldVersion,
},
{
name: "reset --hard reverts feature version",
setup: []fvCommand{
{OldClient, commands.SqlCmd{}, args{"-q", "CREATE TABLE test (pk int PRIMARY KEY);"}},
{OldClient, commands.CommitCmd{}, args{"-a", "-m", "created table"}},
{NewClient, commands.SqlCmd{}, args{"-q", "INSERT INTO test VALUES (0);"}},
{NewClient, commands.ResetCmd{}, args{"--hard"}},
},
expVer: oldVersion,
},
{
name: "new client writes to table, locking out old client",
setup: []fvCommand{
@@ -182,72 +144,6 @@ func TestFeatureVersion(t *testing.T) {
},
expVer: newVersion,
},
{
name: "old client cannot checkout branch written by new client",
setup: []fvCommand{
{OldClient, commands.SqlCmd{}, args{"-q", "CREATE TABLE test (pk int PRIMARY KEY);"}},
{OldClient, commands.SqlCmd{}, args{"-q", "INSERT INTO test VALUES (0);"}},
{OldClient, commands.CommitCmd{}, args{"-a", "-m", "created table test"}},
{OldClient, commands.BranchCmd{}, args{"other"}},
{NewClient, commands.CheckoutCmd{}, args{"other"}},
{NewClient, commands.SqlCmd{}, args{"-q", "INSERT INTO test VALUES (10), (11);"}},
{NewClient, commands.CommitCmd{}, args{"-a", "-m", "added data to test"}},
{NewClient, commands.CheckoutCmd{}, args{"master"}},
// OldClient can read from master
{OldClient, commands.SqlCmd{}, args{"-q", "SELECT * FROM test"}},
},
errCmds: []fvCommand{
// old client can't checkout 'other'
{OldClient, commands.CheckoutCmd{}, args{"other"}},
// old client can't merge 'other'
{OldClient, commands.MergeCmd{}, args{"other"}},
},
expVer: oldVersion,
},
{
name: "fast-forward merge writes feature version",
setup: []fvCommand{
{OldClient, commands.SqlCmd{}, args{"-q", "CREATE TABLE test (pk int PRIMARY KEY);"}},
{OldClient, commands.SqlCmd{}, args{"-q", "INSERT INTO test VALUES (0);"}},
{OldClient, commands.CommitCmd{}, args{"-a", "-m", "created table test"}},
{OldClient, commands.BranchCmd{}, args{"other"}},
{NewClient, commands.CheckoutCmd{}, args{"other"}},
{NewClient, commands.SqlCmd{}, args{"-q", "INSERT INTO test VALUES (10), (11);"}},
{NewClient, commands.CommitCmd{}, args{"-a", "-m", "added data to test"}},
{NewClient, commands.CheckoutCmd{}, args{"master"}},
{NewClient, commands.MergeCmd{}, args{"other"}},
},
errCmds: []fvCommand{
// old client can't write
{OldClient, commands.SqlCmd{}, args{"-q", "INSERT INTO test VALUES (2);"}},
// old client can't read
{OldClient, commands.SqlCmd{}, args{"-q", "SELECT * FROM test;"}},
},
expVer: newVersion,
},
{
name: "3way merge writes feature version",
setup: []fvCommand{
{OldClient, commands.SqlCmd{}, args{"-q", "CREATE TABLE test (pk int PRIMARY KEY);"}},
{OldClient, commands.SqlCmd{}, args{"-q", "INSERT INTO test VALUES (0);"}},
{OldClient, commands.CommitCmd{}, args{"-a", "-m", "created table test"}},
{OldClient, commands.BranchCmd{}, args{"other"}},
{OldClient, commands.SqlCmd{}, args{"-q", "INSERT INTO test VALUES (1);"}},
{OldClient, commands.CommitCmd{}, args{"-a", "-m", "added another row"}},
{NewClient, commands.CheckoutCmd{}, args{"other"}},
{NewClient, commands.SqlCmd{}, args{"-q", "INSERT INTO test VALUES (10), (11);"}},
{NewClient, commands.CommitCmd{}, args{"-a", "-m", "added data to test"}},
{NewClient, commands.CheckoutCmd{}, args{"master"}},
{NewClient, commands.MergeCmd{}, args{"other"}},
},
errCmds: []fvCommand{
// old client can't write
{OldClient, commands.SqlCmd{}, args{"-q", "INSERT INTO test VALUES (2);"}},
// old client can't read
{OldClient, commands.SqlCmd{}, args{"-q", "SELECT * FROM test;"}},
},
expVer: newVersion,
},
}
ctx := context.Background()
-10
View File
@@ -102,16 +102,6 @@ func (root *RootValue) GetFeatureVersion(ctx context.Context) (ver FeatureVersio
return ver, ok, err
}
// SetFeatureVersion writes the Dolt client's FeatureVersion to |root|.
func (root *RootValue) SetFeatureVersion(ctx context.Context) (*RootValue, error) {
st, err := root.valueSt.Set(featureVersKey, types.Int(DoltFeatureVersion))
if err != nil {
return nil, err
}
return newRootValue(root.vrw, st)
}
func (root *RootValue) HasTable(ctx context.Context, tName string) (bool, error) {
val, found, err := root.valueSt.MaybeGet(tablesKey)
-28
View File
@@ -113,11 +113,6 @@ func stageTables(ctx context.Context, db *doltdb.DoltDB, rsw env.RepoStateWriter
return err
}
staged, err = maybeBumpFeatureVersion(ctx, staged, working)
if err != nil {
return err
}
if _, err := env.UpdateWorkingRoot(ctx, db, rsw, working); err == nil {
if sh, err := env.UpdateStagedRoot(ctx, db, rsw, staged); err == nil {
err = rsw.SetStagedHash(ctx, sh)
@@ -176,29 +171,6 @@ func checkTablesForConflicts(ctx context.Context, tbls []string, working *doltdb
return working, nil
}
// maybeBumpFeatureVersion compares the FeatureVersions of |staged| and |working| and
// updates |staged|'s FeatureVersion if they differ.
func maybeBumpFeatureVersion(ctx context.Context, staged, working *doltdb.RootValue) (*doltdb.RootValue, error) {
sfv, ok1, err := staged.GetFeatureVersion(ctx)
if err != nil {
return nil, err
}
wfv, ok2, err := working.GetFeatureVersion(ctx)
if err != nil {
return nil, err
}
if ok1 != ok2 || sfv != wfv {
staged, err = staged.SetFeatureVersion(ctx)
}
if err != nil {
return nil, err
}
return staged, nil
}
// ValidateTables checks that all tables passed exist in at least one of the roots passed.
func ValidateTables(ctx context.Context, tbls []string, roots ...*doltdb.RootValue) error {
var missing []string
-5
View File
@@ -824,11 +824,6 @@ func MergeRoots(ctx context.Context, ourRoot, theirRoot, ancRoot *doltdb.RootVal
return nil, nil, err
}
newRoot, err = newRoot.SetFeatureVersion(ctx)
if err != nil {
return nil, nil, err
}
return newRoot, tblToStats, nil
}
-5
View File
@@ -462,11 +462,6 @@ func (db Database) GetRoot(ctx *sql.Context) (*doltdb.RootValue, error) {
// basic SQL execution engine. If |newRoot|'s FeatureVersion is
// out-of-date with the client, SetRoot will update it.
func (db Database) SetRoot(ctx *sql.Context, newRoot *doltdb.RootValue) error {
newRoot, err := newRoot.SetFeatureVersion(ctx)
if err != nil {
return err
}
h, err := newRoot.HashOf()
if err != nil {
@@ -192,11 +192,6 @@ func (tes *TableEditSession) flush(ctx context.Context) (*doltdb.RootValue, erro
return nil, rootErr
}
newRoot, rootErr = newRoot.SetFeatureVersion(ctx)
if rootErr != nil {
return nil, rootErr
}
tes.root = newRoot
return newRoot, nil
}