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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
use crate::engine::RocksEngine;
use crate::util;
use engine_traits::DecodeProperties;
use engine_traits::Range;
use engine_traits::{Error, Result};
use engine_traits::{
TableProperties, TablePropertiesCollectionIter, TablePropertiesKey, UserCollectedProperties,
};
use engine_traits::{TablePropertiesCollection, TablePropertiesExt};
use rocksdb::table_properties_rc as rc;
use std::ops::Deref;
impl TablePropertiesExt for RocksEngine {
type TablePropertiesCollection = RocksTablePropertiesCollection;
type TablePropertiesCollectionIter = RocksTablePropertiesCollectionIter;
type TablePropertiesKey = RocksTablePropertiesKey;
type TableProperties = RocksTableProperties;
type UserCollectedProperties = RocksUserCollectedProperties;
fn get_properties_of_tables_in_range(
&self,
cf: &str,
ranges: &[Range],
) -> Result<Self::TablePropertiesCollection> {
let cf = util::get_cf_handle(self.as_inner(), cf)?;
let ranges: Vec<_> = ranges.iter().map(util::range_to_rocks_range).collect();
let raw = self
.as_inner()
.get_properties_of_tables_in_range_rc(cf, &ranges);
let raw = raw.map_err(Error::Engine)?;
Ok(RocksTablePropertiesCollection::from_raw(raw))
}
}
pub struct RocksTablePropertiesCollection(rc::TablePropertiesCollection);
impl RocksTablePropertiesCollection {
fn from_raw(raw: rc::TablePropertiesCollection) -> RocksTablePropertiesCollection {
RocksTablePropertiesCollection(raw)
}
}
impl
TablePropertiesCollection<
RocksTablePropertiesCollectionIter,
RocksTablePropertiesKey,
RocksTableProperties,
RocksUserCollectedProperties,
> for RocksTablePropertiesCollection
{
fn iter(&self) -> RocksTablePropertiesCollectionIter {
RocksTablePropertiesCollectionIter(self.0.iter())
}
fn len(&self) -> usize {
self.0.len()
}
}
pub struct RocksTablePropertiesCollectionIter(rc::TablePropertiesCollectionIter);
impl
TablePropertiesCollectionIter<
RocksTablePropertiesKey,
RocksTableProperties,
RocksUserCollectedProperties,
> for RocksTablePropertiesCollectionIter
{
}
impl Iterator for RocksTablePropertiesCollectionIter {
type Item = (RocksTablePropertiesKey, RocksTableProperties);
fn next(&mut self) -> Option<Self::Item> {
self.0
.next()
.map(|(key, props)| (RocksTablePropertiesKey(key), RocksTableProperties(props)))
}
}
pub struct RocksTablePropertiesKey(rc::TablePropertiesKey);
impl TablePropertiesKey for RocksTablePropertiesKey {}
impl Deref for RocksTablePropertiesKey {
type Target = str;
fn deref(&self) -> &str {
self.0.deref()
}
}
pub struct RocksTableProperties(rc::TableProperties);
impl TableProperties<RocksUserCollectedProperties> for RocksTableProperties {
fn num_entries(&self) -> u64 {
self.0.num_entries()
}
fn user_collected_properties(&self) -> RocksUserCollectedProperties {
RocksUserCollectedProperties(self.0.user_collected_properties())
}
}
#[repr(transparent)]
pub struct RocksUserCollectedProperties(rc::UserCollectedProperties);
impl UserCollectedProperties for RocksUserCollectedProperties {
fn get(&self, index: &[u8]) -> Option<&[u8]> {
self.0.get(index)
}
fn len(&self) -> usize {
self.0.len()
}
}
impl DecodeProperties for RocksUserCollectedProperties {
fn decode(&self, k: &str) -> tikv_util::codec::Result<&[u8]> {
self.get(k.as_bytes())
.ok_or(tikv_util::codec::Error::KeyNotFound)
}
}
#[repr(transparent)]
pub struct RocksUserCollectedPropertiesNoRc(rocksdb::UserCollectedProperties);
impl DecodeProperties for RocksUserCollectedPropertiesNoRc {
fn decode(&self, k: &str) -> tikv_util::codec::Result<&[u8]> {
self.0
.get(k.as_bytes())
.ok_or(tikv_util::codec::Error::KeyNotFound)
}
}