-
Notifications
You must be signed in to change notification settings - Fork 8.8k
/
tx_ops.go
79 lines (62 loc) · 1.62 KB
/
tx_ops.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package valinternal
type keyOpsFlag uint8
const (
upsertVal keyOpsFlag = 1 // 1 << 0
metadataUpdate = 2 // 1 << 1
metadataDelete = 4 // 1 << 2
keyDelete = 8 // 1 << 3
)
type compositeKey struct {
ns, coll, key string
}
type txOps map[compositeKey]*keyOps
type keyOps struct {
flag keyOpsFlag
value []byte
metadata []byte
}
////////////////// txOps functions
func (txops txOps) upsert(k compositeKey, val []byte) {
keyops := txops.getOrCreateKeyEntry(k)
keyops.flag += upsertVal
keyops.value = val
}
func (txops txOps) delete(k compositeKey) {
keyops := txops.getOrCreateKeyEntry(k)
keyops.flag += keyDelete
}
func (txops txOps) metadataUpdate(k compositeKey, metadata []byte) {
keyops := txops.getOrCreateKeyEntry(k)
keyops.flag += metadataUpdate
keyops.metadata = metadata
}
func (txops txOps) metadataDelete(k compositeKey) {
keyops := txops.getOrCreateKeyEntry(k)
keyops.flag += metadataDelete
}
func (txops txOps) getOrCreateKeyEntry(k compositeKey) *keyOps {
keyops, ok := txops[k]
if !ok {
keyops = &keyOps{}
txops[k] = keyops
}
return keyops
}
////////////////// keyOps functions
func (keyops keyOps) isDelete() bool {
return keyops.flag&(keyDelete) == keyDelete
}
func (keyops keyOps) isUpsertAndMetadataUpdate() bool {
if keyops.flag&upsertVal == upsertVal {
return keyops.flag&metadataUpdate == metadataUpdate ||
keyops.flag&metadataDelete == metadataDelete
}
return false
}
func (keyops keyOps) isOnlyUpsert() bool {
return keyops.flag|upsertVal == upsertVal
}