Skip to content

Commit d01eca6

Browse files
authored
chore(cubestore): RocksSecondaryIndexValue - support HashAndTTLExtended (#7011)
1 parent 4422f87 commit d01eca6

File tree

5 files changed

+281
-39
lines changed

5 files changed

+281
-39
lines changed

rust/cubestore/cubestore/src/cachestore/cache_item.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@ impl RocksSecondaryIndex<CacheItem, CacheItemIndexKey> for CacheItemRocksIndex {
140140
}
141141
}
142142

143+
fn raw_value_size(&self, row: &CacheItem) -> u32 {
144+
if let Ok(size) = u32::try_from(row.value.len()) {
145+
size
146+
} else {
147+
u32::MAX
148+
}
149+
}
150+
143151
fn key_to_bytes(&self, key: &CacheItemIndexKey) -> Vec<u8> {
144152
match key {
145153
CacheItemIndexKey::ByPrefix(s) | CacheItemIndexKey::ByPath(s) => s.as_bytes().to_vec(),
@@ -157,6 +165,15 @@ impl RocksSecondaryIndex<CacheItem, CacheItemIndexKey> for CacheItemRocksIndex {
157165
true
158166
}
159167

168+
fn store_ttl_extended_info(&self) -> bool {
169+
match self {
170+
// Right now, it's disabled due to compatibility reasons
171+
// TODO(ovr): Enable after migration
172+
CacheItemRocksIndex::ByPath => false,
173+
CacheItemRocksIndex::ByPrefix => false,
174+
}
175+
}
176+
160177
fn get_expire(&self, row: &CacheItem) -> Option<DateTime<Utc>> {
161178
row.get_expire().clone()
162179
}

rust/cubestore/cubestore/src/cachestore/compaction.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use crate::metastore::{IndexId, RocksSecondaryIndexValue, RowKey, SecondaryIndexInfo};
1+
use crate::metastore::{
2+
IndexId, RocksSecondaryIndexValue, RocksSecondaryIndexValueVersion, RowKey, SecondaryIndexInfo,
3+
};
24
use crate::TableId;
35

46
use chrono::{DateTime, Utc};
@@ -123,8 +125,12 @@ impl MetaStoreCacheCompactionFilter {
123125
match RocksSecondaryIndexValue::from_bytes(value, index_info.value_version) {
124126
Err(err) => {
125127
// Index was migrated from old format to the new version, but compaction didnt remove it
126-
if index_info.value_version == 2
127-
&& RocksSecondaryIndexValue::from_bytes(value, 1).is_ok()
128+
if index_info.value_version == RocksSecondaryIndexValueVersion::WithTTLSupport
129+
&& RocksSecondaryIndexValue::from_bytes(
130+
value,
131+
RocksSecondaryIndexValueVersion::OnlyHash,
132+
)
133+
.is_ok()
128134
{
129135
CompactionDecision::Remove
130136
} else {
@@ -137,7 +143,10 @@ impl MetaStoreCacheCompactionFilter {
137143
}
138144
}
139145
Ok(RocksSecondaryIndexValue::Hash(_)) => CompactionDecision::Keep,
140-
Ok(RocksSecondaryIndexValue::HashAndTTL(_, expire)) => {
146+
Ok(
147+
RocksSecondaryIndexValue::HashAndTTL(_, expire)
148+
| RocksSecondaryIndexValue::HashAndTTLExtended(_, expire, _),
149+
) => {
141150
if let Some(expire) = expire {
142151
if expire <= self.current {
143152
self.removed += 1;
@@ -386,7 +395,9 @@ mod tests {
386395

387396
// Indexes with TTL use new format (v2) for indexes, but index migration doesnt skip
388397
// compaction for old rows
389-
let index_value = RocksSecondaryIndexValue::Hash("kek".as_bytes()).to_bytes(1);
398+
let index_value = RocksSecondaryIndexValue::Hash("kek".as_bytes())
399+
.to_bytes(RocksSecondaryIndexValueVersion::OnlyHash)
400+
.unwrap();
390401

391402
match filter.filter(1, &key.to_bytes(), &index_value) {
392403
Decision::Remove => (),

rust/cubestore/cubestore/src/metastore/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ macro_rules! base_rocks_secondary_index {
152152
crate::metastore::RocksSecondaryIndex::get_id(self)
153153
}
154154

155-
fn value_version(&self) -> u32 {
155+
fn value_version(&self) -> crate::metastore::RocksSecondaryIndexValueVersion {
156156
crate::metastore::RocksSecondaryIndex::value_version(self)
157157
}
158158

@@ -168,6 +168,10 @@ macro_rules! base_rocks_secondary_index {
168168
RocksSecondaryIndex::is_ttl(self)
169169
}
170170

171+
fn store_ttl_extended_info(&self) -> bool {
172+
RocksSecondaryIndex::store_ttl_extended_info(self)
173+
}
174+
171175
fn get_expire(&self, row: &$table) -> Option<chrono::DateTime<chrono::Utc>> {
172176
RocksSecondaryIndex::get_expire(self, row)
173177
}

0 commit comments

Comments
 (0)