|
52 | 52 | featureKVStoreBucketKey = []byte("feature-kv-store") |
53 | 53 | ) |
54 | 54 |
|
55 | | -// KVStores provides an Update and View method that will allow the caller to |
56 | | -// perform atomic read and write transactions on and of the key value stores |
57 | | -// offered the KVStoreTx. |
58 | | -type KVStores = DBExecutor[KVStoreTx] |
59 | | - |
60 | | -// KVStoreTx represents a database transaction that can be used for both read |
61 | | -// and writes of the various different key value stores offered for the rule. |
62 | | -type KVStoreTx interface { |
63 | | - // Global returns a persisted global, rule-name indexed, kv store. A |
64 | | - // rule with a given name will have access to this store independent of |
65 | | - // group ID or feature. |
66 | | - Global() KVStore |
67 | | - |
68 | | - // Local returns a persisted local kv store for the rule. Depending on |
69 | | - // how the implementation is initialised, this will either be under the |
70 | | - // group ID namespace or the group ID _and_ feature name namespace. |
71 | | - Local() KVStore |
72 | | - |
73 | | - // GlobalTemp is similar to the Global store except that its contents |
74 | | - // is cleared upon restart of the database. The reason persisting the |
75 | | - // temporary store changes instead of just keeping an in-memory store is |
76 | | - // that we can then guarantee atomicity if changes are made to both |
77 | | - // the permanent and temporary stores. |
78 | | - GlobalTemp() KVStore |
79 | | - |
80 | | - // LocalTemp is similar to the Local store except that its contents is |
81 | | - // cleared upon restart of the database. The reason persisting the |
82 | | - // temporary store changes instead of just keeping an in-memory store is |
83 | | - // that we can then guarantee atomicity if changes are made to both |
84 | | - // the permanent and temporary stores. |
85 | | - LocalTemp() KVStore |
86 | | -} |
87 | | - |
88 | | -// KVStore is in interface representing a key value store. It allows us to |
89 | | -// abstract away the details of the data storage method. |
90 | | -type KVStore interface { |
91 | | - // Get fetches the value under the given key from the underlying kv |
92 | | - // store. If no value is found, nil is returned. |
93 | | - Get(ctx context.Context, key string) ([]byte, error) |
94 | | - |
95 | | - // Set sets the given key-value pair in the underlying kv store. |
96 | | - Set(ctx context.Context, key string, value []byte) error |
97 | | - |
98 | | - // Del deletes the value under the given key in the underlying kv store. |
99 | | - Del(ctx context.Context, key string) error |
100 | | -} |
101 | | - |
102 | | -// RulesDB can be used to initialise a new rules.KVStores. |
103 | | -type RulesDB interface { |
104 | | - // GetKVStores constructs a new rules.KVStores in a namespace defined |
105 | | - // by the rule name, group ID and feature name. |
106 | | - GetKVStores(rule string, groupID session.ID, feature string) KVStores |
107 | | - |
108 | | - // DeleteTempKVStores deletes all temporary kv stores. |
109 | | - DeleteTempKVStores(ctx context.Context) error |
110 | | -} |
111 | | - |
112 | 55 | // GetKVStores constructs a new rules.KVStores backed by a bbolt db. |
113 | 56 | func (db *BoltDB) GetKVStores(rule string, groupID session.ID, |
114 | 57 | feature string) KVStores { |
|
0 commit comments