cubefs

Форк
0
/
admin_proto.go 
1225 строк · 36.6 Кб
1
// Copyright 2018 The CubeFS Authors.
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
12
// implied. See the License for the specific language governing
13
// permissions and limitations under the License.
14

15
package proto
16

17
import (
18
	"encoding/json"
19
	"fmt"
20
	"strconv"
21
	"time"
22

23
	"github.com/cubefs/cubefs/util"
24
)
25

26
// api
27
const (
28
	// Admin APIs
29
	AdminGetMasterApiList                     = "/admin/getMasterApiList"
30
	AdminSetApiQpsLimit                       = "/admin/setApiQpsLimit"
31
	AdminGetApiQpsLimit                       = "/admin/getApiQpsLimit"
32
	AdminRemoveApiQpsLimit                    = "/admin/rmApiQpsLimit"
33
	AdminGetCluster                           = "/admin/getCluster"
34
	AdminSetClusterInfo                       = "/admin/setClusterInfo"
35
	AdminGetMonitorPushAddr                   = "/admin/getMonitorPushAddr"
36
	AdminGetDataPartition                     = "/dataPartition/get"
37
	AdminLoadDataPartition                    = "/dataPartition/load"
38
	AdminCreateDataPartition                  = "/dataPartition/create"
39
	AdminCreatePreLoadDataPartition           = "/dataPartition/createPreLoad"
40
	AdminDecommissionDataPartition            = "/dataPartition/decommission"
41
	AdminDiagnoseDataPartition                = "/dataPartition/diagnose"
42
	AdminResetDataPartitionDecommissionStatus = "/dataPartition/resetDecommissionStatus"
43
	AdminQueryDataPartitionDecommissionStatus = "/dataPartition/queryDecommissionStatus"
44
	AdminDeleteDataReplica                    = "/dataReplica/delete"
45
	AdminAddDataReplica                       = "/dataReplica/add"
46
	AdminDeleteVol                            = "/vol/delete"
47
	AdminUpdateVol                            = "/vol/update"
48
	AdminVolShrink                            = "/vol/shrink"
49
	AdminVolExpand                            = "/vol/expand"
50
	AdminVolForbidden                         = "/vol/forbidden"
51
	AdminVolEnableAuditLog                    = "/vol/auditlog"
52
	AdminCreateVol                            = "/admin/createVol"
53
	AdminGetVol                               = "/admin/getVol"
54
	AdminClusterFreeze                        = "/cluster/freeze"
55
	AdminClusterForbidMpDecommission          = "/cluster/forbidMetaPartitionDecommission"
56
	AdminClusterStat                          = "/cluster/stat"
57
	AdminSetCheckDataReplicasEnable           = "/cluster/setCheckDataReplicasEnable"
58
	AdminGetIP                                = "/admin/getIp"
59
	AdminCreateMetaPartition                  = "/metaPartition/create"
60
	AdminSetMetaNodeThreshold                 = "/threshold/set"
61
	AdminListVols                             = "/vol/list"
62
	AdminSetNodeInfo                          = "/admin/setNodeInfo"
63
	AdminGetNodeInfo                          = "/admin/getNodeInfo"
64
	AdminGetAllNodeSetGrpInfo                 = "/admin/getDomainInfo"
65
	AdminGetNodeSetGrpInfo                    = "/admin/getDomainNodeSetGrpInfo"
66
	AdminGetIsDomainOn                        = "/admin/getIsDomainOn"
67
	AdminUpdateNodeSetCapcity                 = "/admin/updateNodeSetCapcity"
68
	AdminUpdateNodeSetId                      = "/admin/updateNodeSetId"
69
	AdminUpdateNodeSetNodeSelector            = "/admin/updateNodeSetNodeSelector"
70
	AdminUpdateDomainDataUseRatio             = "/admin/updateDomainDataRatio"
71
	AdminUpdateZoneExcludeRatio               = "/admin/updateZoneExcludeRatio"
72
	AdminSetNodeRdOnly                        = "/admin/setNodeRdOnly"
73
	AdminSetDpRdOnly                          = "/admin/setDpRdOnly"
74
	AdminSetConfig                            = "/admin/setConfig"
75
	AdminGetConfig                            = "/admin/getConfig"
76
	AdminDataPartitionChangeLeader            = "/dataPartition/changeleader"
77
	AdminChangeMasterLeader                   = "/master/changeleader"
78
	AdminOpFollowerPartitionsRead             = "/master/opFollowerPartitionRead"
79
	AdminUpdateDecommissionLimit              = "/admin/updateDecommissionLimit"
80
	AdminQueryDecommissionLimit               = "/admin/queryDecommissionLimit"
81
	// #nosec G101
82
	AdminQueryDecommissionToken = "/admin/queryDecommissionToken"
83
	AdminSetFileStats           = "/admin/setFileStatsEnable"
84
	AdminGetFileStats           = "/admin/getFileStatsEnable"
85
	AdminGetClusterValue        = "/admin/getClusterValue"
86
	AdminSetClusterUuidEnable   = "/admin/setClusterUuidEnable"
87
	AdminGetClusterUuid         = "/admin/getClusterUuid"
88
	AdminGenerateClusterUuid    = "/admin/generateClusterUuid"
89
	AdminSetDpDiscard           = "/admin/setDpDiscard"
90
	AdminGetDiscardDp           = "/admin/getDiscardDp"
91

92
	AdminSetConLcNodeNum  = "/admin/setConLcNodeNum"
93
	AdminGetAllLcNodeInfo = "/admin/getAllLcNodeInfo"
94

95
	AdminLcNode = "/admin/lcnode"
96

97
	AdminUpdateDecommissionDiskFactor = "/admin/updateDecommissionDiskFactor"
98
	AdminQueryDecommissionDiskLimit   = "/admin/queryDecommissionDiskLimit"
99
	AdminEnableAutoDecommissionDisk   = "/admin/enableAutoDecommissionDisk"
100
	AdminQueryAutoDecommissionDisk    = "/admin/queryAutoDecommissionDisk"
101
	// graphql master api
102
	AdminClusterAPI = "/api/cluster"
103
	AdminUserAPI    = "/api/user"
104
	AdminVolumeAPI  = "/api/volume"
105

106
	// graphql coonsole api
107
	ConsoleIQL        = "/iql"
108
	ConsoleLoginAPI   = "/login"
109
	ConsoleMonitorAPI = "/cfs_monitor"
110
	ConsoleFile       = "/file"
111
	ConsoleFileDown   = "/file/down"
112
	ConsoleFileUpload = "/file/upload"
113

114
	// Client APIs
115
	ClientDataPartitions = "/client/partitions"
116
	ClientVol            = "/client/vol"
117
	ClientMetaPartition  = "/metaPartition/get"
118
	ClientVolStat        = "/client/volStat"
119
	ClientMetaPartitions = "/client/metaPartitions"
120

121
	// qos api
122
	QosGetStatus           = "/qos/getStatus"
123
	QosGetClientsLimitInfo = "/qos/getClientsInfo"
124
	QosGetZoneLimitInfo    = "/qos/getZoneLimit" // include disk enable
125
	QosUpdate              = "/qos/update"       // include disk enable
126
	QosUpdateMagnify       = "/qos/updateMagnify"
127
	QosUpdateClientParam   = "/qos/updateClientParam"
128
	QosUpdateZoneLimit     = "/qos/updateZoneLimit" // include disk enable
129
	QosUpload              = "/admin/qosUpload"
130
	QosUpdateMasterLimit   = "/qos/masterLimit"
131

132
	// acl api
133
	AdminACL = "/admin/aclOp"
134
	// uid api
135
	AdminUid = "/admin/uidOp"
136

137
	// raft node APIs
138
	AddRaftNode    = "/raftNode/add"
139
	RemoveRaftNode = "/raftNode/remove"
140
	RaftStatus     = "/get/raftStatus"
141

142
	// node APIs
143

144
	AddDataNode                        = "/dataNode/add"
145
	DecommissionDataNode               = "/dataNode/decommission"
146
	QueryDataNodeDecoProgress          = "/dataNode/queryDecommissionProgress"
147
	QueryDataNodeDecoFailedDps         = "/dataNode/queryDecommissionFailedDps"
148
	MigrateDataNode                    = "/dataNode/migrate"
149
	CancelDecommissionDataNode         = "/dataNode/cancelDecommission"
150
	DecommissionDisk                   = "/disk/decommission"
151
	RecommissionDisk                   = "/disk/recommission"
152
	QueryDiskDecoProgress              = "/disk/queryDecommissionProgress"
153
	MarkDecoDiskFixed                  = "/disk/MarkDecommissionDiskFixed"
154
	CancelDecommissionDisk             = "/disk/cancelDecommission"
155
	QueryDecommissionDiskDecoFailedDps = "/disk/queryDecommissionFailedDps"
156
	QueryBadDisks                      = "/disk/queryBadDisks"
157
	RestoreStoppedAutoDecommissionDisk = "/disk/restoreStoppedAutoDecommissionDisk"
158
	QueryAllDecommissionDisk           = "/disk/queryAllDecommissionDisk"
159
	GetDataNode                        = "/dataNode/get"
160
	AddMetaNode                        = "/metaNode/add"
161
	DecommissionMetaNode               = "/metaNode/decommission"
162
	MigrateMetaNode                    = "/metaNode/migrate"
163
	GetMetaNode                        = "/metaNode/get"
164
	AdminUpdateMetaNode                = "/metaNode/update"
165
	AdminUpdateDataNode                = "/dataNode/update"
166
	AdminGetInvalidNodes               = "/invalid/nodes"
167
	AdminLoadMetaPartition             = "/metaPartition/load"
168
	AdminDiagnoseMetaPartition         = "/metaPartition/diagnose"
169
	AdminDecommissionMetaPartition     = "/metaPartition/decommission"
170
	AdminChangeMetaPartitionLeader     = "/metaPartition/changeleader"
171
	AdminBalanceMetaPartitionLeader    = "/metaPartition/balanceLeader"
172
	AdminAddMetaReplica                = "/metaReplica/add"
173
	AdminDeleteMetaReplica             = "/metaReplica/delete"
174
	AdminPutDataPartitions             = "/dataPartitions/set"
175

176
	// admin multi version snapshot
177
	AdminCreateVersion     = "/multiVer/create"
178
	AdminDelVersion        = "/multiVer/del"
179
	AdminGetVersionInfo    = "/multiVer/get"
180
	AdminGetAllVersionInfo = "/multiVer/getAll"
181
	AdminGetVolVer         = "/vol/getVer"
182
	AdminSetVerStrategy    = "/vol/SetVerStrategy"
183

184
	// S3 lifecycle configuration APIS
185
	SetBucketLifecycle    = "/s3/setLifecycle"
186
	GetBucketLifecycle    = "/s3/getLifecycle"
187
	DeleteBucketLifecycle = "/s3/deleteLifecycle"
188

189
	AddLcNode = "/lcNode/add"
190

191
	QueryDisableDisk = "/dataNode/queryDisableDisk"
192
	// Operation response
193
	GetMetaNodeTaskResponse = "/metaNode/response" // Method: 'POST', ContentType: 'application/json'
194
	GetDataNodeTaskResponse = "/dataNode/response" // Method: 'POST', ContentType: 'application/json'
195
	GetLcNodeTaskResponse   = "/lcNode/response"   // Method: 'POST', ContentType: 'application/json'
196

197
	GetTopologyView = "/topo/get"
198
	UpdateZone      = "/zone/update"
199
	GetAllZones     = "/zone/list"
200
	GetAllNodeSets  = "/nodeSet/list"
201
	GetNodeSet      = "/nodeSet/get"
202
	UpdateNodeSet   = "/nodeSet/update"
203

204
	// Header keys
205
	SkipOwnerValidation = "Skip-Owner-Validation"
206
	ForceDelete         = "Force-Delete"
207

208
	// APIs for user management
209
	UserCreate          = "/user/create"
210
	UserDelete          = "/user/delete"
211
	UserUpdate          = "/user/update"
212
	UserUpdatePolicy    = "/user/updatePolicy"
213
	UserRemovePolicy    = "/user/removePolicy"
214
	UserDeleteVolPolicy = "/user/deleteVolPolicy"
215
	UserGetInfo         = "/user/info"
216
	UserGetAKInfo       = "/user/akInfo"
217
	UserTransferVol     = "/user/transferVol"
218
	UserList            = "/user/list"
219
	UsersOfVol          = "/vol/users"
220
	// graphql api for header
221
	HeadAuthorized  = "Authorization"
222
	ParamAuthorized = "_authorization"
223
	UserKey         = "_user_key"
224
	UserInfoKey     = "_user_info_key"
225
	// quota
226
	QuotaCreate = "/quota/create"
227
	QuotaUpdate = "/quota/update"
228
	QuotaDelete = "/quota/delete"
229
	QuotaList   = "/quota/list"
230
	QuotaGet    = "/quota/get"
231
	// QuotaBatchModifyPath = "/quota/batchModifyPath"
232
	QuotaListAll = "/quota/listAll"
233

234
	// s3 qos api
235
	S3QoSSet    = "/s3/qos/set"
236
	S3QoSGet    = "/s3/qos/get"
237
	S3QoSDelete = "/s3/qos/delete"
238
)
239

