Skip to content

Commit

Permalink
Better read only error messages (#3920)
Browse files Browse the repository at this point in the history
* Better read only error messages

* GMS bump

* block table import for server lock
  • Loading branch information
max-hoffman authored Jul 26, 2022
1 parent 0582e5f commit 9dae75e
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 22 deletions.
21 changes: 11 additions & 10 deletions go/cmd/dolt/commands/engine/sqlengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@ type SqlEngine struct {
}

type SqlEngineConfig struct {
InitialDb string
IsReadOnly bool
PrivFilePath string
ServerUser string
ServerPass string
Autocommit bool
Bulk bool
JwksConfig []JwksConfig
InitialDb string
IsReadOnly bool
IsServerLocked bool
PrivFilePath string
ServerUser string
ServerPass string
Autocommit bool
Bulk bool
JwksConfig []JwksConfig
}

// NewSqlEngine returns a SqlEngine
Expand All @@ -67,7 +68,7 @@ func NewSqlEngine(
) (*SqlEngine, error) {

if ok, _ := mrEnv.IsLocked(); ok {
config.IsReadOnly = true
config.IsServerLocked = true
}

parallelism := runtime.GOMAXPROCS(0)
Expand Down Expand Up @@ -106,7 +107,7 @@ func NewSqlEngine(
}

// Set up engine
engine := gms.New(analyzer.NewBuilder(pro).WithParallelism(parallelism).Build(), &gms.Config{IsReadOnly: config.IsReadOnly, TemporaryUsers: tempUsers}).WithBackgroundThreads(bThreads)
engine := gms.New(analyzer.NewBuilder(pro).WithParallelism(parallelism).Build(), &gms.Config{IsReadOnly: config.IsReadOnly, TemporaryUsers: tempUsers, IsServerLocked: config.IsServerLocked}).WithBackgroundThreads(bThreads)
engine.Analyzer.Catalog.MySQLDb.SetPersister(persister)
engine.Analyzer.Catalog.MySQLDb.SetPlugins(map[string]mysql_db.PlaintextAuthPlugin{
"authentication_dolt_jwt": NewAuthenticateDoltJWTPlugin(config.JwksConfig),
Expand Down
7 changes: 1 addition & 6 deletions go/cmd/dolt/commands/sqlserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ func Serve(
}
logrus.SetFormatter(LogFormat{})

isReadOnly := false
if serverConfig.ReadOnly() {
isReadOnly = true
}

var mrEnv *env.MultiRepoEnv
var err error
fs := dEnv.FS
Expand Down Expand Up @@ -134,7 +129,7 @@ func Serve(
// Create SQL Engine with users
config := &engine.SqlEngineConfig{
InitialDb: "",
IsReadOnly: isReadOnly,
IsReadOnly: serverConfig.ReadOnly(),
PrivFilePath: serverConfig.PrivilegeFilePath(),
ServerUser: serverConfig.User(),
ServerPass: serverConfig.Password(),
Expand Down
2 changes: 1 addition & 1 deletion go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ require (
)

require (
github.com/dolthub/go-mysql-server v0.12.1-0.20220725181120-4bb5cae174bc
github.com/dolthub/go-mysql-server v0.12.1-0.20220725212100-c3c1731b2a03
github.com/google/flatbuffers v2.0.6+incompatible
github.com/gosuri/uilive v0.0.4
github.com/kch42/buzhash v0.0.0-20160816060738-9bdec3dec7c6
Expand Down
4 changes: 2 additions & 2 deletions go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/dolthub/fslock v0.0.3 h1:iLMpUIvJKMKm92+N1fmHVdxJP5NdyDK5bK7z7Ba2s2U=
github.com/dolthub/fslock v0.0.3/go.mod h1:QWql+P17oAAMLnL4HGB5tiovtDuAjdDTPbuqx7bYfa0=
github.com/dolthub/go-mysql-server v0.12.1-0.20220725181120-4bb5cae174bc h1:IJDBkqOLPI6CGPG1oQef5QSeOEuX1eQOtO1B1f7tfMs=
github.com/dolthub/go-mysql-server v0.12.1-0.20220725181120-4bb5cae174bc/go.mod h1:JgB3WpY0RMgyAda3YG5VHVncH2B8i1N9Mx9LOp41lIs=
github.com/dolthub/go-mysql-server v0.12.1-0.20220725212100-c3c1731b2a03 h1:ek99hhyjnf3CexTF8Y5Z4XyeOlzQgMlxvFrLKEroNiU=
github.com/dolthub/go-mysql-server v0.12.1-0.20220725212100-c3c1731b2a03/go.mod h1:JgB3WpY0RMgyAda3YG5VHVncH2B8i1N9Mx9LOp41lIs=
github.com/dolthub/ishell v0.0.0-20220112232610-14e753f0f371 h1:oyPHJlzumKta1vnOQqUnfdz+pk3EmnHS3Nd0cCT0I2g=
github.com/dolthub/ishell v0.0.0-20220112232610-14e753f0f371/go.mod h1:dhGBqcCEfK5kuFmeO5+WOx3hqc1k3M29c1oS/R7N4ms=
github.com/dolthub/jsonpath v0.0.0-20210609232853-d49537a30474 h1:xTrR+l5l+1Lfq0NvhiEsctylXinUMFhhsqaEcl414p8=
Expand Down
4 changes: 4 additions & 0 deletions go/libraries/doltcore/mvdata/engine_table_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ type SqlEngineTableWriter struct {
}

func NewSqlEngineTableWriter(ctx context.Context, dEnv *env.DoltEnv, createTableSchema, rowOperationSchema schema.Schema, options *MoverOptions, statsCB noms.StatsCB) (*SqlEngineTableWriter, error) {
if dEnv.IsLocked() {
return nil, env.ErrActiveServerLock.New(dEnv.LockFile())
}

mrEnv, err := env.MultiEnvForDirectory(ctx, dEnv.Config.WriteableConfig(), dEnv.FS, dEnv.Version, dEnv.IgnoreLockFile, dEnv)
if err != nil {
return nil, err
Expand Down
18 changes: 15 additions & 3 deletions integration-tests/bats/sql-server.bats
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ SQL
# attempt to create table (autocommit on), expect either some exception
server_query repo1 1 "CREATE TABLE i_should_not_exist (
c0 INT
)" "" "not authorized"
)" "" "database server is set to read only mode"

# Expect that there are still no tables
run dolt ls
Expand Down Expand Up @@ -205,7 +205,7 @@ SQL

# make a dolt_commit query
skip "read-only flag does not prevent dolt_commit"
server_query repo1 1 "select dolt_commit('--allow-empty', '-m', 'msg')" "" "not authorized: user does not have permission: write"
server_query repo1 1 "select dolt_commit('--allow-empty', '-m', 'msg')" "" "database server is set to read only mode: user does not have permission: write"
}

@test "sql-server: test command line modification" {
Expand Down Expand Up @@ -1425,4 +1425,16 @@ databases:
let PORT="$$ % (65536-1024) + 1024"
run dolt sql-server -P $PORT
[ "$status" -eq 1 ]
}
}

@test "sql-server: sql-server locks database to writes" {
cd repo2
dolt sql -q "create table a (x int primary key)"
start_sql_server
run dolt sql -q "create table b (x int primary key)"
[ "$status" -eq 1 ]
[[ "$output" =~ "database is locked to writes" ]] || false
run dolt sql -q "insert into b values (0)"
[ "$status" -eq 1 ]
[[ "$output" =~ "database is locked to writes" ]] || false
}

0 comments on commit 9dae75e

Please sign in to comment.