/
partition.go
701 lines (644 loc) · 19.5 KB
/
partition.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
// Copyright 2018 The Chubao Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied. See the License for the specific language governing
// permissions and limitations under the License.
package metanode
import (
"bytes"
"encoding/json"
"sort"
"strconv"
"strings"
"sync"
"sync/atomic"
"fmt"
"io/ioutil"
"os"
"path"
"github.com/chubaofs/chubaofs/cmd/common"
"github.com/chubaofs/chubaofs/proto"
"github.com/chubaofs/chubaofs/raftstore"
"github.com/chubaofs/chubaofs/util"
"github.com/chubaofs/chubaofs/util/errors"
"github.com/chubaofs/chubaofs/util/log"
raftproto "github.com/tiglabs/raft/proto"
)
var (
ErrIllegalHeartbeatAddress = errors.New("illegal heartbeat address")
ErrIllegalReplicateAddress = errors.New("illegal replicate address")
)
// Errors
var (
ErrInodeIDOutOfRange = errors.New("inode ID out of range")
)
type sortedPeers []proto.Peer
func (sp sortedPeers) Len() int {
return len(sp)
}
func (sp sortedPeers) Less(i, j int) bool {
return sp[i].ID < sp[j].ID
}
func (sp sortedPeers) Swap(i, j int) {
sp[i], sp[j] = sp[j], sp[i]
}
// MetaPartitionConfig is used to create a meta partition.
type MetaPartitionConfig struct {
// Identity for raftStore group. RaftStore nodes in the same raftStore group must have the same groupID.
PartitionId uint64 `json:"partition_id"`
VolName string `json:"vol_name"`
Start uint64 `json:"start"` // Minimal Inode ID of this range. (Required during initialization)
End uint64 `json:"end"` // Maximal Inode ID of this range. (Required during initialization)
Peers []proto.Peer `json:"peers"` // Peers information of the raftStore
Cursor uint64 `json:"-"` // Cursor ID of the inode that have been assigned
NodeId uint64 `json:"-"`
RootDir string `json:"-"`
BeforeStart func() `json:"-"`
AfterStart func() `json:"-"`
BeforeStop func() `json:"-"`
AfterStop func() `json:"-"`
RaftStore raftstore.RaftStore `json:"-"`
ConnPool *util.ConnectPool `json:"-"`
}
func (c *MetaPartitionConfig) checkMeta() (err error) {
if c.PartitionId <= 0 {
err = errors.NewErrorf("[checkMeta]: partition id at least 1, "+
"now partition id is: %d", c.PartitionId)
return
}
if c.Start < 0 {
err = errors.NewErrorf("[checkMeta]: start at least 0")
return
}
if c.End <= c.Start {
err = errors.NewErrorf("[checkMeta]: end=%v, "+
"start=%v; end <= start", c.End, c.Start)
return
}
if len(c.Peers) <= 0 {
err = errors.NewErrorf("[checkMeta]: must have peers, now peers is 0")
return
}
return
}
func (c *MetaPartitionConfig) sortPeers() {
sp := sortedPeers(c.Peers)
sort.Sort(sp)
}
// OpInode defines the interface for the inode operations.
type OpInode interface {
CreateInode(req *CreateInoReq, p *Packet) (err error)
UnlinkInode(req *UnlinkInoReq, p *Packet) (err error)
UnlinkInodeBatch(req *BatchUnlinkInoReq, p *Packet) (err error)
InodeGet(req *InodeGetReq, p *Packet) (err error)
InodeGetBatch(req *InodeGetReqBatch, p *Packet) (err error)
CreateInodeLink(req *LinkInodeReq, p *Packet) (err error)
EvictInode(req *EvictInodeReq, p *Packet) (err error)
EvictInodeBatch(req *BatchEvictInodeReq, p *Packet) (err error)
SetAttr(reqData []byte, p *Packet) (err error)
GetInodeTree() *BTree
DeleteInode(req *proto.DeleteInodeRequest, p *Packet) (err error)
DeleteInodeBatch(req *proto.DeleteInodeBatchRequest, p *Packet) (err error)
}
type OpExtend interface {
SetXAttr(req *proto.SetXAttrRequest, p *Packet) (err error)
GetXAttr(req *proto.GetXAttrRequest, p *Packet) (err error)
BatchGetXAttr(req *proto.BatchGetXAttrRequest, p *Packet) (err error)
RemoveXAttr(req *proto.RemoveXAttrRequest, p *Packet) (err error)
ListXAttr(req *proto.ListXAttrRequest, p *Packet) (err error)
UpdateSummaryInfo(req *proto.UpdateSummaryInfoRequest, p *Packet) (err error)
}
// OpDentry defines the interface for the dentry operations.
type OpDentry interface {
CreateDentry(req *CreateDentryReq, p *Packet) (err error)
DeleteDentry(req *DeleteDentryReq, p *Packet) (err error)
DeleteDentryBatch(req *BatchDeleteDentryReq, p *Packet) (err error)
UpdateDentry(req *UpdateDentryReq, p *Packet) (err error)
ReadDir(req *ReadDirReq, p *Packet) (err error)
ReadDirLimit(req *ReadDirLimitReq, p *Packet) (err error)
ReadDirOnly(req *ReadDirOnlyReq, p *Packet) (err error)
Lookup(req *LookupReq, p *Packet) (err error)
GetDentryTree() *BTree
}
// OpExtent defines the interface for the extent operations.
type OpExtent interface {
ExtentAppend(req *proto.AppendExtentKeyRequest, p *Packet) (err error)
ExtentAppendWithCheck(req *proto.AppendExtentKeyWithCheckRequest, p *Packet) (err error)
ExtentsList(req *proto.GetExtentsRequest, p *Packet) (err error)
ExtentsTruncate(req *ExtentsTruncateReq, p *Packet) (err error)
BatchExtentAppend(req *proto.AppendExtentKeysRequest, p *Packet) (err error)
}
type OpMultipart interface {
GetMultipart(req *proto.GetMultipartRequest, p *Packet) (err error)
CreateMultipart(req *proto.CreateMultipartRequest, p *Packet) (err error)
AppendMultipart(req *proto.AddMultipartPartRequest, p *Packet) (err error)
RemoveMultipart(req *proto.RemoveMultipartRequest, p *Packet) (err error)
ListMultipart(req *proto.ListMultipartRequest, p *Packet) (err error)
}
// OpMeta defines the interface for the metadata operations.
type OpMeta interface {
OpInode
OpDentry
OpExtent
OpPartition
OpExtend
OpMultipart
}
// OpPartition defines the interface for the partition operations.
type OpPartition interface {
IsLeader() (leaderAddr string, isLeader bool)
GetCursor() uint64
GetBaseConfig() MetaPartitionConfig
ResponseLoadMetaPartition(p *Packet) (err error)
PersistMetadata() (err error)
ChangeMember(changeType raftproto.ConfChangeType, peer raftproto.Peer, context []byte) (resp interface{}, err error)
Reset() (err error)
UpdatePartition(req *UpdatePartitionReq, resp *UpdatePartitionResp) (err error)
DeleteRaft() error
IsExsitPeer(peer proto.Peer) bool
TryToLeader(groupID uint64) error
CanRemoveRaftMember(peer proto.Peer) error
IsEquareCreateMetaPartitionRequst(request *proto.CreateMetaPartitionRequest) (err error)
}
// MetaPartition defines the interface for the meta partition operations.
type MetaPartition interface {
Start() error
Stop()
OpMeta
LoadSnapshot(path string) error
ForceSetMetaPartitionToLoadding()
ForceSetMetaPartitionToFininshLoad()
}
// metaPartition manages the range of the inode IDs.
// When a new inode is requested, it allocates a new inode id for this inode if possible.
// States:
// +-----+ +-------+
// | New | → Restore → | Ready |
// +-----+ +-------+
type metaPartition struct {
config *MetaPartitionConfig
size uint64 // For partition all file size
applyID uint64 // Inode/Dentry max applyID, this index will be update after restoring from the dumped data.
dentryTree *BTree
inodeTree *BTree // btree for inodes
extendTree *BTree // btree for inode extend (XAttr) management
multipartTree *BTree // collection for multipart management
raftPartition raftstore.Partition
stopC chan bool
storeChan chan *storeMsg
state uint32
delInodeFp *os.File
freeList *freeList // free inode list
extDelCh chan []proto.ExtentKey
extReset chan struct{}
vol *Vol
manager *metadataManager
isLoadingMetaPartition bool
summaryLock sync.Mutex
}
func (mp *metaPartition) ForceSetMetaPartitionToLoadding() {
mp.isLoadingMetaPartition = true
}
func (mp *metaPartition) ForceSetMetaPartitionToFininshLoad() {
mp.isLoadingMetaPartition = false
}
// Start starts a meta partition.
func (mp *metaPartition) Start() (err error) {
if atomic.CompareAndSwapUint32(&mp.state, common.StateStandby, common.StateStart) {
defer func() {
var newState uint32
if err != nil {
newState = common.StateStandby
} else {
newState = common.StateRunning
}
atomic.StoreUint32(&mp.state, newState)
}()
if mp.config.BeforeStart != nil {
mp.config.BeforeStart()
}
if err = mp.onStart(); err != nil {
err = errors.NewErrorf("[Start]->%s", err.Error())
return
}
if mp.config.AfterStart != nil {
mp.config.AfterStart()
}
}
return
}
// Stop stops a meta partition.
func (mp *metaPartition) Stop() {
if atomic.CompareAndSwapUint32(&mp.state, common.StateRunning, common.StateShutdown) {
defer atomic.StoreUint32(&mp.state, common.StateStopped)
if mp.config.BeforeStop != nil {
mp.config.BeforeStop()
}
mp.onStop()
if mp.config.AfterStop != nil {
mp.config.AfterStop()
log.LogDebugf("[AfterStop]: partition id=%d execute ok.",
mp.config.PartitionId)
}
}
}
func (mp *metaPartition) onStart() (err error) {
defer func() {
if err == nil {
return
}
mp.onStop()
}()
if err = mp.load(); err != nil {
err = errors.NewErrorf("[onStart]:load partition id=%d: %s",
mp.config.PartitionId, err.Error())
return
}
mp.startSchedule(mp.applyID)
if err = mp.startFreeList(); err != nil {
err = errors.NewErrorf("[onStart] start free list id=%d: %s",
mp.config.PartitionId, err.Error())
return
}
if err = mp.startRaft(); err != nil {
err = errors.NewErrorf("[onStart]start raft id=%d: %s",
mp.config.PartitionId, err.Error())
return
}
return
}
func (mp *metaPartition) onStop() {
mp.stopRaft()
mp.stop()
if mp.delInodeFp != nil {
mp.delInodeFp.Sync()
mp.delInodeFp.Close()
}
}
func (mp *metaPartition) startRaft() (err error) {
var (
heartbeatPort int
replicaPort int
peers []raftstore.PeerAddress
)
if heartbeatPort, replicaPort, err = mp.getRaftPort(); err != nil {
return
}
for _, peer := range mp.config.Peers {
addr := strings.Split(peer.Addr, ":")[0]
rp := raftstore.PeerAddress{
Peer: raftproto.Peer{
ID: peer.ID,
},
Address: addr,
HeartbeatPort: heartbeatPort,
ReplicaPort: replicaPort,
}
peers = append(peers, rp)
}
log.LogDebugf("start partition id=%d raft peers: %s",
mp.config.PartitionId, peers)
pc := &raftstore.PartitionConfig{
ID: mp.config.PartitionId,
Applied: mp.applyID,
Peers: peers,
SM: mp,
}
mp.raftPartition, err = mp.config.RaftStore.CreatePartition(pc)
if err == nil {
mp.ForceSetMetaPartitionToFininshLoad()
}
return
}
func (mp *metaPartition) stopRaft() {
if mp.raftPartition != nil {
// TODO Unhandled errors
//mp.raftPartition.Stop()
}
return
}
func (mp *metaPartition) getRaftPort() (heartbeat, replica int, err error) {
raftConfig := mp.config.RaftStore.RaftConfig()
heartbeatAddrSplits := strings.Split(raftConfig.HeartbeatAddr, ":")
replicaAddrSplits := strings.Split(raftConfig.ReplicateAddr, ":")
if len(heartbeatAddrSplits) != 2 {
err = ErrIllegalHeartbeatAddress
return
}
if len(replicaAddrSplits) != 2 {
err = ErrIllegalReplicateAddress
return
}
heartbeat, err = strconv.Atoi(heartbeatAddrSplits[1])
if err != nil {
return
}
replica, err = strconv.Atoi(replicaAddrSplits[1])
if err != nil {
return
}
return
}
// NewMetaPartition creates a new meta partition with the specified configuration.
func NewMetaPartition(conf *MetaPartitionConfig, manager *metadataManager) MetaPartition {
mp := &metaPartition{
config: conf,
dentryTree: NewBtree(),
inodeTree: NewBtree(),
extendTree: NewBtree(),
multipartTree: NewBtree(),
stopC: make(chan bool),
storeChan: make(chan *storeMsg, 100),
freeList: newFreeList(),
extDelCh: make(chan []proto.ExtentKey, 10000),
extReset: make(chan struct{}),
vol: NewVol(),
manager: manager,
}
return mp
}
// IsLeader returns the raft leader address and if the current meta partition is the leader.
func (mp *metaPartition) IsLeader() (leaderAddr string, ok bool) {
if mp.raftPartition == nil {
return
}
leaderID, _ := mp.raftPartition.LeaderTerm()
if leaderID == 0 {
return
}
ok = leaderID == mp.config.NodeId
for _, peer := range mp.config.Peers {
if leaderID == peer.ID {
leaderAddr = peer.Addr
return
}
}
return
}
func (mp *metaPartition) GetPeers() (peers []string) {
peers = make([]string, 0)
for _, peer := range mp.config.Peers {
if mp.config.NodeId == peer.ID {
continue
}
peers = append(peers, peer.Addr)
}
return
}
// GetCursor returns the cursor stored in the config.
func (mp *metaPartition) GetCursor() uint64 {
return atomic.LoadUint64(&mp.config.Cursor)
}
// PersistMetadata is the wrapper of persistMetadata.
func (mp *metaPartition) PersistMetadata() (err error) {
mp.config.sortPeers()
err = mp.persistMetadata()
return
}
func (mp *metaPartition) LoadSnapshot(snapshotPath string) (err error) {
if err = mp.loadInode(snapshotPath); err != nil {
return
}
if err = mp.loadDentry(snapshotPath); err != nil {
return
}
if err = mp.loadExtend(snapshotPath); err != nil {
return
}
if err = mp.loadMultipart(snapshotPath); err != nil {
return
}
err = mp.loadApplyID(snapshotPath)
return
}
func (mp *metaPartition) load() (err error) {
if err = mp.loadMetadata(); err != nil {
return
}
snapshotPath := path.Join(mp.config.RootDir, snapshotDir)
if err = mp.loadInode(snapshotPath); err != nil {
return
}
if err = mp.loadDentry(snapshotPath); err != nil {
return
}
if err = mp.loadExtend(snapshotPath); err != nil {
return
}
if err = mp.loadMultipart(snapshotPath); err != nil {
return
}
err = mp.loadApplyID(snapshotPath)
return
}
func (mp *metaPartition) store(sm *storeMsg) (err error) {
tmpDir := path.Join(mp.config.RootDir, snapshotDirTmp)
if _, err = os.Stat(tmpDir); err == nil {
// TODO Unhandled errors
os.RemoveAll(tmpDir)
}
err = nil
if err = os.MkdirAll(tmpDir, 0775); err != nil {
return
}
defer func() {
if err != nil {
// TODO Unhandled errors
os.RemoveAll(tmpDir)
}
}()
var crcBuffer = bytes.NewBuffer(make([]byte, 0, 16))
var storeFuncs = []func(dir string, sm *storeMsg) (uint32, error){
mp.storeInode,
mp.storeDentry,
mp.storeExtend,
mp.storeMultipart,
}
for _, storeFunc := range storeFuncs {
var crc uint32
if crc, err = storeFunc(tmpDir, sm); err != nil {
return
}
if crcBuffer.Len() != 0 {
crcBuffer.WriteString(" ")
}
crcBuffer.WriteString(fmt.Sprintf("%d", crc))
}
if err = mp.storeApplyID(tmpDir, sm); err != nil {
return
}
// write crc to file
if err = ioutil.WriteFile(path.Join(tmpDir, SnapshotSign), crcBuffer.Bytes(), 0775); err != nil {
return
}
snapshotDir := path.Join(mp.config.RootDir, snapshotDir)
// check snapshot backup
backupDir := path.Join(mp.config.RootDir, snapshotBackup)
if _, err = os.Stat(backupDir); err == nil {
if err = os.RemoveAll(backupDir); err != nil {
return
}
}
err = nil
// rename snapshot
if _, err = os.Stat(snapshotDir); err == nil {
if err = os.Rename(snapshotDir, backupDir); err != nil {
return
}
}
err = nil
if err = os.Rename(tmpDir, snapshotDir); err != nil {
_ = os.Rename(backupDir, snapshotDir)
return
}
err = os.RemoveAll(backupDir)
return
}
// UpdatePeers updates the peers.
func (mp *metaPartition) UpdatePeers(peers []proto.Peer) {
mp.config.Peers = peers
}
// DeleteRaft deletes the raft partition.
func (mp *metaPartition) DeleteRaft() (err error) {
err = mp.raftPartition.Delete()
return
}
// Return a new inode ID and update the offset.
func (mp *metaPartition) nextInodeID() (inodeId uint64, err error) {
for {
cur := atomic.LoadUint64(&mp.config.Cursor)
end := mp.config.End
if cur >= end {
return 0, ErrInodeIDOutOfRange
}
newId := cur + 1
if atomic.CompareAndSwapUint64(&mp.config.Cursor, cur, newId) {
return newId, nil
}
}
}
// ChangeMember changes the raft member with the specified one.
func (mp *metaPartition) ChangeMember(changeType raftproto.ConfChangeType, peer raftproto.Peer, context []byte) (resp interface{}, err error) {
resp, err = mp.raftPartition.ChangeMember(changeType, peer, context)
return
}
// GetBaseConfig returns the configuration stored in the meta partition. TODO remove? no usage?
func (mp *metaPartition) GetBaseConfig() MetaPartitionConfig {
return *mp.config
}
// UpdatePartition updates the meta partition. TODO remove? no usage?
func (mp *metaPartition) UpdatePartition(req *UpdatePartitionReq,
resp *UpdatePartitionResp) (err error) {
reqData, err := json.Marshal(req)
if err != nil {
resp.Status = proto.TaskFailed
resp.Result = err.Error()
return
}
r, err := mp.submit(opFSMUpdatePartition, reqData)
if err != nil {
resp.Status = proto.TaskFailed
resp.Result = err.Error()
return
}
if status := r.(uint8); status != proto.OpOk {
resp.Status = proto.TaskFailed
p := &Packet{}
p.ResultCode = status
err = errors.NewErrorf("[UpdatePartition]: %s", p.GetResultMsg())
resp.Result = p.GetResultMsg()
}
resp.Status = proto.TaskSucceeds
return
}
func (mp *metaPartition) DecommissionPartition(req []byte) (err error) {
_, err = mp.submit(opFSMDecommissionPartition, req)
return
}
func (mp *metaPartition) IsExsitPeer(peer proto.Peer) bool {
for _, hasExsitPeer := range mp.config.Peers {
if hasExsitPeer.Addr == peer.Addr && hasExsitPeer.ID == peer.ID {
return true
}
}
return false
}
func (mp *metaPartition) TryToLeader(groupID uint64) error {
return mp.raftPartition.TryToLeader(groupID)
}
// ResponseLoadMetaPartition loads the snapshot signature. TODO remove? no usage?
func (mp *metaPartition) ResponseLoadMetaPartition(p *Packet) (err error) {
resp := &proto.MetaPartitionLoadResponse{
PartitionID: mp.config.PartitionId,
DoCompare: true,
}
resp.MaxInode = mp.GetCursor()
resp.InodeCount = uint64(mp.getInodeTree().Len())
resp.DentryCount = uint64(mp.getDentryTree().Len())
resp.ApplyID = mp.applyID
if err != nil {
err = errors.Trace(err,
"[ResponseLoadMetaPartition] check snapshot")
return
}
data, err := json.Marshal(resp)
if err != nil {
err = errors.Trace(err, "[ResponseLoadMetaPartition] marshal")
return
}
p.PacketOkWithBody(data)
return
}
// MarshalJSON is the wrapper of json.Marshal.
func (mp *metaPartition) MarshalJSON() ([]byte, error) {
return json.Marshal(mp.config)
}
// TODO remove? no usage?
// Reset resets the meta partition.
func (mp *metaPartition) Reset() (err error) {
mp.inodeTree.Reset()
mp.dentryTree.Reset()
mp.config.Cursor = 0
mp.applyID = 0
// remove files
filenames := []string{applyIDFile, dentryFile, inodeFile, extendFile, multipartFile}
for _, filename := range filenames {
filepath := path.Join(mp.config.RootDir, filename)
if err = os.Remove(filepath); err != nil {
return
}
}
return
}
//
func (mp *metaPartition) canRemoveSelf() (canRemove bool, err error) {
var partition *proto.MetaPartitionInfo
if partition, err = masterClient.ClientAPI().GetMetaPartition(mp.config.PartitionId); err != nil {
log.LogErrorf("action[canRemoveSelf] err[%v]", err)
return
}
canRemove = false
var existInPeers bool
for _, peer := range partition.Peers {
if mp.config.NodeId == peer.ID {
existInPeers = true
}
}
if !existInPeers {
canRemove = true
return
}
if mp.config.NodeId == partition.OfflinePeerID {
canRemove = true
return
}
return
}