240
var GApiInfo map[string]string = map[string]string{
241
	"admingetmasterapilist":            AdminGetMasterApiList,
242
	"adminsetapiqpslimit":              AdminSetApiQpsLimit,
243
	"admingetcluster":                  AdminGetCluster,
244
	"adminsetclusterinfo":              AdminSetClusterInfo,
245
	"admingetdatapartition":            AdminGetDataPartition,
246
	"adminloaddatapartition":           AdminLoadDataPartition,
247
	"admincreatedatapartition":         AdminCreateDataPartition,
248
	"admincreatepreloaddatapartition":  AdminCreatePreLoadDataPartition,
249
	"admindecommissiondatapartition":   AdminDecommissionDataPartition,
250
	"admindiagnosedatapartition":       AdminDiagnoseDataPartition,
251
	"admindeletedatareplica":           AdminDeleteDataReplica,
252
	"adminadddatareplica":              AdminAddDataReplica,
253
	"admindeletevol":                   AdminDeleteVol,
254
	"adminupdatevol":                   AdminUpdateVol,
255
	"adminvolshrink":                   AdminVolShrink,
256
	"adminvolexpand":                   AdminVolExpand,
257
	"admincreatevol":                   AdminCreateVol,
258
	"admingetvol":                      AdminGetVol,
259
	"adminclusterfreeze":               AdminClusterFreeze,
260
	"adminclusterforbidmpdecommission": AdminClusterForbidMpDecommission,
261
	"adminclusterstat":                 AdminClusterStat,
262
	"admingetip":                       AdminGetIP,
263
	"admincreatemetapartition":         AdminCreateMetaPartition,
264
	"adminsetmetanodethreshold":        AdminSetMetaNodeThreshold,
265
	"adminlistvols":                    AdminListVols,
266
	"adminsetnodeinfo":                 AdminSetNodeInfo,
267
	"admingetnodeinfo":                 AdminGetNodeInfo,
268
	"admingetallnodesetgrpinfo":        AdminGetAllNodeSetGrpInfo,
269
	"admingetnodesetgrpinfo":           AdminGetNodeSetGrpInfo,
270
	"admingetisdomainon":               AdminGetIsDomainOn,
271
	"adminupdatenodesetcapcity":        AdminUpdateNodeSetCapcity,
272
	"adminupdatenodesetid":             AdminUpdateNodeSetId,
273
	"adminupdatedomaindatauseratio":    AdminUpdateDomainDataUseRatio,
274
	"adminupdatezoneexcluderatio":      AdminUpdateZoneExcludeRatio,
275
	"adminsetnoderdonly":               AdminSetNodeRdOnly,
276
	"adminsetdprdonly":                 AdminSetDpRdOnly,
277
	"admindatapartitionchangeleader":   AdminDataPartitionChangeLeader,
278
	"adminsetdpdiscard":                AdminSetDpDiscard,
279
	"admingetdiscarddp":                AdminGetDiscardDp,
280

281
	//"adminclusterapi":                 AdminClusterAPI,
282
	//"adminuserapi":                    AdminUserAPI,
283
	//"adminvolumeapi":                  AdminVolumeAPI,
284
	//"consoleiql":                      ConsoleIQL,
285
	//"consoleloginapi":                 ConsoleLoginAPI,
286
	//"consolemonitorapi":               ConsoleMonitorAPI,
287
	//"consolefile":                     ConsoleFile,
288
	//"consolefiledown":                 ConsoleFileDown,
289
	//"consolefileupload":               ConsoleFileUpload,
290
	"clientdatapartitions":   ClientDataPartitions,
291
	"clientvol":              ClientVol,
292
	"clientmetapartition":    ClientMetaPartition,
293
	"clientvolstat":          ClientVolStat,
294
	"clientmetapartitions":   ClientMetaPartitions,
295
	"qosgetstatus":           QosGetStatus,
296
	"qosgetclientslimitinfo": QosGetClientsLimitInfo,
297
	"qosgetzonelimitinfo":    QosGetZoneLimitInfo,
298
	"qosupdate":              QosUpdate,
299
	//"qosupdatemagnify":               QosUpdateMagnify,
300
	"qosupdateclientparam":            QosUpdateClientParam,
301
	"qosupdatezonelimit":              QosUpdateZoneLimit,
302
	"qosupload":                       QosUpload,
303
	"qosupdatemasterlimit":            QosUpdateMasterLimit,
304
	"addraftnode":                     AddRaftNode,
305
	"removeraftnode":                  RemoveRaftNode,
306
	"raftstatus":                      RaftStatus,
307
	"adddatanode":                     AddDataNode,
308
	"decommissiondatanode":            DecommissionDataNode,
309
	"migratedatanode":                 MigrateDataNode,
310
	"canceldecommissiondatanode":      CancelDecommissionDataNode,
311
	"decommissiondisk":                DecommissionDisk,
312
	"getdatanode":                     GetDataNode,
313
	"addmetanode":                     AddMetaNode,
314
	"decommissionmetanode":            DecommissionMetaNode,
315
	"migratemetanode":                 MigrateMetaNode,
316
	"getmetanode":                     GetMetaNode,
317
	"adminupdatemetanode":             AdminUpdateMetaNode,
318
	"adminupdatedatanode":             AdminUpdateDataNode,
319
	"admingetinvalidnodes":            AdminGetInvalidNodes,
320
	"adminloadmetapartition":          AdminLoadMetaPartition,
321
	"admindiagnosemetapartition":      AdminDiagnoseMetaPartition,
322
	"admindecommissionmetapartition":  AdminDecommissionMetaPartition,
323
	"adminchangemetapartitionleader":  AdminChangeMetaPartitionLeader,
324
	"adminbalancemetapartitionleader": AdminBalanceMetaPartitionLeader,
325
	"adminaddmetareplica":             AdminAddMetaReplica,
326
	"admindeletemetareplica":          AdminDeleteMetaReplica,
327
	"getmetanodetaskresponse":         GetMetaNodeTaskResponse,
328
	"getdatanodetaskresponse":         GetDataNodeTaskResponse,
329
	"gettopologyview":                 GetTopologyView,
330
	"updatezone":                      UpdateZone,
331
	"getallzones":                     GetAllZones,
332
	"usercreate":                      UserCreate,
333
	"userdelete":                      UserDelete,
334
	"userupdate":                      UserUpdate,
335
	"userupdatepolicy":                UserUpdatePolicy,
336
	"userremovepolicy":                UserRemovePolicy,
337
	"userdeletevolpolicy":             UserDeleteVolPolicy,
338
	"usergetinfo":                     UserGetInfo,
339
	"usergetakinfo":                   UserGetAKInfo,
340
	"usertransfervol":                 UserTransferVol,
341
	"userlist":                        UserList,
342
	"usersofvol":                      UsersOfVol,
343
}
344

