diff --git a/go/cmd/dolt/commands/merge_base.go b/go/cmd/dolt/commands/merge_base.go index c860844972..1577c4f80c 100644 --- a/go/cmd/dolt/commands/merge_base.go +++ b/go/cmd/dolt/commands/merge_base.go @@ -16,15 +16,14 @@ package commands import ( "context" - "errors" - "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" + "github.com/gocraft/dbr/v2" + "github.com/gocraft/dbr/v2/dialect" "github.com/dolthub/dolt/go/cmd/dolt/cli" "github.com/dolthub/dolt/go/cmd/dolt/errhand" eventsapi "github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1" "github.com/dolthub/dolt/go/libraries/doltcore/env" - "github.com/dolthub/dolt/go/libraries/doltcore/merge" "github.com/dolthub/dolt/go/libraries/utils/argparser" ) @@ -55,7 +54,6 @@ func (cmd MergeBaseCmd) Docs() *cli.CommandDocumentation { func (cmd MergeBaseCmd) ArgParser() *argparser.ArgParser { ap := argparser.NewArgParserWithMaxArgs(cmd.Name(), 2) - //ap.ArgListHelp = append(ap.ArgListHelp, [2]string{"start-point", "A commit that a new branch should point at."}) return ap } @@ -76,68 +74,25 @@ func (cmd MergeBaseCmd) Exec(ctx context.Context, commandStr string, args []stri return HandleVErrAndExitCode(verr, usage) } - if dEnv.IsLocked() { - return HandleVErrAndExitCode(errhand.VerboseErrorFromError(env.ErrActiveServerLock.New(dEnv.LockFile())), help) + queryist, sqlCtx, closeFunc, err := cliCtx.QueryEngine(ctx) + if err != nil { + return HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage) + } + if closeFunc != nil { + defer closeFunc() } - mergeBaseStr, verr := getMergeBaseFromStrings(ctx, dEnv, apr.Arg(0), apr.Arg(1)) - if verr != nil { - return HandleVErrAndExitCode(verr, usage) + interpolatedQuery, err := dbr.InterpolateForDialect("SELECT DOLT_MERGE_BASE(?, ?)", []interface{}{apr.Arg(0), apr.Arg(1)}, dialect.MySQL) + if err != nil { + return HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage) } - cli.Println(mergeBaseStr) + row, err := GetRowsForSql(queryist, sqlCtx, interpolatedQuery) + if err != nil { + return HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage) + } + + cli.Println(row[0][0].(string)) return 0 } - -// getMergeBaseFromStrings resolves two revisions and returns the merge base -// commit hash string -func getMergeBaseFromStrings(ctx context.Context, dEnv *env.DoltEnv, leftStr, rightStr string) (string, errhand.VerboseError) { - left, verr := ResolveCommitWithVErr(dEnv, leftStr) - if verr != nil { - return "", verr - } - - right, verr := ResolveCommitWithVErr(dEnv, rightStr) - if verr != nil { - return "", verr - } - - mergeBase, err := merge.MergeBase(ctx, left, right) - if err != nil { - verr = errhand.BuildDError("could not find merge-base for args %s %s", leftStr, rightStr).AddCause(err).Build() - return "", verr - } - - return mergeBase.String(), nil -} - -func ResolveCommitWithVErr(dEnv *env.DoltEnv, cSpecStr string) (*doltdb.Commit, errhand.VerboseError) { - cs, err := doltdb.NewCommitSpec(cSpecStr) - - if err != nil { - return nil, errhand.BuildDError("'%s' is not a valid commit", cSpecStr).Build() - } - - headRef, err := dEnv.RepoStateReader().CWBHeadRef() - if err != nil { - return nil, errhand.VerboseErrorFromError(err) - } - - cm, err := dEnv.DoltDB.Resolve(context.TODO(), cs, headRef) - if err != nil { - if errors.Is(err, doltdb.ErrInvalidAncestorSpec) { - return nil, errhand.BuildDError("'%s' could not resolve ancestor spec", cSpecStr).Build() - } else if errors.Is(err, doltdb.ErrBranchNotFound) { - return nil, errhand.BuildDError("unknown ref in commit spec: '%s'", cSpecStr).Build() - } else if doltdb.IsNotFoundErr(err) { - return nil, errhand.BuildDError("'%s' not found", cSpecStr).Build() - } else if errors.Is(err, doltdb.ErrFoundHashNotACommit) { - return nil, errhand.BuildDError("'%s' is not a commit", cSpecStr).Build() - } else { - return nil, errhand.BuildDError("Unexpected error resolving '%s'", cSpecStr).AddCause(err).Build() - } - } - - return cm, nil -} diff --git a/go/cmd/dolt/dolt.go b/go/cmd/dolt/dolt.go index f6a147f2ba..05e0e9a3c1 100644 --- a/go/cmd/dolt/dolt.go +++ b/go/cmd/dolt/dolt.go @@ -142,7 +142,6 @@ var commandsWithoutCliCtx = []cli.Command{ commands.ReadTablesCmd{}, commands.GarbageCollectionCmd{}, commands.FilterBranchCmd{}, - commands.MergeBaseCmd{}, commands.RootsCmd{}, commands.VersionCmd{VersionStr: Version}, commands.DumpCmd{}, diff --git a/go/go.mod b/go/go.mod index 8aae1a41d2..85f3da7628 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-20231011212939-750452c13fa0 + github.com/dolthub/vitess v0.0.0-20231018185551-6acf9c09c4fa 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.20231017193545-6a6034f288b8 + github.com/dolthub/go-mysql-server v0.17.1-0.20231018193155-b175f6f77388 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 12e18a4e57..33f889aca0 100644 --- a/go/go.sum +++ b/go/go.sum @@ -181,8 +181,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.20231017193545-6a6034f288b8 h1:sZegxPavZZqeNclsHntHmLcQ7WaLFjxq9upAMZjNZbw= -github.com/dolthub/go-mysql-server v0.17.1-0.20231017193545-6a6034f288b8/go.mod h1:kL5S5WfmgeiVos4SAUQ2O1LoXbDvwRombuGoCh19az4= +github.com/dolthub/go-mysql-server v0.17.1-0.20231018193155-b175f6f77388 h1:Vzj2+SdblD+GJX4U0+m5a5Ve6lY/rTwOz1wpRwG+uE0= +github.com/dolthub/go-mysql-server v0.17.1-0.20231018193155-b175f6f77388/go.mod h1:Nk8uVbrCJjRlBluG4jtXaP+frjRFtanjOKJTKnvZDTk= 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= @@ -193,8 +193,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-20231011212939-750452c13fa0 h1:ETjYviQleYq+2KuflGbTdRLuk0zw45HXCHS6ApVM6o8= -github.com/dolthub/vitess v0.0.0-20231011212939-750452c13fa0/go.mod h1:IwjNXSQPymrja5pVqmfnYdcy7Uv7eNJNBPK/MEh9OOw= +github.com/dolthub/vitess v0.0.0-20231018185551-6acf9c09c4fa h1:5k+dGyoUAnan2RZmLiYEp8svmEFlJIUfaSKbZ5xXv1s= +github.com/dolthub/vitess v0.0.0-20231018185551-6acf9c09c4fa/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/data_length.go b/go/libraries/doltcore/schema/data_length.go new file mode 100644 index 0000000000..4f1cea62cf --- /dev/null +++ b/go/libraries/doltcore/schema/data_length.go @@ -0,0 +1,49 @@ +// Copyright 2023 Dolthub, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package schema + +import ( + "github.com/dolthub/go-mysql-server/sql" + sqltypes "github.com/dolthub/go-mysql-server/sql/types" +) + +func SchemaAvgLength(schema sql.Schema) uint64 { + var numBytesPerRow uint64 = 0 + for _, col := range schema { + switch n := col.Type.(type) { + case sql.NumberType: + numBytesPerRow += 8 + case sql.StringType: + numBytesPerRow += uint64(n.MaxByteLength()) + case sqltypes.BitType: + numBytesPerRow += 8 + case sql.DatetimeType: + numBytesPerRow += 8 + case sql.DecimalType: + numBytesPerRow += uint64(n.MaximumScale()) + case sql.EnumType: + numBytesPerRow += 2 + case sqltypes.JsonType: + numBytesPerRow += 20 + case sql.NullType: + numBytesPerRow += 1 + case sqltypes.TimeType: + numBytesPerRow += 16 + case sql.YearType: + numBytesPerRow += 8 + } + } + return numBytesPerRow +} diff --git a/go/libraries/doltcore/sqle/dolt_diff_stat_table_function.go b/go/libraries/doltcore/sqle/dolt_diff_stat_table_function.go index 9ccb50770a..baac40591e 100644 --- a/go/libraries/doltcore/sqle/dolt_diff_stat_table_function.go +++ b/go/libraries/doltcore/sqle/dolt_diff_stat_table_function.go @@ -27,10 +27,13 @@ import ( "github.com/dolthub/dolt/go/libraries/doltcore/diff" "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" + "github.com/dolthub/dolt/go/libraries/doltcore/schema" "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dtables" ) +const diffStatDefaultRowCount = 10 + var _ sql.TableFunction = (*DiffStatTableFunction)(nil) var _ sql.ExecSourceRel = (*DiffStatTableFunction)(nil) @@ -74,6 +77,19 @@ func (ds *DiffStatTableFunction) NewInstance(ctx *sql.Context, db sql.Database, return node, nil } +func (ds *DiffStatTableFunction) DataLength(ctx *sql.Context) (uint64, error) { + numBytesPerRow := schema.SchemaAvgLength(ds.Schema()) + numRows, _, err := ds.RowCount(ctx) + if err != nil { + return 0, err + } + return numBytesPerRow * numRows, nil +} + +func (ds *DiffStatTableFunction) RowCount(_ *sql.Context) (uint64, bool, error) { + return diffStatDefaultRowCount, false, nil +} + // Database implements the sql.Databaser interface func (ds *DiffStatTableFunction) Database() sql.Database { return ds.database diff --git a/go/libraries/doltcore/sqle/dolt_diff_summary_table_function.go b/go/libraries/doltcore/sqle/dolt_diff_summary_table_function.go index 32de9218a1..d21dc3ccca 100644 --- a/go/libraries/doltcore/sqle/dolt_diff_summary_table_function.go +++ b/go/libraries/doltcore/sqle/dolt_diff_summary_table_function.go @@ -29,6 +29,8 @@ import ( "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dtables" ) +const diffSummaryDefaultRowCount = 10 + var _ sql.TableFunction = (*DiffSummaryTableFunction)(nil) var _ sql.ExecSourceRel = (*DiffSummaryTableFunction)(nil) @@ -65,6 +67,19 @@ func (ds *DiffSummaryTableFunction) NewInstance(ctx *sql.Context, db sql.Databas return node, nil } +func (ds *DiffSummaryTableFunction) DataLength(ctx *sql.Context) (uint64, error) { + numBytesPerRow := schema.SchemaAvgLength(ds.Schema()) + numRows, _, err := ds.RowCount(ctx) + if err != nil { + return 0, err + } + return numBytesPerRow * numRows, nil +} + +func (ds *DiffSummaryTableFunction) RowCount(_ *sql.Context) (uint64, bool, error) { + return diffSummaryDefaultRowCount, false, nil +} + // Database implements the sql.Databaser interface func (ds *DiffSummaryTableFunction) Database() sql.Database { return ds.database diff --git a/go/libraries/doltcore/sqle/dolt_diff_table_function.go b/go/libraries/doltcore/sqle/dolt_diff_table_function.go index ea8c223e7d..512af4b525 100644 --- a/go/libraries/doltcore/sqle/dolt_diff_table_function.go +++ b/go/libraries/doltcore/sqle/dolt_diff_table_function.go @@ -34,6 +34,8 @@ import ( "github.com/dolthub/dolt/go/store/types" ) +const diffTableDefaultRowCount = 1000 + var ErrInvalidNonLiteralArgument = errors.NewKind("Invalid argument to %s: %s – only literal values supported") var _ sql.TableFunction = (*DiffTableFunction)(nil) @@ -69,6 +71,19 @@ func (dtf *DiffTableFunction) NewInstance(ctx *sql.Context, database sql.Databas return node, nil } +func (dtf *DiffTableFunction) DataLength(ctx *sql.Context) (uint64, error) { + numBytesPerRow := schema.SchemaAvgLength(dtf.Schema()) + numRows, _, err := dtf.RowCount(ctx) + if err != nil { + return 0, err + } + return numBytesPerRow * numRows, nil +} + +func (dtf *DiffTableFunction) RowCount(_ *sql.Context) (uint64, bool, error) { + return diffTableDefaultRowCount, false, nil +} + // Database implements the sql.Databaser interface func (dtf *DiffTableFunction) Database() sql.Database { return dtf.database diff --git a/go/libraries/doltcore/sqle/dolt_log_table_function.go b/go/libraries/doltcore/sqle/dolt_log_table_function.go index c07b85da24..be69fc96a8 100644 --- a/go/libraries/doltcore/sqle/dolt_log_table_function.go +++ b/go/libraries/doltcore/sqle/dolt_log_table_function.go @@ -26,10 +26,13 @@ import ( "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" "github.com/dolthub/dolt/go/libraries/doltcore/env/actions/commitwalk" "github.com/dolthub/dolt/go/libraries/doltcore/merge" + "github.com/dolthub/dolt/go/libraries/doltcore/schema" "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" "github.com/dolthub/dolt/go/store/hash" ) +const logTableDefaultRowCount = 10 + var _ sql.TableFunction = (*LogTableFunction)(nil) var _ sql.ExecSourceRel = (*LogTableFunction)(nil) @@ -76,6 +79,19 @@ func (ltf *LogTableFunction) Database() sql.Database { return ltf.database } +func (ltf *LogTableFunction) DataLength(ctx *sql.Context) (uint64, error) { + numBytesPerRow := schema.SchemaAvgLength(ltf.Schema()) + numRows, _, err := ltf.RowCount(ctx) + if err != nil { + return 0, err + } + return numBytesPerRow * numRows, nil +} + +func (ltf *LogTableFunction) RowCount(_ *sql.Context) (uint64, bool, error) { + return logTableDefaultRowCount, false, nil +} + // WithDatabase implements the sql.Databaser interface func (ltf *LogTableFunction) WithDatabase(database sql.Database) (sql.Node, error) { nltf := *ltf diff --git a/go/libraries/doltcore/sqle/dolt_patch_table_function.go b/go/libraries/doltcore/sqle/dolt_patch_table_function.go index d1f2a687bb..5aacffa568 100644 --- a/go/libraries/doltcore/sqle/dolt_patch_table_function.go +++ b/go/libraries/doltcore/sqle/dolt_patch_table_function.go @@ -57,12 +57,13 @@ var dataChangePartitionKey = []byte(diffTypeData) var schemaAndDataChangePartitionKey = []byte("all") const ( - orderColumnName = "statement_order" - fromColumnName = "from_commit_hash" - toColumnName = "to_commit_hash" - tableNameColumnName = "table_name" - diffTypeColumnName = "diff_type" - statementColumnName = "statement" + orderColumnName = "statement_order" + fromColumnName = "from_commit_hash" + toColumnName = "to_commit_hash" + tableNameColumnName = "table_name" + diffTypeColumnName = "diff_type" + statementColumnName = "statement" + patchTableDefaultRowCount = 100 ) type PatchTableFunction struct { @@ -75,6 +76,19 @@ type PatchTableFunction struct { database sql.Database } +func (p *PatchTableFunction) DataLength(ctx *sql.Context) (uint64, error) { + numBytesPerRow := schema.SchemaAvgLength(p.Schema()) + numRows, _, err := p.RowCount(ctx) + if err != nil { + return 0, err + } + return numBytesPerRow * numRows, nil +} + +func (p *PatchTableFunction) RowCount(_ *sql.Context) (uint64, bool, error) { + return patchTableDefaultRowCount, false, nil +} + func (p *PatchTableFunction) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) { return sql.Collation_binary, 7 } diff --git a/go/libraries/doltcore/sqle/dolt_query_diff_table_function.go b/go/libraries/doltcore/sqle/dolt_query_diff_table_function.go index eaeae60315..399ff8efbe 100644 --- a/go/libraries/doltcore/sqle/dolt_query_diff_table_function.go +++ b/go/libraries/doltcore/sqle/dolt_query_diff_table_function.go @@ -19,11 +19,15 @@ import ( "io" "strings" + "github.com/dolthub/dolt/go/libraries/doltcore/schema" + gms "github.com/dolthub/go-mysql-server" "github.com/dolthub/go-mysql-server/sql" gmstypes "github.com/dolthub/go-mysql-server/sql/types" ) +const queryDiffDefaultRowCount = 100 + var _ sql.TableFunction = (*QueryDiffTableFunction)(nil) var _ sql.CatalogTableFunction = (*QueryDiffTableFunction)(nil) var _ sql.ExecSourceRel = (*QueryDiffTableFunction)(nil) @@ -72,6 +76,19 @@ func (tf *QueryDiffTableFunction) WithCatalog(c sql.Catalog) (sql.TableFunction, return &newInstance, nil } +func (tf *QueryDiffTableFunction) DataLength(ctx *sql.Context) (uint64, error) { + numBytesPerRow := schema.SchemaAvgLength(tf.Schema()) + numRows, _, err := tf.RowCount(ctx) + if err != nil { + return 0, err + } + return numBytesPerRow * numRows, nil +} + +func (tf *QueryDiffTableFunction) RowCount(_ *sql.Context) (uint64, bool, error) { + return queryDiffDefaultRowCount, false, nil +} + func (tf *QueryDiffTableFunction) evalQuery(query sql.Expression) (sql.Schema, sql.RowIter, error) { q, err := query.Eval(tf.ctx, nil) if err != nil { diff --git a/go/libraries/doltcore/sqle/dolt_schema_diff_table_function.go b/go/libraries/doltcore/sqle/dolt_schema_diff_table_function.go index 7f0930b53a..f2c3cab85e 100644 --- a/go/libraries/doltcore/sqle/dolt_schema_diff_table_function.go +++ b/go/libraries/doltcore/sqle/dolt_schema_diff_table_function.go @@ -24,10 +24,13 @@ import ( "github.com/dolthub/go-mysql-server/sql/types" "github.com/dolthub/dolt/go/libraries/doltcore/diff" + "github.com/dolthub/dolt/go/libraries/doltcore/schema" "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" "github.com/dolthub/dolt/go/libraries/doltcore/table/editor" ) +const schemaDiffDefaultRowCount = 100 + var _ sql.TableFunction = (*SchemaDiffTableFunction)(nil) var _ sql.ExecSourceRel = (*SchemaDiffTableFunction)(nil) @@ -81,6 +84,19 @@ func (ds *SchemaDiffTableFunction) NewInstance(ctx *sql.Context, db sql.Database return node, nil } +func (ds *SchemaDiffTableFunction) DataLength(ctx *sql.Context) (uint64, error) { + numBytesPerRow := schema.SchemaAvgLength(ds.Schema()) + numRows, _, err := ds.RowCount(ctx) + if err != nil { + return 0, err + } + return numBytesPerRow * numRows, nil +} + +func (ds *SchemaDiffTableFunction) RowCount(_ *sql.Context) (uint64, bool, error) { + return schemaDiffDefaultRowCount, false, nil +} + // Database implements the sql.Databaser interface func (ds *SchemaDiffTableFunction) Database() sql.Database { return ds.database diff --git a/go/libraries/doltcore/sqle/dtables/branches_table.go b/go/libraries/doltcore/sqle/dtables/branches_table.go index 403abbd9fb..e72aad2ec5 100644 --- a/go/libraries/doltcore/sqle/dtables/branches_table.go +++ b/go/libraries/doltcore/sqle/dtables/branches_table.go @@ -23,11 +23,15 @@ import ( "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" "github.com/dolthub/dolt/go/libraries/doltcore/ref" + "github.com/dolthub/dolt/go/libraries/doltcore/schema" "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" "github.com/dolthub/dolt/go/libraries/doltcore/sqle/index" ) +const branchesDefaultRowCount = 10 + var _ sql.Table = (*BranchesTable)(nil) +var _ sql.StatisticsTable = (*BranchesTable)(nil) var _ sql.UpdatableTable = (*BranchesTable)(nil) var _ sql.DeletableTable = (*BranchesTable)(nil) var _ sql.InsertableTable = (*BranchesTable)(nil) @@ -49,6 +53,19 @@ func NewRemoteBranchesTable(_ *sql.Context, ddb dsess.SqlDatabase) sql.Table { return &BranchesTable{ddb, true} } +func (bt *BranchesTable) DataLength(ctx *sql.Context) (uint64, error) { + numBytesPerRow := schema.SchemaAvgLength(bt.Schema()) + numRows, _, err := bt.RowCount(ctx) + if err != nil { + return 0, err + } + return numBytesPerRow * numRows, nil +} + +func (bt *BranchesTable) RowCount(_ *sql.Context) (uint64, bool, error) { + return branchesDefaultRowCount, false, nil +} + // Name is a sql.Table interface function which returns the name of the table which is defined by the constant // BranchesTableName func (bt *BranchesTable) Name() string { diff --git a/go/libraries/doltcore/sqle/dtables/column_diff_table.go b/go/libraries/doltcore/sqle/dtables/column_diff_table.go index 7840e06f8e..36e959d491 100644 --- a/go/libraries/doltcore/sqle/dtables/column_diff_table.go +++ b/go/libraries/doltcore/sqle/dtables/column_diff_table.go @@ -35,6 +35,8 @@ import ( dtypes "github.com/dolthub/dolt/go/store/types" ) +const columnDiffDefaultRowCount = 100 + // ColumnDiffTable is a sql.Table implementation of a system table that shows which tables and columns have // changed in each commit, across all branches. type ColumnDiffTable struct { @@ -46,6 +48,7 @@ type ColumnDiffTable struct { } var _ sql.Table = (*ColumnDiffTable)(nil) +var _ sql.StatisticsTable = (*ColumnDiffTable)(nil) // var _ sql.IndexAddressable = (*ColumnDiffTable)(nil) @@ -60,6 +63,19 @@ func (dt *ColumnDiffTable) Name() string { return doltdb.ColumnDiffTableName } +func (dt *ColumnDiffTable) DataLength(ctx *sql.Context) (uint64, error) { + numBytesPerRow := schema.SchemaAvgLength(dt.Schema()) + numRows, _, err := dt.RowCount(ctx) + if err != nil { + return 0, err + } + return numBytesPerRow * numRows, nil +} + +func (dt *ColumnDiffTable) RowCount(_ *sql.Context) (uint64, bool, error) { + return columnDiffDefaultRowCount, false, nil +} + // String is a sql.Table interface function which returns the name of the table which is defined by the constant // ColumnDiffTableName func (dt *ColumnDiffTable) String() string { diff --git a/go/libraries/doltcore/sqle/dtables/commit_ancestors_table.go b/go/libraries/doltcore/sqle/dtables/commit_ancestors_table.go index efe3d36b06..f872f24aca 100644 --- a/go/libraries/doltcore/sqle/dtables/commit_ancestors_table.go +++ b/go/libraries/doltcore/sqle/dtables/commit_ancestors_table.go @@ -21,9 +21,12 @@ import ( "github.com/dolthub/go-mysql-server/sql/types" "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" + "github.com/dolthub/dolt/go/libraries/doltcore/schema" "github.com/dolthub/dolt/go/libraries/doltcore/sqle/index" ) +const commitAncestorsDefaultRowCount = 100 + // CommitAncestorsTable is a sql.Table that implements a system table which // shows (commit, parent_commit) relationships for all commits in the repo. type CommitAncestorsTable struct { @@ -32,12 +35,26 @@ type CommitAncestorsTable struct { var _ sql.Table = (*CommitAncestorsTable)(nil) var _ sql.IndexAddressable = (*CommitAncestorsTable)(nil) +var _ sql.StatisticsTable = (*CommitAncestorsTable)(nil) // NewCommitAncestorsTable creates a CommitAncestorsTable func NewCommitAncestorsTable(_ *sql.Context, ddb *doltdb.DoltDB) sql.Table { return &CommitAncestorsTable{ddb: ddb} } +func (dt *CommitAncestorsTable) DataLength(ctx *sql.Context) (uint64, error) { + numBytesPerRow := schema.SchemaAvgLength(dt.Schema()) + numRows, _, err := dt.RowCount(ctx) + if err != nil { + return 0, err + } + return numBytesPerRow * numRows, nil +} + +func (dt *CommitAncestorsTable) RowCount(_ *sql.Context) (uint64, bool, error) { + return commitAncestorsDefaultRowCount, false, nil +} + // Name is a sql.Table interface function which returns the name of the table. func (dt *CommitAncestorsTable) Name() string { return doltdb.CommitAncestorsTableName diff --git a/go/libraries/doltcore/sqle/dtables/commit_diff_table.go b/go/libraries/doltcore/sqle/dtables/commit_diff_table.go index a71c52c29e..15b7e45c28 100644 --- a/go/libraries/doltcore/sqle/dtables/commit_diff_table.go +++ b/go/libraries/doltcore/sqle/dtables/commit_diff_table.go @@ -31,6 +31,8 @@ import ( "github.com/dolthub/dolt/go/store/types" ) +const commitDiffDefaultRowCount = 1000 + var ErrExactlyOneToCommit = errors.New("dolt_commit_diff_* tables must be filtered to a single 'to_commit'") var ErrExactlyOneFromCommit = errors.New("dolt_commit_diff_* tables must be filtered to a single 'from_commit'") var ErrInvalidCommitDiffTableArgs = errors.New("commit_diff_ requires one 'to_commit' and one 'from_commit'") @@ -51,6 +53,7 @@ type CommitDiffTable struct { var _ sql.Table = (*CommitDiffTable)(nil) var _ sql.IndexAddressable = (*CommitDiffTable)(nil) +var _ sql.StatisticsTable = (*CommitDiffTable)(nil) func NewCommitDiffTable(ctx *sql.Context, tblName string, ddb *doltdb.DoltDB, root *doltdb.RootValue) (sql.Table, error) { diffTblName := doltdb.DoltCommitDiffTablePrefix + tblName @@ -88,6 +91,19 @@ func NewCommitDiffTable(ctx *sql.Context, tblName string, ddb *doltdb.DoltDB, ro }, nil } +func (dt *CommitDiffTable) DataLength(ctx *sql.Context) (uint64, error) { + numBytesPerRow := schema.SchemaAvgLength(dt.Schema()) + numRows, _, err := dt.RowCount(ctx) + if err != nil { + return 0, err + } + return numBytesPerRow * numRows, nil +} + +func (dt *CommitDiffTable) RowCount(_ *sql.Context) (uint64, bool, error) { + return commitDiffDefaultRowCount, false, nil +} + func (dt *CommitDiffTable) Name() string { return doltdb.DoltCommitDiffTablePrefix + dt.name } diff --git a/go/libraries/doltcore/sqle/dtables/commits_table.go b/go/libraries/doltcore/sqle/dtables/commits_table.go index c8958ce040..709035282b 100644 --- a/go/libraries/doltcore/sqle/dtables/commits_table.go +++ b/go/libraries/doltcore/sqle/dtables/commits_table.go @@ -21,11 +21,14 @@ import ( "github.com/dolthub/go-mysql-server/sql/types" "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" + "github.com/dolthub/dolt/go/libraries/doltcore/schema" "github.com/dolthub/dolt/go/libraries/doltcore/sqle/index" "github.com/dolthub/dolt/go/store/datas" "github.com/dolthub/dolt/go/store/hash" ) +const commitsDefaultRowCount = 10 + // CommitsTable is a sql.Table that implements a system table which // shows the combined commit log for all branches in the repo. type CommitsTable struct { @@ -35,12 +38,26 @@ type CommitsTable struct { var _ sql.Table = (*CommitsTable)(nil) var _ sql.IndexAddressable = (*CommitsTable)(nil) +var _ sql.StatisticsTable = (*CommitsTable)(nil) // NewCommitsTable creates a CommitsTable func NewCommitsTable(_ *sql.Context, ddb *doltdb.DoltDB) sql.Table { return &CommitsTable{ddb: ddb} } +func (dt *CommitsTable) DataLength(ctx *sql.Context) (uint64, error) { + numBytesPerRow := schema.SchemaAvgLength(dt.Schema()) + numRows, _, err := dt.RowCount(ctx) + if err != nil { + return 0, err + } + return numBytesPerRow * numRows, nil +} + +func (dt *CommitsTable) RowCount(_ *sql.Context) (uint64, bool, error) { + return commitsDefaultRowCount, false, nil +} + // Name is a sql.Table interface function which returns the name of the table. func (dt *CommitsTable) Name() string { return doltdb.CommitsTableName diff --git a/go/libraries/doltcore/sqle/dtables/diff_table.go b/go/libraries/doltcore/sqle/dtables/diff_table.go index 7678319756..4c33d7d4cf 100644 --- a/go/libraries/doltcore/sqle/dtables/diff_table.go +++ b/go/libraries/doltcore/sqle/dtables/diff_table.go @@ -38,6 +38,8 @@ import ( "github.com/dolthub/dolt/go/store/types" ) +const diffTableDefaultRowCount = 10 + const ( toCommit = "to_commit" fromCommit = "from_commit" @@ -53,6 +55,7 @@ const ( var _ sql.Table = (*DiffTable)(nil) var _ sql.IndexedTable = (*DiffTable)(nil) var _ sql.IndexAddressable = (*DiffTable)(nil) +var _ sql.StatisticsTable = (*DiffTable)(nil) type DiffTable struct { name string @@ -123,6 +126,19 @@ func NewDiffTable(ctx *sql.Context, tblName string, ddb *doltdb.DoltDB, root *do }, nil } +func (dt *DiffTable) DataLength(ctx *sql.Context) (uint64, error) { + numBytesPerRow := schema.SchemaAvgLength(dt.Schema()) + numRows, _, err := dt.RowCount(ctx) + if err != nil { + return 0, err + } + return numBytesPerRow * numRows, nil +} + +func (dt *DiffTable) RowCount(_ *sql.Context) (uint64, bool, error) { + return diffTableDefaultRowCount, false, nil +} + func (dt *DiffTable) Name() string { return doltdb.DoltDiffTablePrefix + dt.name } diff --git a/go/libraries/doltcore/sqle/dtables/log_table.go b/go/libraries/doltcore/sqle/dtables/log_table.go index 5448b863b7..8c92ba7e6a 100644 --- a/go/libraries/doltcore/sqle/dtables/log_table.go +++ b/go/libraries/doltcore/sqle/dtables/log_table.go @@ -23,11 +23,14 @@ import ( "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" "github.com/dolthub/dolt/go/libraries/doltcore/env/actions/commitwalk" + "github.com/dolthub/dolt/go/libraries/doltcore/schema" "github.com/dolthub/dolt/go/libraries/doltcore/sqle/index" "github.com/dolthub/dolt/go/store/hash" "github.com/dolthub/dolt/go/store/prolly" ) +const logsDefaultRowCount = 100 + // LogTable is a sql.Table implementation that implements a system table which shows the dolt commit log type LogTable struct { ddb *doltdb.DoltDB @@ -47,21 +50,26 @@ func NewLogTable(_ *sql.Context, ddb *doltdb.DoltDB, head *doltdb.Commit) sql.Ta // DataLength implements sql.StatisticsTable func (dt *LogTable) DataLength(ctx *sql.Context) (uint64, error) { - return uint64(4*types.Text.MaxByteLength()*4 + 16), nil + numBytesPerRow := schema.SchemaAvgLength(dt.Schema()) + numRows, _, err := dt.RowCount(ctx) + if err != nil { + return 0, err + } + return numBytesPerRow * numRows, nil } // RowCount implements sql.StatisticsTable -func (dt *LogTable) RowCount(ctx *sql.Context) (uint64, error) { +func (dt *LogTable) RowCount(ctx *sql.Context) (uint64, bool, error) { cc, err := dt.head.GetCommitClosure(ctx) if err != nil { // TODO: remove this when we deprecate LD - return 1000, nil + return logsDefaultRowCount, false, nil } if cc.IsEmpty() { - return 1, nil + return 1, true, nil } cnt, err := cc.Count() - return uint64(cnt + 1), err + return uint64(cnt + 1), true, err } // Name is a sql.Table interface function which returns the name of the table which is defined by the constant diff --git a/go/libraries/doltcore/sqle/dtables/remotes_table.go b/go/libraries/doltcore/sqle/dtables/remotes_table.go index b64a7b5f00..d0499966a6 100644 --- a/go/libraries/doltcore/sqle/dtables/remotes_table.go +++ b/go/libraries/doltcore/sqle/dtables/remotes_table.go @@ -23,15 +23,19 @@ import ( "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" "github.com/dolthub/dolt/go/libraries/doltcore/env" + "github.com/dolthub/dolt/go/libraries/doltcore/schema" "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" "github.com/dolthub/dolt/go/libraries/doltcore/sqle/index" ) +const remotesDefaultRowCount = 1 + var _ sql.Table = (*RemotesTable)(nil) var _ sql.UpdatableTable = (*RemotesTable)(nil) var _ sql.DeletableTable = (*RemotesTable)(nil) var _ sql.InsertableTable = (*RemotesTable)(nil) var _ sql.ReplaceableTable = (*RemotesTable)(nil) +var _ sql.StatisticsTable = (*RemotesTable)(nil) // RemotesTable is a sql.Table implementation that implements a system table which shows the dolt remotes type RemotesTable struct { @@ -43,6 +47,19 @@ func NewRemotesTable(_ *sql.Context, ddb *doltdb.DoltDB) sql.Table { return &RemotesTable{ddb} } +func (bt *RemotesTable) DataLength(ctx *sql.Context) (uint64, error) { + numBytesPerRow := schema.SchemaAvgLength(bt.Schema()) + numRows, _, err := bt.RowCount(ctx) + if err != nil { + return 0, err + } + return numBytesPerRow * numRows, nil +} + +func (bt *RemotesTable) RowCount(_ *sql.Context) (uint64, bool, error) { + return remotesDefaultRowCount, false, nil +} + // Name is a sql.Table interface function which returns the name of the table which is defined by the constant // RemotesTableName func (bt *RemotesTable) Name() string { diff --git a/go/libraries/doltcore/sqle/dtables/status_table.go b/go/libraries/doltcore/sqle/dtables/status_table.go index a6ead600e0..9b7eba36d8 100644 --- a/go/libraries/doltcore/sqle/dtables/status_table.go +++ b/go/libraries/doltcore/sqle/dtables/status_table.go @@ -24,9 +24,12 @@ import ( "github.com/dolthub/dolt/go/libraries/doltcore/diff" "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" "github.com/dolthub/dolt/go/libraries/doltcore/env" + "github.com/dolthub/dolt/go/libraries/doltcore/schema" "github.com/dolthub/dolt/go/libraries/doltcore/sqle/index" ) +const statusDefaultRowCount = 10 + // StatusTable is a sql.Table implementation that implements a system table which shows the dolt branches type StatusTable struct { ddb *doltdb.DoltDB @@ -34,6 +37,21 @@ type StatusTable struct { rootsProvider env.RootsProvider } +var _ sql.StatisticsTable = (*StatusTable)(nil) + +func (s StatusTable) DataLength(ctx *sql.Context) (uint64, error) { + numBytesPerRow := schema.SchemaAvgLength(s.Schema()) + numRows, _, err := s.RowCount(ctx) + if err != nil { + return 0, err + } + return numBytesPerRow * numRows, nil +} + +func (s StatusTable) RowCount(_ *sql.Context) (uint64, bool, error) { + return statusDefaultRowCount, false, nil +} + func (s StatusTable) Name() string { return doltdb.StatusTableName } diff --git a/go/libraries/doltcore/sqle/dtables/tags_table.go b/go/libraries/doltcore/sqle/dtables/tags_table.go index 51a08fb4cb..1a145f51d9 100644 --- a/go/libraries/doltcore/sqle/dtables/tags_table.go +++ b/go/libraries/doltcore/sqle/dtables/tags_table.go @@ -21,10 +21,14 @@ import ( "github.com/dolthub/go-mysql-server/sql/types" "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" + "github.com/dolthub/dolt/go/libraries/doltcore/schema" "github.com/dolthub/dolt/go/libraries/doltcore/sqle/index" ) +const tagsDefaultRowCount = 10 + var _ sql.Table = (*TagsTable)(nil) +var _ sql.StatisticsTable = (*TagsTable)(nil) // TagsTable is a sql.Table implementation that implements a system table which shows the dolt tags type TagsTable struct { @@ -36,6 +40,19 @@ func NewTagsTable(_ *sql.Context, ddb *doltdb.DoltDB) sql.Table { return &TagsTable{ddb: ddb} } +func (dt *TagsTable) DataLength(ctx *sql.Context) (uint64, error) { + numBytesPerRow := schema.SchemaAvgLength(dt.Schema()) + numRows, _, err := dt.RowCount(ctx) + if err != nil { + return 0, err + } + return numBytesPerRow * numRows, nil +} + +func (dt *TagsTable) RowCount(_ *sql.Context) (uint64, bool, error) { + return tagsDefaultRowCount, false, nil +} + // Name is a sql.Table interface function which returns the name of the table which is defined by the constant // TagsTableName func (dt *TagsTable) Name() string { diff --git a/go/libraries/doltcore/sqle/dtables/unscoped_diff_table.go b/go/libraries/doltcore/sqle/dtables/unscoped_diff_table.go index 8864b9e3c1..a94f748e3f 100644 --- a/go/libraries/doltcore/sqle/dtables/unscoped_diff_table.go +++ b/go/libraries/doltcore/sqle/dtables/unscoped_diff_table.go @@ -28,6 +28,7 @@ import ( "github.com/dolthub/dolt/go/libraries/doltcore/diff" "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" + "github.com/dolthub/dolt/go/libraries/doltcore/schema" "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" "github.com/dolthub/dolt/go/libraries/doltcore/sqle/index" "github.com/dolthub/dolt/go/libraries/utils/set" @@ -35,6 +36,8 @@ import ( "github.com/dolthub/dolt/go/store/hash" ) +const unscopedDiffDefaultRowCount = 1000 + var workingSetPartitionKey = []byte("workingset") var commitHistoryPartitionKey = []byte("commithistory") var commitHashCol = "commit_hash" @@ -51,6 +54,7 @@ type UnscopedDiffTable struct { } var _ sql.Table = (*UnscopedDiffTable)(nil) +var _ sql.StatisticsTable = (*UnscopedDiffTable)(nil) var _ sql.IndexAddressable = (*UnscopedDiffTable)(nil) // NewUnscopedDiffTable creates an UnscopedDiffTable @@ -58,6 +62,19 @@ func NewUnscopedDiffTable(_ *sql.Context, dbName string, ddb *doltdb.DoltDB, hea return &UnscopedDiffTable{dbName: dbName, ddb: ddb, head: head} } +func (dt *UnscopedDiffTable) DataLength(ctx *sql.Context) (uint64, error) { + numBytesPerRow := schema.SchemaAvgLength(dt.Schema()) + numRows, _, err := dt.RowCount(ctx) + if err != nil { + return 0, err + } + return numBytesPerRow * numRows, nil +} + +func (dt *UnscopedDiffTable) RowCount(_ *sql.Context) (uint64, bool, error) { + return unscopedDiffDefaultRowCount, false, nil +} + // Name is a sql.Table interface function which returns the name of the table which is defined by the constant // DiffTableName func (dt *UnscopedDiffTable) Name() string { diff --git a/go/libraries/doltcore/sqle/tables.go b/go/libraries/doltcore/sqle/tables.go index 45b002f94f..7bc8368617 100644 --- a/go/libraries/doltcore/sqle/tables.go +++ b/go/libraries/doltcore/sqle/tables.go @@ -397,44 +397,18 @@ func (t *DoltTable) IsTemporary() bool { // DataLength implements the sql.StatisticsTable interface. func (t *DoltTable) DataLength(ctx *sql.Context) (uint64, error) { - schema := t.Schema() - var numBytesPerRow uint64 = 0 - for _, col := range schema { - switch n := col.Type.(type) { - case sql.NumberType: - numBytesPerRow += 8 - case sql.StringType: - numBytesPerRow += uint64(n.MaxByteLength()) - case sqltypes.BitType: - numBytesPerRow += 1 - case sql.DatetimeType: - numBytesPerRow += 8 - case sql.DecimalType: - numBytesPerRow += uint64(n.MaximumScale()) - case sql.EnumType: - numBytesPerRow += 2 - case sqltypes.JsonType: - numBytesPerRow += 20 - case sql.NullType: - numBytesPerRow += 1 - case sqltypes.TimeType: - numBytesPerRow += 16 - case sql.YearType: - numBytesPerRow += 8 - } - } - + numBytesPerRow := schema.SchemaAvgLength(t.Schema()) numRows, err := t.numRows(ctx) if err != nil { return 0, err } - return numBytesPerRow * numRows, nil } // RowCount implements the sql.StatisticsTable interface. -func (t *DoltTable) RowCount(ctx *sql.Context) (uint64, error) { - return t.numRows(ctx) +func (t *DoltTable) RowCount(ctx *sql.Context) (uint64, bool, error) { + rows, err := t.numRows(ctx) + return rows, true, err } func (t *DoltTable) PrimaryKeySchema() sql.PrimaryKeySchema { diff --git a/go/libraries/doltcore/sqle/temp_table.go b/go/libraries/doltcore/sqle/temp_table.go index 7f1887bedc..a49a15dd3a 100644 --- a/go/libraries/doltcore/sqle/temp_table.go +++ b/go/libraries/doltcore/sqle/temp_table.go @@ -175,12 +175,13 @@ func setTempTableRoot(t *TempTable) func(ctx *sql.Context, dbName string, newRoo } } -func (t *TempTable) RowCount(ctx *sql.Context) (uint64, error) { +func (t *TempTable) RowCount(ctx *sql.Context) (uint64, bool, error) { rows, err := t.table.GetRowData(ctx) if err != nil { - return 0, err + return 0, false, err } - return rows.Count() + cnt, err := rows.Count() + return cnt, true, err } func (t *TempTable) GetIndexes(ctx *sql.Context) ([]sql.Index, error) { diff --git a/integration-tests/bats/sql-local-remote.bats b/integration-tests/bats/sql-local-remote.bats index f2cf1a3738..b44138721a 100644 --- a/integration-tests/bats/sql-local-remote.bats +++ b/integration-tests/bats/sql-local-remote.bats @@ -1245,6 +1245,27 @@ SQL run dolt ls [ $status -eq 0 ] remoteOutput=$output + + [[ "$localOutput" == "$remoteOutput" ]] || false +} + +@test "sql-local-remote: verify dolt merge-base behavior" { + cd altDB + dolt checkout -b feature + dolt sql -q "create table table4 (pk int PRIMARY KEY)" + dolt add . + dolt commit -m "created table3" + + run dolt --verbose-engine-setup merge-base main feature + [ $status -eq 0 ] + [[ "$output" =~ "starting local mode" ]] || false + localOutput="${lines[1]}" + + start_sql_server altDB + run dolt --verbose-engine-setup merge-base main feature + [ $status -eq 0 ] + [[ "$output" =~ "starting remote mode" ]] || false + remoteOutput="${lines[1]}" [[ "$localOutput" == "$remoteOutput" ]] || false } 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 4cc2551d58..5a696d7132 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 @@ -1674,3 +1674,65 @@ tests: result: columns: ["d"] rows: [] +# Assert that we can gracefully transition to standby even when there are no +# dolt databases which we are replicating. +- name: dolt_cluster_transition_to_standby no dolt databases exist + 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: + - query: "show databases" + result: + columns: ["Database"] + rows: + - ["dolt_cluster"] + - ["information_schema"] + - ["mysql"] + - exec: "call dolt_cluster_transition_to_standby('2', '1')" + - on: server2 + queries: + - exec: "call dolt_assume_cluster_role('primary', '2')" + - on: server2 + queries: + - exec: "call dolt_cluster_transition_to_standby('3', '1')" + - on: server1 + queries: + - exec: "call dolt_assume_cluster_role('primary', '3')"