1
// Copyright 2018 The CubeFS Authors.
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
7
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12
// implied. See the License for the specific language governing
13
// permissions and limitations under the License.
21
"github.com/cubefs/cubefs/proto"
22
"github.com/cubefs/cubefs/util/log"
25
// DataPartition defines the struct of data partition that will be used on the meta node.
26
type DataPartition struct {
35
// GetAllAddrs returns all addresses of the data partition.
36
func (dp *DataPartition) GetAllAddrs() (m string) {
37
return strings.Join(dp.Hosts[1:], proto.AddrSplit) + proto.AddrSplit
40
// DataPartitionsView defines the view of the data node.
41
type DataPartitionsView struct {
42
DataPartitions []*DataPartition
45
func NewDataPartitionsView() *DataPartitionsView {
46
return &DataPartitionsView{}
49
// Vol defines the view of the data partition with the read/write lock.
52
dataPartitionView map[uint64]*DataPartition
53
volDeleteLockTime int64
56
// NewVol returns a new volume instance.
59
dataPartitionView: make(map[uint64]*DataPartition),
63
// GetPartition returns the data partition based on the given partition ID.
64
func (v *Vol) GetPartition(partitionID uint64) *DataPartition {
67
return v.dataPartitionView[partitionID]
70
// UpdatePartitions updates the data partition.
71
func (v *Vol) UpdatePartitions(partitions *DataPartitionsView) {
72
for _, dp := range partitions.DataPartitions {
73
log.LogDebugf("action[UpdatePartitions] dp (id:%v,status:%v)", dp.PartitionID, dp.Status)
78
func (v *Vol) replaceOrInsert(partition *DataPartition) {
81
v.dataPartitionView[partition.PartitionID] = partition