Skip to content

Commit 5ae0093

Browse files
authored
Merge pull request #726 from zhyass/feature_set
*: add config lower-case-table-names to support case insensitive tabl…
2 parents 23eda68 + 1bdd2f4 commit 5ae0093

File tree

21 files changed

+1280
-1011
lines changed

21 files changed

+1280
-1011
lines changed

docs/api.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,17 @@ This document describes the RadonDB REST API, which allows users to achieve most
5555
Path: /v1/radon/config
5656
Method: PUT
5757
Request: {
58-
"max-connections": The maximum permitted number of simultaneous client connections,
59-
"max-result-size": The maximum result size(in bytes) of a query,
60-
"max-join-rows": The maximum number of rows that will be held in memory for join's intermediate results,
61-
"ddl-timeout": The execution timeout(in millisecond) for DDL statements,
62-
"query-timeout": The execution timeout(in millisecond) for DML statements,
63-
"twopc-enable": Enables(true or false) radon two phase commit, for distrubuted transaction,
64-
"allowip": ["allow-ip-1", "allow-ip-2", "allow-ip-regexp"],
65-
"audit-mode": The audit log mode, "N": disabled, "R": read enabled, "W": write enabled, "A": read/write enabled,
66-
"blocks-readonly": The size of a block when create hash tables,
67-
"load-balance": Enables(0 or 1) load balance, for read-write separation.
58+
"max-connections": The maximum permitted number of simultaneous client connections,
59+
"max-result-size": The maximum result size(in bytes) of a query,
60+
"max-join-rows": The maximum number of rows that will be held in memory for join's intermediate results,
61+
"ddl-timeout": The execution timeout(in millisecond) for DDL statements,
62+
"query-timeout": The execution timeout(in millisecond) for DML statements,
63+
"twopc-enable": Enables(true or false) radon two phase commit, for distrubuted transaction,
64+
"allowip": ["allow-ip-1", "allow-ip-2", "allow-ip-regexp"],
65+
"audit-mode": The audit log mode, "N": disabled, "R": read enabled, "W": write enabled, "A": read/write enabled,
66+
"blocks-readonly": The size of a block when create hash tables,
67+
"load-balance": Enables(0 or 1) load balance, for read-write separation,
68+
"lower-case-table-names": If set 0, table names are stored as specified and comparisons are case-sensitive. If set 1, not case-sensitive.
6869
}
6970
7071
```

intergration/radon-test/r/select.result

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ sum(a) b
2929
select c from integrate_test.t;
3030
ERROR 1054 (42S22): Unknown column 'c' in 'field list'
3131

32+
select a from integrate_test.T;
33+
ERROR 1146 (42S02): Table 'T' doesn't exist
34+
35+
select a from INTEGRATE_TEST.t;
36+
ERROR 1146 (42S02): Table 'INTEGRATE_TEST.t' doesn't exist
37+
38+
select tt.a from integrate_test.t as TT;
39+
ERROR 1105 (HY000): unsupported: unknown.column.'tt.a'.in.field.list
40+
3241

3342
create table integrate_test.s(a int key, b int) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3443

intergration/radon-test/t/select.test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ select a, b c from integrate_test.t where a in (0,1,2) order by C desc;
88
select a, b from integrate_test.t where A>0;
99
select sum(a), b from integrate_test.t where a>=0 group by B;
1010
select c from integrate_test.t;
11+
select a from integrate_test.T;
12+
select a from INTEGRATE_TEST.t;
13+
select tt.a from integrate_test.t as TT;
1114

1215
create table integrate_test.s(a int key, b int) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1316
insert into integrate_test.s(a, b) values(0,1), (2,2);

src/config/config.go

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ const (
2424

2525
// ProxyConfig tuple.
2626
type ProxyConfig struct {
27-
IPS []string `json:"allowip"`
28-
MetaDir string `json:"meta-dir"`
29-
Endpoint string `json:"endpoint"`
30-
TwopcEnable bool `json:"twopc-enable"`
31-
LoadBalance int `json:"load-balance"` // 0 -- disable balance, 1 -- enable balance to replica
27+
IPS []string `json:"allowip"`
28+
MetaDir string `json:"meta-dir"`
29+
Endpoint string `json:"endpoint"`
30+
TwopcEnable bool `json:"twopc-enable"`
31+
LoadBalance int `json:"load-balance"` // 0 -- disable balance, 1 -- enable balance to replica
32+
LowerCaseTableNames int `json:"lower-case-table-names"` // 0 -- case sensitive, 1 -- case insensitive
3233

3334
MaxConnections int `json:"max-connections"`
3435
MaxResultSize int `json:"max-result-size"`
@@ -48,18 +49,19 @@ type ProxyConfig struct {
4849
// DefaultProxyConfig returns default proxy config.
4950
func DefaultProxyConfig() *ProxyConfig {
5051
return &ProxyConfig{
51-
MetaDir: "./radon-meta",
52-
Endpoint: "127.0.0.1:3308",
53-
LoadBalance: 0,
54-
MaxConnections: 1024,
55-
MaxResultSize: 1024 * 1024 * 1024, // 1GB
56-
MaxJoinRows: 32768,
57-
DDLTimeout: 10 * 3600 * 1000, // 10hours
58-
QueryTimeout: 5 * 60 * 1000, // 5minutes
59-
PeerAddress: "127.0.0.1:8080",
60-
LongQueryTime: 5, // 5 seconds
61-
StreamBufferSize: 1024 * 1024 * 32, // 32MB
62-
IdleTxnTimeout: 60, // 60 seconds
52+
MetaDir: "./radon-meta",
53+
Endpoint: "127.0.0.1:3308",
54+
LoadBalance: 0,
55+
LowerCaseTableNames: 0,
56+
MaxConnections: 1024,
57+
MaxResultSize: 1024 * 1024 * 1024, // 1GB
58+
MaxJoinRows: 32768,
59+
DDLTimeout: 10 * 3600 * 1000, // 10hours
60+
QueryTimeout: 5 * 60 * 1000, // 5minutes
61+
PeerAddress: "127.0.0.1:8080",
62+
LongQueryTime: 5, // 5 seconds
63+
StreamBufferSize: 1024 * 1024 * 32, // 32MB
64+
IdleTxnTimeout: 60, // 60 seconds
6365
}
6466
}
6567

src/ctl/v1/radon.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,18 @@ import (
1818
)
1919

2020
type radonParams struct {
21-
MaxConnections *int `json:"max-connections"`
22-
MaxResultSize *int `json:"max-result-size"`
23-
MaxJoinRows *int `json:"max-join-rows"`
24-
DDLTimeout *int `json:"ddl-timeout"`
25-
QueryTimeout *int `json:"query-timeout"`
26-
TwoPCEnable *bool `json:"twopc-enable"`
27-
LoadBalance *int `json:"load-balance"`
28-
AllowIP []string `json:"allowip,omitempty"`
29-
AuditMode *string `json:"audit-mode"`
30-
StreamBufferSize *int `json:"stream-buffer-size"`
31-
Blocks *int `json:"blocks-readonly"`
21+
MaxConnections *int `json:"max-connections"`
22+
MaxResultSize *int `json:"max-result-size"`
23+
MaxJoinRows *int `json:"max-join-rows"`
24+
DDLTimeout *int `json:"ddl-timeout"`
25+
QueryTimeout *int `json:"query-timeout"`
26+
TwoPCEnable *bool `json:"twopc-enable"`
27+
LoadBalance *int `json:"load-balance"`
28+
AllowIP []string `json:"allowip,omitempty"`
29+
AuditMode *string `json:"audit-mode"`
30+
StreamBufferSize *int `json:"stream-buffer-size"`
31+
Blocks *int `json:"blocks-readonly"`
32+
LowerCaseTableNames *int `json:"lower-case-table-names"`
3233
}
3334

3435
// RadonConfigHandler impl.
@@ -80,6 +81,9 @@ func radonConfigHandler(log *xlog.Log, proxy *proxy.Proxy, w rest.ResponseWriter
8081
if p.Blocks != nil {
8182
proxy.SetBlocks(*p.Blocks)
8283
}
84+
if p.LowerCaseTableNames != nil {
85+
proxy.SetLowerCaseTableNames(*p.LowerCaseTableNames)
86+
}
8387

8488
// reset the allow ip table list.
8589
proxy.IPTable().Refresh()

src/ctl/v1/radon_test.go

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,33 +36,35 @@ func TestCtlV1RadonConfig(t *testing.T) {
3636
handler := api.MakeHandler()
3737

3838
type radonParams1 struct {
39-
MaxConnections int `json:"max-connections"`
40-
MaxResultSize int `json:"max-result-size"`
41-
MaxJoinRows int `json:"max-join-rows"`
42-
DDLTimeout int `json:"ddl-timeout"`
43-
QueryTimeout int `json:"query-timeout"`
44-
TwoPCEnable bool `json:"twopc-enable"`
45-
LoadBalance int `json:"load-balance"`
46-
AllowIP []string `json:"allowip,omitempty"`
47-
AuditMode string `json:"audit-mode"`
48-
StreamBufferSize int `json:"stream-buffer-size"`
49-
Blocks int `json:"blocks-readonly"`
39+
MaxConnections int `json:"max-connections"`
40+
MaxResultSize int `json:"max-result-size"`
41+
MaxJoinRows int `json:"max-join-rows"`
42+
DDLTimeout int `json:"ddl-timeout"`
43+
QueryTimeout int `json:"query-timeout"`
44+
TwoPCEnable bool `json:"twopc-enable"`
45+
LoadBalance int `json:"load-balance"`
46+
AllowIP []string `json:"allowip,omitempty"`
47+
AuditMode string `json:"audit-mode"`
48+
StreamBufferSize int `json:"stream-buffer-size"`
49+
Blocks int `json:"blocks-readonly"`
50+
LowerCaseTableNames int `json:"lower-case-table-names"`
5051
}
5152

5253
// 200.
5354
{
5455
// client
5556
p := &radonParams1{
56-
MaxConnections: 1023,
57-
MaxResultSize: 1073741823,
58-
MaxJoinRows: 32767,
59-
QueryTimeout: 33,
60-
TwoPCEnable: true,
61-
LoadBalance: 1,
62-
AllowIP: []string{"127.0.0.1", "127.0.0.2"},
63-
AuditMode: "A",
64-
StreamBufferSize: 16777216,
65-
Blocks: 128,
57+
MaxConnections: 1023,
58+
MaxResultSize: 1073741823,
59+
MaxJoinRows: 32767,
60+
QueryTimeout: 33,
61+
TwoPCEnable: true,
62+
LoadBalance: 1,
63+
AllowIP: []string{"127.0.0.1", "127.0.0.2"},
64+
AuditMode: "A",
65+
StreamBufferSize: 16777216,
66+
Blocks: 128,
67+
LowerCaseTableNames: 1,
6668
}
6769
recorded := test.RunRequest(t, handler, test.MakeSimpleRequest("PUT", "http://localhost/v1/radon/config", p))
6870
recorded.CodeIs(200)
@@ -79,6 +81,7 @@ func TestCtlV1RadonConfig(t *testing.T) {
7981
assert.Equal(t, "A", radonConf.Audit.Mode)
8082
assert.Equal(t, 16777216, radonConf.Proxy.StreamBufferSize)
8183
assert.Equal(t, 128, radonConf.Router.Blocks)
84+
assert.Equal(t, 1, radonConf.Proxy.LowerCaseTableNames)
8285
}
8386

8487
// Unset AllowIP.

src/proxy/initdb.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ package proxy
1010

1111
import (
1212
"fmt"
13+
"strings"
1314

1415
"github.com/xelabs/go-mysqlstack/driver"
1516
"github.com/xelabs/go-mysqlstack/sqldb"
@@ -25,6 +26,10 @@ func (spanner *Spanner) ComInitDB(session *driver.Session, database string) erro
2526
return err
2627
}
2728

29+
if spanner.isLowerCaseTableNames() {
30+
database = strings.ToLower(database)
31+
}
32+
2833
privilegePlug := spanner.plugins.PlugPrivilege()
2934
isSet := privilegePlug.CheckUserPrivilegeIsSet(session.User())
3035
if !isSet {

src/proxy/initdb_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ func TestProxyUseDatabase(t *testing.T) {
3535
assert.Nil(t, err)
3636
}
3737

38+
// lower case.
39+
{
40+
session := proxy.sessions.getSession(1).session
41+
spanner := proxy.Spanner()
42+
spanner.ComInitDB(session, "TEST")
43+
assert.Equal(t, "TEST", session.Schema())
44+
45+
proxy.SetLowerCaseTableNames(1)
46+
spanner.ComInitDB(session, "TEST")
47+
assert.Equal(t, "test", session.Schema())
48+
}
49+
3850
// use db.
3951
{
4052
_, err := driver.NewConn("mock", "mock", address, "test", "utf8")

src/proxy/proxy.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,3 +314,11 @@ func (p *Proxy) SetBlocks(blocks int) {
314314
p.log.Info("proxy.SetBlocks:[%d->%d]", p.conf.Router.Blocks, blocks)
315315
p.conf.Router.Blocks = blocks
316316
}
317+
318+
// SetLowerCaseTableNames used to set LowerCaseTableNames to false or true.
319+
func (p *Proxy) SetLowerCaseTableNames(lowerCase int) {
320+
p.mu.Lock()
321+
defer p.mu.Unlock()
322+
p.log.Info("proxy.SetLowerCaseTableNames:[%v->%v]", p.conf.Proxy.LowerCaseTableNames, lowerCase)
323+
p.conf.Proxy.LowerCaseTableNames = lowerCase
324+
}

src/proxy/proxy_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ func TestProxy1(t *testing.T) {
105105
assert.Equal(t, 0, proxy.conf.Proxy.LoadBalance)
106106
}
107107

108+
// SetLowerCaseTableNames.
109+
{
110+
proxy.SetLowerCaseTableNames(1)
111+
assert.Equal(t, 1, proxy.conf.Proxy.LowerCaseTableNames)
112+
proxy.SetLowerCaseTableNames(0)
113+
assert.Equal(t, 0, proxy.conf.Proxy.LowerCaseTableNames)
114+
}
115+
108116
// FlushConfig.
109117
{
110118
err := proxy.FlushConfig()

0 commit comments

Comments
 (0)