mirror of
https://github.com/dolthub/dolt.git
synced 2025-12-30 16:12:39 -06:00
go/cmd/dolt: sql-server.lock/sql-server.info changes. PR feedback.
This commit is contained in:
@@ -104,8 +104,6 @@ func (cmd FilterBranchCmd) Exec(ctx context.Context, commandStr string, args []s
|
||||
return HandleVErrAndExitCode(verr, usage)
|
||||
}
|
||||
|
||||
// TODO: Assert that dEnv.DoltDB.AccessMode() != ReadOnly
|
||||
|
||||
queryString := apr.GetValueOrDefault(QueryFlag, "")
|
||||
verbose := apr.Contains(cli.VerboseFlag)
|
||||
continueOnErr := apr.Contains(continueFlag)
|
||||
|
||||
@@ -88,7 +88,12 @@ func (cmd GarbageCollectionCmd) Exec(ctx context.Context, commandStr string, arg
|
||||
help, usage := cli.HelpAndUsagePrinters(cli.CommandDocsForCommandString(commandStr, gcDocs, ap))
|
||||
apr := cli.ParseArgsOrDie(ap, args, help)
|
||||
|
||||
// TODO: Assert that dEnv.DoltDB.AccessMode() != ReadOnly?
|
||||
// We assert this here simply because the implementation of GC can
|
||||
// delay actually trying to write to the chunk store for a long time
|
||||
// after doing a lot or work. It's better to fail early.
|
||||
if dEnv.IsAccessModeReadOnly() {
|
||||
return HandleVErrAndExitCode(errhand.VerboseErrorFromError(env.ErrDatabaseIsLocked), help)
|
||||
}
|
||||
|
||||
var err error
|
||||
if apr.Contains(cli.ShallowFlag) {
|
||||
|
||||
@@ -71,8 +71,6 @@ func (cmd RebuildCmd) Exec(ctx context.Context, commandStr string, args []string
|
||||
return HandleErr(errhand.BuildDError("Both the table and index names must be provided.").Build(), usage)
|
||||
}
|
||||
|
||||
// TODO: Error if dEnv.DoltDB.AccessMode() == ReadOnly?
|
||||
|
||||
working, err := dEnv.WorkingRoot(context.Background())
|
||||
if err != nil {
|
||||
return HandleErr(errhand.BuildDError("Unable to get working.").AddCause(err).Build(), nil)
|
||||
|
||||
@@ -170,8 +170,6 @@ func (cmd ImportCmd) Exec(ctx context.Context, commandStr string, args []string,
|
||||
return 1
|
||||
}
|
||||
|
||||
// TODO: Error if dEnv.DoltDB.AccessMode() == ReadOnly?
|
||||
|
||||
return commands.HandleVErrAndExitCode(importSchema(ctx, dEnv, apr), usage)
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/utils/filesys"
|
||||
)
|
||||
|
||||
const ServerLocalCredsFile = "sql-server.lock"
|
||||
const ServerLocalCredsFile = "sql-server.info"
|
||||
|
||||
// LocalCreds is a struct that contains information about how to access the
|
||||
// locally running server for a CLI process which wants to operate against a
|
||||
@@ -87,7 +87,7 @@ func WriteLocalCreds(fs filesys.Filesys, creds *LocalCreds) error {
|
||||
|
||||
// Starting at `fs`, look for the a ServerLocalCredsFile in the .dolt directory
|
||||
// of this directory and every parent directory, until we find one. When we
|
||||
// find we, we return its contents if we can open and parse it successfully.
|
||||
// find one, we return its contents if we can open and parse it successfully.
|
||||
// Otherwise, we return an error associated with attempting to read it. If we
|
||||
// do not find anything all the way up to the root of the filesystem, returns
|
||||
// `nil` *LocalCreds and a `nil` error.
|
||||
@@ -136,14 +136,6 @@ func LoadLocalCreds(fs filesys.Filesys) (creds *LocalCreds, err error) {
|
||||
data := strings.TrimSpace(string(b[:n]))
|
||||
|
||||
parts := strings.Split(data, ":")
|
||||
if len(parts) == 1 {
|
||||
// Legacy Lock file. We can remove this code path in a couple of months (6/2023)
|
||||
pid, err := strconv.Atoi(parts[0])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &LocalCreds{Pid: pid, Port: -1, Secret: ""}, nil
|
||||
}
|
||||
if len(parts) != 3 {
|
||||
return nil, fmt.Errorf("invalid lock file format")
|
||||
}
|
||||
|
||||
@@ -72,8 +72,6 @@ func (cmd StashClearCmd) Exec(ctx context.Context, commandStr string, args []str
|
||||
help, usage := cli.HelpAndUsagePrinters(cli.CommandDocsForCommandString(commandStr, stashClearDocs, ap))
|
||||
apr := cli.ParseArgsOrDie(ap, args, help)
|
||||
|
||||
// TODO: Error if dEnv.DoltDB.AccessMode() == ReadOnly?
|
||||
|
||||
if apr.NArg() != 0 {
|
||||
usage()
|
||||
return 1
|
||||
|
||||
@@ -75,8 +75,6 @@ func (cmd StashDropCmd) Exec(ctx context.Context, commandStr string, args []stri
|
||||
help, usage := cli.HelpAndUsagePrinters(cli.CommandDocsForCommandString(commandStr, stashDropDocs, ap))
|
||||
apr := cli.ParseArgsOrDie(ap, args, help)
|
||||
|
||||
// TODO: Error if dEnv.DoltDB.AccessMode() == ReadOnly?
|
||||
|
||||
var idx = 0
|
||||
var err error
|
||||
if apr.NArg() == 1 {
|
||||
|
||||
@@ -72,8 +72,6 @@ func (cmd StashListCmd) Exec(ctx context.Context, commandStr string, args []stri
|
||||
help, usage := cli.HelpAndUsagePrinters(cli.CommandDocsForCommandString(commandStr, stashListDocs, ap))
|
||||
cli.ParseArgsOrDie(ap, args, help)
|
||||
|
||||
// TODO: Error if dEnv.DoltDB.AccessMode() == ReadOnly?
|
||||
|
||||
err := listStashes(ctx, dEnv)
|
||||
if err != nil {
|
||||
return commands.HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage)
|
||||
|
||||
@@ -81,8 +81,6 @@ func (cmd StashPopCmd) Exec(ctx context.Context, commandStr string, args []strin
|
||||
help, usage := cli.HelpAndUsagePrinters(cli.CommandDocsForCommandString(commandStr, stashPopDocs, ap))
|
||||
apr := cli.ParseArgsOrDie(ap, args, help)
|
||||
|
||||
// TODO: Error if dEnv.DoltDB.AccessMode() == ReadOnly?
|
||||
|
||||
_, sqlCtx, closer, err := cliCtx.QueryEngine(ctx)
|
||||
if err != nil {
|
||||
cli.PrintErrln(err.Error())
|
||||
|
||||
@@ -99,8 +99,6 @@ func (cmd StashCmd) Exec(ctx context.Context, commandStr string, args []string,
|
||||
return 1
|
||||
}
|
||||
|
||||
// TODO: Error if dEnv.DoltDB.AccessMode() == ReadOnly?
|
||||
|
||||
err := stashChanges(ctx, dEnv, apr)
|
||||
if err != nil {
|
||||
return commands.HandleStageError(err)
|
||||
|
||||
@@ -676,17 +676,20 @@ If you're interested in running this command against a remote host, hit us up on
|
||||
}
|
||||
}
|
||||
|
||||
usedEnv := targetEnv
|
||||
if usedEnv == nil && useDb != "" {
|
||||
usedEnv = mrEnv.GetEnv(useDb)
|
||||
}
|
||||
// If our targetEnv is still |nil| and we don't have an environment
|
||||
// which we will be using based on |useDb|, then our initialization
|
||||
// here did not find a repository we will be operating against.
|
||||
noValidRepository := targetEnv == nil && (useDb == "" || mrEnv.GetEnv(useDb) == nil)
|
||||
|
||||
// There is no target environment detected. This is allowed for a small number of commands.
|
||||
// We don't expect that number to grow, so we list them here.
|
||||
// It's also allowed when --help is passed.
|
||||
// So we defer the error until the caller tries to use the cli.LateBindQueryist
|
||||
isDoltEnvironmentRequired := subcommandName != "init" && subcommandName != "sql" && subcommandName != "sql-server" && subcommandName != "sql-client"
|
||||
if usedEnv == nil && isDoltEnvironmentRequired {
|
||||
// Not having a valid repository as we start to execute a CLI command
|
||||
// implementation is allowed for a small number of commands. We don't
|
||||
// expect this set of commands to grow, so we list them here.
|
||||
//
|
||||
// This is also allowed when --help is passed. So we defer the error
|
||||
// until the caller tries to use the cli.LateBindQueryist.
|
||||
isValidRepositoryRequired := subcommandName != "init" && subcommandName != "sql" && subcommandName != "sql-server" && subcommandName != "sql-client"
|
||||
|
||||
if noValidRepository && isValidRepositoryRequired {
|
||||
return func(ctx context.Context) (cli.Queryist, *sql.Context, func(), error) {
|
||||
return nil, nil, nil, fmt.Errorf("The current directory is not a valid dolt repository.")
|
||||
}, nil
|
||||
@@ -713,7 +716,7 @@ If you're interested in running this command against a remote host, hit us up on
|
||||
if dEnv.DoltDB != nil {
|
||||
allReposAreReadOnly = allReposAreReadOnly && dEnv.IsAccessModeReadOnly()
|
||||
}
|
||||
return false, nil
|
||||
return !allReposAreReadOnly, nil
|
||||
})
|
||||
lookForServer = allReposAreReadOnly
|
||||
}
|
||||
|
||||
1
go/libraries/doltcore/env/environment.go
vendored
1
go/libraries/doltcore/env/environment.go
vendored
@@ -75,6 +75,7 @@ var ErrFailedToWriteRepoState = errors.New("failed to write repo state")
|
||||
var ErrRemoteAddressConflict = errors.New("address conflict with a remote")
|
||||
var ErrDoltRepositoryNotFound = errors.New("can no longer find .dolt dir on disk")
|
||||
var ErrFailedToAccessDB = goerrors.NewKind("failed to access '%s' database: can no longer find .dolt dir on disk")
|
||||
var ErrDatabaseIsLocked = errors.New("the database is locked by another dolt process")
|
||||
|
||||
// DoltEnv holds the state of the current environment used by the cli.
|
||||
type DoltEnv struct {
|
||||
|
||||
@@ -32,7 +32,7 @@ import (
|
||||
// A ChunkStore's |ExclusiveAccessMode| can indicate to a client what type of
|
||||
// exclusive access and concurrency control are support by the ChunkStore, and
|
||||
// for a ChunkStore instance which the client is holding, what level of access
|
||||
// it has. Typically, a ChunkStore will by Mode_Shared, which means multiple
|
||||
// it has. Typically, a ChunkStore will be in Mode_Shared, which means multiple
|
||||
// processes can concurrently write to the chunk store and the chunk store can
|
||||
// change out from under the process. Other possible modes, currently only used
|
||||
// by local ChunkStores using the chunk journal in go/store/nbs are
|
||||
@@ -42,6 +42,11 @@ import (
|
||||
// while this ChunkStore is open.
|
||||
type ExclusiveAccessMode uint8
|
||||
|
||||
// Note: the order of these constants is relied on in nbs/GenerationalNBS. The
|
||||
// order should go from least restricted access to most restricted access. If a
|
||||
// client has many stores with different levels of accses, a common question
|
||||
// they want to answer is: what is the most restricted access across all of
|
||||
// these stores.
|
||||
const (
|
||||
ExclusiveAccessMode_Shared = iota
|
||||
ExclusiveAccessMode_Exclusive
|
||||
|
||||
@@ -28,7 +28,7 @@ import (
|
||||
driver "github.com/dolthub/dolt/go/libraries/doltcore/dtestutils/sql_server_driver"
|
||||
)
|
||||
|
||||
func TestSQLServerLockFile(t *testing.T) {
|
||||
func TestSQLServerInfoFile(t *testing.T) {
|
||||
t.Run("With Two Repos", func(t *testing.T) {
|
||||
u, err := driver.NewDoltUser()
|
||||
require.NoError(t, err)
|
||||
@@ -46,8 +46,8 @@ func TestSQLServerLockFile(t *testing.T) {
|
||||
t.Run("With server running in root", func(t *testing.T) {
|
||||
RunServerUntilEndOfTest(t, rs, &driver.Server{})
|
||||
|
||||
t.Run("sql-server.lock file exists", func(t *testing.T) {
|
||||
location := filepath.Join(rs.Dir, ".dolt/sql-server.lock")
|
||||
t.Run("sql-server.info file exists", func(t *testing.T) {
|
||||
location := filepath.Join(rs.Dir, ".dolt/sql-server.info")
|
||||
f, err := os.Open(location)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.Close())
|
||||
@@ -98,8 +98,8 @@ func TestSQLServerLockFile(t *testing.T) {
|
||||
require.Regexp(t, "db_two", outstr)
|
||||
})
|
||||
})
|
||||
t.Run("sql-server.lock in root no longer exists", func(t *testing.T) {
|
||||
location := filepath.Join(rs.Dir, ".dolt/sql-server.lock")
|
||||
t.Run("sql-server.info in root no longer exists", func(t *testing.T) {
|
||||
location := filepath.Join(rs.Dir, ".dolt/sql-server.info")
|
||||
f, err := os.Open(location)
|
||||
if f != nil {
|
||||
defer f.Close()
|
||||
@@ -211,9 +211,9 @@ func TestSQLServerLockFile(t *testing.T) {
|
||||
require.Error(t, err)
|
||||
})
|
||||
})
|
||||
t.Run("With stale sql-server.lock file in root", func(t *testing.T) {
|
||||
t.Run("With stale sql-server.info file in root", func(t *testing.T) {
|
||||
Setup := func(t *testing.T) {
|
||||
path := filepath.Join(rs.Dir, ".dolt/sql-server.lock")
|
||||
path := filepath.Join(rs.Dir, ".dolt/sql-server.info")
|
||||
err := os.WriteFile(path, []byte("1:3306:this_is_not_a_real_secret"), 0600)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() { os.Remove(path) })
|
||||
@@ -244,9 +244,9 @@ func TestSQLServerLockFile(t *testing.T) {
|
||||
require.Regexp(t, "db_one", outstr)
|
||||
})
|
||||
})
|
||||
t.Run("With malformed sql-server.lock file in root", func(t *testing.T) {
|
||||
t.Run("With malformed sql-server.info file in root", func(t *testing.T) {
|
||||
Setup := func(t *testing.T) {
|
||||
path := filepath.Join(rs.Dir, ".dolt/sql-server.lock")
|
||||
path := filepath.Join(rs.Dir, ".dolt/sql-server.info")
|
||||
err := os.WriteFile(path, []byte("1:3306:this_is_not_a_real_secret:extra:fields:make:it:fail"), 0600)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() { os.Remove(path) })
|
||||
Reference in New Issue
Block a user