Skip to content

Commit

Permalink
fix: update code
Browse files Browse the repository at this point in the history
  • Loading branch information
devillove084 committed Sep 17, 2024
1 parent 2bfd1c7 commit cd2455a
Show file tree
Hide file tree
Showing 27 changed files with 577 additions and 750 deletions.
1,083 changes: 500 additions & 583 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2024-03-04"
channel = "nightly-2024-09-10"
components = ["rustfmt", "clippy", "miri", "rust-analyzer"]
2 changes: 1 addition & 1 deletion src/query_engine/src/executor/aggregate/hash_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ macro_rules! hash_array_float {
///
/// The number of rows to hash is determined by `hashes_buffer.len()`.
/// `hashes_buffer` should be pre-sized appropriately
#[cfg(not(feature = "force_hash_collisions"))]
// #[cfg(not(feature = "force_hash_collisions"))]
pub fn create_hashes<'a>(
arrays: &[ArrayRef],
random_state: &RandomState,
Expand Down
2 changes: 2 additions & 0 deletions src/query_engine/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#![deny(clippy::all)]
#![allow(clippy::doc_lazy_continuation)]
#![allow(clippy::too_long_first_doc_paragraph)]
#![allow(clippy::diverging_sub_expression)]
#![allow(clippy::single_range_in_vec_init)]
#![allow(clippy::useless_vec)]
Expand Down
36 changes: 0 additions & 36 deletions src/query_engine/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,10 @@ use std::path::PathBuf;
#[derive(Parser)]
#[command(version, about, long_about = None)]
struct Cli {
// /// Optional name to operate on
// db_path: Option<String>,
/// Sets a custom config file
#[arg(short, long, value_name = "DB_PATH")]
db_path: Option<PathBuf>,
// #[arg(short, long, value_name = "FILE")]
// db_path: Option<PathBuf>,

// /// Turn debugging information on
// #[arg(short, long, action = clap::ArgAction::Count)]
// debug: u8,

// #[command(subcommand)]
// command: Option<Commands>,
}

// #[derive(Subcommand)]
// enum Commands {
// /// does testing things
// Test {
// /// lists test values
// #[arg(short, long)]
// list: bool,
// },
// }

#[tokio::main]
async fn main() -> Result<()> {
env_logger::init();
Expand All @@ -52,17 +30,3 @@ async fn main() -> Result<()> {

Ok(())
}

// fn create_csv_table(db: &Database, table_name: &str) -> Result<()> {
// let table_name = table_name.to_string();
// let filepath = format!("/home/luhuanbing/TemplateDB/tests/csv/{}.csv", table_name);
// println!("file path is: {:?}", filepath);
// db.create_csv_table(table_name, filepath)?;

// Ok(())
// }

// fn create_template_db(db: &Database) -> Result<()> {
// // db.create_mem_table()
// todo!()
// }
1 change: 1 addition & 0 deletions src/query_engine/src/optimizer/rules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ mod rule_test_util {
use crate::parser::parse;
use crate::planner_test::Planner;

#[allow(dead_code)]
pub struct RuleTest {
pub name: &'static str,
pub sql: &'static str,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ use super::{BoundExpression, BoundExpressionBase, ColumnBinding};
use crate::planner::{BindError, ExpressionBinder, SqlparserResolver, LOGGING_TARGET};
use crate::types::LogicalType;

/// A BoundColumnRef expression represents a ColumnRef expression that was bound to an actual table
/// and column index. It is not yet executable, however. The ColumnBindingResolver transforms the
/// BoundColumnRefExpressions into BoundReferenceExpressions, which refer to indexes into the
/// physical chunks that pass through the executor.
/// A BoundColumnRef expression represents a ColumnRef expression.
///
/// Be bounded to an actual table and column index. It is not yet executable, however.
/// The ColumnBindingResolver transforms the BoundColumnRefExpressions into BoundReferenceExpressions,
/// which refer to indexes into the physical chunks that pass through the executor.
#[derive(new, Debug, Clone)]
pub struct BoundColumnRefExpression {
pub(crate) base: BoundExpressionBase,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl Binder {
let val = ExpressionExecutor::execute_scalar(limit_expr)?;
Self::cast_delimiter_val(val)
} else {
u64::max_value()
u64::MAX
};

let offset = query
Expand Down
2 changes: 1 addition & 1 deletion src/query_engine/src/planner/constants.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub static INVALID_INDEX: usize = std::usize::MAX;
pub static INVALID_INDEX: usize = usize::MAX;
1 change: 0 additions & 1 deletion src/query_engine/src/storage/csv.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::collections::{BTreeMap, HashMap};
use std::fs::File;
use std::sync::{Arc, Mutex};
use std::usize;

use arrow::array::StringArray;
use arrow::csv::{reader, Reader, ReaderBuilder};
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/src/consensus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ pub mod command;
pub mod commit;
pub mod env;
pub mod epaxos;
pub mod error;
// pub mod error;
pub mod executor;
pub mod id;
pub mod message;
pub mod node;
// pub mod node;
pub mod options;
pub mod paxos;
pub mod quorum;
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![deny(clippy::all)]
#![allow(clippy::enum_variant_names)]
#![allow(clippy::mutable_key_type)]
#![feature(async_closure)]
#![feature(btree_extract_if)]
#![feature(hash_extract_if)]
Expand All @@ -8,7 +9,6 @@
#![feature(allocator_api)]
#![feature(vec_into_raw_parts)]
#![feature(type_alias_impl_trait)]
#![feature(associated_type_bounds)]
#![allow(incomplete_features)]

pub mod consensus;
Expand Down
3 changes: 0 additions & 3 deletions src/storage_engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ prost = "0.11.0"
blink-alloc = "0.3.1"
moka = { version = "0.12.5", features = ["future"] }

[target.'cfg(not(target_env = "msvc"))'.dependencies]
tikv-jemallocator = "0.5"

[build-dependencies]
tonic-build = "0.8.0"

Expand Down
10 changes: 3 additions & 7 deletions src/storage_engine/src/cache/bloom_filter_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ impl BloomFilter {
pub fn new(bits_per_key: usize) -> Self {
// 0.69 =~ ln(2) and we intentionally round down to reduce probing cost a little bit
let mut k = bits_per_key as f32 * 0.69;
if k > 30f32 {
k = 30f32;
} else if k < 1f32 {
k = 1f32;
}
k = k.clamp(1f32, 30f32);
Self {
k: k as usize,
bits_per_key,
Expand Down Expand Up @@ -48,7 +44,7 @@ impl FilterPolicy for BloomFilter {
return true;
};
let mut h = Self::bloom_hash(key);
let delta = (h >> 17) | (h << 15); // rotate right 17 bits
let delta = (h >> 17) | h.rotate_left(15); // rotate right 17 bits
for _ in 0..k {
let bit_pos = h % u32::try_from(bits).expect("truncate error");
if (filter[(bit_pos / 8) as usize] & (1 << (bit_pos % 8))) == 0 {
Expand Down Expand Up @@ -76,7 +72,7 @@ impl FilterPolicy for BloomFilter {

for key in keys {
let mut h = Self::bloom_hash(key.as_slice());
let delta = (h >> 17) | (h << 15); // rotate right 17 bits
let delta = (h >> 17) | h.rotate_left(15); // rotate right 17 bits
for _ in 0..self.k {
let bit_pos = h % (bits as u32);
dst[(bit_pos / 8) as usize] |= 1 << (bit_pos % 8);
Expand Down
13 changes: 0 additions & 13 deletions src/storage_engine/src/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,6 @@ pub mod new_lru_cache;
pub mod sharded_cache;
pub mod table_cache;

/// A `Cache` is an interface that maps keys to values.
/// It has internal synchronization and may be safely accessed concurrently from
/// multiple threads.
/// It may automatically evict entries to make room for new entries.
/// Values have a specified charge against the cache capacity.
/// For example, a cache where the values are variable length strings, may use the
/// length of the string as the charge for the string.
///
/// A builtin cache implementation with a least-recently-used eviction
/// policy is provided.
/// Clients may use their own implementations if
/// they want something more sophisticated (like scan-resistance, a
/// custom eviction policy, variable cache sizing, etc.)
pub trait CacheSync<K, V>: Sync + Send
where
K: Sync + Send,
Expand Down
72 changes: 36 additions & 36 deletions src/storage_engine/src/db_impl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1264,43 +1264,43 @@ mod tests {
// assert_eq!(t.all_entires_for(b"foo"), "[ ]");
// }

#[test]
fn test_overlap_in_level_0() {
for t in default_cases() {
// Fill levels 1 and 2 to disable the pushing or new memtables to levels > 0
t.put("100", "v100").unwrap();
t.put("999", "v999").unwrap();
t.inner.force_compact_mem_table().unwrap();
t.delete("100").unwrap();
t.delete("999").unwrap();
t.inner.force_compact_mem_table().unwrap();
assert_eq!("0,1,1", t.file_count_per_level());

// Make files spanning the following ranges in level-0:
// files[0] 200 .. 900
// files[1] 300 .. 500
// Note that filtes are sorted by smallest key
t.put("300", "v300").unwrap();
t.put("500", "v500").unwrap();
t.inner.force_compact_mem_table().unwrap();
t.put("200", "v200").unwrap();
t.put("600", "v600").unwrap();
t.put("900", "v000").unwrap();
t.inner.force_compact_mem_table().unwrap();
assert_eq!("2,1,1", t.file_count_per_level());
// #[test]
// fn test_overlap_in_level_0() {
// for t in default_cases() {
// // Fill levels 1 and 2 to disable the pushing or new memtables to levels > 0
// t.put("100", "v100").unwrap();
// t.put("999", "v999").unwrap();
// t.inner.force_compact_mem_table().unwrap();
// t.delete("100").unwrap();
// t.delete("999").unwrap();
// t.inner.force_compact_mem_table().unwrap();
// assert_eq!("0,1,1", t.file_count_per_level());

// // Make files spanning the following ranges in level-0:
// // files[0] 200 .. 900
// // files[1] 300 .. 500
// // Note that filtes are sorted by smallest key
// t.put("300", "v300").unwrap();
// t.put("500", "v500").unwrap();
// t.inner.force_compact_mem_table().unwrap();
// t.put("200", "v200").unwrap();
// t.put("600", "v600").unwrap();
// t.put("900", "v000").unwrap();
// t.inner.force_compact_mem_table().unwrap();
// assert_eq!("2,1,1", t.file_count_per_level());

// Compact away the placeholder files we created initially
t.compact_range_at(1, None, None).unwrap();
t.compact_range_at(2, None, None).unwrap();
assert_eq!("2", t.file_count_per_level());
// // Compact away the placeholder files we created initially
// t.compact_range_at(1, None, None).unwrap();
// t.compact_range_at(2, None, None).unwrap();
// assert_eq!("2", t.file_count_per_level());

// Do a memtable compaction
t.delete("600").unwrap();
t.inner.force_compact_mem_table().unwrap();
assert_eq!("3", t.file_count_per_level());
t.assert_get("600", None);
}
}
// // Do a memtable compaction
// t.delete("600").unwrap();
// t.inner.force_compact_mem_table().unwrap();
// assert_eq!("3", t.file_count_per_level());
// t.assert_get("600", None);
// }
// }

// #[test]
// fn test_l0_compaction_when_reopen() {
Expand Down Expand Up @@ -1369,7 +1369,7 @@ mod tests {

#[test]
fn test_custom_comparator() {
use std::{cmp::Ordering, str, usize};
use std::{cmp::Ordering, str};
#[derive(Clone, Default)]
struct NumberComparator {}
fn to_number(n: &[u8]) -> usize {
Expand Down
6 changes: 3 additions & 3 deletions src/storage_engine/src/db_impl/template_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ impl<S: Storage + Clone + 'static, C: Comparator + 'static> DBImpl<S, C> {
let mut mem_compaction_duration = 0;
input_iter.seek_to_first();

let mut last_sequence_for_key = u64::max_value();
let mut last_sequence_for_key = u64::MAX;
// TODO: Use Option<&[u8]> instead
let mut current_ukey: Option<Vec<u8>> = None;
while input_iter.valid() && !self.is_shutting_down.load(Ordering::Acquire) {
Expand All @@ -1178,7 +1178,7 @@ impl<S: Storage + Clone + 'static, C: Comparator + 'static> DBImpl<S, C> {
{
// First occurrence of this user key
current_ukey = Some(key.user_key.to_vec());
last_sequence_for_key = u64::max_value();
last_sequence_for_key = u64::MAX;
}
// Keep the still-in-use old key or not
if last_sequence_for_key <= c.oldest_snapshot_alive
Expand Down Expand Up @@ -1222,7 +1222,7 @@ impl<S: Storage + Clone + 'static, C: Comparator + 'static> DBImpl<S, C> {
}
None => {
current_ukey = None;
last_sequence_for_key = u64::max_value();
last_sequence_for_key = u64::MAX;
}
}
input_iter.next();
Expand Down
1 change: 1 addition & 0 deletions src/storage_engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#![deny(clippy::all)]
#![allow(clippy::too_long_first_doc_paragraph)]
#![allow(clippy::field_reassign_with_default)]
#![allow(clippy::module_inception)]
#![allow(clippy::needless_range_loop)]
Expand Down
5 changes: 0 additions & 5 deletions src/storage_engine/src/manager/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,11 +621,6 @@ fn key_is_before_file<C: Comparator>(
/// file number and file size are both u64, so 2 * size_of(u64)
pub const FILE_META_LENGTH: usize = 2 * mem::size_of::<u64>();

/// An internal iterator. For a given version/level pair, yields
/// information about the files in the level. For a given entry, key()
/// is the largest key that occurs in the file, and value() is an
/// 16-byte value containing the file number and file size, both
/// encoded using `encode_fixed_u64`
pub struct LevelFileNumIterator<C: Comparator> {
files: Vec<Arc<FileMetaData>>,
icmp: InternalKeyComparator<C>,
Expand Down
8 changes: 4 additions & 4 deletions src/storage_engine/src/manager/version_edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,31 +494,31 @@ mod tests {
#[test]
fn test_set_log_number() {
let mut edit = VersionEdit::new(7);
let log_num = u64::max_value();
let log_num = u64::MAX;
edit.set_log_number(log_num);
assert_eq!(edit.log_number.unwrap(), log_num);
}

#[test]
fn test_set_prev_log_number() {
let mut edit = VersionEdit::new(7);
let prev_log_num = u64::max_value();
let prev_log_num = u64::MAX;
edit.set_prev_log_number(prev_log_num);
assert_eq!(edit.prev_log_number.unwrap(), prev_log_num);
}

#[test]
fn test_set_next_file() {
let mut edit = VersionEdit::new(7);
let next_file = u64::max_value();
let next_file = u64::MAX;
edit.set_next_file(next_file);
assert_eq!(edit.next_file_number.unwrap(), next_file);
}

#[test]
fn test_set_last_sequence() {
let mut edit = VersionEdit::new(7);
let last_sequence = u64::max_value();
let last_sequence = u64::MAX;
edit.set_last_sequence(last_sequence);
assert_eq!(edit.last_sequence.unwrap(), last_sequence);
}
Expand Down
Loading

0 comments on commit cd2455a

Please sign in to comment.