345
// const TimeFormat = "2006-01-02 15:04:05"
346

347
const (
348
	TimeFormat                 = "2006-01-02 15:04:05"
349
	DefaultDirChildrenNumLimit = 20000000
350
	MinDirChildrenNumLimit     = 1000000
351
)
352

353
// HTTPReply uniform response structure
354
type HTTPReply struct {
355
	Code int32       `json:"code"`
356
	Msg  string      `json:"msg"`
357
	Data interface{} `json:"data"`
358
}
359

360
type HTTPReplyRaw struct {
361
	Code int32           `json:"code"`
362
	Msg  string          `json:"msg"`
363
	Data json.RawMessage `json:"data"`
364
}
365

366
func (raw *HTTPReplyRaw) Unmarshal(body []byte) error {
367
	r := new(HTTPReplyRaw)
368
	if err := json.Unmarshal(body, r); err != nil {
369
		return fmt.Errorf("httpreply unmarshal [%s]", err.Error())
370
	}
371
	*raw = *r
372
	return nil
373
}
374

375
func (raw *HTTPReplyRaw) Success() error {
376
	if code := raw.Code; code != ErrCodeSuccess {
377
		err := ParseErrorCode(code)
378
		return fmt.Errorf("httpreply code[%d] err[%s] msg[%s]", code, err.Error(), raw.Msg)
379
	}
380
	return nil
381
}
382

