...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package mvcc
16
17 import (
18 "fmt"
19
20 "go.etcd.io/etcd/api/v3/mvccpb"
21 "go.etcd.io/etcd/server/v3/mvcc/backend"
22 "go.etcd.io/etcd/server/v3/mvcc/buckets"
23 )
24
25 func WriteKV(be backend.Backend, kv mvccpb.KeyValue) {
26 ibytes := newRevBytes()
27 revToBytes(revision{main: kv.ModRevision}, ibytes)
28
29 d, err := kv.Marshal()
30 if err != nil {
31 panic(fmt.Errorf("cannot marshal event: %v", err))
32 }
33
34 be.BatchTx().LockOutsideApply()
35 be.BatchTx().UnsafePut(buckets.Key, ibytes, d)
36 be.BatchTx().Unlock()
37 }
38
39 func UnsafeSetScheduledCompact(tx backend.BatchTx, value int64) {
40 rbytes := newRevBytes()
41 revToBytes(revision{main: value}, rbytes)
42 tx.UnsafePut(buckets.Meta, scheduledCompactKeyName, rbytes)
43 }
44
45 func UnsafeReadFinishedCompact(tx backend.ReadTx) (int64, bool) {
46 _, finishedCompactBytes := tx.UnsafeRange(buckets.Meta, finishedCompactKeyName, nil, 0)
47 if len(finishedCompactBytes) != 0 {
48 return bytesToRev(finishedCompactBytes[0]).main, true
49 }
50 return 0, false
51 }
52
53 func UnsafeReadScheduledCompact(tx backend.ReadTx) (int64, bool) {
54 _, scheduledCompactBytes := tx.UnsafeRange(buckets.Meta, scheduledCompactKeyName, nil, 0)
55 if len(scheduledCompactBytes) != 0 {
56 return bytesToRev(scheduledCompactBytes[0]).main, true
57 }
58 return 0, false
59 }
60
View as plain text