k3s/vendor/github.com/k3s-io/kine/pkg/server/compact.go

42 lines
1.2 KiB
Go
Raw Normal View History

2019-08-22 05:12:46 +00:00
package server
import (
"context"
2019-12-12 01:27:03 +00:00
"go.etcd.io/etcd/etcdserver/etcdserverpb"
"go.etcd.io/etcd/mvcc/mvccpb"
2019-08-22 05:12:46 +00:00
)
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
2019-08-22 05:12:46 +00:00
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
2019-08-22 05:12:46 +00:00
return &etcdserverpb.TxnResponse{
Header: &etcdserverpb.ResponseHeader{},
Succeeded: false,
2019-08-22 05:12:46 +00:00
Responses: []*etcdserverpb.ResponseOp{
{
Response: &etcdserverpb.ResponseOp_ResponseRange{
ResponseRange: &etcdserverpb.RangeResponse{
2019-08-22 05:12:46 +00:00
Header: &etcdserverpb.ResponseHeader{},
Kvs: []*mvccpb.KeyValue{
&mvccpb.KeyValue{},
},
Count: 1,
2019-08-22 05:12:46 +00:00
},
},
},
},
}, nil
}