forked from k3s-io/kine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compact.go
41 lines (37 loc) · 1.2 KB
/
compact.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
package server
import (
"context"
"go.etcd.io/etcd/api/v3/etcdserverpb"
"go.etcd.io/etcd/api/v3/mvccpb"
)
func isCompact(txn *etcdserverpb.TxnRequest) bool {
// See https://github.com/kubernetes/kubernetes/blob/442a69c3bdf6fe8e525b05887e57d89db1e2f3a5/staging/src/k8s.io/apiserver/pkg/storage/etcd3/compact.go#L72
return len(txn.Compare) == 1 &&
txn.Compare[0].Target == etcdserverpb.Compare_VERSION &&
txn.Compare[0].Result == etcdserverpb.Compare_EQUAL &&
len(txn.Success) == 1 &&
txn.Success[0].GetRequestPut() != nil &&
len(txn.Failure) == 1 &&
txn.Failure[0].GetRequestRange() != nil &&
string(txn.Compare[0].Key) == "compact_rev_key"
}
func (l *LimitedServer) compact(ctx context.Context) (*etcdserverpb.TxnResponse, error) {
// return comparison failure so that the apiserver does not bother compacting
return &etcdserverpb.TxnResponse{
Header: &etcdserverpb.ResponseHeader{},
Succeeded: false,
Responses: []*etcdserverpb.ResponseOp{
{
Response: &etcdserverpb.ResponseOp_ResponseRange{
ResponseRange: &etcdserverpb.RangeResponse{
Header: &etcdserverpb.ResponseHeader{},
Kvs: []*mvccpb.KeyValue{
{},
},
Count: 1,
},
},
},
},
}, nil
}