Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the heapsize dependency. #115

Merged
merged 6 commits into from
Jan 8, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ rusty-tags.vi

# default rocksdb data dir
rocksdb

# OS X
.DS_Store
32 changes: 0 additions & 32 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ futures-channel = "0.2.1"
futures-core = "0.2.1"
futures-executor = "0.2.1"
futures-util = "0.2.1"
heapsize = "0.4.2"
heapsize_derive = "0.1.4"
hex = "0.3.2"
itertools = "0.5.9"
lazy_static = "1.2"
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2018-12-30
nightly-2018-12-31
1 change: 0 additions & 1 deletion src/bin/repl/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ extern crate clap;
extern crate env_logger;
extern crate failure;
extern crate futures_executor;
extern crate heapsize;
extern crate locustdb;
extern crate log;
extern crate nom;
Expand Down
1 change: 0 additions & 1 deletion src/disk_store/rocksdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::str;

use byteorder::{ByteOrder, BigEndian};
use capnp::{serialize, Word, message};
use heapsize::HeapSizeOf;
use self::rocksdb::*;
use storage_format_capnp::*;

Expand Down
2 changes: 1 addition & 1 deletion src/engine/data_types/byte_slices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use engine::data_types::*;
use ingest::raw_val::RawVal;


#[derive(HeapSizeOf, Debug, Clone)]
#[derive(Debug, Clone)]
pub struct ByteSlices<'a> {
pub row_len: usize,
pub data: Vec<&'a [u8]>,
Expand Down
4 changes: 2 additions & 2 deletions src/engine/data_types/types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use mem_store::*;

#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, HeapSizeOf)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub enum EncodingType {
Str,
OptStr,
Expand Down Expand Up @@ -110,7 +110,7 @@ impl EncodingType {
}
}

