Skip to content

Commit cf7fbde

Browse files
authored
Revert "Sync from release-20200720"
1 parent 4f60c23 commit cf7fbde

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+1536
-4769
lines changed

cli/api/metaapi.go

-8
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,6 @@ type MetaHttpClient struct {
8787
// NewMasterHelper returns a new MasterClient instance.
8888
func NewMetaHttpClient(host string, useSSL bool) *MetaHttpClient {
8989
mc := &MetaHttpClient{host: host, useSSL: useSSL}
90-
var err error
91-
_, err = log.InitLog("/tmp/cfs", "cli", log.DebugLevel, nil)
92-
if err != nil {
93-
fmt.Printf("init cli log err[%v]", err)
94-
}
9590
return mc
9691
}
9792

@@ -218,7 +213,6 @@ func (mc *MetaHttpClient) GetMetaPartition(pid uint64) (cursor uint64, err error
218213
if err != nil {
219214
log.LogErrorf("action[GetMetaPartition],pid:%v,err:%v", pid, err)
220215
}
221-
log.LogFlush()
222216
}()
223217
request := newAPIRequest(http.MethodGet, "/getPartitionById")
224218
request.params["pid"] = fmt.Sprintf("%v", pid)
@@ -242,7 +236,6 @@ func (mc *MetaHttpClient) GetAllDentry(pid uint64) (dentryMap map[string]*metano
242236
if err != nil {
243237
log.LogErrorf("action[GetAllDentry],pid:%v,err:%v", pid, err)
244238
}
245-
log.LogFlush()
246239
}()
247240
dentryMap = make(map[string]*metanode.Dentry, 0)
248241
request := newAPIRequest(http.MethodGet, "/getAllDentry")
@@ -293,7 +286,6 @@ func (mc *MetaHttpClient) GetAllInodes(pid uint64) (rstMap map[uint64]*Inode, er
293286
if err != nil {
294287
log.LogErrorf("action[GetAllInodes],pid:%v,err:%v", pid, err)
295288
}
296-
log.LogFlush()
297289
}()
298290
reqURL := fmt.Sprintf("http://%v%v?pid=%v", mc.host, "/getAllInodes", pid)
299291
log.LogDebugf("reqURL=%v", reqURL)

cli/build.sh

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
#!/usr/bin/env bash
2-
BranchName=`git rev-parse --abbrev-ref HEAD`
3-
CommitID=`git rev-parse HEAD`
2+
RootPath=$(cd $(dirname $0)/..; pwd)
3+
4+
Version=`git describe --abbrev=0 --tags 2>/dev/null`
5+
BranchName=`git rev-parse --abbrev-ref HEAD 2>/dev/null`
6+
CommitID=`git rev-parse HEAD 2>/dev/null`
47
BuildTime=`date +%Y-%m-%d\ %H:%M`
58

9+
SrcPath=${RootPath}/cli
10+
TargetFile=${1:-$RootPath/cli/cfs-cli}
11+
612
[[ "-$GOPATH" == "-" ]] && { echo "GOPATH not set"; exit 1; }
713

8-
go build -ldflags "-X main.CommitID=${CommitID} -X main.BranchName=${BranchName} -X 'main.BuildTime=${BuildTime}'" -o cfs-cli
14+
LDFlags="-X github.com/chubaofs/chubaofs/proto.Version=${Version} \
15+
-X github.com/chubaofs/chubaofs/proto.CommitID=${CommitID} \
16+
-X github.com/chubaofs/chubaofs/proto.BranchName=${BranchName} \
17+
-X 'github.com/chubaofs/chubaofs/proto.BuildTime=${BuildTime}' "
18+
19+
go build \
20+
-ldflags "${LDFlags}" \
21+
-o $TargetFile \
22+
${SrcPath}/*.go

cli/cli.go

+11-6
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ package main
1616

1717
import (
1818
"fmt"
19-
"os"
20-
2119
"github.com/chubaofs/chubaofs/cli/cmd"
2220
"github.com/chubaofs/chubaofs/sdk/master"
21+
"github.com/chubaofs/chubaofs/util/log"
2322
"github.com/spf13/cobra"
23+
"os"
2424
)
2525

2626
var (
@@ -32,17 +32,19 @@ var (
3232
func runCLI() (err error) {
3333
var cfg *cmd.Config
3434
if cfg, err = cmd.LoadConfig(); err != nil {
35+
fmt.Printf("init cli log err[%v]", err)
3536
return
3637
}
37-
cfscli := setupCommands(cfg)
38-
err = cfscli.Execute()
38+
cfsCli := setupCommands(cfg)
39+
if err = cfsCli.Execute(); err != nil {
40+
log.LogErrorf("Command fail, err:%v", err)
41+
}
3942
return
4043
}
4144

4245
func setupCommands(cfg *cmd.Config) *cobra.Command {
4346
var mc = master.NewMasterClient(cfg.MasterAddr, false)
44-
mc.DataNodeProfPort = cfg.DataNodeProfPort
45-
mc.MetaNodeProfPort = cfg.MetaNodeProfPort
47+
mc.SetTimeout(cfg.Timeout)
4648
cfsRootCmd := cmd.NewRootCmd(mc)
4749
var completionCmd = &cobra.Command{
4850
Use: "completion",
@@ -75,7 +77,10 @@ following command to execute:
7577

7678
func main() {
7779
var err error
80+
_, err = log.InitLog("/tmp/cfs", "cli", log.DebugLevel, nil)
81+
defer log.LogFlush()
7882
if err = runCLI(); err != nil {
83+
log.LogFlush()
7984
_, _ = fmt.Fprintf(os.Stderr, "Error: %v\n", err)
8085
os.Exit(1)
8186
}

cli/cmd/cluster.go

+42-26
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package cmd
1616

1717
import (
1818
"fmt"
19-
"os"
2019
"strconv"
2120

2221
"github.com/chubaofs/chubaofs/proto"
@@ -65,14 +64,12 @@ func newClusterInfoCmd(client *master.MasterClient) *cobra.Command {
6564
var cv *proto.ClusterView
6665
var delPara map[string]string
6766
if cv, err = client.AdminAPI().GetCluster(); err != nil {
68-
errout("Get cluster info fail:\n%v\n", err)
69-
os.Exit(1)
67+
errout("Error: %v", err)
7068
}
7169
stdout("[Cluster]\n")
7270
stdout(formatClusterView(cv))
7371
if delPara, err = client.AdminAPI().GetDeleteParas(); err != nil {
74-
errout("Get delete param fail:\n%v\n", err)
75-
os.Exit(1)
72+
errout("Error: %v", err)
7673
}
7774
stdout(fmt.Sprintf(" BatchCount : %v\n", delPara[nodeDeleteBatchCountKey]))
7875
stdout(fmt.Sprintf(" MarkDeleteRate : %v\n", delPara[nodeMarkDeleteRateKey]))
@@ -89,11 +86,18 @@ func newClusterStatCmd(client *master.MasterClient) *cobra.Command {
8986
Use: CliOpStatus,
9087
Short: cmdClusterStatShort,
9188
Run: func(cmd *cobra.Command, args []string) {
92-
var err error
93-
var cs *proto.ClusterStatInfo
89+
var (
90+
err error
91+
cs *proto.ClusterStatInfo
92+
)
93+
defer func() {
94+
if err != nil {
95+
errout("Error: %v", err)
96+
}
97+
}()
9498
if cs, err = client.AdminAPI().GetClusterStat(); err != nil {
95-
errout("Get cluster info fail:\n%v\n", err)
96-
os.Exit(1)
99+
err = fmt.Errorf("Get cluster info fail:\n%v\n", err)
100+
return
97101
}
98102
stdout("[Cluster Status]\n")
99103
stdout(formatClusterStat(cs))
@@ -105,26 +109,32 @@ func newClusterStatCmd(client *master.MasterClient) *cobra.Command {
105109

106110
func newClusterFreezeCmd(client *master.MasterClient) *cobra.Command {
107111
var cmd = &cobra.Command{
108-
Use: CliOpFreeze + " [ENABLE]",
112+
Use: CliOpFreeze + " [ENABLE]",
109113
ValidArgs: []string{"true", "false"},
110-
Short: cmdClusterFreezeShort,
111-
Args: cobra.MinimumNArgs(1),
114+
Short: cmdClusterFreezeShort,
115+
Args: cobra.MinimumNArgs(1),
112116
Long: `Turn on or off the automatic allocation of the data partitions.
113117
If 'freeze=false', ChubaoFS WILL automatically allocate new data partitions for the volume when:
114118
1. the used space is below the max capacity,
115119
2. and the number of r&w data partition is less than 20.
116120
117121
If 'freeze=true', ChubaoFS WILL NOT automatically allocate new data partitions `,
118122
Run: func(cmd *cobra.Command, args []string) {
119-
var err error
120-
var enable bool
123+
var (
124+
err error
125+
enable bool
126+
)
127+
defer func() {
128+
if err != nil {
129+
errout("Error: %v", err)
130+
}
131+
}()
121132
if enable, err = strconv.ParseBool(args[0]); err != nil {
122-
errout("Parse bool fail: %v\n", err)
123-
os.Exit(1)
133+
err = fmt.Errorf("Parse bool fail: %v\n", err)
134+
return
124135
}
125136
if err = client.AdminAPI().IsFreezeCluster(enable); err != nil {
126-
errout("Failed: %v\n", err)
127-
os.Exit(1)
137+
return
128138
}
129139
if enable {
130140
stdout("Freeze cluster successful!\n")
@@ -144,19 +154,25 @@ func newClusterSetThresholdCmd(client *master.MasterClient) *cobra.Command {
144154
Long: `Set the threshold of memory on each meta node.
145155
If the memory usage reaches this threshold, all the mata partition will be readOnly.`,
146156
Run: func(cmd *cobra.Command, args []string) {
147-
var err error
148-
var threshold float64
157+
var (
158+
err error
159+
threshold float64
160+
)
161+
defer func() {
162+
if err != nil {
163+
errout("Error: %v", err)
164+
}
165+
}()
149166
if threshold, err = strconv.ParseFloat(args[0], 64); err != nil {
150-
errout("Parse Float fail: %v\n", err)
151-
os.Exit(1)
167+
err = fmt.Errorf("Parse Float fail: %v\n", err)
168+
return
152169
}
153170
if threshold > 1.0 {
154-
errout("Threshold too big\n")
155-
os.Exit(1)
171+
err = fmt.Errorf("Threshold too big\n")
172+
return
156173
}
157174
if err = client.AdminAPI().SetMetaNodeThreshold(threshold); err != nil {
158-
errout("Failed: %v\n", err)
159-
os.Exit(1)
175+
return
160176
}
161177
stdout("MetaNode threshold is set to %v!\n", threshold)
162178
},

cli/cmd/compatibility.go

+22-20
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@
1515
package cmd
1616

1717
import (
18-
"os"
18+
"fmt"
1919
"github.com/chubaofs/chubaofs/cli/api"
20-
"github.com/spf13/cobra"
2120
"github.com/chubaofs/chubaofs/metanode"
22-
"fmt"
23-
"strconv"
24-
"github.com/chubaofs/chubaofs/util/log"
2521
"github.com/chubaofs/chubaofs/proto"
22+
"github.com/spf13/cobra"
2623
"reflect"
24+
"strconv"
2725
)
2826

2927
const (
@@ -55,24 +53,21 @@ func newMetaCompatibilityCmd() *cobra.Command {
5553
Aliases: []string{"meta"},
5654
Args: cobra.MinimumNArgs(3),
5755
Run: func(cmd *cobra.Command, args []string) {
58-
var err error
5956
var (
57+
err error
6058
snapshotPath = args[0]
6159
host = args[1]
6260
pid = args[2]
6361
)
6462
client := api.NewMetaHttpClient(host, false)
6563
defer func() {
6664
if err != nil {
67-
errout("Verify metadata consistency failed: %v\n", err)
68-
log.LogError(err)
69-
log.LogFlush()
70-
os.Exit(1)
65+
errout("Error: %v", err)
7166
}
7267
}()
7368
id, err := strconv.ParseUint(pid, 10, 64)
7469
if err != nil {
75-
errout("parse pid[%v] failed: %v\n", pid, err)
70+
err = fmt.Errorf("parse pid[%v] failed: %v\n", pid, err)
7671
return
7772
}
7873
cursor, err := client.GetMetaPartition(id)
@@ -90,11 +85,9 @@ func newMetaCompatibilityCmd() *cobra.Command {
9085
}
9186
stdout("[Meta partition is %v, verify result]\n", id)
9287
if err = verifyDentry(client, mp); err != nil {
93-
stdout("%v\n", err)
9488
return
9589
}
9690
if err = verifyInode(client, mp); err != nil {
97-
stdout("%v\n", err)
9891
return
9992
}
10093
stdout("All meta has checked\n")
@@ -111,25 +104,27 @@ func verifyDentry(client *api.MetaHttpClient, mp metanode.MetaPartition) (err er
111104
mp.GetDentryTree().Ascend(func(d metanode.BtreeItem) bool {
112105
dentry, ok := d.(*metanode.Dentry)
113106
if !ok {
114-
stdout("item type is not *metanode.Dentry")
107+
stdout("item type is not *metanode.Dentry \n")
115108
err = fmt.Errorf("item type is not *metanode.Dentry")
116-
return false
109+
return true
117110
}
118111
key := fmt.Sprintf("%v_%v", dentry.ParentId, dentry.Name)
119112
oldDentry, ok := dentryMap[key]
120113
if !ok {
121-
stdout("dentry %v is not in old version", key)
114+
stdout("dentry %v is not in old version \n", key)
122115
err = fmt.Errorf("dentry %v is not in old version", key)
123116
return false
124117
}
125118
if !reflect.DeepEqual(dentry, oldDentry) {
126-
stdout("dentry %v is not equal with old version", key)
119+
stdout("dentry %v is not equal with old version \n", key)
127120
err = fmt.Errorf("dentry %v is not equal with old version,dentry[%v],oldDentry[%v]", key, dentry, oldDentry)
128121
return false
129122
}
130123
return true
131124
})
132-
stdout("The number of dentry is %v, all dentry are consistent \n", mp.GetDentryTree().Len())
125+
if err == nil {
126+
stdout("The number of dentry is %v, all dentry are consistent \n", mp.GetDentryTree().Len())
127+
}
133128
return
134129
}
135130

@@ -142,12 +137,15 @@ func verifyInode(client *api.MetaHttpClient, mp metanode.MetaPartition) (err err
142137
mp.GetInodeTree().Ascend(func(d metanode.BtreeItem) bool {
143138
inode, ok := d.(*metanode.Inode)
144139
if !ok {
140+
stdout("item type is not *metanode.Inode \n")
141+
err = fmt.Errorf("item type is not *metanode.Inode")
145142
return true
146143
}
147144
oldInode, ok := inodesMap[inode.Inode]
148145
if !ok {
149146
stdout("inode %v is not in old version \n", inode.Inode)
150-
return true
147+
err = fmt.Errorf("inode %v is not in old version", inode.Inode)
148+
return false
151149
}
152150
localInode = &api.Inode{
153151
Inode: inode.Inode,
@@ -171,9 +169,13 @@ func verifyInode(client *api.MetaHttpClient, mp metanode.MetaPartition) (err err
171169
})
172170
if !reflect.DeepEqual(oldInode, localInode) {
173171
stdout("inode %v is not equal with old version,inode[%v],oldInode[%v]\n", inode.Inode, inode, oldInode)
172+
err = fmt.Errorf("inode %v is not equal with old version,inode[%v],oldInode[%v]\n", inode.Inode, inode, oldInode)
173+
return false
174174
}
175175
return true
176176
})
177-
stdout("The number of inodes is %v, all inodes are consistent \n", mp.GetInodeTree().Len())
177+
if err == nil {
178+
stdout("The number of inodes is %v, all inodes are consistent \n", mp.GetInodeTree().Len())
179+
}
178180
return
179181
}

0 commit comments

Comments
 (0)