Skip to content

Commit

Permalink
Second pass in separation of source from header files
Browse files Browse the repository at this point in the history
  • Loading branch information
anuragkh committed Jun 4, 2018
1 parent 63dc722 commit f5663f2
Show file tree
Hide file tree
Showing 39 changed files with 333 additions and 330 deletions.
1 change: 1 addition & 0 deletions javaclient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ set(JAVA_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}/java")
set(JAVA_DOC_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${DOC_INSTALL_DIR}/java")

set(CONFLUO_CLIENT_ARTIFACTS confluo-client-0.1.0.jar confluo-client-0.1.0.pom)
set(SERVER_EXEC "${CMAKE_CURRENT_BINARY_DIR}/../librpc/confluod")

set(BUILD_XML_IN "${CMAKE_CURRENT_SOURCE_DIR}/build.xml.in")
set(BUILD_XML "${CMAKE_CURRENT_BINARY_DIR}/build.xml")
Expand Down
2 changes: 1 addition & 1 deletion javaclient/build.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
description="Run the test cases">
<mkdir dir="${maven.test.reports}"/>
<junit printSummary="yes" haltonerror="true" haltonfailure="true" fork="true" dir=".">
<env key="CONFLUO_SERVER_EXEC" value="@PROJECT_BINARY_DIR@/bin/confluod"/>
<env key="CONFLUO_SERVER_EXEC" value="@SERVER_EXEC@"/>
<sysproperty key="basedir" value="@CMAKE_CURRENT_SOURCE_DIR@"/>
<formatter type="xml"/>
<formatter type="plain" usefile="false"/>
Expand Down
9 changes: 4 additions & 5 deletions libconfluo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ add_library(confluo STATIC
src/compression/confluo_encoder.cc
src/container/data_log.cc
src/container/reflog.cc
src/container/cursor/alert_cursor.cc
src/container/cursor/offset_cursors.cc
src/container/cursor/record_cursors.cc
src/parser/aggregate_parser.cc
src/parser/expression_compiler.cc
src/parser/expression_parser.cc
Expand Down Expand Up @@ -182,11 +185,7 @@ add_library(confluo STATIC
src/types/raw_data.cc
src/types/numeric.cc
src/types/type_properties.cc
src/types/type_manager.cc
src/container/cursor/alert_cursor.cc
src/container/cursor/offset_cursors.cc
src/container/cursor/record_cursors.cc
)
src/types/type_manager.cc)
target_link_libraries(confluo confluoutils)

if (BUILD_TESTS)
Expand Down
2 changes: 1 addition & 1 deletion libconfluo/confluo/archival/filter_archiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class filter_load_utils {
if (num_aggs > 0) {
size_t size = sizeof(aggregate) * num_aggs;
ptr_aux_block aux(state_type::D_ARCHIVED, encoding_type::D_UNENCODED);
aggregate *archived_aggs = static_cast<aggregate *>(ALLOCATOR.alloc(size, aux));
aggregate *archived_aggs = static_cast<aggregate *>(allocator::instance().alloc(size, aux));
storage::lifecycle_util<aggregate>::construct(archived_aggs);
for (size_t i = 0; i < num_aggs; i++) {
data_type type = reader.read<data_type>();
Expand Down
4 changes: 2 additions & 2 deletions libconfluo/confluo/archival/monolog_linear_archiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class monolog_linear_archiver : public archiver {
writer_.commit<monolog_linear_archival_action>(action);

ptr_aux_block aux(state_type::D_ARCHIVED, archival_configuration_params::DATA_LOG_ENCODING_TYPE());
void *archived_bucket = ALLOCATOR.mmap(off.path(), static_cast<off_t>(off.offset()), enc_size, aux);
void *archived_bucket = allocator::instance().mmap(off.path(), static_cast<off_t>(off.offset()), enc_size, aux);
log_->data()[archival_tail_ / BUCKET_SIZE].swap_ptr(encoded_ptr<T>(archived_bucket));
}

Expand Down Expand Up @@ -117,7 +117,7 @@ class monolog_linear_load_utils {
size_t size = reader.read<ptr_metadata>().data_size_;

ptr_aux_block aux(state_type::D_ARCHIVED, archival_configuration_params::DATA_LOG_ENCODING_TYPE());
void *encoded_bucket = ALLOCATOR.mmap(off.path(), static_cast<off_t>(off.offset()), size, aux);
void *encoded_bucket = allocator::instance().mmap(off.path(), static_cast<off_t>(off.offset()), size, aux);
buckets[load_offset / BUCKET_SIZE].init_ptr(encoded_ptr<T>(encoded_bucket));

log.reserve(BUCKET_SIZE);
Expand Down
2 changes: 0 additions & 2 deletions libconfluo/confluo/atomic_multilog_metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ struct trigger_metadata {
* Writer for metadata
*/
class metadata_writer {

public:
typedef bool metadata_writer_state;
static const metadata_writer_state UNINIT = false;
Expand Down Expand Up @@ -285,7 +284,6 @@ class metadata_writer {
void write_trigger_metadata(const std::string &trigger_name,
const std::string &trigger_expr,
uint64_t periodicity_ms);

private:
std::string filename_;
std::ofstream out_;
Expand Down
8 changes: 4 additions & 4 deletions libconfluo/confluo/container/monolog/monolog_exp2_linear.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,10 @@ class monolog_exp2_linear_base {
*/
void try_allocate_bucket(__atomic_bucket_ref* container, size_t bucket_idx, __atomic_bucket_copy_ref& copy) {
storage::ptr_aux_block aux(storage::state_type::D_IN_MEMORY, storage::encoding_type::D_UNENCODED);
void *new_bucket_data = ALLOCATOR.alloc(BUCKET_SIZE * sizeof(T), aux);
void *new_bucket_data = allocator::instance().alloc(BUCKET_SIZE * sizeof(T), aux);
memset(new_bucket_data, 0xFF, BUCKET_SIZE * sizeof(T));
if (!container[bucket_idx].atomic_init(storage::encoded_ptr<T>(new_bucket_data))) {
ALLOCATOR.dealloc(new_bucket_data);
allocator::instance().dealloc(new_bucket_data);
}
container[bucket_idx].atomic_copy(copy);
}
Expand All @@ -364,11 +364,11 @@ class monolog_exp2_linear_base {
*/
storage::encoded_ptr<T> try_allocate_bucket(__atomic_bucket_ref *container, size_t bucket_idx) {
storage::ptr_aux_block aux(storage::state_type::D_IN_MEMORY, storage::encoding_type::D_UNENCODED);
void *new_bucket_data = ALLOCATOR.alloc(BUCKET_SIZE * sizeof(T), aux);
void *new_bucket_data = allocator::instance().alloc(BUCKET_SIZE * sizeof(T), aux);
storage::encoded_ptr<T> enc_ptr(new_bucket_data);
memset(new_bucket_data, 0xFF, BUCKET_SIZE * sizeof(T));
if (!container[bucket_idx].atomic_init(enc_ptr)) {
ALLOCATOR.dealloc(new_bucket_data);
allocator::instance().dealloc(new_bucket_data);
return container[bucket_idx].atomic_load();
}
return enc_ptr;
Expand Down
3 changes: 1 addition & 2 deletions libconfluo/confluo/planner/query_plan.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ class query_plan : public std::vector<std::shared_ptr<query_op>> {
* @param schema The schema for the query plan
* @param expr The query plan expression
*/
query_plan(const data_log *dlog, const schema_t *schema,
const parser::compiled_expression &expr);
query_plan(const data_log *dlog, const schema_t *schema, const parser::compiled_expression &expr);

/**
* Gets a string representation of the query plan
Expand Down
8 changes: 7 additions & 1 deletion libconfluo/confluo/storage/allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
namespace confluo {

/** Static storage allocator */
static storage::storage_allocator ALLOCATOR;
class allocator {
public:
static storage::storage_allocator &instance() {
static storage::storage_allocator alloc;
return alloc;
}
};

}

Expand Down
10 changes: 6 additions & 4 deletions libconfluo/confluo/storage/ptr_metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,25 @@ struct alloc_type {
* Pointer metadata set for memory allocated by the
* allocator. Not all fields may necessarily be set.
*/
typedef struct ptr_metadata {

struct ptr_metadata {
// Do NOT re-order.
uint32_t data_size_ : 32; // size of data
uint16_t offset_: 16; // data offset from allocated pointer location
uint16_t thread_id_ : 11; // allocating thread id
uint8_t alloc_type_ : 1; // allocation type
uint8_t aux_ : 4; // data-related state information

ptr_metadata() = default;

~ptr_metadata() = default;

/**
* Get metadata associated with a pointer
* @param ptr The pointer to get metadaata of
* @return The metadata associated with the pointer
*/
static ptr_metadata *get(void *ptr);

} ptr_metadata;
};

}
}
Expand Down
15 changes: 6 additions & 9 deletions libconfluo/confluo/storage/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,9 @@ typedef void (*flush_fn)(void *ptr, size_t size);
* Contains the particular storage mode
*/
enum storage_mode {
/** Stores data in memory */
IN_MEMORY = 0,
/** Has relaxed durability guarantees */
DURABLE_RELAXED = 1,
/** Persisted storage */
DURABLE = 2
IN_MEMORY = 0, /** Stores data in memory */
DURABLE_RELAXED = 1, /** Has relaxed durability guarantees */
DURABLE = 2 /** Persisted storage */
};

/**
Expand Down Expand Up @@ -91,7 +88,7 @@ struct in_memory {
*/
inline static void *allocate_bucket(const std::string &path, size_t size) {
ptr_aux_block aux(state_type::D_IN_MEMORY, encoding_type::D_UNENCODED);
return ALLOCATOR.alloc(size, aux);
return allocator::instance().alloc(size, aux);
}

/**
Expand Down Expand Up @@ -145,7 +142,7 @@ struct durable_relaxed {
*/
inline static void *allocate_bucket(const std::string &path, size_t size) {
ptr_aux_block aux(state_type::D_IN_MEMORY, encoding_type::D_UNENCODED);
return ALLOCATOR.mmap(path, size, aux);
return allocator::instance().mmap(path, size, aux);
}

/**
Expand Down Expand Up @@ -199,7 +196,7 @@ struct durable {
*/
inline static void *allocate_bucket(const std::string &path, size_t size) {
ptr_aux_block aux(state_type::D_IN_MEMORY, encoding_type::D_UNENCODED);
return ALLOCATOR.mmap(path, size, aux);
return allocator::instance().mmap(path, size, aux);
}

/**
Expand Down
1 change: 0 additions & 1 deletion libconfluo/confluo/storage/storage_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ class storage_allocator {

static const int MAX_CLEANUP_RETRIES = 10;
static void no_op() {}

};

}
Expand Down
8 changes: 4 additions & 4 deletions libconfluo/confluo/storage/swappable_encoded_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class read_only_encoded_ptr {
* @param data decoded data buffer
*/
void encode(size_t idx, size_t len, const T *data) {
enc_ptr_.encode(idx + offset_, len, data);
enc_ptr_.encode(idx + offset_, data, len);
}

/**
Expand Down Expand Up @@ -179,10 +179,10 @@ class read_only_encoded_ptr {
bool uses_first_count = ptr_aux_block::get(metadata).state_ == state_type::D_IN_MEMORY;
if (uses_first_count && ref_counts_->decrement_first_and_compare()) {
lifecycle_util<T>::destroy(internal_ptr);
ALLOCATOR.dealloc(internal_ptr);
allocator::instance().dealloc(internal_ptr);
} else if (!uses_first_count && ref_counts_->decrement_second_and_compare()) {
lifecycle_util<T>::destroy(internal_ptr);
ALLOCATOR.dealloc(internal_ptr);
allocator::instance().dealloc(internal_ptr);
}
}
}
Expand Down Expand Up @@ -360,7 +360,7 @@ class swappable_encoded_ptr {
static void destroy_dealloc(encoded_ptr<T> encoded_ptr) {
void *internal_ptr = encoded_ptr.ptr();
lifecycle_util<T>::destroy(internal_ptr);
ALLOCATOR.dealloc(internal_ptr);
allocator::instance().dealloc(internal_ptr);
}

mutable reference_counts ref_counts_; // mutable reference counts for logically const functions
Expand Down
6 changes: 3 additions & 3 deletions libconfluo/confluo/storage/swappable_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ class read_only_ptr {
bool uses_first_count = aux.state_ == state_type::D_IN_MEMORY;
if (uses_first_count && ref_counts_->decrement_first_and_compare()) {
lifecycle_util<T>::destroy(ptr_);
ALLOCATOR.dealloc(ptr_);
allocator::instance().dealloc(ptr_);
} else if (!uses_first_count && ref_counts_->decrement_second_and_compare()) {
lifecycle_util<T>::destroy(ptr_);
ALLOCATOR.dealloc(ptr_);
allocator::instance().dealloc(ptr_);
}
}
}
Expand Down Expand Up @@ -288,7 +288,7 @@ class swappable_ptr {
*/
static void destroy_dealloc(T *ptr) {
lifecycle_util<T>::destroy(ptr);
ALLOCATOR.dealloc(ptr);
allocator::instance().dealloc(ptr);
}

mutable reference_counts ref_counts_; // mutable reference counts for logically const functions
Expand Down
33 changes: 17 additions & 16 deletions libconfluo/confluo/types/numeric.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ data_type max(const data_type &t1, const data_type &t2);

class numeric {
public:
/** The maximum size of data a numeric can hold in bytes */
static const size_t MAX_SIZE = sizeof(uint64_t);

/**
* Constructs a numeric of the none type
*/
Expand Down Expand Up @@ -184,8 +181,7 @@ class numeric {
* @throw invalid_operation_exception
* @return True if the relational comparison is true, false otherwise
*/
static bool relop(reational_op_id id, const numeric &first,
const numeric &second);
static bool relop(reational_op_id id, const numeric &first, const numeric &second);

/**
* Less than operator
Expand Down Expand Up @@ -302,8 +298,7 @@ class numeric {
*
* @return A numeric containing the result of the binary expression
*/
static numeric binaryop(binary_op_id id, const numeric &first,
const numeric &second);
static numeric binaryop(binary_op_id id, const numeric &first, const numeric &second);

/**
* The addition operator
Expand Down Expand Up @@ -524,10 +519,8 @@ class numeric {
*
* @return The value of type T
*/
template<typename T,
typename std::enable_if<
std::is_integral<T>::value || std::is_floating_point<T>::value, T>::type * =
nullptr>
template<typename T, typename std::enable_if<std::is_integral<T>::value || std::is_floating_point<T>::value,
T>::type * = nullptr>
T &as() {
return *reinterpret_cast<T *>(data_);
}
Expand All @@ -539,10 +532,8 @@ class numeric {
*
* @return The value of type T that is not modifiable
*/
template<typename T,
typename std::enable_if<
std::is_integral<T>::value || std::is_floating_point<T>::value, T>::type * =
nullptr>
template<typename T, typename std::enable_if<std::is_integral<T>::value || std::is_floating_point<T>::value,
T>::type * = nullptr>
const T &as() const {
return *reinterpret_cast<const T *>(data_);
}
Expand All @@ -554,13 +545,23 @@ class numeric {
*/
std::string to_string() const;

/**
* Get the type for the numeric
*
* @return The numeric type
*/
data_type type();

/**
* Get raw data for the numeric
*
* @return Raw data for the numeric
*/
uint8_t *data();

private:
data_type type_;
uint8_t data_[MAX_SIZE];
uint8_t data_[sizeof(uint64_t)];
};

// Cast functions for primitive types
Expand Down
39 changes: 13 additions & 26 deletions libconfluo/confluo/types/primitive_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,19 @@ namespace confluo {
*/
enum primitive_type
: uint16_t {
/** Identifier for the none type */
D_NONE = 0,
/** Identifier for the boolean type */
D_BOOL = 1,
/** Identifier for the character type */
D_CHAR = 2,
/** Identifier for the unsigned character type */
D_UCHAR = 3,
/** Identifier for the short type */
D_SHORT = 4,
/** Identifier for the unsigned short type */
D_USHORT = 5,
/** Identifier for the signed integer type */
D_INT = 6,
/** Identifier for the unsigned integer type */
D_UINT = 7,
/** Identifier for the long type */
D_LONG = 8,
/** Identifier for the unsigned long type */
D_ULONG = 9,
/** Identifier for the float type */
D_FLOAT = 10,
/** Identifier for the double type */
D_DOUBLE = 11,
/** Identifier for the string type */
D_STRING = 12
D_NONE = 0, /** Identifier for the none type */
D_BOOL = 1, /** Identifier for the boolean type */
D_CHAR = 2, /** Identifier for the character type */
D_UCHAR = 3, /** Identifier for the unsigned character type */
D_SHORT = 4, /** Identifier for the short type */
D_USHORT = 5, /** Identifier for the unsigned short type */
D_INT = 6, /** Identifier for the signed integer type */
D_UINT = 7, /** Identifier for the unsigned integer type */
D_LONG = 8, /** Identifier for the long type */
D_ULONG = 9, /** Identifier for the unsigned long type */
D_FLOAT = 10, /** Identifier for the float type */
D_DOUBLE = 11, /** Identifier for the double type */
D_STRING = 12 /** Identifier for the string type */
};

class limits {
Expand Down
Loading

0 comments on commit f5663f2

Please sign in to comment.