383
func (raw *HTTPReplyRaw) Bytes() []byte {
384
	return raw.Data
385
}
386

387
func (raw *HTTPReplyRaw) String() string {
388
	return string(raw.Bytes())
389
}
390

391
func (raw *HTTPReplyRaw) Int64() (int64, error) {
392
	return strconv.ParseInt(string(raw.Data), 10, 64)
393
}
394

395
func (raw *HTTPReplyRaw) Uint64() (uint64, error) {
396
	return strconv.ParseUint(string(raw.Data), 10, 64)
397
}
398

399
func (raw *HTTPReplyRaw) Result(result interface{}) error {
400
	return json.Unmarshal(raw.Data, result)
401
}
402

403
func UnmarshalHTTPReply(body []byte, result interface{}) error {
404
	raw := new(HTTPReplyRaw)
405
	if err := raw.Unmarshal(body); err != nil {
406
		return err
407
	}
408
	if err := raw.Success(); err != nil {
409
		return err
410
	}
411

412
	if result == nil {
413
		return nil
414
	}
415
	switch v := result.(type) {
416
	case *string:
417
		*v = raw.String()
418
	case *int64:
419
		val, err := raw.Int64()
420
		if err != nil {
421
			return err
422
		}
423
		*v = val
424
	case *uint64:
425
		val, err := raw.Uint64()
426
		if err != nil {
427
			return err
428
		}
429
		*v = val
430
	default:
431
		return raw.Result(result)
432
	}
433
	return nil
434
}
435

436
// RegisterMetaNodeResp defines the response to register a meta node.
437
type RegisterMetaNodeResp struct {
438
	ID uint64
439
}
440

441
type AclIpInfo struct {
442
	Ip    string
443
	CTime int64
444
}
445

446
type AclRsp struct {
447
	Info    string
448
	OK      bool
449
	List    []*AclIpInfo
450
	Reserve string
451
}
452

453
type UidSpaceRsp struct {
454
	Info        string
455
	OK          bool
456
	UidSpaceArr []*UidSpaceInfo
457
	Reserve     string
458
}
459

460
type VolumeVerStrategy struct {
461
	KeepVerCnt  int
462
	Periodic    int
463
	Enable      bool
464
	ForceUpdate bool
465
	UTime       time.Time
466
}
467

468
func (v *VolumeVerStrategy) GetPeriodic() int {
469
	return v.Periodic
470
}
471

472
func (v *VolumeVerStrategy) GetPeriodicSecond() int {
473
	// return v.Periodic*24*3600
474
	return v.Periodic * 3600
475
}
476

477
func (v *VolumeVerStrategy) TimeUp(curTime time.Time) bool {
478
	return v.UTime.Add(time.Second * time.Duration(v.GetPeriodicSecond())).Before(curTime)
479
}
480

