github.com/matrixorigin/matrixone@v0.7.0/pkg/pb/metadata/metadata.go (about)

     1  // Copyright 2022 Matrix Origin
     2  //
     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
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     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 implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package metadata
    16  
    17  import (
    18  	"bytes"
    19  	"fmt"
    20  	"strings"
    21  )
    22  
    23  // IsEmpty return true if is a empty DNShard
    24  func (m DNShard) IsEmpty() bool {
    25  	return m.ShardID == 0
    26  }
    27  
    28  // Equal returns true if DNShard is same
    29  func (m DNShard) Equal(dn DNShard) bool {
    30  	return m.ShardID == dn.ShardID && m.ReplicaID == dn.ReplicaID
    31  }
    32  
    33  // DebugString returns debug string
    34  func (m DNShard) DebugString() string {
    35  	return fmt.Sprintf("%d-%d-%d-%s", m.ShardID, m.ReplicaID, m.LogShardID, m.Address)
    36  }
    37  
    38  // DebugString returns debug string
    39  func (m DNStore) DebugString() string {
    40  	n := len(m.Shards)
    41  	var buf bytes.Buffer
    42  	buf.WriteString(m.UUID)
    43  	buf.WriteString("/")
    44  	buf.WriteString(fmt.Sprintf("%d", len(m.Shards)))
    45  	buf.WriteString(" DNShards[")
    46  	for idx, shard := range m.Shards {
    47  		buf.WriteString(shard.DebugString())
    48  		if idx < n-1 {
    49  			buf.WriteString(", ")
    50  		}
    51  	}
    52  	buf.WriteString("]")
    53  	return buf.String()
    54  }
    55  
    56  // DebugString returns debug string
    57  func (m CNStore) DebugString() string {
    58  	return fmt.Sprintf("%s/%s", m.UUID, m.Role.String())
    59  }
    60  
    61  // MustParseCNRole parse CN Role from role string
    62  func MustParseCNRole(role string) CNRole {
    63  	if v, ok := CNRole_value[strings.ToUpper(role)]; ok {
    64  		return CNRole(v)
    65  	}
    66  	panic(fmt.Sprintf("invalid CN Role %s", role))
    67  }