diff --git a/go/cmd/dolt/commands/engine/sqlengine.go b/go/cmd/dolt/commands/engine/sqlengine.go index fd8602ad2e..f87e4819f2 100644 --- a/go/cmd/dolt/commands/engine/sqlengine.go +++ b/go/cmd/dolt/commands/engine/sqlengine.go @@ -130,6 +130,7 @@ func NewSqlEngine( config.ClusterController.RegisterStoredProcedures(pro) pro.InitDatabaseHook = cluster.NewInitDatabaseHook(config.ClusterController, bThreads, pro.InitDatabaseHook) + pro.DropDatabaseHook = config.ClusterController.DropDatabaseHook // Create the engine engine := gms.New(analyzer.NewBuilder(pro).WithParallelism(parallelism).Build(), &gms.Config{ diff --git a/go/cmd/dolt/dolt.go b/go/cmd/dolt/dolt.go index 2d6ac96502..51c89d9070 100644 --- a/go/cmd/dolt/dolt.go +++ b/go/cmd/dolt/dolt.go @@ -63,7 +63,7 @@ import ( ) const ( - Version = "1.16.1" + Version = "1.16.2" ) var dumpDocsCommand = &commands.DumpDocsCmd{} diff --git a/go/go.mod b/go/go.mod index 5afcf93677..e553f62f88 100644 --- a/go/go.mod +++ b/go/go.mod @@ -15,7 +15,7 @@ require ( github.com/dolthub/fslock v0.0.3 github.com/dolthub/ishell v0.0.0-20221214210346-d7db0b066488 github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81 - github.com/dolthub/vitess v0.0.0-20230920190630-648c869b4af5 + github.com/dolthub/vitess v0.0.0-20230920212116-eb645ef178c2 github.com/dustin/go-humanize v1.0.0 github.com/fatih/color v1.13.0 github.com/flynn-archive/go-shlex v0.0.0-20150515145356-3f9db97f8568 @@ -59,7 +59,7 @@ require ( github.com/cespare/xxhash v1.1.0 github.com/creasty/defaults v1.6.0 github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2 - github.com/dolthub/go-mysql-server v0.17.1-0.20230920194330-b191f408cb8f + github.com/dolthub/go-mysql-server v0.17.1-0.20230920214618-75692cb811e7 github.com/dolthub/swiss v0.1.0 github.com/goccy/go-json v0.10.2 github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 diff --git a/go/go.sum b/go/go.sum index 6eeae88766..776bd37c4b 100644 --- a/go/go.sum +++ b/go/go.sum @@ -180,8 +180,8 @@ 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-icu-regex v0.0.0-20230524105445-af7e7991c97e h1:kPsT4a47cw1+y/N5SSCkma7FhAPw7KeGmD6c9PBZW9Y= github.com/dolthub/go-icu-regex v0.0.0-20230524105445-af7e7991c97e/go.mod h1:KPUcpx070QOfJK1gNe0zx4pA5sicIK1GMikIGLKC168= -github.com/dolthub/go-mysql-server v0.17.1-0.20230920194330-b191f408cb8f h1:2XPzY579wcp2Mq/B11GH4UQlTvaxNWLOEUCfgPmIIRg= -github.com/dolthub/go-mysql-server v0.17.1-0.20230920194330-b191f408cb8f/go.mod h1:Q4x3bXy1fzb7/HyhIXc35cXj0J7ETS6K0FwlbTNw9m4= +github.com/dolthub/go-mysql-server v0.17.1-0.20230920214618-75692cb811e7 h1:QWo34tf44CmwZh27GMqgPrNU0cr+Fc9ULoX6o40PwMQ= +github.com/dolthub/go-mysql-server v0.17.1-0.20230920214618-75692cb811e7/go.mod h1:9xeYTIAFZLOdDZzuOf1HQF5Td6OYqMt24IRSJM0ayjM= github.com/dolthub/ishell v0.0.0-20221214210346-d7db0b066488 h1:0HHu0GWJH0N6a6keStrHhUAK5/o9LVfkh44pvsV4514= github.com/dolthub/ishell v0.0.0-20221214210346-d7db0b066488/go.mod h1:ehexgi1mPxRTk0Mok/pADALuHbvATulTh6gzr7NzZto= github.com/dolthub/jsonpath v0.0.2-0.20230525180605-8dc13778fd72 h1:NfWmngMi1CYUWU4Ix8wM+USEhjc+mhPlT9JUR/anvbQ= @@ -192,8 +192,8 @@ github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81 h1:7/v8q9X github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81/go.mod h1:siLfyv2c92W1eN/R4QqG/+RjjX5W2+gCTRjZxBjI3TY= github.com/dolthub/swiss v0.1.0 h1:EaGQct3AqeP/MjASHLiH6i4TAmgbG/c4rA6a1bzCOPc= github.com/dolthub/swiss v0.1.0/go.mod h1:BeucyB08Vb1G9tumVN3Vp/pyY4AMUnr9p7Rz7wJ7kAQ= -github.com/dolthub/vitess v0.0.0-20230920190630-648c869b4af5 h1:RfDb0ycMTSPu+0dpJZSNZAiI3lanJR5IrHirEVP/CVg= -github.com/dolthub/vitess v0.0.0-20230920190630-648c869b4af5/go.mod h1:IwjNXSQPymrja5pVqmfnYdcy7Uv7eNJNBPK/MEh9OOw= +github.com/dolthub/vitess v0.0.0-20230920212116-eb645ef178c2 h1:L2ST5YNistuYVkVfZcTp5ItVpTNQ0i6oGGM7l6If9ME= +github.com/dolthub/vitess v0.0.0-20230920212116-eb645ef178c2/go.mod h1:IwjNXSQPymrja5pVqmfnYdcy7Uv7eNJNBPK/MEh9OOw= github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= diff --git a/go/libraries/doltcore/schema/typeinfo/int.go b/go/libraries/doltcore/schema/typeinfo/int.go index 0a7e94b08b..fc862c5f93 100644 --- a/go/libraries/doltcore/schema/typeinfo/int.go +++ b/go/libraries/doltcore/schema/typeinfo/int.go @@ -144,7 +144,8 @@ func (ti *intType) Equals(other TypeInfo) bool { return false } if ti2, ok := other.(*intType); ok { - return ti.sqlIntType.Type() == ti2.sqlIntType.Type() + return ti.sqlIntType.Type() == ti2.sqlIntType.Type() && + ti.sqlIntType.DisplayWidth() == ti2.sqlIntType.DisplayWidth() } return false } diff --git a/go/libraries/doltcore/schema/typeinfo/typeinfo.go b/go/libraries/doltcore/schema/typeinfo/typeinfo.go index 94dac92b57..bca2437edc 100644 --- a/go/libraries/doltcore/schema/typeinfo/typeinfo.go +++ b/go/libraries/doltcore/schema/typeinfo/typeinfo.go @@ -145,7 +145,13 @@ func FromSqlType(sqlType sql.Type) (TypeInfo, error) { case sqltypes.Null: return UnknownType, nil case sqltypes.Int8: - return Int8Type, nil + // MySQL allows only the TINYINT type to have a display width, so it's the only + // integer type that needs to be checked for it's underlying NumberType data. + numberType, ok := sqlType.(sql.NumberType) + if !ok { + return nil, fmt.Errorf("expected sql.NumberType, but received: %T", sqlType) + } + return &intType{numberType}, nil case sqltypes.Int16: return Int16Type, nil case sqltypes.Int24: diff --git a/go/libraries/doltcore/schema/typeinfo/uint.go b/go/libraries/doltcore/schema/typeinfo/uint.go index 78c3bde98b..1d21f1e91a 100644 --- a/go/libraries/doltcore/schema/typeinfo/uint.go +++ b/go/libraries/doltcore/schema/typeinfo/uint.go @@ -144,7 +144,8 @@ func (ti *uintType) Equals(other TypeInfo) bool { return false } if ti2, ok := other.(*uintType); ok { - return ti.sqlUintType.Type() == ti2.sqlUintType.Type() + return ti.sqlUintType.Type() == ti2.sqlUintType.Type() && + ti.sqlUintType.DisplayWidth() == ti2.sqlUintType.DisplayWidth() } return false } diff --git a/go/libraries/doltcore/sqle/cluster/commithook.go b/go/libraries/doltcore/sqle/cluster/commithook.go index b917522b40..3dfb169fbd 100644 --- a/go/libraries/doltcore/sqle/cluster/commithook.go +++ b/go/libraries/doltcore/sqle/cluster/commithook.go @@ -43,6 +43,7 @@ type commithook struct { mu sync.Mutex wg sync.WaitGroup cond *sync.Cond + shutdown atomic.Bool nextHead hash.Hash lastPushedHead hash.Hash nextPushAttempt time.Time @@ -126,7 +127,7 @@ func (h *commithook) replicate(ctx context.Context) { h.mu.Lock() defer h.mu.Unlock() shouldHeartbeat := false - for { + for !h.shutdown.Load() { lgr := h.logger() // Shutdown for context canceled. if ctx.Err() != nil { @@ -371,7 +372,7 @@ func (h *commithook) tick(ctx context.Context) { defer h.wg.Done() ticker := time.NewTicker(1 * time.Second) defer ticker.Stop() - for { + for !h.shutdown.Load() { select { case <-ctx.Done(): return @@ -381,6 +382,11 @@ func (h *commithook) tick(ctx context.Context) { } } +func (h *commithook) databaseWasDropped() { + h.shutdown.Store(true) + h.cond.Signal() +} + func (h *commithook) recordSuccessfulRemoteSrvCommit() { h.mu.Lock() defer h.mu.Unlock() diff --git a/go/libraries/doltcore/sqle/cluster/controller.go b/go/libraries/doltcore/sqle/cluster/controller.go index 4d50d44480..a5bc5f8e0b 100644 --- a/go/libraries/doltcore/sqle/cluster/controller.go +++ b/go/libraries/doltcore/sqle/cluster/controller.go @@ -310,6 +310,27 @@ func (c *Controller) RegisterStoredProcedures(store procedurestore) { store.Register(newTransitionToStandbyProcedure(c)) } +func (c *Controller) DropDatabaseHook(dbname string) { + if c == nil { + return + } + c.mu.Lock() + defer c.mu.Unlock() + + j := 0 + for i := 0; i < len(c.commithooks); i++ { + if c.commithooks[i].dbname == dbname { + c.commithooks[i].databaseWasDropped() + continue + } + if j != i { + c.commithooks[j] = c.commithooks[i] + } + j += 1 + } + c.commithooks = c.commithooks[:j] +} + func (c *Controller) ClusterDatabase() sql.Database { if c == nil { return nil diff --git a/go/libraries/doltcore/sqle/database_provider.go b/go/libraries/doltcore/sqle/database_provider.go index 260b2ab600..224d599b46 100644 --- a/go/libraries/doltcore/sqle/database_provider.go +++ b/go/libraries/doltcore/sqle/database_provider.go @@ -48,6 +48,7 @@ type DoltDatabaseProvider struct { functions map[string]sql.Function externalProcedures sql.ExternalStoredProcedureRegistry InitDatabaseHook InitDatabaseHook + DropDatabaseHook DropDatabaseHook mu *sync.RWMutex defaultBranch string @@ -446,6 +447,7 @@ func (p DoltDatabaseProvider) CreateCollatedDatabase(ctx *sql.Context, name stri } type InitDatabaseHook func(ctx *sql.Context, pro DoltDatabaseProvider, name string, env *env.DoltEnv) error +type DropDatabaseHook func(name string) // ConfigureReplicationDatabaseHook sets up replication for a newly created database as necessary // TODO: consider the replication heads / all heads setting @@ -635,6 +637,12 @@ func (p DoltDatabaseProvider) DropDatabase(ctx *sql.Context, name string) error return err } + if p.DropDatabaseHook != nil { + // For symmetry with InitDatabaseHook and the names we see in + // MultiEnv initialization, we use `name` here, not `dbKey`. + p.DropDatabaseHook(name) + } + rootDbLoc, err := p.fs.Abs("") if err != nil { return err diff --git a/go/libraries/doltcore/sqle/sqlddl_test.go b/go/libraries/doltcore/sqle/sqlddl_test.go index 4a83ba5e92..874f8ee848 100644 --- a/go/libraries/doltcore/sqle/sqlddl_test.go +++ b/go/libraries/doltcore/sqle/sqlddl_test.go @@ -137,7 +137,8 @@ func TestCreateTable(t *testing.T) { c23 tinyint unsigned, c24 smallint unsigned, c25 mediumint unsigned, - c26 bigint unsigned)`, + c26 bigint unsigned, + c27 tinyint(1))`, expectedSchema: dtestutils.CreateSchema( schemaNewColumn(t, "c0", 594, gmstypes.Int32, true, schema.NotNullConstraint{}), schemaNewColumn(t, "c1", 601, gmstypes.Int8, false), @@ -166,6 +167,7 @@ func TestCreateTable(t *testing.T) { schemaNewColumn(t, "c24", 8689, gmstypes.Uint16, false), schemaNewColumn(t, "c25", 5243, gmstypes.Uint24, false), schemaNewColumn(t, "c26", 9338, gmstypes.Uint64, false), + schemaNewColumn(t, "c27", 5981, gmstypes.Boolean, false), ), }, { diff --git a/go/libraries/doltcore/sqle/sqlselect_test.go b/go/libraries/doltcore/sqle/sqlselect_test.go index 3c000c984b..e5213712f2 100644 --- a/go/libraries/doltcore/sqle/sqlselect_test.go +++ b/go/libraries/doltcore/sqle/sqlselect_test.go @@ -466,7 +466,7 @@ func BasicSelectTests() []SelectTest { Query: "select is_married and age >= 40 from people where last_name = 'Simpson' order by id limit 2", ExpectedRows: []sql.Row{{true}, {false}}, ExpectedSqlSchema: sql.Schema{ - &sql.Column{Name: "is_married and age >= 40", Type: gmstypes.Int8}, + &sql.Column{Name: "is_married and age >= 40", Type: gmstypes.Boolean}, }, }, { @@ -480,7 +480,7 @@ func BasicSelectTests() []SelectTest { }, ExpectedSqlSchema: sql.Schema{ &sql.Column{Name: "first_name", Type: typeinfo.StringDefaultType.ToSqlType()}, - &sql.Column{Name: "not_marge", Type: gmstypes.Int8}, + &sql.Column{Name: "not_marge", Type: gmstypes.Boolean}, }, }, { diff --git a/integration-tests/bats/schema-import.bats b/integration-tests/bats/schema-import.bats index a0b2059005..653e02f91d 100755 --- a/integration-tests/bats/schema-import.bats +++ b/integration-tests/bats/schema-import.bats @@ -338,7 +338,7 @@ DELIM [ "$status" -eq 0 ] [[ "$output" =~ '- `a` varchar(16383),' ]] || false [[ "$output" =~ '- `b` float,' ]] || false - [[ "$output" =~ '- `c` tinyint,' ]] || false + [[ "$output" =~ '- `c` tinyint(1),' ]] || false # assert no columns were added [[ ! "$output" = "+ \`" ]] || false } diff --git a/integration-tests/bats/types.bats b/integration-tests/bats/types.bats index 5b5eec5b28..82fd08931c 100644 --- a/integration-tests/bats/types.bats +++ b/integration-tests/bats/types.bats @@ -190,12 +190,11 @@ CREATE TABLE test ( SQL run dolt schema show [ "$status" -eq "0" ] - [[ "$output" =~ "\`v\` tinyint" ]] || false + [[ "$output" =~ "\`v\` tinyint(1)" ]] || false # check information_schema.COLUMNS table - # TODO : 'column_type' should be 'tinyint(1)' run dolt sql -q "select * from information_schema.COLUMNS where table_name = 'test' and column_name = 'v';" -r csv - [[ "$output" =~ 'test,v,2,,YES,tinyint,,,3,0,,,,tinyint,"","","insert,references,select,update","","",' ]] || false + [[ "$output" =~ 'test,v,2,,YES,tinyint,,,3,0,,,,tinyint(1),"","","insert,references,select,update","","",' ]] || false } @test "types: BOOLEAN" { @@ -208,7 +207,7 @@ CREATE TABLE test ( SQL run dolt schema show [ "$status" -eq "0" ] - [[ "$output" =~ "\`v\` tinyint" ]] || false + [[ "$output" =~ "\`v\` tinyint(1)" ]] || false dolt sql -q "INSERT INTO test VALUES (1, true);" run dolt sql -q "SELECT * FROM test" [ "$status" -eq "0" ] @@ -219,9 +218,8 @@ SQL [[ "${lines[3]}" =~ " 0 " ]] || false # check information_schema.COLUMNS table - # TODO : 'column_type' should be 'tinyint(1)' run dolt sql -q "select * from information_schema.COLUMNS where table_name = 'test' and column_name = 'v';" -r csv - [[ "$output" =~ 'test,v,2,,YES,tinyint,,,3,0,,,,tinyint,"","","insert,references,select,update","","",' ]] || false + [[ "$output" =~ 'test,v,2,,YES,tinyint,,,3,0,,,,tinyint(1),"","","insert,references,select,update","","",' ]] || false } @test "types: CHAR(10)" { diff --git a/integration-tests/go-sql-server-driver/tests/sql-server-cluster.yaml b/integration-tests/go-sql-server-driver/tests/sql-server-cluster.yaml index 638747ffd3..8ffc7a8d0d 100644 --- a/integration-tests/go-sql-server-driver/tests/sql-server-cluster.yaml +++ b/integration-tests/go-sql-server-driver/tests/sql-server-cluster.yaml @@ -1417,3 +1417,68 @@ tests: - exec: 'call dolt_gc()' error_match: "must be the primary" - exec: 'call dolt_gc("--shallow")' +- name: dropped database no longer in dolt_cluster_status + multi_repos: + - name: server1 + with_files: + - name: server.yaml + contents: | + log_level: trace + listener: + host: 0.0.0.0 + port: 3309 + cluster: + standby_remotes: + - name: standby + remote_url_template: http://localhost:3852/{database} + bootstrap_role: primary + bootstrap_epoch: 1 + remotesapi: + port: 3851 + server: + args: ["--config", "server.yaml"] + port: 3309 + - name: server2 + with_files: + - name: server.yaml + contents: | + log_level: trace + listener: + host: 0.0.0.0 + port: 3310 + cluster: + standby_remotes: + - name: standby + remote_url_template: http://localhost:3851/{database} + bootstrap_role: standby + bootstrap_epoch: 1 + remotesapi: + port: 3852 + server: + args: ["--config", "server.yaml"] + port: 3310 + connections: + - on: server1 + queries: + - exec: 'create database repo1' + - exec: 'use repo1' + - exec: 'SET @@GLOBAL.dolt_cluster_ack_writes_timeout_secs = 10' + - exec: 'create table vals (i int primary key)' + - query: "select `database`, standby_remote, role, epoch, replication_lag_millis is not null as `replication_lag_millis`, current_error from dolt_cluster.dolt_cluster_status" + result: + columns: ["database","standby_remote","role","epoch","replication_lag_millis","current_error"] + rows: + - ["repo1", "standby", "primary", "1", "1", "NULL"] + - exec: 'use dolt_cluster' + - exec: 'drop database repo1' + - query: 'show databases' + result: + columns: ["Database"] + rows: + - ["dolt_cluster"] + - ["information_schema"] + - ["mysql"] + - query: "select `database`, standby_remote, role, epoch, replication_lag_millis is not null as `replication_lag_millis`, current_error from dolt_cluster.dolt_cluster_status" + result: + columns: ["database","standby_remote","role","epoch","replication_lag_millis","current_error"] + rows: []