mirror of
https://github.com/dolthub/dolt.git
synced 2026-04-20 19:31:56 -05:00
Merge branch 'main' into james/multipoint
This commit is contained in:
+1
-1
@@ -57,7 +57,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
Version = "0.50.1"
|
||||
Version = "0.50.2"
|
||||
)
|
||||
|
||||
var dumpDocsCommand = &commands.DumpDocsCmd{}
|
||||
|
||||
+5
-18
@@ -90,9 +90,8 @@ type DoltEnv struct {
|
||||
RepoState *RepoState
|
||||
RSLoadErr error
|
||||
|
||||
DoltDB *doltdb.DoltDB
|
||||
DBLoadError error
|
||||
DbFormatError error
|
||||
DoltDB *doltdb.DoltDB
|
||||
DBLoadError error
|
||||
|
||||
FS filesys.Filesys
|
||||
urlStr string
|
||||
@@ -103,18 +102,14 @@ type DoltEnv struct {
|
||||
|
||||
// Load loads the DoltEnv for the .dolt directory determined by resolving the specified urlStr with the specified Filesys.
|
||||
func Load(ctx context.Context, hdp HomeDirProvider, fs filesys.Filesys, urlStr string, version string) *DoltEnv {
|
||||
return loadWithFormat(ctx, hdp, fs, urlStr, version, nil)
|
||||
}
|
||||
|
||||
func loadWithFormat(ctx context.Context, hdp HomeDirProvider, fs filesys.Filesys, urlStr, version string, binFormat *types.NomsBinFormat) *DoltEnv {
|
||||
config, cfgErr := LoadDoltCliConfig(hdp, fs)
|
||||
cfg, cfgErr := LoadDoltCliConfig(hdp, fs)
|
||||
repoState, rsErr := LoadRepoState(fs)
|
||||
|
||||
ddb, dbLoadErr := doltdb.LoadDoltDB(ctx, types.Format_Default, urlStr, fs)
|
||||
|
||||
dEnv := &DoltEnv{
|
||||
Version: version,
|
||||
Config: config,
|
||||
Config: cfg,
|
||||
CfgLoadErr: cfgErr,
|
||||
RepoState: repoState,
|
||||
RSLoadErr: rsErr,
|
||||
@@ -171,15 +166,7 @@ func loadWithFormat(ctx context.Context, hdp HomeDirProvider, fs filesys.Filesys
|
||||
}
|
||||
}
|
||||
|
||||
var dbFormatErr error
|
||||
if rsErr == nil && dbLoadErr == nil {
|
||||
if binFormat != nil && dEnv.DoltDB.Format() != binFormat {
|
||||
dbFormatErr = fmt.Errorf("database with incompatible DOLT_DEFAULT_BIN_FORMAT")
|
||||
dEnv.DbFormatError = dbFormatErr
|
||||
}
|
||||
}
|
||||
|
||||
if rsErr == nil && dbLoadErr == nil && dbFormatErr == nil {
|
||||
// If the working set isn't present in the DB, create it from the repo state. This step can be removed post 1.0.
|
||||
_, err := dEnv.WorkingSet(ctx)
|
||||
if errors.Is(err, doltdb.ErrWorkingSetNotFound) {
|
||||
@@ -199,7 +186,7 @@ func GetDefaultInitBranch(cfg config.ReadableConfig) string {
|
||||
// Valid returns whether this environment has been properly initialized. This is useful because although every command
|
||||
// gets a DoltEnv, not all of them require it, and we allow invalid dolt envs to be passed around for this reason.
|
||||
func (dEnv *DoltEnv) Valid() bool {
|
||||
return dEnv.CfgLoadErr == nil && dEnv.DBLoadError == nil && dEnv.DbFormatError == nil && dEnv.HasDoltDir() && dEnv.HasDoltDataDir()
|
||||
return dEnv.CfgLoadErr == nil && dEnv.DBLoadError == nil && dEnv.HasDoltDir() && dEnv.HasDoltDataDir()
|
||||
}
|
||||
|
||||
// initWorkingSetFromRepoState sets the working set for the env's head to mirror the contents of the repo state file.
|
||||
|
||||
+54
-15
@@ -30,6 +30,7 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/utils/config"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/earl"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/filesys"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/set"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
|
||||
@@ -270,12 +271,9 @@ func MultiEnvForDirectory(
|
||||
//dEnv = Load(ctx, GetCurrentUserHomeDir, fs, doltdb.LocalDirDoltDB, version)
|
||||
}
|
||||
|
||||
var binFormat *types.NomsBinFormat
|
||||
envSet := map[string]*DoltEnv{}
|
||||
if dEnv.Valid() {
|
||||
binFormat = dEnv.DoltDB.Format()
|
||||
mrEnv.AddEnv(dbName, dEnv)
|
||||
} else {
|
||||
binFormat = types.Format_Default
|
||||
envSet[dbName] = dEnv
|
||||
}
|
||||
|
||||
// If there are other directories in the directory, try to load them as additional databases
|
||||
@@ -291,20 +289,26 @@ func MultiEnvForDirectory(
|
||||
return false
|
||||
}
|
||||
|
||||
newEnv := loadWithFormat(ctx, GetCurrentUserHomeDir, newFs, doltdb.LocalDirDoltDB, dEnv.Version, binFormat)
|
||||
newEnv := Load(ctx, GetCurrentUserHomeDir, newFs, doltdb.LocalDirDoltDB, dEnv.Version)
|
||||
if newEnv.Valid() {
|
||||
mrEnv.AddEnv(dirToDBName(dir), newEnv)
|
||||
if binFormat == nil {
|
||||
binFormat = newEnv.DoltDB.Format()
|
||||
}
|
||||
envSet[dirToDBName(dir)] = newEnv
|
||||
}
|
||||
if newEnv.DbFormatError != nil {
|
||||
logrus.Infof("incompatible format for database '%s'; expected '%s', found '%s'", dir, binFormat.VersionString(), newEnv.DoltDB.Format().VersionString())
|
||||
}
|
||||
|
||||
return false
|
||||
})
|
||||
|
||||
enforceSingleFormat(envSet)
|
||||
|
||||
// if the current directory database is in out set,
|
||||
// add it first so it will be the current database
|
||||
var ok bool
|
||||
if dEnv, ok = envSet[dbName]; ok {
|
||||
mrEnv.AddEnv(dbName, dEnv)
|
||||
delete(envSet, dbName)
|
||||
}
|
||||
for dbName, dEnv = range envSet {
|
||||
mrEnv.AddEnv(dbName, dEnv)
|
||||
}
|
||||
|
||||
return mrEnv, nil
|
||||
}
|
||||
|
||||
@@ -341,6 +345,7 @@ func MultiEnvForPaths(
|
||||
ignoreLockFile: ignoreLockFile,
|
||||
}
|
||||
|
||||
envSet := map[string]*DoltEnv{}
|
||||
for name, path := range nameToPath {
|
||||
absPath, err := fs.Abs(path)
|
||||
|
||||
@@ -364,13 +369,47 @@ func MultiEnvForPaths(
|
||||
} else if dEnv.CfgLoadErr != nil {
|
||||
return nil, fmt.Errorf("error loading environment '%s' at path '%s': %s", name, absPath, dEnv.CfgLoadErr.Error())
|
||||
}
|
||||
envSet[name] = dEnv
|
||||
}
|
||||
|
||||
mrEnv.AddEnv(name, dEnv)
|
||||
enforceSingleFormat(envSet)
|
||||
for dbName, dEnv := range envSet {
|
||||
mrEnv.AddEnv(dbName, dEnv)
|
||||
}
|
||||
|
||||
return mrEnv, nil
|
||||
}
|
||||
|
||||
// enforceSingleFormat enforces that constraint that all databases in
|
||||
// a multi-database environment have the same NomsBinFormat.
|
||||
// Databases are removed from the MultiRepoEnv to ensure this is true.
|
||||
func enforceSingleFormat(envSet map[string]*DoltEnv) {
|
||||
formats := set.NewEmptyStrSet()
|
||||
for _, dEnv := range envSet {
|
||||
formats.Add(dEnv.DoltDB.Format().VersionString())
|
||||
}
|
||||
|
||||
var nbf string
|
||||
// if present, prefer types.Format_Default
|
||||
if ok := formats.Contains(types.Format_Default.VersionString()); ok {
|
||||
nbf = types.Format_Default.VersionString()
|
||||
} else {
|
||||
// otherwise, pick an arbitrary format
|
||||
for _, dEnv := range envSet {
|
||||
nbf = dEnv.DoltDB.Format().VersionString()
|
||||
}
|
||||
}
|
||||
|
||||
template := "incompatible format for database '%s'; expected '%s', found '%s'"
|
||||
for name, dEnv := range envSet {
|
||||
found := dEnv.DoltDB.Format().VersionString()
|
||||
if found != nbf {
|
||||
logrus.Infof(template, name, nbf, found)
|
||||
delete(envSet, name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func DBNamesAndPathsFromDir(fs filesys.Filesys, path string) ([]EnvNameAndPath, error) {
|
||||
var envNamesAndPaths []EnvNameAndPath
|
||||
err := fs.Iter(path, false, func(path string, size int64, isDir bool) (stop bool) {
|
||||
|
||||
@@ -251,10 +251,9 @@ teardown() {
|
||||
}
|
||||
|
||||
@test "init: create a database when current working directory does not have a database yet" {
|
||||
# it creates old format even though there is new format db exists in the current directory.
|
||||
set_dolt_user "baz", "baz@bash.com"
|
||||
|
||||
# Default format is OLD (__LD_1__) when DOLT_DEFAULT_BIN_FORMAT is undefined
|
||||
# Default format is NEW (__DOLT__) when DOLT_DEFAULT_BIN_FORMAT is undefined
|
||||
if [ "$DOLT_DEFAULT_BIN_FORMAT" = "" ]
|
||||
then
|
||||
orig_bin_format="__DOLT__"
|
||||
@@ -281,10 +280,9 @@ teardown() {
|
||||
[[ $output =~ "test" ]] || false
|
||||
|
||||
cd test
|
||||
dolt version
|
||||
run dolt version
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "$orig_bin_format" ]] || false
|
||||
[[ "$output" =~ "__DOLT__" ]] || false
|
||||
}
|
||||
|
||||
assert_valid_repository () {
|
||||
|
||||
@@ -102,7 +102,8 @@ make__DOLT__db() {
|
||||
make__DOLT__db new1
|
||||
make__LD_1__db old1
|
||||
|
||||
DOLT_DEFAULT_BIN_FORMAT="__DOLT__" dolt init
|
||||
export DOLT_DEFAULT_BIN_FORMAT="__DOLT__"
|
||||
dolt init
|
||||
run dolt sql -q "SHOW DATABASES;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "incompatible format for database 'old1'; expected '__DOLT__', found '__LD_1__'" ]] || false
|
||||
@@ -111,7 +112,8 @@ make__DOLT__db() {
|
||||
[[ ! "$output" =~ "| old1" ]] || false
|
||||
|
||||
rm -r .dolt
|
||||
DOLT_DEFAULT_BIN_FORMAT="__LD_1__" dolt init
|
||||
export DOLT_DEFAULT_BIN_FORMAT="__LD_1__"
|
||||
dolt init
|
||||
run dolt sql -q "SHOW DATABASES;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "incompatible format for database 'new1'; expected '__LD_1__', found '__DOLT__'" ]] || false
|
||||
|
||||
Reference in New Issue
Block a user