@@ -116,6 +116,7 @@ func NewCluster(lg *zap.Logger, opts ...ClusterOption) *RaftCluster {
116
116
removed : make (map [types.ID ]bool ),
117
117
downgradeInfo : & serverversion.DowngradeInfo {Enabled : false },
118
118
maxLearners : clOpts .maxLearners ,
119
+ v2store : v2store .New (),
119
120
}
120
121
}
121
122
@@ -400,9 +401,7 @@ func (c *RaftCluster) ValidateConfigurationChange(cc raftpb.ConfChange) error {
400
401
func (c * RaftCluster ) AddMember (m * Member , shouldApplyV3 ShouldApplyV3 ) {
401
402
c .Lock ()
402
403
defer c .Unlock ()
403
- if c .v2store != nil {
404
- mustSaveMemberToStore (c .lg , c .v2store , m )
405
- }
404
+ mustSaveMemberToStore (c .lg , c .v2store , m )
406
405
407
406
if m .ID == c .localID {
408
407
setIsLearnerMetric (m )
@@ -438,9 +437,8 @@ func (c *RaftCluster) AddMember(m *Member, shouldApplyV3 ShouldApplyV3) {
438
437
func (c * RaftCluster ) RemoveMember (id types.ID , shouldApplyV3 ShouldApplyV3 ) {
439
438
c .Lock ()
440
439
defer c .Unlock ()
441
- if c .v2store != nil {
442
- mustDeleteMemberFromStore (c .lg , c .v2store , id )
443
- }
440
+ mustDeleteMemberFromStore (c .lg , c .v2store , id )
441
+
444
442
if c .be != nil && shouldApplyV3 {
445
443
c .be .MustDeleteMemberFromBackend (id )
446
444
@@ -482,9 +480,8 @@ func (c *RaftCluster) UpdateAttributes(id types.ID, attr Attributes, shouldApply
482
480
483
481
if m , ok := c .members [id ]; ok {
484
482
m .Attributes = attr
485
- if c .v2store != nil {
486
- mustUpdateMemberAttrInStore (c .lg , c .v2store , m )
487
- }
483
+ mustUpdateMemberAttrInStore (c .lg , c .v2store , m )
484
+
488
485
if c .be != nil && shouldApplyV3 {
489
486
c .be .MustSaveMemberToBackend (m )
490
487
}
@@ -514,11 +511,9 @@ func (c *RaftCluster) PromoteMember(id types.ID, shouldApplyV3 ShouldApplyV3) {
514
511
c .Lock ()
515
512
defer c .Unlock ()
516
513
517
- if c .v2store != nil {
518
- m := * (c .members [id ])
519
- m .RaftAttributes .IsLearner = false
520
- mustUpdateMemberInStore (c .lg , c .v2store , & m )
521
- }
514
+ m := * (c .members [id ])
515
+ m .RaftAttributes .IsLearner = false
516
+ mustUpdateMemberInStore (c .lg , c .v2store , & m )
522
517
523
518
if id == c .localID {
524
519
isLearner .Set (0 )
@@ -548,11 +543,10 @@ func (c *RaftCluster) UpdateRaftAttributes(id types.ID, raftAttr RaftAttributes,
548
543
c .Lock ()
549
544
defer c .Unlock ()
550
545
551
- if c .v2store != nil {
552
- m := * (c .members [id ])
553
- m .RaftAttributes = raftAttr
554
- mustUpdateMemberInStore (c .lg , c .v2store , & m )
555
- }
546
+ m := * (c .members [id ])
547
+ m .RaftAttributes = raftAttr
548
+ mustUpdateMemberInStore (c .lg , c .v2store , & m )
549
+
556
550
if c .be != nil && shouldApplyV3 {
557
551
c .members [id ].RaftAttributes = raftAttr
558
552
c .be .MustSaveMemberToBackend (c .members [id ])
@@ -609,9 +603,9 @@ func (c *RaftCluster) SetVersion(ver *semver.Version, onSet func(*zap.Logger, *s
609
603
c .version = ver
610
604
sv := semver .Must (semver .NewVersion (version .Version ))
611
605
serverversion .MustDetectDowngrade (c .lg , sv , c .version )
612
- if c . v2store != nil {
613
- mustSaveClusterVersionToStore (c .lg , c .v2store , ver )
614
- }
606
+
607
+ mustSaveClusterVersionToStore (c .lg , c .v2store , ver )
608
+
615
609
if c .be != nil && shouldApplyV3 {
616
610
c .be .MustSaveClusterVersionToBackend (ver )
617
611
}
0 commit comments