-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
compaction_concurrency_client.go
54 lines (48 loc) · 1.69 KB
/
compaction_concurrency_client.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
// Copyright 2022 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
package kvserver
import (
"context"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/rpc"
"github.com/cockroachdb/cockroach/pkg/rpc/nodedialer"
"github.com/cockroachdb/errors"
)
// CompactionConcurrencyClient is used to temporarily modify the
// compaction concurrency of a client until the request is cancelled.
type CompactionConcurrencyClient struct {
nd *nodedialer.Dialer
}
// NewCompactionConcurrencyClient constructs a new CompactionConcurrencyClient.
func NewCompactionConcurrencyClient(nd *nodedialer.Dialer) *CompactionConcurrencyClient {
return &CompactionConcurrencyClient{nd: nd}
}
// SetCompactionConcurrency is a tree.CompactionConcurrencyFunc.
func (c *CompactionConcurrencyClient) SetCompactionConcurrency(
ctx context.Context, nodeID, storeID int32, compactionConcurrency uint64,
) error {
conn, err := c.nd.Dial(ctx, roachpb.NodeID(nodeID), rpc.DefaultClass)
if err != nil {
return errors.Wrapf(err, "could not dial node ID %d", nodeID)
}
client := NewPerStoreClient(conn)
req := &CompactionConcurrencyRequest{
StoreRequestHeader: StoreRequestHeader{
NodeID: roachpb.NodeID(nodeID),
StoreID: roachpb.StoreID(storeID),
},
CompactionConcurrency: compactionConcurrency,
}
_, err = client.SetCompactionConcurrency(ctx, req)
if err != nil {
return err
}
return nil
}