25
"github.com/cubefs/cubefs/depends/tiglabs/raft/util"
26
"github.com/cubefs/cubefs/util/log"
36
DefaultDataPartitionSize = 120 * GB
37
TaskWorkerInterval = 1
43
ReadBlockSize = BlockSize
45
ExtentSize = BlockCount * BlockSize
47
BlockHeaderSize = 4096
48
SyscallTryMaxTimes = 3
49
PacketHeaderVerSize = 65
53
PageSize = 4 * util.KB
73
DefaultTinySizeLimit = 1 * MB
76
type MultiVersionSeq uint64
78
func Min(a, b int) int {
85
func Max(a, b int) int {
93
func IsIPV4(val interface{}) bool {
94
ip4Pattern := `((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)`
95
ip4 := regexpCompile(ip4Pattern)
96
return isMatch(ip4, val)
99
func GetIp(addr string) (ip string) {
101
if arr = strings.Split(addr, ":"); len(arr) < 2 {
104
ip = strings.Trim(arr[0], " ")
108
func getIpAndPort(ipAddr string) (ip string, port string, success bool) {
110
arr := strings.Split(ipAddr, ":")
112
log.LogWarnf("action[GetIpAndPort] ipAddr[%v] invalid", ipAddr)
115
ip = strings.Trim(arr[0], " ")
116
port = strings.Trim(arr[1], " ")
121
func getDomainAndPort(domainAddr string) (domain string, port string, success bool) {
123
arr := strings.Split(domainAddr, ":")
125
log.LogWarnf("action[GetDomainAndPort] domainAddr[%v] invalid", domainAddr)
128
domain = strings.Trim(arr[0], " ")
129
port = strings.Trim(arr[1], " ")
134
func IsIPV4Addr(ipAddr string) bool {
135
ip, _, ok := getIpAndPort(ipAddr)
142
func ParseIpAddrToDomainAddr(ipAddr string) (domainAddr string) {
143
ip, port, ok := getIpAndPort(ipAddr)
147
domains, err := net.LookupAddr(ip)
149
log.LogWarnf("action[ParseIpAddrToDomainAddr] failed, ipAddr[%v], ip[%v], err[%v]", ipAddr, ip, err)
152
for _, v := range domains {
154
if domain[len(domain)-1] == '.' {
155
domain = domain[0 : len(domain)-1]
157
if len(domainAddr) != 0 {
160
domainAddr += fmt.Sprintf("%s:%v", domain, port)
165
func ParseAddrToIpAddr(addr string) (ipAddr string, success bool) {
167
if IsIPV4Addr(addr) {
171
if parsedAddr, ok := ParseDomainAddrToIpAddr(addr); ok {
179
func ParseDomainAddrToIpAddr(domainAddr string) (ipAddr string, success bool) {
181
domain, port, ok := getDomainAndPort(domainAddr)
185
ips, err := net.LookupHost(domain)
187
log.LogWarnf("action[ParseDomainAddrToIpAddr] failed, domainAddr[%v], domain[%v], err[%v]",
188
domainAddr, domain, err)
192
log.LogWarnf("action[ParseDomainAddrToIpAddr] ips is null, domainAddr[%v], domain[%v]",
196
for i := 0; i < len(ips); i += 1 {
197
if ips[i] != ips[0] {
198
log.LogWarnf("action[ParseDomainAddrToIpAddr] the number of ips is not one,"+
199
"domainAddr[%v], domain[%v], ips[%v], err[%v]", domainAddr, domain, ips, err)
203
ipAddr = fmt.Sprintf("%s:%v", ips[0], port)
208
func regexpCompile(str string) *regexp.Regexp {
209
return regexp.MustCompile("^" + str + "$")
212
func isMatch(exp *regexp.Regexp, val interface{}) bool {
213
switch v := val.(type) {
215
return exp.MatchString(string(v))
219
return exp.MatchString(v)
225
func GenerateKey(volName string, ino uint64, offset uint64) string {
226
return fmt.Sprintf("%v_%v_%016x", volName, ino, offset)
229
func GenerateRepVolKey(volName string, ino uint64, dpId uint64, extentId uint64, offset uint64) string {
230
return fmt.Sprintf("%v_%v_%v_%v_%016x", volName, ino, dpId, extentId, offset)
233
func OneDaySec() int64 {
237
func CalcAuthKey(key string) (authKey string) {
239
_, _ = h.Write([]byte(key))
240
cipherStr := h.Sum(nil)
241
return strings.ToLower(hex.EncodeToString(cipherStr))