Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

persistent session interface #595

Merged
merged 38 commits into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
5c030e5
initial config move
max-hoffman Oct 18, 2021
a7cd857
merge main
max-hoffman Oct 18, 2021
542b7d7
fix system var / session var disconnect
max-hoffman Oct 18, 2021
e4618a3
put daylon's naming back
max-hoffman Oct 18, 2021
3f4d2cb
save progress, todo refactor PersistedSession
max-hoffman Oct 19, 2021
33f7532
PersistedSession
max-hoffman Oct 19, 2021
195c6b3
change file name
max-hoffman Oct 19, 2021
c26492d
[ga-format-pr] Run ./format_repo.sh to fix formatting
max-hoffman Oct 19, 2021
ef200a5
fmt
max-hoffman Oct 19, 2021
bd07b04
Merge branch 'max/sql-config' of github.com:dolthub/go-mysql-server i…
max-hoffman Oct 19, 2021
55e85ba
persist tests
max-hoffman Oct 20, 2021
9cb4a66
prefixConf tests
max-hoffman Oct 20, 2021
af72cd3
[ga-format-pr] Run ./format_repo.sh to fix formatting
max-hoffman Oct 20, 2021
4f3be69
fmt
max-hoffman Oct 20, 2021
7310261
Merge branch 'main' into max/sql-config
max-hoffman Oct 20, 2021
1bff3eb
interface{} to int
max-hoffman Oct 20, 2021
9096470
Merge branch 'max/sql-config' of github.com:dolthub/go-mysql-server i…
max-hoffman Oct 20, 2021
8d42b9b
add system vars reset function for testing
max-hoffman Oct 20, 2021
87943a6
add persisted defaults loading tests
max-hoffman Oct 21, 2021
650be2a
[ga-format-pr] Run ./format_repo.sh to fix formatting
max-hoffman Oct 21, 2021
335c383
Add NoDefaults tests
max-hoffman Oct 21, 2021
672d2d0
zach's comments
max-hoffman Oct 22, 2021
f6a3319
merge upstream
max-hoffman Oct 22, 2021
cd28cc7
[ga-format-pr] Run ./format_repo.sh to fix formatting
max-hoffman Oct 22, 2021
44325f6
small fixes
max-hoffman Oct 22, 2021
f20483a
Merge branch 'max/sql-config' of github.com:dolthub/go-mysql-server i…
max-hoffman Oct 22, 2021
85c2e0a
engine tests, name tweaks
max-hoffman Oct 25, 2021
db4620e
fix server config tests
max-hoffman Oct 25, 2021
7e90010
missed default in switch
max-hoffman Oct 25, 2021
f1c9b6e
reorder tesets
max-hoffman Oct 25, 2021
dffc288
Fix formatting
max-hoffman Oct 25, 2021
d191098
Interface tweaks
max-hoffman Oct 26, 2021
7da66bf
fix test
max-hoffman Oct 26, 2021
41f9ba1
Bump read timeout, was breaking dolt tests
max-hoffman Oct 27, 2021
15c0533
Merge branch 'max/sql-config' of github.com:dolthub/go-mysql-server i…
max-hoffman Oct 27, 2021
0aeeabd
Separate server from conf
max-hoffman Oct 27, 2021
49ad446
Zach's comments
max-hoffman Oct 29, 2021
43a1226
small fixes
max-hoffman Oct 29, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion auth/audit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func TestAuditLog(t *testing.T) {
m["err"] = err
require.Equal(m, e.Data)

s := sql.NewSession("server", sql.Client{Address: "client", User: "user"}, id)
s := sql.NewBaseSessionWithClientServer("server", sql.Client{Address: "client", User: "user"}, id)
ctx := sql.NewContext(context.TODO(),
sql.WithSession(s),
sql.WithPid(pid),
Expand Down
2 changes: 1 addition & 1 deletion auth/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func testAuthorization(
t.Run(fmt.Sprintf("%s-%s", c.user, c.query), func(t *testing.T) {
req := require.New(t)

session := sql.NewSession("localhost", sql.Client{Address: "client", User: c.user}, uint32(i))
session := sql.NewBaseSessionWithClientServer("localhost", sql.Client{Address: "client", User: c.user}, uint32(i))
ctx := sql.NewContext(context.TODO(),
sql.WithSession(session),
sql.WithPid(uint64(i))).WithCurrentDB("test")
Expand Down
4 changes: 2 additions & 2 deletions driver/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type SessionBuilder interface {
// DefaultSessionBuilder creates basic SQL sessions.
type DefaultSessionBuilder struct{}

// NewSession calls sql.NewSession.
// NewSession calls sql.NewBaseSessionWithClientServer.
func (DefaultSessionBuilder) NewSession(ctx context.Context, id uint32, conn *Connector) (sql.Session, error) {
return sql.NewSession(conn.Server(), sql.Client{Address: fmt.Sprintf("#%d", id)}, id), nil
return sql.NewBaseSessionWithClientServer(conn.Server(), sql.Client{Address: fmt.Sprintf("#%d", id)}, id), nil
}
2 changes: 1 addition & 1 deletion enginetest/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func TestShowProcessList(t *testing.T) {
addr := "127.0.0.1:34567"

p := sqle.NewProcessList()
sess := sql.NewSession("0.0.0.0:3306", sql.Client{Address: addr, User: "foo"}, 1)
sess := sql.NewBaseSessionWithClientServer("0.0.0.0:3306", sql.Client{Address: addr, User: "foo"}, 1)
ctx := sql.NewContext(context.Background(), sql.WithPid(1), sql.WithSession(sess), sql.WithProcessList(p))

ctx, err := p.AddProcess(ctx, "SELECT foo")
Expand Down
55 changes: 53 additions & 2 deletions enginetest/enginetests.go
Original file line number Diff line number Diff line change
Expand Up @@ -3520,6 +3520,57 @@ func TestColumnDefaults(t *testing.T, harness Harness) {
})
}

func TestPersist(t *testing.T, harness Harness, newPersistableSess func(ctx *sql.Context) sql.PersistableSession) {
q := []struct {
Name string
Query string
Expected []sql.Row
ExpectedGlobal interface{}
ExpectedPersist interface{}
}{
{
Query: "SET PERSIST max_connections = 1000;",
Expected: []sql.Row{{}},
ExpectedGlobal: int64(1000),
ExpectedPersist: int64(1000),
}, {
Query: "SET @@PERSIST.max_connections = 1000;",
Expected: []sql.Row{{}},
ExpectedGlobal: int64(1000),
ExpectedPersist: int64(1000),
}, {
Query: "SET PERSIST_ONLY max_connections = 1000;",
Expected: []sql.Row{{}},
ExpectedGlobal: int64(151),
ExpectedPersist: int64(1000),
},
}

e := NewEngine(t, harness)
ctx := NewContext(harness)

for _, tt := range q {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need tests of reset here as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no parser support for RESET yet

t.Run(tt.Name, func(t *testing.T) {
sql.InitSystemVariables()
ctx.Session = newPersistableSess(ctx)

TestQueryWithContext(t, ctx, e, tt.Query, tt.Expected, nil, nil)

if tt.ExpectedGlobal != nil {
_, res, _ := sql.SystemVariables.GetGlobal("max_connections")
require.Equal(t, tt.ExpectedGlobal, res)
}

if tt.ExpectedGlobal != nil {
res, err := ctx.Session.(sql.PersistableSession).GetPersistedValue("max_connections")
require.NoError(t, err)
assert.Equal(t,
tt.ExpectedPersist, res)
}
})
}
}

var pid uint64

func NewContext(harness Harness) *sql.Context {
Expand Down Expand Up @@ -3570,8 +3621,8 @@ func NewSession(harness Harness) *sql.Context {

// NewBaseSession returns a new BaseSession compatible with these tests. Most tests will work with any session
// implementation, but for full compatibility use a session based on this one.
func NewBaseSession() sql.Session {
return sql.NewSession("address", sql.Client{Address: "client", User: "user"}, 1)
func NewBaseSession() *sql.BaseSession {
return sql.NewBaseSessionWithClientServer("address", sql.Client{Address: "client", User: "user"}, 1)
}

func NewContextWithEngine(harness Harness, engine *sqle.Engine) *sql.Context {
Expand Down
9 changes: 9 additions & 0 deletions enginetest/memory_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,15 @@ func TestAddDropPks(t *testing.T) {
enginetest.TestAddDropPks(t, enginetest.NewDefaultMemoryHarness())
}

func TestPersist(t *testing.T) {
newSess := func(ctx *sql.Context) sql.PersistableSession {
persistedGlobals := memory.GlobalsMap{}
persistedSess := memory.NewInMemoryPersistedSession(ctx.Session, persistedGlobals)
return persistedSess
}
enginetest.TestPersist(t, enginetest.NewDefaultMemoryHarness(), newSess)
}

func unmergableIndexDriver(dbs []sql.Database) sql.IndexDriver {
return memory.NewIndexDriver("mydb", map[string][]sql.DriverIndex{
"mytable": {
Expand Down
37 changes: 19 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
module github.com/dolthub/go-mysql-server

require (
github.com/VividCortex/gohistogram v1.0.0 // indirect
github.com/cespare/xxhash v1.1.0
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81
github.com/dolthub/vitess v0.0.0-20211013185428-a8845fb919c1
github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
github.com/go-kit/kit v0.9.0
github.com/go-kit/kit v0.10.0
github.com/go-sql-driver/mysql v1.6.0
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/google/go-cmp v0.3.0 // indirect
github.com/golang/glog v0.0.0-20210429001901-424d2337a529
github.com/google/uuid v1.2.0
github.com/hashicorp/golang-lru v0.5.3
github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/lestrrat-go/strftime v1.0.1
github.com/mitchellh/hashstructure v1.0.0
github.com/hashicorp/golang-lru v0.5.4
github.com/kr/text v0.2.0 // indirect
github.com/lestrrat-go/strftime v1.0.4
github.com/mitchellh/hashstructure v1.1.0
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/oliveagle/jsonpath v0.0.0-20180606110733-2e52cf6e6852
github.com/opentracing/opentracing-go v1.1.0
github.com/opentracing/opentracing-go v1.2.0
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0
github.com/sanity-io/litter v1.2.0
github.com/shopspring/decimal v0.0.0-20191130220710-360f2bc03045
github.com/sirupsen/logrus v1.4.2
github.com/shopspring/decimal v1.2.0
github.com/sirupsen/logrus v1.8.1
github.com/src-d/go-oniguruma v1.1.0
github.com/stretchr/testify v1.7.0
github.com/tebeka/strftime v0.1.4 // indirect
golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect
golang.org/x/sync v0.0.0-20190423024810-112230192c58
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 // indirect
google.golang.org/grpc v1.27.0 // indirect
golang.org/x/net v0.0.0-20210505214959-0714010a04ed // indirect
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9
golang.org/x/sys v0.0.0-20210503173754-0981d6026fa6 // indirect
golang.org/x/tools v0.1.0 // indirect
google.golang.org/genproto v0.0.0-20210506142907-4a47615972c2 // indirect
google.golang.org/grpc v1.37.0 // indirect
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b // indirect
gopkg.in/src-d/go-errors.v1 v1.0.0
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
)

replace github.com/oliveagle/jsonpath => github.com/dolthub/jsonpath v0.0.0-20210609232853-d49537a30474
Expand Down
Loading