Merge remote-tracking branch 'origin/main' into aaron/cluster-replication-hook

This commit is contained in:
Aaron Son
2022-09-29 09:51:54 -07:00
6 changed files with 137 additions and 8 deletions

View File

@@ -219,7 +219,7 @@ MySQL comes with a MySQL server called `mysqld` and a MySQL client called `mysql
mysql Ver 8.0.29 for macos12.2 on x86_64 (Homebrew)
```
Now, to connect the `mysql` client to Dolt, you have to force the MySQL client through the TCP interface by passing in a host and port. The default is the socket interface which Dolt supports, but is not on by default. The MySQL client also requires you specify a user, in this case `root`.
Now, to connect the `mysql` client to Dolt, you are going to force the MySQL client through the TCP interface by passing in a host and port. The default is the socket interface which Dolt supports, but is only available on `localhost`. So, it's better to show off the TCP interface. The MySQL client also requires you specify a user, in this case `root`.
```bash
% mysql --host 127.0.0.1 --port 3306 -uroot

View File

@@ -57,7 +57,7 @@ import (
)
const (
Version = "0.41.6"
Version = "0.41.7"
)
var dumpDocsCommand = &commands.DumpDocsCmd{}

View File

@@ -16,7 +16,7 @@ require (
github.com/dolthub/ishell v0.0.0-20220112232610-14e753f0f371
github.com/dolthub/mmap-go v1.0.4-0.20201107010347-f9f2a9588a66
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81
github.com/dolthub/vitess v0.0.0-20220927165657-8eb73ed0ff24
github.com/dolthub/vitess v0.0.0-20220929061157-c71cf6a7768e
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
@@ -57,7 +57,7 @@ require (
require (
github.com/aliyun/aliyun-oss-go-sdk v2.2.5+incompatible
github.com/cenkalti/backoff/v4 v4.1.3
github.com/dolthub/go-mysql-server v0.12.1-0.20220927222348-8b178aa50764
github.com/dolthub/go-mysql-server v0.12.1-0.20220929062247-323a847921de
github.com/google/flatbuffers v2.0.6+incompatible
github.com/kch42/buzhash v0.0.0-20160816060738-9bdec3dec7c6
github.com/mitchellh/go-ps v1.0.0

View File

@@ -178,8 +178,8 @@ github.com/dolthub/flatbuffers v1.13.0-dh.1 h1:OWJdaPep22N52O/0xsUevxJ6Qfw1M2txC
github.com/dolthub/flatbuffers v1.13.0-dh.1/go.mod h1:CorYGaDmXjHz1Z7i50PYXG1Ricn31GcA2wNOTFIQAKE=
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.20220927222348-8b178aa50764 h1:7cJCBFyyHl1pGrNgME77mUkkzlSZ94jo3vZOQb/xan4=
github.com/dolthub/go-mysql-server v0.12.1-0.20220927222348-8b178aa50764/go.mod h1:8zHF9V5MPmb3dWB2kGjeltnHQc15QdynK9GnwSutreA=
github.com/dolthub/go-mysql-server v0.12.1-0.20220929062247-323a847921de h1:YkKR9AOt/Mta3suApA5bEwwTF/GbdYLva3zVbP0lxi0=
github.com/dolthub/go-mysql-server v0.12.1-0.20220929062247-323a847921de/go.mod h1:Ndof+jmKE/AISRWgeyx+RUvNlAtMOPSUzTM/iCOfx70=
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=
@@ -188,8 +188,8 @@ github.com/dolthub/mmap-go v1.0.4-0.20201107010347-f9f2a9588a66 h1:WRPDbpJWEnPxP
github.com/dolthub/mmap-go v1.0.4-0.20201107010347-f9f2a9588a66/go.mod h1:N5ZIbMGuDUpTpOFQ7HcsN6WSIpTGQjHP+Mz27AfmAgk=
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81 h1:7/v8q9XGFa6q5Ap4Z/OhNkAMBaK5YeuEzwJt+NZdhiE=
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81/go.mod h1:siLfyv2c92W1eN/R4QqG/+RjjX5W2+gCTRjZxBjI3TY=
github.com/dolthub/vitess v0.0.0-20220927165657-8eb73ed0ff24 h1:2ARLp21egNaEvWIN4/tfprcyAlWsRj4bdey+Hv7HMEM=
github.com/dolthub/vitess v0.0.0-20220927165657-8eb73ed0ff24/go.mod h1:oVFIBdqMFEkt4Xz2fzFJBNtzKhDEjwdCF0dzde39iKs=
github.com/dolthub/vitess v0.0.0-20220929061157-c71cf6a7768e h1:vC5OgmUm1Dd8vQP1YqgRvYMbHvrLNdQkd3S7udbS3BQ=
github.com/dolthub/vitess v0.0.0-20220929061157-c71cf6a7768e/go.mod h1:oVFIBdqMFEkt4Xz2fzFJBNtzKhDEjwdCF0dzde39iKs=
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=

View File

@@ -47,6 +47,7 @@ const (
var ErrWorkingSetChanges = goerrors.NewKind("Cannot switch working set, session state is dirty. " +
"Rollback or commit changes before changing working sets.")
var ErrSessionNotPeristable = errors.New("session is not persistable")
var ErrCurrentBranchDeleted = errors.New("current branch has been force deleted. run 'USE <database>/<branch>' to checkout a different branch, or reconnect to the server")
// DoltSession is the sql.Session implementation used by dolt. It is accessible through a *sql.Context instance
type DoltSession struct {
@@ -177,6 +178,36 @@ func (d *DoltSession) Flush(ctx *sql.Context, dbName string) error {
return d.SetRoot(ctx, dbName, ws.WorkingRoot())
}
// ValidateSession validates a working set if there are a valid sessionState with non-nil working set.
// If there is no sessionState or its current working set not defined, then no need for validation,
// so no error is returned.
func (d *DoltSession) ValidateSession(ctx *sql.Context, dbName string) error {
sessionState, ok, err := d.LookupDbState(ctx, dbName)
if !ok {
return nil
}
if err != nil {
return err
}
if sessionState.WorkingSet == nil {
return nil
}
wsRef := sessionState.WorkingSet.Ref()
_, err = sessionState.dbData.Ddb.ResolveWorkingSet(ctx, wsRef)
if err == doltdb.ErrWorkingSetNotFound {
_, err = d.newWorkingSetForHead(ctx, wsRef, dbName)
// if the current head is not found, the branch was force deleted, so use nil working set.
if errors.Is(err, doltdb.ErrBranchNotFound) {
return ErrCurrentBranchDeleted
} else if err != nil {
return err
}
} else if err != nil {
return err
}
return nil
}
// StartTransaction refreshes the state of this session and starts a new transaction.
func (d *DoltSession) StartTransaction(ctx *sql.Context, dbName string, tCharacteristic sql.TransactionCharacteristic) (sql.Transaction, error) {
if TransactionsDisabled(ctx) {

View File

@@ -201,6 +201,104 @@ var DoltBranchMultiSessionScriptTests = []queries.ScriptTest{
},
},
},
{
Name: "Test multi-session behavior for force deleting active branch with autocommit on",
Assertions: []queries.ScriptTestAssertion{
{
Query: "/* client a */ SET @@autocommit=1;",
Expected: []sql.Row{},
},
{
Query: "/* client a */ CALL DOLT_CHECKOUT('-b', 'branch1');",
Expected: []sql.Row{{0}},
},
{
Query: "/* client a */ select active_branch();",
Expected: []sql.Row{{"branch1"}},
},
{
Query: "/* client b */ select active_branch();",
Expected: []sql.Row{{"main"}},
},
{
Query: "/* client b */ select name from dolt_branches order by name;",
Expected: []sql.Row{{"branch1"}, {"main"}},
},
{
Query: "/* client b */ CALL DOLT_BRANCH('-D', 'branch1');",
Expected: []sql.Row{{0}},
},
{
Query: "/* client b */ select name from dolt_branches;",
Expected: []sql.Row{{"main"}},
},
{
Query: "/* client a */ select name from dolt_branches;",
ExpectedErrStr: "Error 1105: current branch has been force deleted. run 'USE <database>/<branch>' to checkout a different branch, or reconnect to the server",
},
{
Query: "/* client a */ CALL DOLT_CHECKOUT('main');",
ExpectedErrStr: "Error 1105: current branch has been force deleted. run 'USE <database>/<branch>' to checkout a different branch, or reconnect to the server",
},
{
Query: "/* client a */ USE dolt/main;",
Expected: []sql.Row{},
},
{
Query: "/* client a */ select active_branch();",
Expected: []sql.Row{{"main"}},
},
},
},
{
Name: "Test multi-session behavior for force deleting active branch with autocommit off",
Assertions: []queries.ScriptTestAssertion{
{
Query: "/* client a */ SET @@autocommit=0;",
Expected: []sql.Row{},
},
{
Query: "/* client a */ CALL DOLT_CHECKOUT('-b', 'branch1');",
Expected: []sql.Row{{0}},
},
{
Query: "/* client a */ select active_branch();",
Expected: []sql.Row{{"branch1"}},
},
{
Query: "/* client b */ select active_branch();",
Expected: []sql.Row{{"main"}},
},
{
Query: "/* client b */ select name from dolt_branches order by name;",
Expected: []sql.Row{{"branch1"}, {"main"}},
},
{
Query: "/* client b */ CALL DOLT_BRANCH('-D', 'branch1');",
Expected: []sql.Row{{0}},
},
{
Query: "/* client b */ select name from dolt_branches;",
Expected: []sql.Row{{"main"}},
},
{
Query: "/* client a */ select name from dolt_branches;",
ExpectedErrStr: "Error 1105: current branch has been force deleted. run 'USE <database>/<branch>' to checkout a different branch, or reconnect to the server",
},
{
Query: "/* client a */ CALL DOLT_CHECKOUT('main');",
ExpectedErrStr: "Error 1105: current branch has been force deleted. run 'USE <database>/<branch>' to checkout a different branch, or reconnect to the server",
},
{
Query: "/* client a */ USE dolt/main;",
Expected: []sql.Row{},
},
{
Query: "/* client a */ select active_branch();",
Expected: []sql.Row{{"main"}},
},
},
},
}
// TestDoltMultiSessionBehavior runs tests that exercise multi-session logic on a running SQL server. Statements