-
Notifications
You must be signed in to change notification settings - Fork 0
/
z.go
65 lines (58 loc) · 1.65 KB
/
z.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* Copyright (c) 2000-2018, 达梦数据库有限公司.
* All rights reserved.
*/
package dm
import "sort"
const (
TYPE_WELL_DISTRIBUTE = 0
TYPE_HEAD_FIRST = 1
)
type epSelector struct {
dbs []*ep
}
func newEPSelector(dbs []*ep) *epSelector {
return &epSelector{dbs}
}
func (s *epSelector) sortDBList(first bool) []*ep {
if !first {
// 按sort从大到小排序,相同sort值顺序不变
sort.Slice(s.dbs, func(i, j int) bool {
return s.dbs[i].getSort(first) > s.dbs[j].getSort(first)
})
}
return s.dbs
}
func (s *epSelector) checkServerMode(conn *Connection, last bool) (bool, error) {
// 只连dsc control节点
if conn.dmConnector.loginDscCtrl && !conn.dscControl {
conn.close()
return false, ECGO_INVALID_SERVER_MODE.throw()
}
// 模式不匹配, 这里使用的是连接之前的sort,连接之后server的状态可能发生改变sort也可能改变
if conn.dmConnector.loginStatus > 0 && int(conn.SvrStat) != conn.dmConnector.loginStatus {
conn.close()
return false, ECGO_INVALID_SERVER_MODE.throw()
}
if last {
switch conn.dmConnector.loginMode {
case LOGIN_MODE_PRIMARY_ONLY:
return conn.SvrMode == SERVER_MODE_PRIMARY, nil
case LOGIN_MODE_STANDBY_ONLY:
return conn.SvrMode == SERVER_MODE_STANDBY, nil
default:
return true, nil
}
}
switch conn.dmConnector.loginMode {
case LOGIN_MODE_NORMAL_FIRST:
return conn.SvrMode == SERVER_MODE_NORMAL, nil
case LOGIN_MODE_PRIMARY_FIRST, LOGIN_MODE_PRIMARY_ONLY:
return conn.SvrMode == SERVER_MODE_PRIMARY, nil
case LOGIN_MODE_STANDBY_FIRST, LOGIN_MODE_STANDBY_ONLY:
return conn.SvrMode == SERVER_MODE_STANDBY, nil
default:
break
}
return false, nil
}