#[derive(Copy, Clone, Debug, PartialEq, HeapSizeOf)]
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum BasicType {
String,
Integer,
Expand Down
2 changes: 1 addition & 1 deletion src/engine/data_types/val_rows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use ingest::raw_val::RawVal;
use mem_store::value::Val;


#[derive(HeapSizeOf, Debug, Clone)]
#[derive(Debug, Clone)]
pub struct ValRows<'a> {
pub row_len: usize,
pub data: Vec<Val<'a>>,
Expand Down
7 changes: 3 additions & 4 deletions src/engine/data_types/vec_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ use std::io::Cursor;

use num::PrimInt;
use byteorder::{NativeEndian, ReadBytesExt};
use heapsize::HeapSizeOf;
use ingest::raw_val::RawVal;
use itertools::Itertools;

use mem_store::value::Val;
use engine::data_types::*;


pub trait VecData<T>: PartialEq + Ord + Copy + Debug + Sync + Send + HeapSizeOf {
pub trait VecData<T>: PartialEq + Ord + Copy + Debug + Sync + Send {
fn unwrap<'a, 'b>(vec: &'b Data<'a>) -> &'b [T] where T: 'a;
fn unwrap_mut<'a, 'b>(vec: &'b mut Data<'a>) -> &'b mut Vec<T> where T: 'a;
fn wrap_one(_value: T) -> RawVal { panic!("Can't wrap scalar of type {:?}", Self::t()) }
Expand Down Expand Up @@ -186,7 +185,7 @@ impl CastUsize for u64 {
fn cast_usize(&self) -> usize { *self as usize }
}

#[derive(Debug, PartialEq, PartialOrd, Ord, Eq, Copy, Clone, HeapSizeOf)]
#[derive(Debug, PartialEq, PartialOrd, Ord, Eq, Copy, Clone)]
pub enum MergeOp {
TakeLeft,
TakeRight,
Expand All @@ -206,7 +205,7 @@ impl VecData<MergeOp> for MergeOp {
}


#[derive(Debug, PartialEq, PartialOrd, Ord, Eq, Copy, Clone, HeapSizeOf)]
#[derive(Debug, PartialEq, PartialOrd, Ord, Eq, Copy, Clone)]
pub struct Premerge {
pub left: u32,
pub right: u32,
Expand Down
10 changes: 8 additions & 2 deletions src/ingest/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use ingest::raw_val::RawVal;
use ingest::input_column::InputColumn;
use std::cmp;


#[derive(PartialEq, Debug, HeapSizeOf)]
#[derive(PartialEq, Debug)]
pub struct Buffer {
pub buffer: HashMap<String, MixedCol>,
pub length: usize,
Expand Down Expand Up @@ -77,5 +76,12 @@ impl Buffer {
pub fn len(&self) -> usize {
self.length
}

pub fn heap_size_of_children(&self) -> usize {
self.buffer.iter().map(|(_, v)| {
// Currently does not take into account the memory of String.
v.heap_size_of_children()
}).sum()
}
}

12 changes: 11 additions & 1 deletion src/ingest/raw_val.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::fmt;
use std::mem;
use engine::data_types::BasicType;


#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, HeapSizeOf)]
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
pub enum RawVal {
Int(i64),
Str(String),
Expand All @@ -17,6 +18,15 @@ impl RawVal {
RawVal::Null => BasicType::Null,
}
}

pub fn heap_size_of_children(&self) -> usize {
match *self {
RawVal::Int(_) => mem::size_of::<i64>(),
zhzy0077 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The i64 would be part of the RawVal, since it does not cause a heap allocation this should just return 0.

RawVal::Str(ref s) => s.capacity() * mem::size_of::<u8>(),
RawVal::Null => 0,
}
}

}

impl fmt::Display for RawVal {
Expand Down
3 changes: 0 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ extern crate futures_channel;
extern crate futures_core;
extern crate futures_executor;
extern crate futures_util;
extern crate heapsize;
#[macro_use]
extern crate heapsize_derive;
extern crate hex;
extern crate itertools;
#[macro_use]
Expand Down
4 changes: 2 additions & 2 deletions src/mem_store/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use engine::*;
use engine::data_types::*;
use engine::planning::QueryPlanner;

#[derive(Debug, Clone, HeapSizeOf)]
#[derive(Debug, Clone)]
pub struct Codec {
ops: Vec<CodecOp>,
column_name: String,
Expand Down Expand Up @@ -265,7 +265,7 @@ impl Codec {
}
}

#[derive(Debug, Clone, Copy, PartialEq, HeapSizeOf)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum CodecOp {
Nullable,
Add(EncodingType, i64),
Expand Down
23 changes: 11 additions & 12 deletions src/mem_store/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ use mem_store::*;
use engine::data_types::*;
use mem_store::lz4;

use heapsize::HeapSizeOf;


#[derive(HeapSizeOf)]
pub struct Column {
name: String,
len: usize,
Expand Down Expand Up @@ -107,6 +103,11 @@ impl Column {
pub fn basic_type(&self) -> BasicType { self.codec.decoded_type() }
pub fn section_encoding_type(&self, section: usize) -> EncodingType { self.data[section].encoding_type() }


pub fn heap_size_of_children(&self) -> usize {
self.data.iter().map(|section| section.heap_size_of_children()).sum()
}

pub fn mem_tree(&self, tree: &mut MemTreeColumn, depth: usize) {
if depth == 0 { return; }
let size_bytes = self.heap_size_of_children();
Expand Down Expand Up @@ -292,16 +293,14 @@ impl DataSection {
}
}
}
}

impl HeapSizeOf for DataSection {
fn heap_size_of_children(&self) -> usize {
pub fn heap_size_of_children(&self) -> usize {
match self {
DataSection::U8(ref x) => x.heap_size_of_children(),
DataSection::U16(ref x) => x.heap_size_of_children(),
DataSection::U32(ref x) => x.heap_size_of_children(),
DataSection::U64(ref x) => x.heap_size_of_children(),
DataSection::I64(ref x) => x.heap_size_of_children(),
DataSection::U8(ref x) => x.capacity() * mem::size_of::<u8>(),
DataSection::U16(ref x) => x.capacity() * mem::size_of::<u16>(),
DataSection::U32(ref x) => x.capacity() * mem::size_of::<u32>(),
DataSection::U64(ref x) => x.capacity() * mem::size_of::<u64>(),
DataSection::I64(ref x) => x.capacity() * mem::size_of::<i64>(),
DataSection::Null(_) => 0,
}
}
Expand Down
34 changes: 21 additions & 13 deletions src/mem_store/partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::sync::{Arc, Mutex, MutexGuard};
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};

use disk_store::interface::*;
use heapsize::HeapSizeOf;
use ingest::buffer::Buffer;
use mem_store::*;
use scheduler::disk_read_scheduler::DiskReadScheduler;
Expand Down Expand Up @@ -165,19 +164,27 @@ impl Partition {
self.cols.iter()
.map(|handle| {
let c = handle.col.lock().unwrap();
(handle.name().to_string(), c.heap_size_of_children())
(handle.name().to_string(), match *c {
Some(ref x) => x.heap_size_of_children(),
None => 0
})
})
.collect()
}
}

impl HeapSizeOf for Partition {
fn heap_size_of_children(&self) -> usize {
self.cols.iter().map(|handle| handle.col.lock().unwrap().heap_size_of_children()).sum()
pub fn heap_size_of_children(&self) -> usize {
self.cols.iter()
.map(|handle| {
let c = handle.col.lock().unwrap();
match *c {
Some(ref x) => x.heap_size_of_children(),
None => 0
}
})
.sum()
}
}


pub struct ColumnHandle {
key: (PartitionID, String),
size_bytes: AtomicUsize,
Expand Down Expand Up @@ -242,11 +249,12 @@ impl ColumnHandle {
pub fn update_size_bytes(&self, size_bytes: usize) {
self.size_bytes.store(size_bytes, Ordering::SeqCst)
}
}

impl HeapSizeOf for ColumnHandle {
fn heap_size_of_children(&self) -> usize {
if self.is_resident() { self.size_bytes() } else { 0 }
pub fn heap_size_of_children(&self) -> usize {
if self.is_resident() {
self.size_bytes()
} else {
0
}
}
}

}
13 changes: 11 additions & 2 deletions src/mem_store/raw_col.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use std::iter::repeat;
use std::ops::BitOr;
use std::sync::Arc;
use std::mem;

use ingest::raw_val::RawVal;
use mem_store::*;
use mem_store::column_builder::*;

// Can eliminate this? Used by in-memory buffer.
#[derive(PartialEq, Debug, HeapSizeOf)]
#[derive(PartialEq, Debug)]
pub struct MixedCol {
types: ColType,
data: Vec<RawVal>,
Expand Down Expand Up @@ -69,6 +70,14 @@ impl MixedCol {
Arc::new(Column::null(name, self.data.len()))
}
}

pub fn heap_size_of_children(&self) -> usize {
let data_size = self.data.iter().map(|v| v.heap_size_of_children()).sum::<usize>()
+ self.data.capacity() * mem::size_of::<RawVal>();
let type_size = mem::size_of::<ColType>();

data_size + type_size
}
}

impl Default for MixedCol {
Expand All @@ -80,7 +89,7 @@ impl Default for MixedCol {
}
}

#[derive(PartialEq, Debug, Copy, Clone, HeapSizeOf)]
#[derive(PartialEq, Debug, Copy, Clone)]
struct ColType {
contains_string: bool,
contains_int: bool,
Expand Down
Loading