Skip to content

Commit

Permalink
Revert "Sync from release-20200720"
Browse files Browse the repository at this point in the history
  • Loading branch information
awzhgw authored Nov 11, 2020
1 parent 4f60c23 commit cf7fbde
Show file tree
Hide file tree
Showing 87 changed files with 1,536 additions and 4,769 deletions.
8 changes: 0 additions & 8 deletions cli/api/metaapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@ type MetaHttpClient struct {
// NewMasterHelper returns a new MasterClient instance.
func NewMetaHttpClient(host string, useSSL bool) *MetaHttpClient {
mc := &MetaHttpClient{host: host, useSSL: useSSL}
var err error
_, err = log.InitLog("/tmp/cfs", "cli", log.DebugLevel, nil)
if err != nil {
fmt.Printf("init cli log err[%v]", err)
}
return mc
}

Expand Down Expand Up @@ -218,7 +213,6 @@ func (mc *MetaHttpClient) GetMetaPartition(pid uint64) (cursor uint64, err error
if err != nil {
log.LogErrorf("action[GetMetaPartition],pid:%v,err:%v", pid, err)
}
log.LogFlush()
}()
request := newAPIRequest(http.MethodGet, "/getPartitionById")
request.params["pid"] = fmt.Sprintf("%v", pid)
Expand All @@ -242,7 +236,6 @@ func (mc *MetaHttpClient) GetAllDentry(pid uint64) (dentryMap map[string]*metano
if err != nil {
log.LogErrorf("action[GetAllDentry],pid:%v,err:%v", pid, err)
}
log.LogFlush()
}()
dentryMap = make(map[string]*metanode.Dentry, 0)
request := newAPIRequest(http.MethodGet, "/getAllDentry")
Expand Down Expand Up @@ -293,7 +286,6 @@ func (mc *MetaHttpClient) GetAllInodes(pid uint64) (rstMap map[uint64]*Inode, er
if err != nil {
log.LogErrorf("action[GetAllInodes],pid:%v,err:%v", pid, err)
}
log.LogFlush()
}()
reqURL := fmt.Sprintf("http://%v%v?pid=%v", mc.host, "/getAllInodes", pid)
log.LogDebugf("reqURL=%v", reqURL)
Expand Down
20 changes: 17 additions & 3 deletions cli/build.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
#!/usr/bin/env bash
BranchName=`git rev-parse --abbrev-ref HEAD`
CommitID=`git rev-parse HEAD`
RootPath=$(cd $(dirname $0)/..; pwd)

Version=`git describe --abbrev=0 --tags 2>/dev/null`
BranchName=`git rev-parse --abbrev-ref HEAD 2>/dev/null`
CommitID=`git rev-parse HEAD 2>/dev/null`
BuildTime=`date +%Y-%m-%d\ %H:%M`

SrcPath=${RootPath}/cli
TargetFile=${1:-$RootPath/cli/cfs-cli}

[[ "-$GOPATH" == "-" ]] && { echo "GOPATH not set"; exit 1; }

go build -ldflags "-X main.CommitID=${CommitID} -X main.BranchName=${BranchName} -X 'main.BuildTime=${BuildTime}'" -o cfs-cli
LDFlags="-X github.com/chubaofs/chubaofs/proto.Version=${Version} \
-X github.com/chubaofs/chubaofs/proto.CommitID=${CommitID} \
-X github.com/chubaofs/chubaofs/proto.BranchName=${BranchName} \
-X 'github.com/chubaofs/chubaofs/proto.BuildTime=${BuildTime}' "

go build \
-ldflags "${LDFlags}" \
-o $TargetFile \
${SrcPath}/*.go
17 changes: 11 additions & 6 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ package main

import (
"fmt"
"os"

"github.com/chubaofs/chubaofs/cli/cmd"
"github.com/chubaofs/chubaofs/sdk/master"
"github.com/chubaofs/chubaofs/util/log"
"github.com/spf13/cobra"
"os"
)

var (
Expand All @@ -32,17 +32,19 @@ var (
func runCLI() (err error) {
var cfg *cmd.Config
if cfg, err = cmd.LoadConfig(); err != nil {
fmt.Printf("init cli log err[%v]", err)
return
}
cfscli := setupCommands(cfg)
err = cfscli.Execute()
cfsCli := setupCommands(cfg)
if err = cfsCli.Execute(); err != nil {
log.LogErrorf("Command fail, err:%v", err)
}
return
}

func setupCommands(cfg *cmd.Config) *cobra.Command {
var mc = master.NewMasterClient(cfg.MasterAddr, false)
mc.DataNodeProfPort = cfg.DataNodeProfPort
mc.MetaNodeProfPort = cfg.MetaNodeProfPort
mc.SetTimeout(cfg.Timeout)
cfsRootCmd := cmd.NewRootCmd(mc)
var completionCmd = &cobra.Command{
Use: "completion",
Expand Down Expand Up @@ -75,7 +77,10 @@ following command to execute:

func main() {
var err error
_, err = log.InitLog("/tmp/cfs", "cli", log.DebugLevel, nil)
defer log.LogFlush()
if err = runCLI(); err != nil {
log.LogFlush()
_, _ = fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
Expand Down
68 changes: 42 additions & 26 deletions cli/cmd/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package cmd

import (
"fmt"
"os"
"strconv"

"github.com/chubaofs/chubaofs/proto"
Expand Down Expand Up @@ -65,14 +64,12 @@ func newClusterInfoCmd(client *master.MasterClient) *cobra.Command {
var cv *proto.ClusterView
var delPara map[string]string
if cv, err = client.AdminAPI().GetCluster(); err != nil {
errout("Get cluster info fail:\n%v\n", err)
os.Exit(1)
errout("Error: %v", err)
}
stdout("[Cluster]\n")
stdout(formatClusterView(cv))
if delPara, err = client.AdminAPI().GetDeleteParas(); err != nil {
errout("Get delete param fail:\n%v\n", err)
os.Exit(1)
errout("Error: %v", err)
}
stdout(fmt.Sprintf(" BatchCount : %v\n", delPara[nodeDeleteBatchCountKey]))
stdout(fmt.Sprintf(" MarkDeleteRate : %v\n", delPara[nodeMarkDeleteRateKey]))
Expand All @@ -89,11 +86,18 @@ func newClusterStatCmd(client *master.MasterClient) *cobra.Command {
Use: CliOpStatus,
Short: cmdClusterStatShort,
Run: func(cmd *cobra.Command, args []string) {
var err error
var cs *proto.ClusterStatInfo
var (
err error
cs *proto.ClusterStatInfo
)
defer func() {
if err != nil {
errout("Error: %v", err)
}
}()
if cs, err = client.AdminAPI().GetClusterStat(); err != nil {
errout("Get cluster info fail:\n%v\n", err)
os.Exit(1)
err = fmt.Errorf("Get cluster info fail:\n%v\n", err)
return
}
stdout("[Cluster Status]\n")
stdout(formatClusterStat(cs))
Expand All @@ -105,26 +109,32 @@ func newClusterStatCmd(client *master.MasterClient) *cobra.Command {

func newClusterFreezeCmd(client *master.MasterClient) *cobra.Command {
var cmd = &cobra.Command{
Use: CliOpFreeze + " [ENABLE]",
Use: CliOpFreeze + " [ENABLE]",
ValidArgs: []string{"true", "false"},
Short: cmdClusterFreezeShort,
Args: cobra.MinimumNArgs(1),
Short: cmdClusterFreezeShort,
Args: cobra.MinimumNArgs(1),
Long: `Turn on or off the automatic allocation of the data partitions.
If 'freeze=false', ChubaoFS WILL automatically allocate new data partitions for the volume when:
1. the used space is below the max capacity,
2. and the number of r&w data partition is less than 20.
If 'freeze=true', ChubaoFS WILL NOT automatically allocate new data partitions `,
Run: func(cmd *cobra.Command, args []string) {
var err error
var enable bool
var (
err error
enable bool
)
defer func() {
if err != nil {
errout("Error: %v", err)
}
}()
if enable, err = strconv.ParseBool(args[0]); err != nil {
errout("Parse bool fail: %v\n", err)
os.Exit(1)
err = fmt.Errorf("Parse bool fail: %v\n", err)
return
}
if err = client.AdminAPI().IsFreezeCluster(enable); err != nil {
errout("Failed: %v\n", err)
os.Exit(1)
return
}
if enable {
stdout("Freeze cluster successful!\n")
Expand All @@ -144,19 +154,25 @@ func newClusterSetThresholdCmd(client *master.MasterClient) *cobra.Command {
Long: `Set the threshold of memory on each meta node.
If the memory usage reaches this threshold, all the mata partition will be readOnly.`,
Run: func(cmd *cobra.Command, args []string) {
var err error
var threshold float64
var (
err error
threshold float64
)
defer func() {
if err != nil {
errout("Error: %v", err)
}
}()
if threshold, err = strconv.ParseFloat(args[0], 64); err != nil {
errout("Parse Float fail: %v\n", err)
os.Exit(1)
err = fmt.Errorf("Parse Float fail: %v\n", err)
return
}
if threshold > 1.0 {
errout("Threshold too big\n")
os.Exit(1)
err = fmt.Errorf("Threshold too big\n")
return
}
if err = client.AdminAPI().SetMetaNodeThreshold(threshold); err != nil {
errout("Failed: %v\n", err)
os.Exit(1)
return
}
stdout("MetaNode threshold is set to %v!\n", threshold)
},
Expand Down
42 changes: 22 additions & 20 deletions cli/cmd/compatibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
package cmd

import (
"os"
"fmt"
"github.com/chubaofs/chubaofs/cli/api"
"github.com/spf13/cobra"
"github.com/chubaofs/chubaofs/metanode"
"fmt"
"strconv"
"github.com/chubaofs/chubaofs/util/log"
"github.com/chubaofs/chubaofs/proto"
"github.com/spf13/cobra"
"reflect"
"strconv"
)

const (
Expand Down Expand Up @@ -55,24 +53,21 @@ func newMetaCompatibilityCmd() *cobra.Command {
Aliases: []string{"meta"},
Args: cobra.MinimumNArgs(3),
Run: func(cmd *cobra.Command, args []string) {
var err error
var (
err error
snapshotPath = args[0]
host = args[1]
pid = args[2]
)
client := api.NewMetaHttpClient(host, false)
defer func() {
if err != nil {
errout("Verify metadata consistency failed: %v\n", err)
log.LogError(err)
log.LogFlush()
os.Exit(1)
errout("Error: %v", err)
}
}()
id, err := strconv.ParseUint(pid, 10, 64)
if err != nil {
errout("parse pid[%v] failed: %v\n", pid, err)
err = fmt.Errorf("parse pid[%v] failed: %v\n", pid, err)
return
}
cursor, err := client.GetMetaPartition(id)
Expand All @@ -90,11 +85,9 @@ func newMetaCompatibilityCmd() *cobra.Command {
}
stdout("[Meta partition is %v, verify result]\n", id)
if err = verifyDentry(client, mp); err != nil {
stdout("%v\n", err)
return
}
if err = verifyInode(client, mp); err != nil {
stdout("%v\n", err)
return
}
stdout("All meta has checked\n")
Expand All @@ -111,25 +104,27 @@ func verifyDentry(client *api.MetaHttpClient, mp metanode.MetaPartition) (err er
mp.GetDentryTree().Ascend(func(d metanode.BtreeItem) bool {
dentry, ok := d.(*metanode.Dentry)
if !ok {
stdout("item type is not *metanode.Dentry")
stdout("item type is not *metanode.Dentry \n")
err = fmt.Errorf("item type is not *metanode.Dentry")
return false
return true
}
key := fmt.Sprintf("%v_%v", dentry.ParentId, dentry.Name)
oldDentry, ok := dentryMap[key]
if !ok {
stdout("dentry %v is not in old version", key)
stdout("dentry %v is not in old version \n", key)
err = fmt.Errorf("dentry %v is not in old version", key)
return false
}
if !reflect.DeepEqual(dentry, oldDentry) {
stdout("dentry %v is not equal with old version", key)
stdout("dentry %v is not equal with old version \n", key)
err = fmt.Errorf("dentry %v is not equal with old version,dentry[%v],oldDentry[%v]", key, dentry, oldDentry)
return false
}
return true
})
stdout("The number of dentry is %v, all dentry are consistent \n", mp.GetDentryTree().Len())
if err == nil {
stdout("The number of dentry is %v, all dentry are consistent \n", mp.GetDentryTree().Len())
}
return
}

Expand All @@ -142,12 +137,15 @@ func verifyInode(client *api.MetaHttpClient, mp metanode.MetaPartition) (err err
mp.GetInodeTree().Ascend(func(d metanode.BtreeItem) bool {
inode, ok := d.(*metanode.Inode)
if !ok {
stdout("item type is not *metanode.Inode \n")
err = fmt.Errorf("item type is not *metanode.Inode")
return true
}
oldInode, ok := inodesMap[inode.Inode]
if !ok {
stdout("inode %v is not in old version \n", inode.Inode)
return true
err = fmt.Errorf("inode %v is not in old version", inode.Inode)
return false
}
localInode = &api.Inode{
Inode: inode.Inode,
Expand All @@ -171,9 +169,13 @@ func verifyInode(client *api.MetaHttpClient, mp metanode.MetaPartition) (err err
})
if !reflect.DeepEqual(oldInode, localInode) {
stdout("inode %v is not equal with old version,inode[%v],oldInode[%v]\n", inode.Inode, inode, oldInode)
err = fmt.Errorf("inode %v is not equal with old version,inode[%v],oldInode[%v]\n", inode.Inode, inode, oldInode)
return false
}
return true
})
stdout("The number of inodes is %v, all inodes are consistent \n", mp.GetInodeTree().Len())
if err == nil {
stdout("The number of inodes is %v, all inodes are consistent \n", mp.GetInodeTree().Len())
}
return
}
Loading

0 comments on commit cf7fbde

Please sign in to comment.