Skip to content

Commit 34fba28

Browse files
authored
Update default read source setting (#5)
1 parent 16088f3 commit 34fba28

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

mssqlx.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1432,7 +1432,7 @@ func ConnectMasterSlaves(driverName string, masterDSNs []string, slaveDSNs []str
14321432
// default cluster options
14331433
opts := &clusterOptions{
14341434
isWsrep: false,
1435-
readQuerySource: ReadQuerySourceSlaves,
1435+
readQuerySource: ReadQuerySourceAll,
14361436
}
14371437

14381438
for _, optFn := range options {

mssqlx_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,12 +467,12 @@ func TestConnectMasterSlave(t *testing.T) {
467467

468468
// check read-query source
469469
db, _ = ConnectMasterSlaves(driver, nil, nil)
470-
if db.readBalancer() != db.slaves {
470+
if db.readBalancer() != db.all {
471471
t.Fatal("Initialize master slave fail")
472472
}
473473

474-
db, _ = ConnectMasterSlaves(driver, nil, nil, WithReadQuerySource(ReadQuerySourceAll))
475-
if db.readBalancer() != db.all {
474+
db, _ = ConnectMasterSlaves(driver, nil, nil, WithReadQuerySource(ReadQuerySourceSlaves))
475+
if db.readBalancer() != db.slaves {
476476
t.Fatal("Initialize master slave fail")
477477
}
478478
}
@@ -1817,6 +1817,8 @@ func TestStressQueries(t *testing.T) {
18171817
}
18181818

18191819
_RunWithSchema(schema, t, func(db *DBs, t *testing.T) {
1820+
require.Equal(t, ReadQuerySourceAll, db.readQuerySource)
1821+
18201822
ch := make(chan struct{}, 100)
18211823

18221824
type StressType struct {

options.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ package mssqlx
44
type ReadQuerySource int
55

66
const (
7-
// ReadQuerySourceSlaves indicates: read-queries will be distributed only among slaves.
8-
// This is default value.
7+
// ReadQuerySourceSlaves setting indicates: read-queries will be distributed only among slaves.
98
//
109
// Note: there is no option for Master. One could use functions like `QueryMaster`, etc
1110
// to query from masters only.
1211
ReadQuerySourceSlaves ReadQuerySource = iota
13-
// ReadQuerySourceAll indicates: read-queries will be distributed among both masters and slaves.
12+
13+
// ReadQuerySourceAll setting indicates: read-queries will be distributed among both masters and slaves.
14+
//
15+
// Note: this is default setting.
1416
ReadQuerySourceAll
1517
)
1618

0 commit comments

Comments
 (0)