cubefs

Форк
0
/
allocator.go 
98 строк · 2.5 Кб
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 proxy
16

17
import (
18
	"github.com/cubefs/cubefs/blobstore/api/proxy"
19
	errcode "github.com/cubefs/cubefs/blobstore/common/errors"
20
	"github.com/cubefs/cubefs/blobstore/common/rpc"
21
	"github.com/cubefs/cubefs/blobstore/common/trace"
22
)
23

24
// Alloc vids and bids from allocator
25
func (s *Service) Alloc(c *rpc.Context) {
26
	args := new(proxy.AllocVolsArgs)
27
	if err := c.ParseArgs(args); err != nil {
28
		c.RespondError(err)
29
		return
30
	}
31

32
	ctx := c.Request.Context()
33
	span := trace.SpanFromContextSafe(ctx)
34

35
	if args.BidCount == 0 || args.Fsize == 0 {
36
		c.RespondError(errcode.ErrIllegalArguments)
37
		return
38
	}
39
	span.Infof("accept Alloc request, args: %v", args)
40
	resp, err := s.volumeMgr.Alloc(ctx, args)
41
	if err != nil {
42
		span.Errorf("alloc volume failed, err: %v", err)
43
		c.RespondError(err)
44
		return
45
	}
46
	c.RespondJSON(resp)
47
	span.Infof("alloc request response: %v", resp)
48
}
49

50
// List the volumes in this allocator
51
func (s *Service) List(c *rpc.Context) {
52
	args := new(proxy.ListVolsArgs)
53
	if err := c.ParseArgs(args); err != nil {
54
		c.RespondError(err)
55
		return
56
	}
57

58
	ctx := c.Request.Context()
59
	span := trace.SpanFromContextSafe(ctx)
60

61
	if !args.CodeMode.IsValid() {
62
		c.RespondError(errcode.ErrIllegalArguments)
63
		return
64
	}
65

66
	span.Infof("accept List request, args: %v", args)
67
	vids, volumes, err := s.volumeMgr.List(ctx, args.CodeMode)
68
	if err != nil {
69
		c.RespondError(err)
70
		return
71
	}
72
	resp := &proxy.VolumeList{
73
		Vids:    vids,
74
		Volumes: volumes,
75
	}
76
	c.RespondJSON(resp)
77
	span.Infof("list request response: %v", resp)
78
}
79

80
// Discard use for management to remove invalid volumes in time
81
func (s *Service) Discard(c *rpc.Context) {
82
	args := new(proxy.DiscardVolsArgs)
83
	if err := c.ParseArgs(args); err != nil {
84
		c.RespondError(err)
85
		return
86
	}
87

88
	ctx := c.Request.Context()
89
	span := trace.SpanFromContextSafe(ctx)
90

91
	span.Infof("accept Discard request, args: %v", args)
92

93
	err := s.volumeMgr.Discard(ctx, args)
94
	if err != nil {
95
		c.RespondError(err)
96
		return
97
	}
98
}
99

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

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

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

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