481
type VolumeVerInfo struct {
482
	Name             string
483
	VerSeq           uint64
484
	VerSeqPrepare    uint64
485
	VerPrepareStatus uint8
486
	Enabled          bool
487
}
488

489
// ClusterInfo defines the cluster infomation.
490
type ClusterInfo struct {
491
	Cluster                     string
492
	Ip                          string
493
	MetaNodeDeleteBatchCount    uint64
494
	MetaNodeDeleteWorkerSleepMs uint64
495
	DataNodeDeleteLimitRate     uint64
496
	DataNodeAutoRepairLimitRate uint64
497
	DpMaxRepairErrCnt           uint64
498
	DirChildrenNumLimit         uint32
499
	EbsAddr                     string
500
	ServicePath                 string
501
	ClusterUuid                 string
502
	ClusterUuidEnable           bool
503
}
504

505
// CreateDataPartitionRequest defines the request to create a data partition.
506
type CreateDataPartitionRequest struct {
507
	PartitionTyp        int
508
	PartitionId         uint64
509
	PartitionSize       int
510
	ReplicaNum          int
511
	VolumeId            string
512
	IsRandomWrite       bool
513
	Members             []Peer
514
	Hosts               []string
515
	CreateType          int
516
	LeaderSize          int
517
	DecommissionedDisks []string
518
	IsMultiVer          bool
519
	VerSeq              uint64
520
}
521

522
// CreateDataPartitionResponse defines the response to the request of creating a data partition.
523
type CreateDataPartitionResponse struct {
524
	PartitionId uint64
525
	Status      uint8
526
	Result      string
527
}
528

529
// DeleteDataPartitionRequest defines the request to delete a data partition.
530
type DeleteDataPartitionRequest struct {
531
	DataPartitionType string
532
	PartitionId       uint64
533
	PartitionSize     int
534
}
535

536
// DeleteDataPartitionResponse defines the response to the request of deleting a data partition.
537
type DeleteDataPartitionResponse struct {
538
	Status      uint8
539
	Result      string
540
	PartitionId uint64
541
}
542

543
// DataPartitionDecommissionRequest defines the request of decommissioning a data partition.
544
type DataPartitionDecommissionRequest struct {
545
	PartitionId uint64
546
	RemovePeer  Peer
547
	AddPeer     Peer
548
}
549

550
// AddDataPartitionRaftMemberRequest defines the request of add raftMember a data partition.
551
type AddDataPartitionRaftMemberRequest struct {
552
	PartitionId uint64
553
	AddPeer     Peer
554
}
555

556
// RemoveDataPartitionRaftMemberRequest defines the request of add raftMember a data partition.
557
type RemoveDataPartitionRaftMemberRequest struct {
558
	PartitionId uint64
559
	RemovePeer  Peer
560
	Force       bool
561
}
562

563
// AddMetaPartitionRaftMemberRequest defines the request of add raftMember a meta partition.
564
type AddMetaPartitionRaftMemberRequest struct {
565
	PartitionId uint64
566
	AddPeer     Peer
567
}
568

569
// RemoveMetaPartitionRaftMemberRequest defines the request of add raftMember a meta partition.
570
type RemoveMetaPartitionRaftMemberRequest struct {
571
	PartitionId uint64
572
	RemovePeer  Peer
573
}
574

575
// LoadDataPartitionRequest defines the request of loading a data partition.
576
type LoadDataPartitionRequest struct {
577
	PartitionId uint64
578
}
579

580
// LoadDataPartitionResponse defines the response to the request of loading a data partition.
581
type LoadDataPartitionResponse struct {
582
	PartitionId       uint64
583
	Used              uint64
584
	PartitionSnapshot []*File
585
	Status            uint8
586
	PartitionStatus   int
587
	Result            string
588
	VolName           string
589
}
590

591
type StopDataPartitionRepairRequest struct {
592
	PartitionId uint64
593
	Stop        bool
594
}
595

596
// DeleteDataPartitionResponse defines the response to the request of deleting a data partition.
597
type StopDataPartitionRepairResponse struct {
598
	Status      uint8
599
	Result      string
600
	PartitionId uint64
601
}
602

603
// File defines the file struct.
604
type File struct {
605
	Name     string
606
	Crc      uint32
607
	Size     uint32
608
	Modified int64
609
	ApplyID  uint64
610
}
611

612
// LoadMetaPartitionMetricRequest defines the request of loading the meta partition metrics.
613
type LoadMetaPartitionMetricRequest struct {
614
	PartitionID uint64
615
	Start       uint64
616
	End         uint64
617
}
618

619
// LoadMetaPartitionMetricResponse defines the response to the request of loading the meta partition metrics.
620
type LoadMetaPartitionMetricResponse struct {
621
	Start    uint64
622
	End      uint64
623
	MaxInode uint64
624
	Status   uint8
625
	Result   string
626
}
627

628
type UidLimitToMetaNode struct {
629
	UidLimitInfo []*UidSpaceInfo
630
}
631

632
type QosToDataNode struct {
633
	EnableDiskQos     bool
634
	QosIopsReadLimit  uint64
635
	QosIopsWriteLimit uint64
636
	QosFlowReadLimit  uint64
637
	QosFlowWriteLimit uint64
638
}
639

640
// MultiVersionOpRequest defines the request of
641
type MultiVersionOpRequest struct {
642
	VolumeID   string
643
	VerSeq     uint64
644
	Op         uint8
645
	Addr       string
646
	VolVerList []*VolVersionInfo
647
}
648

649
// MultiVersionOpResponse defines the response to the request of l.
650
type MultiVersionOpResponse struct {
651
	VolumeID string
652
	Addr     string
653
	Op       uint8
654
	VerSeq   uint64
655
	Status   uint8
656
	Result   string
657
}
658

659
type QuotaHeartBeatInfos struct {
660
	QuotaHbInfos []*QuotaHeartBeatInfo
661
}
662

663
type TxInfo struct {
664
	Volume     string
665
	Mask       TxOpMask
666
	OpLimitVal int
667
}
668

669
type TxInfos struct {
670
	TxInfo []*TxInfo
671
}
672

