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"
2020-10-28 07:38:43 +00:00
"go.etcd.io/etcd/mvcc/mvccpb"
2019-08-22 05:12:46 +00:00
)
func isCompact ( txn * etcdserverpb . TxnRequest ) bool {
2020-10-28 07:38:43 +00:00
// 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 ) {
2020-10-28 07:38:43 +00:00
// 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 { } ,
2020-10-28 07:38:43 +00:00
Succeeded : false ,
2019-08-22 05:12:46 +00:00
Responses : [ ] * etcdserverpb . ResponseOp {
{
2020-10-28 07:38:43 +00:00
Response : & etcdserverpb . ResponseOp_ResponseRange {
ResponseRange : & etcdserverpb . RangeResponse {
2019-08-22 05:12:46 +00:00
Header : & etcdserverpb . ResponseHeader { } ,
2020-10-28 07:38:43 +00:00
Kvs : [ ] * mvccpb . KeyValue {
& mvccpb . KeyValue { } ,
} ,
Count : 1 ,
2019-08-22 05:12:46 +00:00
} ,
} ,
} ,
} ,
} , nil
}