Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
orchestrator
提交
db31af5d
O
orchestrator
项目概览
github
/
orchestrator
9 个月 前同步成功
通知
18
Star
5143
Fork
916
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
orchestrator
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
db31af5d
编写于
7月 14, 2021
作者:
P
Philipp Heckel
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add some unit tests
上级
9b07606b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
113 addition
and
2 deletion
+113
-2
go/inst/instance_topology_dao.go
go/inst/instance_topology_dao.go
+2
-2
go/inst/instance_topology_dao_test.go
go/inst/instance_topology_dao_test.go
+111
-0
未找到文件。
go/inst/instance_topology_dao.go
浏览文件 @
db31af5d
...
...
@@ -676,10 +676,10 @@ func classifyAndPrioritizeReplicas(replicas []*Instance, includeNonReplicatingIn
}
}
// Sort replicas by priority, promotion rule and name
// Sort replicas by priority
(higher number means higher priority)
, promotion rule and name
sort
.
Slice
(
possibleSemiSyncReplicas
,
func
(
i
,
j
int
)
bool
{
if
possibleSemiSyncReplicas
[
i
]
.
SemiSyncPriority
!=
possibleSemiSyncReplicas
[
j
]
.
SemiSyncPriority
{
return
possibleSemiSyncReplicas
[
i
]
.
SemiSyncPriority
<
possibleSemiSyncReplicas
[
j
]
.
SemiSyncPriority
return
possibleSemiSyncReplicas
[
i
]
.
SemiSyncPriority
>
possibleSemiSyncReplicas
[
j
]
.
SemiSyncPriority
}
if
possibleSemiSyncReplicas
[
i
]
.
PromotionRule
!=
possibleSemiSyncReplicas
[
j
]
.
PromotionRule
{
return
possibleSemiSyncReplicas
[
i
]
.
PromotionRule
.
BetterThan
(
possibleSemiSyncReplicas
[
j
]
.
PromotionRule
)
...
...
go/inst/instance_topology_dao_test.go
0 → 100644
浏览文件 @
db31af5d
package
inst
import
(
"github.com/openark/golib/log"
"github.com/openark/orchestrator/go/config"
"testing"
)
func
init
()
{
config
.
Config
.
HostnameResolveMethod
=
"none"
config
.
MarkConfigurationLoaded
()
log
.
SetLevel
(
log
.
ERROR
)
}
func
newTestReplica
(
key
string
,
masterKey
string
,
lastCheckValid
bool
,
downtimed
bool
,
semiSyncPriority
uint
,
promotionRule
CandidatePromotionRule
,
replicationState
ReplicationThreadState
)
*
Instance
{
return
&
Instance
{
Key
:
InstanceKey
{
Hostname
:
key
,
Port
:
3306
},
MasterKey
:
InstanceKey
{
Hostname
:
masterKey
,
Port
:
3306
},
ReadBinlogCoordinates
:
BinlogCoordinates
{
LogFile
:
"mysql.000001"
,
LogPos
:
10
},
ReplicationSQLThreadState
:
replicationState
,
ReplicationIOThreadState
:
replicationState
,
IsLastCheckValid
:
lastCheckValid
,
IsDowntimed
:
downtimed
,
SemiSyncPriority
:
semiSyncPriority
,
PromotionRule
:
promotionRule
,
}
}
func
expectInstancesMatch
(
t
*
testing
.
T
,
actual
[]
*
Instance
,
expected
[]
*
Instance
)
{
if
len
(
expected
)
!=
len
(
actual
)
{
t
.
Fatalf
(
"Actual instance list %+v does not match expected list %+v"
,
actual
,
expected
)
}
for
i
:=
range
actual
{
if
actual
[
i
]
!=
expected
[
i
]
{
t
.
Fatalf
(
"Actual instance %+v does not match expected %+v"
,
actual
[
i
],
expected
[
i
])
}
}
}
func
TestClassifyAndPrioritizeReplicas_NoPrioritiesSamePromotionRule_NameTiebreaker
(
t
*
testing
.
T
)
{
replica1
:=
newTestReplica
(
"replica1"
,
"master1"
,
true
,
false
,
1
,
NeutralPromoteRule
,
ReplicationThreadStateRunning
)
replica2
:=
newTestReplica
(
"replica2"
,
"master1"
,
true
,
false
,
1
,
NeutralPromoteRule
,
ReplicationThreadStateRunning
)
replica3
:=
newTestReplica
(
"replica3"
,
"master1"
,
true
,
false
,
1
,
NeutralPromoteRule
,
ReplicationThreadStateRunning
)
replicas
:=
[]
*
Instance
{
replica3
,
replica2
,
replica1
}
// inverse order!
possibleSemiSyncReplicas
,
asyncReplicas
,
excludedReplicas
:=
classifyAndPrioritizeReplicas
(
replicas
,
nil
)
expectInstancesMatch
(
t
,
possibleSemiSyncReplicas
,
[]
*
Instance
{
replica1
,
replica2
,
replica3
})
expectInstancesMatch
(
t
,
asyncReplicas
,
[]
*
Instance
{})
expectInstancesMatch
(
t
,
excludedReplicas
,
[]
*
Instance
{})
}
func
TestClassifyAndPrioritizeReplicas_WithPriorities
(
t
*
testing
.
T
)
{
replica1
:=
newTestReplica
(
"replica1"
,
"master1"
,
true
,
false
,
1
,
NeutralPromoteRule
,
ReplicationThreadStateRunning
)
replica2
:=
newTestReplica
(
"replica2"
,
"master1"
,
true
,
false
,
3
,
NeutralPromoteRule
,
ReplicationThreadStateRunning
)
replica3
:=
newTestReplica
(
"replica3"
,
"master1"
,
true
,
false
,
2
,
NeutralPromoteRule
,
ReplicationThreadStateRunning
)
replicas
:=
[]
*
Instance
{
replica1
,
replica2
,
replica3
}
possibleSemiSyncReplicas
,
asyncReplicas
,
excludedReplicas
:=
classifyAndPrioritizeReplicas
(
replicas
,
nil
)
expectInstancesMatch
(
t
,
possibleSemiSyncReplicas
,
[]
*
Instance
{
replica2
,
replica3
,
replica1
})
expectInstancesMatch
(
t
,
asyncReplicas
,
[]
*
Instance
{})
expectInstancesMatch
(
t
,
excludedReplicas
,
[]
*
Instance
{})
}
func
TestClassifyAndPrioritizeReplicas_WithPrioritiesAndPromotionRules_PriorityTakesPrecedence
(
t
*
testing
.
T
)
{
replica1
:=
newTestReplica
(
"replica1"
,
"master1"
,
true
,
false
,
1
,
PreferPromoteRule
,
ReplicationThreadStateRunning
)
replica2
:=
newTestReplica
(
"replica2"
,
"master1"
,
true
,
false
,
3
,
MustNotPromoteRule
,
ReplicationThreadStateRunning
)
replica3
:=
newTestReplica
(
"replica3"
,
"master1"
,
true
,
false
,
2
,
NeutralPromoteRule
,
ReplicationThreadStateRunning
)
replicas
:=
[]
*
Instance
{
replica1
,
replica2
,
replica3
}
possibleSemiSyncReplicas
,
asyncReplicas
,
excludedReplicas
:=
classifyAndPrioritizeReplicas
(
replicas
,
nil
)
expectInstancesMatch
(
t
,
possibleSemiSyncReplicas
,
[]
*
Instance
{
replica2
,
replica3
,
replica1
})
expectInstancesMatch
(
t
,
asyncReplicas
,
[]
*
Instance
{})
expectInstancesMatch
(
t
,
excludedReplicas
,
[]
*
Instance
{})
}
func
TestClassifyAndPrioritizeReplicas_LastCheckInvalidAndNotReplication
(
t
*
testing
.
T
)
{
replica1
:=
newTestReplica
(
"replica1"
,
"master1"
,
true
,
false
,
1
,
MustNotPromoteRule
,
ReplicationThreadStateRunning
)
replica2
:=
newTestReplica
(
"replica2"
,
"master1"
,
true
,
false
,
1
,
NeutralPromoteRule
,
ReplicationThreadStateStopped
)
replica3
:=
newTestReplica
(
"replica3"
,
"master1"
,
false
,
false
,
1
,
PreferPromoteRule
,
ReplicationThreadStateRunning
)
replicas
:=
[]
*
Instance
{
replica1
,
replica2
,
replica3
}
possibleSemiSyncReplicas
,
asyncReplicas
,
excludedReplicas
:=
classifyAndPrioritizeReplicas
(
replicas
,
nil
)
expectInstancesMatch
(
t
,
possibleSemiSyncReplicas
,
[]
*
Instance
{
replica1
})
expectInstancesMatch
(
t
,
asyncReplicas
,
[]
*
Instance
{})
expectInstancesMatch
(
t
,
excludedReplicas
,
[]
*
Instance
{
replica2
,
replica3
})
}
func
TestClassifyAndPrioritizeReplicas_Downtimed
(
t
*
testing
.
T
)
{
replica1
:=
newTestReplica
(
"replica1"
,
"master1"
,
true
,
false
,
1
,
NeutralPromoteRule
,
ReplicationThreadStateRunning
)
replica2
:=
newTestReplica
(
"replica2"
,
"master1"
,
true
,
false
,
1
,
NeutralPromoteRule
,
ReplicationThreadStateRunning
)
replica3
:=
newTestReplica
(
"replica3"
,
"master1"
,
true
,
true
,
1
,
MustNotPromoteRule
,
ReplicationThreadStateRunning
)
replica4
:=
newTestReplica
(
"replica4"
,
"master1"
,
true
,
false
,
0
,
MustNotPromoteRule
,
ReplicationThreadStateRunning
)
replicas
:=
[]
*
Instance
{
replica1
,
replica2
,
replica3
,
replica4
}
possibleSemiSyncReplicas
,
asyncReplicas
,
excludedReplicas
:=
classifyAndPrioritizeReplicas
(
replicas
,
nil
)
expectInstancesMatch
(
t
,
possibleSemiSyncReplicas
,
[]
*
Instance
{
replica1
,
replica2
})
expectInstancesMatch
(
t
,
asyncReplicas
,
[]
*
Instance
{
replica3
,
replica4
})
expectInstancesMatch
(
t
,
excludedReplicas
,
[]
*
Instance
{})
}
func
TestClassifyAndPrioritizeReplicas_NonReplicatingReplica
(
t
*
testing
.
T
)
{
replica1
:=
newTestReplica
(
"replica1"
,
"master1"
,
true
,
false
,
1
,
NeutralPromoteRule
,
ReplicationThreadStateRunning
)
replica2
:=
newTestReplica
(
"replica2"
,
"master1"
,
true
,
false
,
1
,
NeutralPromoteRule
,
ReplicationThreadStateRunning
)
replica3
:=
newTestReplica
(
"replica3"
,
"master1"
,
true
,
false
,
1
,
MustNotPromoteRule
,
ReplicationThreadStateStopped
)
replicas
:=
[]
*
Instance
{
replica1
,
replica2
,
replica3
}
possibleSemiSyncReplicas
,
asyncReplicas
,
excludedReplicas
:=
classifyAndPrioritizeReplicas
(
replicas
,
&
replica3
.
Key
)
// Non-replicating instance
expectInstancesMatch
(
t
,
possibleSemiSyncReplicas
,
[]
*
Instance
{
replica1
,
replica2
,
replica3
})
expectInstancesMatch
(
t
,
asyncReplicas
,
[]
*
Instance
{})
expectInstancesMatch
(
t
,
excludedReplicas
,
[]
*
Instance
{})
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录