673
// HeartBeatRequest define the heartbeat request.
674
type HeartBeatRequest struct {
675
	CurrTime   int64
676
	MasterAddr string
677
	FLReadVols []string
678
	QosToDataNode
679
	FileStatsEnable bool
680
	UidLimitToMetaNode
681
	QuotaHeartBeatInfos
682
	TxInfos
683
	ForbiddenVols     []string
684
	DisableAuditVols  []string
685
	DecommissionDisks []string // NOTE: for datanode
686
}
687

688
// DataPartitionReport defines the partition report.
689
type DataPartitionReport struct {
690
	VolName                    string
691
	PartitionID                uint64
692
	PartitionStatus            int
693
	Total                      uint64
694
	Used                       uint64
695
	DiskPath                   string
696
	IsLeader                   bool
697
	ExtentCount                int
698
	NeedCompare                bool
699
	DecommissionRepairProgress float64
700
}
701

702
type DataNodeQosResponse struct {
703
	IopsRLimit uint64
704
	IopsWLimit uint64
705
	FlowRlimit uint64
706
	FlowWlimit uint64
707
	Status     uint8
708
	Result     string
709
}
710

711
type BadDiskStat struct {
712
	DiskPath             string
713
	TotalPartitionCnt    int
714
	DiskErrPartitionList []uint64
715
}
716

717
// DataNodeHeartbeatResponse defines the response to the data node heartbeat.
718
type DataNodeHeartbeatResponse struct {
719
	Total               uint64
720
	Used                uint64
721
	Available           uint64
722
	TotalPartitionSize  uint64 // volCnt * volsize
723
	RemainingCapacity   uint64 // remaining capacity to create partition
724
	CreatedPartitionCnt uint32
725
	MaxCapacity         uint64 // maximum capacity to create partition
726
	StartTime           int64
727
	ZoneName            string
728
	PartitionReports    []*DataPartitionReport
729
	Status              uint8
730
	Result              string
731
	BadDisks            []string           // Keep this old field for compatibility
732
	BadDiskStats        []BadDiskStat      // key: disk path
733
	CpuUtil             float64            `json:"cpuUtil"`
734
	IoUtils             map[string]float64 `json:"ioUtil"`
735
}
736

737
// MetaPartitionReport defines the meta partition report.
738
type MetaPartitionReport struct {
739
	PartitionID      uint64
740
	Start            uint64
741
	End              uint64
742
	Status           int
743
	Size             uint64
744
	MaxInodeID       uint64
745
	IsLeader         bool
746
	VolName          string
747
	InodeCnt         uint64
748
	DentryCnt        uint64
749
	TxCnt            uint64
750
	TxRbInoCnt       uint64
751
	TxRbDenCnt       uint64
752
	FreeListLen      uint64
753
	UidInfo          []*UidReportSpaceInfo
754
	QuotaReportInfos []*QuotaReportInfo
755
}
756

757
// MetaNodeHeartbeatResponse defines the response to the meta node heartbeat request.
758
type MetaNodeHeartbeatResponse struct {
759
	ZoneName             string
760
	Total                uint64
761
	MemUsed              uint64
762
	MetaPartitionReports []*MetaPartitionReport
763
	Status               uint8
764
	Result               string
765
	CpuUtil              float64 `json:"cpuUtil"`
766
}
767

768
// LcNodeHeartbeatResponse defines the response to the lc node heartbeat.
769
type LcNodeHeartbeatResponse struct {
770
	Status                uint8
771
	Result                string
772
	LcTaskCountLimit      int
773
	LcScanningTasks       map[string]*LcNodeRuleTaskResponse
774
	SnapshotScanningTasks map[string]*SnapshotVerDelTaskResponse
775
}
776

777
// DeleteFileRequest defines the request to delete a file.
778
type DeleteFileRequest struct {
779
	VolId uint64
780
	Name  string
781
}
782

783
// DeleteFileResponse defines the response to the request of deleting a file.
784
type DeleteFileResponse struct {
785
	Status uint8
786
	Result string
787
	VolId  uint64
788
	Name   string
789
}
790

791
// DeleteMetaPartitionRequest defines the request of deleting a meta partition.
792
type DeleteMetaPartitionRequest struct {
793
	PartitionID uint64
794
}
795

796
// DeleteMetaPartitionResponse defines the response to the request of deleting a meta partition.
797
type DeleteMetaPartitionResponse struct {
798
	PartitionID uint64
799
	Status      uint8
800
	Result      string
801
}
802

803
// UpdateMetaPartitionRequest defines the request to update a meta partition.
804
type UpdateMetaPartitionRequest struct {
805
	PartitionID uint64
806
	VolName     string
807
	Start       uint64
808
	End         uint64
809
}
810

811
// UpdateMetaPartitionResponse defines the response to the request of updating the meta partition.
812
type UpdateMetaPartitionResponse struct {
813
	PartitionID uint64
814
	VolName     string
815
	End         uint64
816
	Status      uint8
817
	Result      string
818
}
819

820
// MetaPartitionDecommissionRequest defines the request of decommissioning a meta partition.
821
type MetaPartitionDecommissionRequest struct {
822
	PartitionID uint64
823
	VolName     string
824
	RemovePeer  Peer
825
	AddPeer     Peer
826
}
827

828
// MetaPartitionDecommissionResponse defines the response to the request of decommissioning a meta partition.
829
type MetaPartitionDecommissionResponse struct {
830
	PartitionID uint64
831
	VolName     string
832
	Status      uint8
833
	Result      string
834
}
835

836
// MetaPartitionLoadRequest defines the request to load meta partition.
837
type MetaPartitionLoadRequest struct {
838
	PartitionID uint64
839
}
840

841
// MetaPartitionLoadResponse defines the response to the request of loading meta partition.
842
type MetaPartitionLoadResponse struct {
843
	PartitionID uint64
844
	DoCompare   bool
845
	ApplyID     uint64
846
	CommittedID uint64
847
	MaxInode    uint64
848
	DentryCount uint64
849
	InodeCount  uint64
850
	Addr        string
851
}
852

