MCPcopy Create free account
hub / github.com/elastic/devfiler / Table

Interface Table

src/storage/table.rs:104–221  ·  view source on GitHub ↗

Typed database table.

Source from the content-addressed store, hash-verified

102
103/// Typed database table.
104pub trait Table: RawTable + Sized + From<rocksdb::DB> {
105 /// Key format.
106 type Key: TableKey;
107
108 /// Value format.
109 type Value: rkyv::Archive + rkyv::Serialize<AllocSerializer<4096>> + 'static;
110
111 /// Defines the table's merge behavior.
112 const MERGE_OP: MergeOperator<Self> = MergeOperator::Default;
113
114 /// Defines the table's storage optimization.
115 const STORAGE_OPT: StorageOpt = StorageOpt::RandomAccess;
116
117 /// LRU cache size for this table. Set to 0 to disable caching.
118 const CACHE_SIZE: usize = 16384;
119
120 /// Removes the record with the given key from the table.
121 fn remove(&self, key: Self::Key) {
122 let key_raw = key.into_raw();
123
124 // Remove from cache
125 if Self::CACHE_SIZE > 0 {
126 let mut cache = self.cache().lock().unwrap();
127 cache.pop(key_raw.as_ref());
128 }
129
130 self.raw().delete(key_raw).unwrap();
131 }
132
133 /// Inserts the given value at the given key.
134 ///
135 /// If the record already exists, the previous value is replaced.
136 fn insert(&self, key: Self::Key, value: Self::Value) {
137 let key_raw = key.into_raw();
138 let value_bytes = rkyv::to_bytes(&value).unwrap();
139
140 // Update cache
141 if Self::CACHE_SIZE > 0 {
142 let mut cache = self.cache().lock().unwrap();
143 cache.put(key_raw.as_ref().to_vec(), value_bytes.to_vec());
144 }
145
146 match Self::MERGE_OP {
147 MergeOperator::Default => self.raw().put(key_raw, value_bytes).unwrap(),
148 MergeOperator::Associative(_) => self.raw().merge(key_raw, value_bytes).unwrap(),
149 }
150 }
151
152 /// Create a new insertion batch.
153 fn batched_insert(&self) -> InsertionBatch<'_, Self> {
154 InsertionBatch(self, rocksdb::WriteBatch::default())
155 }
156
157 /// Get the value at the given key.
158 ///
159 /// Returns `None` if the key isn't present.
160 fn get(&self, key: Self::Key) -> Option<TableValueRef<Self::Value, SmallVec<[u8; 64]>>> {
161 let key_raw = key.into_raw();

Callers 15

flush_eventsMethod · 0.80
test_cache_functionalityFunction · 0.80
insertMethod · 0.80
ingest_locationsFunction · 0.80
process_sampleFunction · 0.80
ingest_locationsFunction · 0.80
tailFunction · 0.80
flush_eventsMethod · 0.80
wrap_mergeFunction · 0.80
line_number_for_vaMethod · 0.80
mk_time_gridFunction · 0.80
weight_childrenMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected