cubefs

Форк
0
113 строк · 3.7 Кб
1
// Copyright 2022 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 blobnode
16

17
import (
18
	"context"
19
	"fmt"
20
	"io"
21

22
	"github.com/cubefs/cubefs/blobstore/common/errors"
23
	"github.com/cubefs/cubefs/blobstore/common/proto"
24
	"github.com/cubefs/cubefs/blobstore/common/rpc"
25
)
26

27
type Config struct {
28
	rpc.Config
29
}
30

31
type client struct {
32
	rpc.Client
33
}
34

35
func New(cfg *Config) StorageAPI {
36
	return &client{rpc.NewClient(&cfg.Config)}
37
}
38

39
func (c *client) String(ctx context.Context, host string) string {
40
	return ""
41
}
42

43
func (c *client) IsOnline(ctx context.Context, host string) (b bool) {
44
	return true
45
}
46

47
func (c *client) Close(ctx context.Context, host string) (err error) {
48
	return nil
49
}
50

51
func (c *client) Stat(ctx context.Context, host string) (dis []*DiskInfo, err error) {
52
	urlStr := fmt.Sprintf("%v/stat", host)
53
	dis = make([]*DiskInfo, 0)
54
	err = c.GetWith(ctx, urlStr, &dis)
55
	return
56
}
57

58
type ConfigReloadArgs struct {
59
	Key   string `json:"key"`
60
	Value string `json:"value"`
61
}
62

63
type InspectRateArgs struct {
64
	Rate int `json:"rate"`
65
}
66

67
type DiskStatArgs struct {
68
	DiskID proto.DiskID `json:"diskid"`
69
}
70

71
func (c *client) DiskInfo(ctx context.Context, host string, args *DiskStatArgs) (di *DiskInfo, err error) {
72
	if !IsValidDiskID(args.DiskID) {
73
		return nil, errors.ErrInvalidDiskId
74
	}
75

76
	urlStr := fmt.Sprintf("%v/disk/stat/diskid/%v", host, args.DiskID)
77
	di = new(DiskInfo)
78
	err = c.GetWith(ctx, urlStr, di)
79
	return
80
}
81

82
type StorageAPI interface {
83
	String(ctx context.Context, host string) string
84
	IsOnline(ctx context.Context, host string) bool
85
	Close(ctx context.Context, host string) error
86
	Stat(ctx context.Context, host string) (infos []*DiskInfo, err error)
87
	DiskInfo(ctx context.Context, host string, args *DiskStatArgs) (di *DiskInfo, err error)
88

89
	// chunks
90
	CreateChunk(ctx context.Context, host string, args *CreateChunkArgs) (err error)
91
	StatChunk(ctx context.Context, host string, args *StatChunkArgs) (ci *ChunkInfo, err error)
92
	ReleaseChunk(ctx context.Context, host string, args *ChangeChunkStatusArgs) (err error)
93
	SetChunkReadonly(ctx context.Context, host string, args *ChangeChunkStatusArgs) (err error)
94
	SetChunkReadwrite(ctx context.Context, host string, args *ChangeChunkStatusArgs) (err error)
95
	ListChunks(ctx context.Context, host string, args *ListChunkArgs) (cis []*ChunkInfo, err error)
96

97
	// shard
98
	GetShard(ctx context.Context, host string, args *GetShardArgs) (body io.ReadCloser, shardCrc uint32, err error)
99
	RangeGetShard(ctx context.Context, host string, args *RangeGetShardArgs) (body io.ReadCloser, shardCrc uint32, err error)
100
	PutShard(ctx context.Context, host string, args *PutShardArgs) (crc uint32, err error)
101
	StatShard(ctx context.Context, host string, args *StatShardArgs) (si *ShardInfo, err error)
102
	MarkDeleteShard(ctx context.Context, host string, args *DeleteShardArgs) (err error)
103
	DeleteShard(ctx context.Context, host string, args *DeleteShardArgs) (err error)
104
	ListShards(ctx context.Context, host string, args *ListShardsArgs) (sis []*ShardInfo, next proto.BlobID, err error)
105

106
	WorkerAPI
107
}
108

109
// WorkerAPI woker api on blobnode.
110
type WorkerAPI interface {
111
	RepairShard(ctx context.Context, host string, args *proto.ShardRepairTask) (err error)
112
	WorkerStats(ctx context.Context, host string) (ret WorkerStats, err error)
113
}
114

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

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

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

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