853
// DataPartitionResponse defines the response from a data node to the master that is related to a data partition.
854
type DataPartitionResponse struct {
855
	PartitionType int
856
	PartitionID   uint64
857
	Status        int8
858
	ReplicaNum    uint8
859
	Hosts         []string
860
	LeaderAddr    string
861
	Epoch         uint64
862
	IsRecover     bool
863
	PartitionTTL  int64
864
	IsDiscard     bool
865
}
866

867
// DataPartitionsView defines the view of a data partition
868
type DataPartitionsView struct {
869
	DataPartitions []*DataPartitionResponse
870
}
871

872
func NewDataPartitionsView() (dataPartitionsView *DataPartitionsView) {
873
	dataPartitionsView = new(DataPartitionsView)
874
	dataPartitionsView.DataPartitions = make([]*DataPartitionResponse, 0)
875
	return
876
}
877

878
// MetaPartitionView defines the view of a meta partition
879
type MetaPartitionView struct {
880
	PartitionID uint64
881
	Start       uint64
882
	End         uint64
883
	MaxInodeID  uint64
884
	InodeCount  uint64
885
	DentryCount uint64
886
	FreeListLen uint64
887
	TxCnt       uint64
888
	TxRbInoCnt  uint64
889
	TxRbDenCnt  uint64
890
	IsRecover   bool
891
	Members     []string
892
	LeaderAddr  string
893
	Status      int8
894
}
895

896
type DataNodeDisksRequest struct{}
897

898
type DataNodeDisksResponse struct{}
899

900
type OSSSecure struct {
901
	AccessKey string
902
	SecretKey string
903
}
904

905
// VolView defines the view of a volume
906
type VolView struct {
907
	Name           string
908
	Owner          string
909
	Status         uint8
910
	FollowerRead   bool
911
	MetaPartitions []*MetaPartitionView
912
	DataPartitions []*DataPartitionResponse
913
	DomainOn       bool
914
	OSSSecure      *OSSSecure
915
	CreateTime     int64
916
	DeleteLockTime int64
917
	CacheTTL       int
918
	VolType        int
919
}
920

921
func (v *VolView) SetOwner(owner string) {
922
	v.Owner = owner
923
}
924

925
func (v *VolView) SetOSSSecure(accessKey, secretKey string) {
926
	v.OSSSecure = &OSSSecure{AccessKey: accessKey, SecretKey: secretKey}
927
}
928

929
func NewVolView(name string, status uint8, followerRead bool, createTime int64, cacheTTL int, volType int, deleteLockTime int64) (view *VolView) {
930
	view = new(VolView)
931
	view.Name = name
932
	view.FollowerRead = followerRead
933
	view.CreateTime = createTime
934
	view.DeleteLockTime = deleteLockTime
935
	view.Status = status
936
	view.MetaPartitions = make([]*MetaPartitionView, 0)
937
	view.DataPartitions = make([]*DataPartitionResponse, 0)
938
	view.CacheTTL = cacheTTL
939
	view.VolType = volType
940
	return
941
}
942

943
func NewMetaPartitionView(partitionID, start, end uint64, status int8) (mpView *MetaPartitionView) {
944
	mpView = new(MetaPartitionView)
945
	mpView.PartitionID = partitionID
946
	mpView.Start = start
947
	mpView.End = end
948
	mpView.Status = status
949
	mpView.Members = make([]string, 0)
950
	return
951
}
952

953
const (
954
	QosStateNormal   uint8 = 0x01
955
	QosStateHitLimit uint8 = 0x02
956

957
	MinIopsLimit uint64 = 3
958
	MinFLowLimit uint64 = 128 * util.KB
959
)
960

961
const (
962
	IopsReadType  uint32 = 0x01
963
	IopsWriteType uint32 = 0x02
964
	FlowReadType  uint32 = 0x03
965
	FlowWriteType uint32 = 0x04
966
)
967

968
const (
969
	QosDefaultBurst                   = 16000000
970
	QosDefaultClientCnt        uint32 = 100
971
	QosDefaultDiskMaxFLowLimit int    = 0x7FFFFFFF
972
	QosDefaultDiskMaxIoLimit   int    = 100000
973
)
974

975
func QosTypeString(factorType uint32) string {
976
	switch factorType {
977
	case IopsReadType:
978
		return "IopsRead"
979
	case IopsWriteType:
980
		return "IopsWrite"
981
	case FlowReadType:
982
		return "FlowRead"
983
	case FlowWriteType:
984
		return "FlowWrite"
985
	default:
986
		return "unkown"
987
	}
988
}
989

990
type ClientLimitInfo struct {
991
	UsedLimit  uint64
992
	UsedBuffer uint64
993
	Used       uint64
994
	Need       uint64
995
}
996

997
type ClientReportLimitInfo struct {
998
	ID        uint64
999
	FactorMap map[uint32]*ClientLimitInfo
1000
	Host      string
1001
	Status    uint8
1002
	_         string // reserved
1003
}
1004

1005
func NewClientReportLimitInfo() *ClientReportLimitInfo {
1006
	return &ClientReportLimitInfo{
1007
		FactorMap: make(map[uint32]*ClientLimitInfo),
1008
	}
1009
}
1010

1011
type LimitRsp2Client struct {
1012
	ID            uint64
1013
	Enable        bool
1014
	ReqPeriod     uint32
1015
	HitTriggerCnt uint8
1016
	FactorMap     map[uint32]*ClientLimitInfo
1017
	Magnify       map[uint32]uint32
1018
	_             string // reserved
1019
}
1020

1021
func NewLimitRsp2Client() *LimitRsp2Client {
1022
	limit := &LimitRsp2Client{
1023
		FactorMap: make(map[uint32]*ClientLimitInfo),
1024
		Magnify:   make(map[uint32]uint32),
1025
	}
1026
	return limit
1027
}
1028

1029
type UidSimpleInfo struct {
1030
	UID     uint32
1031
	Limited bool
1032
}
1033

