Skip to content

Commit 17019a4

Browse files
authored
[Feat] add scan ycsb & [Fix] primary key prefix in key partition (#47)
* [Feat] add scan ycsb * [Fix] primary key prefix in key partition * [Fix] cargo fmt
1 parent fe092bb commit 17019a4

File tree

5 files changed

+65
-2
lines changed

5 files changed

+65
-2
lines changed

src/location/ob_part_desc.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -643,9 +643,19 @@ impl ObKeyPartDesc {
643643
is_min_max &= v.is_max();
644644
}
645645

646+
// For partition key, the first part of the row key is the partition key
647+
let part_ref_column_size = self
648+
.ob_part_desc_obj
649+
.ordered_part_ref_column_row_key_relations
650+
.len();
646651
// Note: Java / ODP may not query all the partitions, and will return an error
647652
// instead
648-
if is_min_max || !self.is_equal_keys(start, end) {
653+
if is_min_max
654+
|| !self.is_equal_keys(
655+
&start[0..part_ref_column_size],
656+
&end[0..part_ref_column_size],
657+
)
658+
{
649659
let mut part_ids: Vec<i64> = Vec::with_capacity(self.part_num as usize);
650660
for i in 0..self.part_num as i64 {
651661
part_ids.push(i);

ycsb-rs/src/db.rs

+7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ pub trait DB {
1212
fn insert(&self, table: &str, key: &str, values: &HashMap<&str, String>) -> Result<()>;
1313
fn read(&self, table: &str, key: &str, result: &mut HashMap<String, String>) -> Result<()>;
1414
fn update(&self, table: &str, key: &str, values: &HashMap<&str, String>) -> Result<()>;
15+
fn scan(
16+
&self,
17+
table: &str,
18+
startkey: &str,
19+
endkey: &str,
20+
values: &mut HashMap<String, String>,
21+
) -> Result<()>;
1522
}
1623

1724
pub fn create_db(db: &str, config: Arc<OBKVClientInitStruct>) -> Result<Rc<dyn DB>> {

ycsb-rs/src/obkv_client.rs

+25-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::{collections::HashMap, sync::Arc, time::Duration};
2020
use anyhow::Result;
2121
#[allow(unused)]
2222
use obkv::error::CommonErrCode;
23-
use obkv::{Builder, ClientConfig, ObTableClient, RunningMode, Table, Value};
23+
use obkv::{Builder, ClientConfig, ObTableClient, RunningMode, Table, TableQuery, Value};
2424

2525
use crate::{db::DB, properties::Properties};
2626

@@ -180,4 +180,28 @@ impl DB for OBKVClient {
180180

181181
Ok(())
182182
}
183+
184+
#[allow(unused)]
185+
fn scan(
186+
&self,
187+
table: &str,
188+
startkey: &str,
189+
endkey: &str,
190+
result: &mut HashMap<String, String>,
191+
) -> Result<()> {
192+
let result = self
193+
.client
194+
.query(table)
195+
.select(COLUMN_NAMES.iter().map(|s| s.to_string()).collect())
196+
.primary_index()
197+
.add_scan_range(
198+
vec![Value::from(startkey)],
199+
true,
200+
vec![Value::from(endkey)],
201+
true,
202+
)
203+
.execute();
204+
assert!(result.is_ok());
205+
Ok(())
206+
}
183207
}

ycsb-rs/src/sqlite.rs

+11
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,15 @@ impl DB for SQLite {
7676
fn update(&self, table: &str, key: &str, values: &HashMap<&str, String>) -> Result<()> {
7777
todo!()
7878
}
79+
80+
#[allow(unused_variables)]
81+
fn scan(
82+
&self,
83+
table: &str,
84+
startkey: &str,
85+
endkey: &str,
86+
values: &mut HashMap<String, String>,
87+
) -> Result<()> {
88+
todo!()
89+
}
7990
}

ycsb-rs/src/workload/core_workload.rs

+11
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,14 @@ impl CoreWorkload {
177177
db.update(&self.table, &dbkey, &values).unwrap();
178178
}
179179

180+
fn ob_transaction_scan(&self, db: Arc<OBKVClient>) {
181+
let start = self.next_key_num();
182+
let dbstart = format!("{}", fnvhash64(start));
183+
let dbend = format!("{}", fnvhash64(start));
184+
let mut result = HashMap::new();
185+
db.scan(&self.table, &dbstart, &dbend, &mut result).unwrap();
186+
}
187+
180188
fn next_key_num(&self) -> u64 {
181189
// FIXME: Handle case where keychooser is an ExponentialGenerator.
182190
// FIXME: Handle case where keynum is > transactioninsertkeysequence's last
@@ -267,6 +275,9 @@ impl Workload for CoreWorkload {
267275
CoreOperation::Update => {
268276
self.ob_transaction_update(db);
269277
}
278+
CoreOperation::Scan => {
279+
self.ob_transaction_scan(db);
280+
}
270281
_ => todo!(),
271282
}
272283
}

0 commit comments

Comments
 (0)