-
Notifications
You must be signed in to change notification settings - Fork 6
/
admin.go
564 lines (490 loc) · 22.6 KB
/
admin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
package varlog
//go:generate mockgen -package varlog -destination admin_mock.go . Admin
import (
"context"
stderrors "errors"
"github.com/kakao/varlog/proto/admpb"
pbtypes "github.com/gogo/protobuf/types"
"github.com/gogo/status"
"github.com/pkg/errors"
"google.golang.org/grpc/codes"
"github.com/kakao/varlog/pkg/rpc"
"github.com/kakao/varlog/pkg/types"
"github.com/kakao/varlog/pkg/verrors"
"github.com/kakao/varlog/proto/snpb"
"github.com/kakao/varlog/proto/varlogpb"
)
// Admin provides various methods to manage the varlog cluster.
type Admin interface {
// TODO (jun): Specify types of errors, for instance, retriable, bad request, server's internal error.
// GetStorageNode returns the metadata of the storage node specified by the argument snid.
// If the admin server does not check the heartbeat of the storage node
// yet, some fields are zero values, for instance, LastHeartbeatTime,
// and Storages, Status, and StartTime of StorageNodeMetadataDescriptor.
// It returns the ErrNotExist if the storage node does not exist.
// It returns the ErrUnavailable if the cluster metadata cannot be
// fetched from the metadata repository.
GetStorageNode(ctx context.Context, snid types.StorageNodeID, opts ...AdminCallOption) (*admpb.StorageNodeMetadata, error)
// ListStorageNodes returns a list of storage node metadata.
// If the admin server does not check the heartbeat of the storage node
// yet, some fields are zero values, for instance, LastHeartbeatTime,
// and Storages, Status, and StartTime of StorageNodeMetadataDescriptor.
// It returns the ErrUnavailable if the cluster metadata cannot be fetched from the metadata repository.
//
// Note that it should return an empty slice rather than nil to encode
// to an empty array in JSON if no storage node exists in the cluster.
ListStorageNodes(ctx context.Context, opts ...AdminCallOption) ([]admpb.StorageNodeMetadata, error)
// GetStorageNodes returns a map of StorageNodeIDs and their addresses.
// If the admin server does not check the heartbeat of the storage node
// yet, some fields are zero values, for instance, LastHeartbeatTime,
// and Storages, Status, and StartTime of StorageNodeMetadataDescriptor.
// It returns the ErrUnavailable if the cluster metadata cannot be fetched from the metadata repository.
//
// Deprecated: Use ListStorageNodes.
GetStorageNodes(ctx context.Context, opts ...AdminCallOption) (map[types.StorageNodeID]admpb.StorageNodeMetadata, error)
// AddStorageNode registers a storage node, whose ID and address are
// the argument snid and addr respectively, to the cluster.
// It is okay to call AddStorageNode more than one time to add the same
// storage node.
// Once the storage node is registered, the pair of snid and addr
// should not be changed.
AddStorageNode(ctx context.Context, snid types.StorageNodeID, addr string, opts ...AdminCallOption) (*admpb.StorageNodeMetadata, error)
// UnregisterStorageNode unregisters a storage node identified by the
// argument snid from the cluster.
// It is okay to unregister not existed storage node.
// If the storage node still has running log stream replicas, it
// returns an error.
UnregisterStorageNode(ctx context.Context, snid types.StorageNodeID, opts ...AdminCallOption) error
// GetTopic returns the metadata of the topic specified by the argument
// tpid.
// It returns the ErrNotExist error if the topic does not exist.
// If the admin could not fetch cluster metadata, it returns an error,
// and users can retry this RPC.
GetTopic(ctx context.Context, tpid types.TopicID, opts ...AdminCallOption) (*varlogpb.TopicDescriptor, error)
// ListTopics returns a list of all topics in the cluster.
//
// Note that it should return an empty slice rather than nil to encode
// to an empty array in JSON if no topic exists in the cluster.
ListTopics(ctx context.Context, opts ...AdminCallOption) ([]varlogpb.TopicDescriptor, error)
// AddTopic adds a new topic and returns its metadata including a
// unique topid ID.
// It returns an error if rejected by the metadata repository due to
// redundant topic ID or something else, and users can retry this RPC.
AddTopic(ctx context.Context, opts ...AdminCallOption) (*varlogpb.TopicDescriptor, error)
// UnregisterTopic removes a topic identified by the argument tpid from
// the cluster.
// It is okay to delete not existed topic.
// It returns an error if it tries to delete the topic which has active
// log streams.
// If the admin could not fetch cluster metadata, it returns an error,
// and users can retry this RPC.
UnregisterTopic(ctx context.Context, tpid types.TopicID, opts ...AdminCallOption) error
// GetLogStream returns metadata of log stream specified by the argument tpid and lsid.
// It returns an error if there is no topic or log stream.
GetLogStream(ctx context.Context, tpid types.TopicID, lsid types.LogStreamID, opts ...AdminCallOption) (*varlogpb.LogStreamDescriptor, error)
// ListLogStreams returns a list of log streams belonging to the topic
// tpid.
//
// Note that it should return an empty slice rather than nil to encode
// to an empty array in JSON if no log stream exists in the topic.
ListLogStreams(ctx context.Context, tpid types.TopicID, opts ...AdminCallOption) ([]varlogpb.LogStreamDescriptor, error)
// DescribeTopic returns detailed metadata of the topic.
// Deprecated: Use ListLogStreams.
DescribeTopic(ctx context.Context, topicID types.TopicID, opts ...AdminCallOption) (*admpb.DescribeTopicResponse, error)
// AddLogStream adds a new log stream to the topic tpid.
// It returns the error code ResourceExhausted if the number of log streams
// is reached the upper limit.
//
// The admin server chooses proper replicas if the argument replicas are empty.
// Otherwise, if the argument replicas are defined, the admin server
// creates a new log stream with the given configuration by the
// argument replicas. Each
// `proto/varlogpb.(ReplicaDescriptor).StorageNodePath` in the argument
// replicas should be set. In this case, the following conditions
// should be satisfied:
// - The number of replicas should be equal to the replication factor.
// - Each storage node for each replica should exist.
// - The log stream, which tries to add, should not exist.
//
// Internally, it waits for the log stream for being sealed and unsealed.
AddLogStream(ctx context.Context, tpid types.TopicID, replicas []*varlogpb.ReplicaDescriptor, opts ...AdminCallOption) (*varlogpb.LogStreamDescriptor, error)
// UpdateLogStream changes replicas of the log stream.
// This method swaps two replicas - the argument poppedReplica and
// pushedReplica. The poppedReplica is the old replica that belonged to
// the log stream, however, pushedReplica is the new replica to be
// added to the log stream. Note that
// `proto/varlogpb.(ReplicaDescriptor).StorageNodePath` in the
// poppedReplica and pushedReplica should be set.
UpdateLogStream(ctx context.Context, tpid types.TopicID, lsid types.LogStreamID, poppedReplica varlogpb.ReplicaDescriptor, pushedReplica varlogpb.ReplicaDescriptor, opts ...AdminCallOption) (*varlogpb.LogStreamDescriptor, error)
// UnregisterLogStream unregisters a log stream from the cluster.
UnregisterLogStream(ctx context.Context, tpid types.TopicID, lsid types.LogStreamID, opts ...AdminCallOption) error
// RemoveLogStreamReplica removes a log stream replica from the storage
// node.
RemoveLogStreamReplica(ctx context.Context, snid types.StorageNodeID, tpid types.TopicID, lsid types.LogStreamID, opts ...AdminCallOption) error
// Seal seals the log stream identified by the argument tpid and lsid.
Seal(ctx context.Context, tpid types.TopicID, lsid types.LogStreamID, opts ...AdminCallOption) (*admpb.SealResponse, error)
// Unseal unseals the log stream identified by the argument tpid and
// lsid.
Unseal(ctx context.Context, tpid types.TopicID, lsid types.LogStreamID, opts ...AdminCallOption) (*varlogpb.LogStreamDescriptor, error)
// Sync copies logs of the log stream identified by the argument tpid
// and lsid from the source storage node to the destination storage
// node.
Sync(ctx context.Context, tpid types.TopicID, lsid types.LogStreamID, srcid, dstid types.StorageNodeID, opts ...AdminCallOption) (*snpb.SyncStatus, error)
// Trim deletes logs whose GLSNs are less than or equal to the argument
// lastGLSN.
// Note that the return type of this method can be changed soon.
Trim(ctx context.Context, tpid types.TopicID, lastGLSN types.GLSN, opts ...AdminCallOption) (map[types.LogStreamID]map[types.StorageNodeID]error, error)
GetMetadataRepositoryNode(ctx context.Context, nid types.NodeID, opts ...AdminCallOption) (*varlogpb.MetadataRepositoryNode, error)
ListMetadataRepositoryNodes(ctx context.Context, opts ...AdminCallOption) ([]varlogpb.MetadataRepositoryNode, error)
// GetMRMembers returns metadata repositories of the cluster.
GetMRMembers(ctx context.Context, opts ...AdminCallOption) (*admpb.GetMRMembersResponse, error)
AddMetadataRepositoryNode(ctx context.Context, raftURL, rpcAddr string, opts ...AdminCallOption) (*varlogpb.MetadataRepositoryNode, error)
// AddMRPeer registers a new metadata repository to the cluster.
AddMRPeer(ctx context.Context, raftURL, rpcAddr string, opts ...AdminCallOption) (types.NodeID, error)
DeleteMetadataRepositoryNode(ctx context.Context, nid types.NodeID, opts ...AdminCallOption) error
// RemoveMRPeer unregisters the metadata repository from the cluster.
RemoveMRPeer(ctx context.Context, raftURL string, opts ...AdminCallOption) error
// Close closes a connection to the admin server.
// Once this method is called, the Client can't be used anymore.
Close() error
}
var _ Admin = (*admin)(nil)
type admin struct {
adminConfig
address string
rpcConn *rpc.Conn
rpcClient admpb.ClusterManagerClient
}
// NewAdmin creates Admin that connects to admin server by using the argument addr.
func NewAdmin(ctx context.Context, addr string, opts ...AdminOption) (Admin, error) {
rpcConn, err := rpc.NewConn(ctx, addr)
if err != nil {
return nil, err
}
cli := &admin{
adminConfig: newAdminConfig(opts),
address: addr,
rpcConn: rpcConn,
rpcClient: admpb.NewClusterManagerClient(rpcConn.Conn),
}
return cli, nil
}
func (c *admin) Close() error {
return c.rpcConn.Close()
}
func (c *admin) GetStorageNode(ctx context.Context, snid types.StorageNodeID, opts ...AdminCallOption) (*admpb.StorageNodeMetadata, error) {
cfg := newAdminCallConfig(c.adminCallOptions, opts)
ctx, cancel := cfg.withTimeoutContext(ctx)
defer cancel()
rsp, err := c.rpcClient.GetStorageNode(ctx, &admpb.GetStorageNodeRequest{
StorageNodeID: snid,
})
if err != nil {
code := status.Convert(err).Code()
if code == codes.NotFound {
err = verrors.ErrNotExist
} else if code == codes.Unavailable {
err = verrors.ErrUnavailable
}
return nil, errors.WithMessage(err, "admin: get storage node")
}
return rsp.StorageNode, nil
}
func (c *admin) ListStorageNodes(ctx context.Context, opts ...AdminCallOption) ([]admpb.StorageNodeMetadata, error) {
cfg := newAdminCallConfig(c.adminCallOptions, opts)
ctx, cancel := cfg.withTimeoutContext(ctx)
defer cancel()
rsp, err := c.rpcClient.ListStorageNodes(ctx, &admpb.ListStorageNodesRequest{})
if err != nil {
code := status.Convert(err).Code()
if code == codes.NotFound {
err = verrors.ErrNotExist
} else if code == codes.Unavailable {
err = verrors.ErrUnavailable
}
return nil, errors.WithMessage(err, "admin: list storage nodes")
}
if len(rsp.StorageNodes) > 0 {
return rsp.StorageNodes, nil
}
return []admpb.StorageNodeMetadata{}, nil
}
func (c *admin) GetStorageNodes(ctx context.Context, opts ...AdminCallOption) (map[types.StorageNodeID]admpb.StorageNodeMetadata, error) {
snms, err := c.ListStorageNodes(ctx, opts...)
if err != nil {
return nil, err
}
ret := make(map[types.StorageNodeID]admpb.StorageNodeMetadata, len(snms))
for _, snm := range snms {
ret[snm.StorageNode.StorageNodeID] = snm
}
return ret, nil
}
func (c *admin) AddStorageNode(ctx context.Context, snid types.StorageNodeID, addr string, opts ...AdminCallOption) (*admpb.StorageNodeMetadata, error) {
cfg := newAdminCallConfig(c.adminCallOptions, opts)
ctx, cancel := cfg.withTimeoutContext(ctx)
defer cancel()
rsp, err := c.rpcClient.AddStorageNode(ctx, &admpb.AddStorageNodeRequest{
StorageNode: varlogpb.StorageNode{
StorageNodeID: snid,
Address: addr,
},
})
return rsp.GetStorageNode(), err
}
func (c *admin) UnregisterStorageNode(ctx context.Context, storageNodeID types.StorageNodeID, opts ...AdminCallOption) error {
cfg := newAdminCallConfig(c.adminCallOptions, opts)
ctx, cancel := cfg.withTimeoutContext(ctx)
defer cancel()
_, err := c.rpcClient.UnregisterStorageNode(ctx, &admpb.UnregisterStorageNodeRequest{StorageNodeID: storageNodeID})
return err
}
func (c *admin) GetTopic(ctx context.Context, tpid types.TopicID, opts ...AdminCallOption) (*varlogpb.TopicDescriptor, error) {
cfg := newAdminCallConfig(c.adminCallOptions, opts)
ctx, cancel := cfg.withTimeoutContext(ctx)
defer cancel()
rsp, err := c.rpcClient.GetTopic(ctx, &admpb.GetTopicRequest{
TopicID: tpid,
})
if err != nil {
if st := status.Convert(err); st.Code() == codes.NotFound {
err = verrors.ErrNotExist
}
return nil, errors.WithMessage(err, "admin: get topic")
}
return rsp.GetTopic(), nil
}
func (c *admin) ListTopics(ctx context.Context, opts ...AdminCallOption) ([]varlogpb.TopicDescriptor, error) {
cfg := newAdminCallConfig(c.adminCallOptions, opts)
ctx, cancel := cfg.withTimeoutContext(ctx)
defer cancel()
rsp, err := c.rpcClient.ListTopics(ctx, &admpb.ListTopicsRequest{})
if err != nil {
return nil, errors.WithMessage(err, "admin: list topics")
}
if len(rsp.Topics) > 0 {
return rsp.Topics, nil
}
return []varlogpb.TopicDescriptor{}, nil
}
func (c *admin) AddTopic(ctx context.Context, opts ...AdminCallOption) (*varlogpb.TopicDescriptor, error) {
cfg := newAdminCallConfig(c.adminCallOptions, opts)
ctx, cancel := cfg.withTimeoutContext(ctx)
defer cancel()
rsp, err := c.rpcClient.AddTopic(ctx, &admpb.AddTopicRequest{})
if err != nil {
return nil, err
}
return rsp.Topic, nil
}
func (c *admin) UnregisterTopic(ctx context.Context, topicID types.TopicID, opts ...AdminCallOption) error {
cfg := newAdminCallConfig(c.adminCallOptions, opts)
ctx, cancel := cfg.withTimeoutContext(ctx)
defer cancel()
_, err := c.rpcClient.UnregisterTopic(ctx, &admpb.UnregisterTopicRequest{TopicID: topicID})
return err
}
func (c *admin) GetLogStream(ctx context.Context, tpid types.TopicID, lsid types.LogStreamID, opts ...AdminCallOption) (*varlogpb.LogStreamDescriptor, error) {
cfg := newAdminCallConfig(c.adminCallOptions, opts)
ctx, cancel := cfg.withTimeoutContext(ctx)
defer cancel()
rsp, err := c.rpcClient.GetLogStream(ctx, &admpb.GetLogStreamRequest{
TopicID: tpid,
LogStreamID: lsid,
})
if err != nil {
if st := status.Convert(err); st.Code() == codes.NotFound {
err = verrors.ErrNotExist
}
return nil, errors.WithMessage(err, "admin: get log stream")
}
return rsp.GetLogStream(), nil
}
func (c *admin) ListLogStreams(ctx context.Context, tpid types.TopicID, opts ...AdminCallOption) ([]varlogpb.LogStreamDescriptor, error) {
cfg := newAdminCallConfig(c.adminCallOptions, opts)
ctx, cancel := cfg.withTimeoutContext(ctx)
defer cancel()
rsp, err := c.rpcClient.ListLogStreams(ctx, &admpb.ListLogStreamsRequest{
TopicID: tpid,
})
if err != nil {
return nil, errors.WithMessage(err, "admin: list log streams")
}
if len(rsp.LogStreams) > 0 {
return rsp.LogStreams, nil
}
return []varlogpb.LogStreamDescriptor{}, nil
}
func (c *admin) DescribeTopic(ctx context.Context, topicID types.TopicID, opts ...AdminCallOption) (*admpb.DescribeTopicResponse, error) {
cfg := newAdminCallConfig(c.adminCallOptions, opts)
ctx, cancel := cfg.withTimeoutContext(ctx)
defer cancel()
rsp, err := c.rpcClient.DescribeTopic(ctx, &admpb.DescribeTopicRequest{TopicID: topicID})
return rsp, err
}
func (c *admin) AddLogStream(ctx context.Context, topicID types.TopicID, replicas []*varlogpb.ReplicaDescriptor, opts ...AdminCallOption) (*varlogpb.LogStreamDescriptor, error) {
cfg := newAdminCallConfig(c.adminCallOptions, opts)
ctx, cancel := cfg.withTimeoutContext(ctx)
defer cancel()
rsp, err := c.rpcClient.AddLogStream(ctx, &admpb.AddLogStreamRequest{
TopicID: topicID,
Replicas: replicas,
})
return rsp.GetLogStream(), err
}
func (c *admin) UpdateLogStream(ctx context.Context, topicID types.TopicID, logStreamID types.LogStreamID, poppedReplica, pushedReplica varlogpb.ReplicaDescriptor, opts ...AdminCallOption) (*varlogpb.LogStreamDescriptor, error) {
cfg := newAdminCallConfig(c.adminCallOptions, opts)
ctx, cancel := cfg.withTimeoutContext(ctx)
defer cancel()
rsp, err := c.rpcClient.UpdateLogStream(ctx, &admpb.UpdateLogStreamRequest{
TopicID: topicID,
LogStreamID: logStreamID,
PoppedReplica: poppedReplica,
PushedReplica: pushedReplica,
})
if err == nil {
return rsp.LogStream, nil
}
// TODO: Use gRPC's code to decide if the error is retriable or not.
return nil, err
}
func (c *admin) UnregisterLogStream(ctx context.Context, topicID types.TopicID, logStreamID types.LogStreamID, opts ...AdminCallOption) error {
cfg := newAdminCallConfig(c.adminCallOptions, opts)
ctx, cancel := cfg.withTimeoutContext(ctx)
defer cancel()
_, err := c.rpcClient.UnregisterLogStream(ctx, &admpb.UnregisterLogStreamRequest{
TopicID: topicID,
LogStreamID: logStreamID,
})
return err
}
func (c *admin) RemoveLogStreamReplica(ctx context.Context, storageNodeID types.StorageNodeID, topicID types.TopicID, logStreamID types.LogStreamID, opts ...AdminCallOption) error {
cfg := newAdminCallConfig(c.adminCallOptions, opts)
ctx, cancel := cfg.withTimeoutContext(ctx)
defer cancel()
_, err := c.rpcClient.RemoveLogStreamReplica(ctx, &admpb.RemoveLogStreamReplicaRequest{
StorageNodeID: storageNodeID,
TopicID: topicID,
LogStreamID: logStreamID,
})
return err
}
func (c *admin) Seal(ctx context.Context, topicID types.TopicID, logStreamID types.LogStreamID, opts ...AdminCallOption) (*admpb.SealResponse, error) {
cfg := newAdminCallConfig(c.adminCallOptions, opts)
ctx, cancel := cfg.withTimeoutContext(ctx)
defer cancel()
rsp, err := c.rpcClient.Seal(ctx, &admpb.SealRequest{
TopicID: topicID,
LogStreamID: logStreamID,
})
return rsp, err
}
func (c *admin) Unseal(ctx context.Context, topicID types.TopicID, logStreamID types.LogStreamID, opts ...AdminCallOption) (*varlogpb.LogStreamDescriptor, error) {
cfg := newAdminCallConfig(c.adminCallOptions, opts)
ctx, cancel := cfg.withTimeoutContext(ctx)
defer cancel()
rsp, err := c.rpcClient.Unseal(ctx, &admpb.UnsealRequest{
TopicID: topicID,
LogStreamID: logStreamID,
})
return rsp.GetLogStream(), err
}
func (c *admin) Sync(ctx context.Context, topicID types.TopicID, logStreamID types.LogStreamID, srcStorageNodeID, dstStorageNodeID types.StorageNodeID, opts ...AdminCallOption) (*snpb.SyncStatus, error) {
cfg := newAdminCallConfig(c.adminCallOptions, opts)
ctx, cancel := cfg.withTimeoutContext(ctx)
defer cancel()
rsp, err := c.rpcClient.Sync(ctx, &admpb.SyncRequest{
TopicID: topicID,
LogStreamID: logStreamID,
SrcStorageNodeID: srcStorageNodeID,
DstStorageNodeID: dstStorageNodeID,
})
return rsp.GetStatus(), err
}
func (c *admin) Trim(ctx context.Context, topicID types.TopicID, lastGLSN types.GLSN, opts ...AdminCallOption) (map[types.LogStreamID]map[types.StorageNodeID]error, error) {
cfg := newAdminCallConfig(c.adminCallOptions, opts)
ctx, cancel := cfg.withTimeoutContext(ctx)
defer cancel()
rsp, err := c.rpcClient.Trim(ctx, &admpb.TrimRequest{
TopicID: topicID,
LastGLSN: lastGLSN,
})
if err != nil {
return nil, err
}
ret := make(map[types.LogStreamID]map[types.StorageNodeID]error)
for _, result := range rsp.Results {
lsid := result.LogStreamID
if _, ok := ret[lsid]; !ok {
ret[lsid] = make(map[types.StorageNodeID]error)
}
var err error
if len(result.Error) > 0 {
err = stderrors.New(result.Error)
}
ret[lsid][result.StorageNodeID] = err
}
return ret, nil
}
func (c *admin) GetMetadataRepositoryNode(ctx context.Context, nid types.NodeID, opts ...AdminCallOption) (*varlogpb.MetadataRepositoryNode, error) {
cfg := newAdminCallConfig(c.adminCallOptions, opts)
ctx, cancel := cfg.withTimeoutContext(ctx)
defer cancel()
rsp, err := c.rpcClient.GetMetadataRepositoryNode(ctx, &admpb.GetMetadataRepositoryNodeRequest{
NodeID: nid,
})
return rsp.GetNode(), err
}
func (c *admin) ListMetadataRepositoryNodes(ctx context.Context, opts ...AdminCallOption) ([]varlogpb.MetadataRepositoryNode, error) {
cfg := newAdminCallConfig(c.adminCallOptions, opts)
ctx, cancel := cfg.withTimeoutContext(ctx)
defer cancel()
rsp, err := c.rpcClient.ListMetadataRepositoryNodes(ctx, &admpb.ListMetadataRepositoryNodesRequest{})
if err != nil {
return nil, errors.WithMessage(err, "admin: list metadata repositories")
}
if len(rsp.Nodes) > 0 {
return rsp.Nodes, nil
}
return []varlogpb.MetadataRepositoryNode{}, nil
}
func (c *admin) GetMRMembers(ctx context.Context, opts ...AdminCallOption) (*admpb.GetMRMembersResponse, error) {
cfg := newAdminCallConfig(c.adminCallOptions, opts)
ctx, cancel := cfg.withTimeoutContext(ctx)
defer cancel()
rsp, err := c.rpcClient.GetMRMembers(ctx, &pbtypes.Empty{})
return rsp, err
}
func (c *admin) AddMetadataRepositoryNode(ctx context.Context, raftURL, rpcAddr string, opts ...AdminCallOption) (*varlogpb.MetadataRepositoryNode, error) {
cfg := newAdminCallConfig(c.adminCallOptions, opts)
ctx, cancel := cfg.withTimeoutContext(ctx)
defer cancel()
rsp, err := c.rpcClient.AddMetadataRepositoryNode(ctx, &admpb.AddMetadataRepositoryNodeRequest{
RaftURL: raftURL,
RPCAddr: rpcAddr,
})
return rsp.GetNode(), err
}
func (c *admin) AddMRPeer(ctx context.Context, raftURL, rpcAddr string, opts ...AdminCallOption) (types.NodeID, error) {
cfg := newAdminCallConfig(c.adminCallOptions, opts)
ctx, cancel := cfg.withTimeoutContext(ctx)
defer cancel()
rsp, err := c.rpcClient.AddMRPeer(ctx, &admpb.AddMRPeerRequest{RaftURL: raftURL, RPCAddr: rpcAddr})
return rsp.GetNodeID(), err
}
func (c *admin) DeleteMetadataRepositoryNode(ctx context.Context, nid types.NodeID, opts ...AdminCallOption) error {
cfg := newAdminCallConfig(c.adminCallOptions, opts)
ctx, cancel := cfg.withTimeoutContext(ctx)
defer cancel()
_, err := c.rpcClient.DeleteMetadataRepositoryNode(ctx, &admpb.DeleteMetadataRepositoryNodeRequest{
NodeID: nid,
})
return err
}
func (c *admin) RemoveMRPeer(ctx context.Context, raftURL string, opts ...AdminCallOption) error {
cfg := newAdminCallConfig(c.adminCallOptions, opts)
ctx, cancel := cfg.withTimeoutContext(ctx)
defer cancel()
_, err := c.rpcClient.RemoveMRPeer(ctx, &admpb.RemoveMRPeerRequest{RaftURL: raftURL})
return err
}