1034
// SimpleVolView defines the simple view of a volume
1035
type SimpleVolView struct {
1036
	ID                      uint64
1037
	Name                    string
1038
	Owner                   string
1039
	ZoneName                string
1040
	DpReplicaNum            uint8
1041
	MpReplicaNum            uint8
1042
	InodeCount              uint64
1043
	DentryCount             uint64
1044
	MaxMetaPartitionID      uint64
1045
	Status                  uint8
1046
	Capacity                uint64 // GB
1047
	RwDpCnt                 int
1048
	MpCnt                   int
1049
	DpCnt                   int
1050
	FollowerRead            bool
1051
	NeedToLowerReplica      bool
1052
	Authenticate            bool
1053
	CrossZone               bool
1054
	DefaultPriority         bool
1055
	DomainOn                bool
1056
	CreateTime              string
1057
	DeleteLockTime          int64
1058
	EnableToken             bool
1059
	EnablePosixAcl          bool
1060
	EnableQuota             bool
1061
	EnableTransaction       string
1062
	TxTimeout               int64
1063
	TxConflictRetryNum      int64
1064
	TxConflictRetryInterval int64
1065
	TxOpLimit               int
1066
	Description             string
1067
	DpSelectorName          string
1068
	DpSelectorParm          string
1069
	DefaultZonePrior        bool
1070
	DpReadOnlyWhenVolFull   bool
1071

1072
	VolType          int
1073
	ObjBlockSize     int
1074
	CacheCapacity    uint64
1075
	CacheAction      int
1076
	CacheThreshold   int
1077
	CacheHighWater   int
1078
	CacheLowWater    int
1079
	CacheLruInterval int
1080
	CacheTtl         int
1081
	CacheRule        string
1082
	PreloadCapacity  uint64
1083
	Uids             []UidSimpleInfo
1084
	// multi version snapshot
1085
	LatestVer      uint64
1086
	Forbidden      bool
1087
	EnableAuditLog bool
1088
}
1089

1090
type NodeSetInfo struct {
1091
	ID           uint64
1092
	ZoneName     string
1093
	Capacity     int
1094
	DataUseRatio float64
1095
	MetaUseRatio float64
1096
	MetaUsed     uint64
1097
	MetaTotal    uint64
1098
	MetaNodes    []*MetaNodeInfo
1099
	DataUsed     uint64
1100
	DataTotal    uint64
1101
	DataNodes    []*DataNodeInfo
1102
}
1103

1104
type SimpleNodeSetGrpInfo struct {
1105
	ID          uint64
1106
	Status      uint8
1107
	NodeSetInfo []NodeSetInfo
1108
}
1109

1110
type SimpleNodeSetGrpInfoList struct {
1111
	DomainId             uint64
1112
	Status               uint8
1113
	SimpleNodeSetGrpInfo []*SimpleNodeSetGrpInfo
1114
}
1115

1116
type DomainNodeSetGrpInfoList struct {
1117
	DomainOn              bool
1118
	DataRatioLimit        float64
1119
	ZoneExcludeRatioLimit float64
1120
	NeedDomain            bool
1121
	ExcludeZones          []string
1122
	DomainNodeSetGrpInfo  []*SimpleNodeSetGrpInfoList
1123
}
1124

1125
// MasterAPIAccessResp defines the response for getting meta partition
1126
type MasterAPIAccessResp struct {
1127
	APIResp APIAccessResp `json:"api_resp"`
1128
	Data    []byte        `json:"data"`
1129
}
1130

1131
type VolInfo struct {
1132
	Name                  string
1133
	Owner                 string
1134
	CreateTime            int64
1135
	Status                uint8
1136
	TotalSize             uint64
1137
	UsedSize              uint64
1138
	DpReadOnlyWhenVolFull bool
1139
}
1140

1141
func NewVolInfo(name, owner string, createTime int64, status uint8, totalSize, usedSize uint64, dpReadOnlyWhenVolFull bool) *VolInfo {
1142
	return &VolInfo{
1143
		Name:                  name,
1144
		Owner:                 owner,
1145
		CreateTime:            createTime,
1146
		Status:                status,
1147
		TotalSize:             totalSize,
1148
		UsedSize:              usedSize,
1149
		DpReadOnlyWhenVolFull: dpReadOnlyWhenVolFull,
1150
	}
1151
}
1152

1153
// ZoneView define the view of zone
1154
type ZoneView struct {
1155
	Name                string
1156
	Status              string
1157
	DataNodesetSelector string
1158
	MetaNodesetSelector string
1159
	NodeSet             map[uint64]*NodeSetView
1160
}
1161

1162
type NodeSetView struct {
1163
	DataNodeLen int
1164
	MetaNodeLen int
1165
	MetaNodes   []NodeView
1166
	DataNodes   []NodeView
1167
}
1168

1169
// TopologyView provides the view of the topology view of the cluster
1170
type TopologyView struct {
1171
	Zones []*ZoneView
1172
}
1173

1174
const (
1175
	PartitionTypeNormal  = 0
1176
	PartitionTypeCache   = 1
1177
	PartitionTypePreLoad = 2
1178
)
1179

1180
func GetDpType(volType int, isPreload bool) int {
1181
	if volType == VolumeTypeHot {
1182
		return PartitionTypeNormal
1183
	}
1184

1185
	if isPreload {
1186
		return PartitionTypePreLoad
1187
	}
1188

1189
	return PartitionTypeCache
1190
}
1191

1192
func IsCacheDp(typ int) bool {
1193
	return typ == PartitionTypeCache
1194
}
1195

1196
func IsNormalDp(typ int) bool {
1197
	return typ == PartitionTypeNormal
1198
}
1199

1200
func IsPreLoadDp(typ int) bool {
1201
	return typ == PartitionTypePreLoad
1202
}
1203

1204
const (
1205
	VolumeTypeHot  = 0
1206
	VolumeTypeCold = 1
1207
)
1208

1209
func IsCold(typ int) bool {
1210
	return typ == VolumeTypeCold
1211
}
1212

1213
func IsHot(typ int) bool {
1214
	return typ == VolumeTypeHot
1215
}
1216

1217
const (
1218
	NoCache = 0
1219
	RCache  = 1
1220
	RWCache = 2
1221
)
1222

1223
const (
1224
	LFClient = 1 // low frequency client
1225
)
1226

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.