Skip to content

Commit

Permalink
finish test_epoch && test correctness wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
马少楠 authored and 马少楠 committed Nov 11, 2019
1 parent 6249326 commit 163121b
Show file tree
Hide file tree
Showing 73 changed files with 5,488 additions and 140 deletions.
20 changes: 0 additions & 20 deletions ART/EpochGuard.h

This file was deleted.

37 changes: 13 additions & 24 deletions ART/N.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#include "N.h"
#include "EpochGuard.h"
#include "N16.h"
#include "N256.h"
#include "N4.h"
#include "N48.h"
#include "threadinfo.h"
#include "EpochGuard.h"
#include <algorithm>
#include <assert.h>
#include <iostream>

using namespace NVMMgr_ns;

namespace PART_ns {
static unsigned long write_latency_in_ns = 0;
static unsigned long cpu_freq_mhz = 2100;
Expand Down Expand Up @@ -47,16 +49,6 @@ void N::clflush(char *data, int len, bool front, bool back) {
if (back)
mfence();
}
#ifdef LOCK_INIT
void lock_initialization() {
printf("lock table size = %lu\n", lock_initializer.size());
for (uint64_t i = 0; i < lock_initializer.size(); i++) {
// check if the node is locked
if (lock_initializer[i]->isLocked(lock_initializer[i]->getVersion()))
lock_initializer[i]->writeUnlock();
}
}
#endif

void N::helpFlush(std::atomic<N *> *n) {
if (n == nullptr)
Expand Down Expand Up @@ -168,8 +160,7 @@ void N::change(N *node, uint8_t key, N *val) {

template <typename curN, typename biggerN>
void N::insertGrow(curN *n, N *parentNode, uint8_t keyParent, uint8_t key,
N *val, NTypes type,
bool &needRestart) {
N *val, NTypes type, bool &needRestart) {
if (n->insert(key, val, true)) {
n->writeUnlock();
return;
Expand Down Expand Up @@ -201,8 +192,7 @@ void N::insertGrow(curN *n, N *parentNode, uint8_t keyParent, uint8_t key,

template <typename curN>
void N::insertCompact(curN *n, N *parentNode, uint8_t keyParent, uint8_t key,
N *val, NTypes type,
bool &needRestart) {
N *val, NTypes type, bool &needRestart) {
// compact and lock parent
parentNode->writeLockOrRestart(needRestart);
if (needRestart) {
Expand All @@ -227,28 +217,28 @@ void N::insertCompact(curN *n, N *parentNode, uint8_t keyParent, uint8_t key,
}

void N::insertAndUnlock(N *node, N *parentNode, uint8_t keyParent, uint8_t key,
N *val, bool &needRestart) {
N *val, bool &needRestart) {
switch (node->getType()) {
case NTypes::N4: {
auto n = static_cast<N4 *>(node);
if (n->compactCount == 4 && n->count <= 3) {
insertCompact<N4>(n, parentNode, keyParent, key, val, NTypes::N4,
needRestart);
needRestart);
break;
}
insertGrow<N4, N16>(n, parentNode, keyParent, key, val, NTypes::N16,
needRestart);
needRestart);
break;
}
case NTypes::N16: {
auto n = static_cast<N16 *>(node);
if (n->compactCount == 16 && n->count <= 14) {
insertCompact<N16>(n, parentNode, keyParent, key, val, NTypes::N16,
needRestart);
needRestart);
break;
}
insertGrow<N16, N48>(n, parentNode, keyParent, key, val, NTypes::N48,
needRestart);
needRestart);
break;
}
case NTypes::N48: {
Expand All @@ -259,7 +249,7 @@ void N::insertAndUnlock(N *node, N *parentNode, uint8_t keyParent, uint8_t key,
break;
}
insertGrow<N48, N256>(n, parentNode, keyParent, key, val, NTypes::N256,
needRestart);
needRestart);
break;
}
case NTypes::N256: {
Expand Down Expand Up @@ -326,8 +316,7 @@ void N::deleteChildren(N *node) {

template <typename curN, typename smallerN>
void N::removeAndShrink(curN *n, N *parentNode, uint8_t keyParent, uint8_t key,
NTypes type,
bool &needRestart) {
NTypes type, bool &needRestart) {
if (n->remove(key, parentNode == nullptr, true)) {
n->writeUnlock();
return;
Expand Down Expand Up @@ -381,7 +370,7 @@ void N::removeAndUnlock(N *node, uint8_t key, N *parentNode, uint8_t keyParent,
case NTypes::N256: {
auto n = static_cast<N256 *>(node);
removeAndShrink<N256, N48>(n, parentNode, keyParent, key, NTypes::N48,
needRestart);
needRestart);
break;
}
}
Expand Down
43 changes: 17 additions & 26 deletions ART/N.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ namespace PART_ns {
enum class NTypes : uint8_t { N4 = 1, N16 = 2, N48 = 3, N256 = 4, Leaf = 5 };

class BaseNode {
public:
public:
NTypes type;
BaseNode(NTypes type_) : type(type_){}
BaseNode(NTypes type_) : type(type_) {}
virtual ~BaseNode() {}
};

class Leaf : public BaseNode{
class Leaf : public BaseNode {
public:
size_t key_len;
uint64_t key;
Expand All @@ -37,7 +38,7 @@ class Leaf : public BaseNode{
uint64_t value;

public:
Leaf(const Key *k): BaseNode(NTypes::Leaf) {
Leaf(const Key *k) : BaseNode(NTypes::Leaf) {
key_len = k->key_len;
value = k->value;
#ifdef KEY_INLINE
Expand All @@ -49,6 +50,8 @@ class Leaf : public BaseNode{
memcpy(fkey, k->fkey, key_len);
#endif
}
// use for test
Leaf() : BaseNode(NTypes::Leaf) {}

virtual ~Leaf() {
// TODO
Expand All @@ -69,38 +72,30 @@ struct Prefix {
uint8_t prefix[maxStoredPrefixLength];
};
static_assert(sizeof(Prefix) == 8, "Prefix should be 64 bit long");
#ifdef LOCK_INIT
class N;
static tbb::concurrent_vector<N *> lock_initializer;
void lock_initialization();
#endif
class N : public BaseNode{

class N : public BaseNode {
protected:
N(NTypes type, uint32_t level, const uint8_t *prefix, uint32_t prefixLength)
: BaseNode(type), level(level) {
setType(type);
setPrefix(prefix, prefixLength, false);
#ifdef LOCK_INIT
lock_initializer.push_back(this);
#endif
}

N(NTypes type, uint32_t level, const Prefix &prefi)
: BaseNode(type), prefix(prefi), level(level) {
setType(type);
#ifdef LOCK_INIT
lock_initializer.push_back(this);
#endif
}

N(const N &) = delete;

N(N &&) = delete;

virtual ~N() {}

// 3b type 60b version 1b lock 1b obsolete
std::atomic<uint64_t> typeVersionLockObsolete{0b100};
// version 1, unlocked, not obsolete
std::atomic<Prefix> prefix;
alignas(64) std::atomic<Prefix> prefix;
const uint32_t level;
uint16_t count = 0;
uint16_t compactCount = 0;
Expand Down Expand Up @@ -156,14 +151,12 @@ class N : public BaseNode{
static std::atomic<N *> *getChild(const uint8_t k, N *node);

static void insertAndUnlock(N *node, N *parentNode, uint8_t keyParent,
uint8_t key, N *val,
bool &needRestart);
uint8_t key, N *val, bool &needRestart);

static void change(N *node, uint8_t key, N *val);

static void removeAndUnlock(N *node, uint8_t key, N *parentNode,
uint8_t keyParent,
bool &needRestart);
uint8_t keyParent, bool &needRestart);

Prefix getPrefi() const;

Expand All @@ -189,18 +182,16 @@ class N : public BaseNode{

template <typename curN, typename biggerN>
static void insertGrow(curN *n, N *parentNode, uint8_t keyParent,
uint8_t key, N *val, NTypes type,
bool &needRestart);
uint8_t key, N *val, NTypes type, bool &needRestart);

template <typename curN>
static void insertCompact(curN *n, N *parentNode, uint8_t keyParent,
uint8_t key, N *val, NTypes type,
bool &needRestart);
bool &needRestart);

template <typename curN, typename smallerN>
static void removeAndShrink(curN *n, N *parentNode, uint8_t keyParent,
uint8_t key, NTypes type,
bool &needRestart);
uint8_t key, NTypes type, bool &needRestart);

static void getChildren(N *node, uint8_t start, uint8_t end,
std::tuple<uint8_t, std::atomic<N *> *> children[],
Expand Down
1 change: 0 additions & 1 deletion ART/Tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ Tree::~Tree() {
close_nvm_mgr();
}


void *Tree::lookup(const Key *k) const {
// enter a new epoch
EpochGuard NewEpoch;
Expand Down
1 change: 0 additions & 1 deletion ART/Tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class Tree {

void rebuild();


void *lookup(const Key *k) const;

bool lookupRange(const Key *start, const Key *end, const Key *continueKey,
Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ else ()
message(STATUS "Build type is set to ${CMAKE_BUILD_TYPE}")
endif ()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -O2 -march=native -mavx -mavx2 -DNDEBUG")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -g -march=native -mavx -mavx2 -DNDEBUG")

## Instruction options for Cache line flush
add_definitions(-DCLFLUSH)
Expand All @@ -17,6 +17,7 @@ add_definitions(-DCLFLUSH)

link_libraries(pthread atomic boost_system boost_thread gtest)
find_library(TbbLib tbb)

include_directories(./ART
./benchmark
./nvm_mgr
Expand Down
14 changes: 5 additions & 9 deletions benchmark/coordinator.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ template <typename K, typename V, int size> class Coordinator {
stick_this_thread_to_core(workerid);
bar->wait();

auto tinfo = art->getThreadInfo();

unsigned long tx = 0;

double total_update_latency_breaks[3] = {0.0, 0.0, 0.0};
Expand Down Expand Up @@ -146,17 +144,17 @@ template <typename K, typename V, int size> class Coordinator {
// break;
case INSERT:
// printf("[%d] start insert %lld\n", workerid, d);
res = art->insert(k, tinfo);
res = art->insert(k);
if (res == PART_ns::Tree::OperationResults::Success) {
count++;
}
break;
case REMOVE:

art->remove(k, tinfo);
art->remove(k);
break;
case GET:
art->lookup(k, tinfo);
art->lookup(k);

// if (tx % 100 == 0) {
// sync_latency(total_find_latency_breaks,
Expand Down Expand Up @@ -360,19 +358,17 @@ template <typename K, typename V, int size> class Coordinator {
std::thread **pid = new std::thread *[conf.num_threads];
bar = new boost::barrier(conf.num_threads + 1);

auto tinfo = art->getThreadInfo();

PART_ns::Key *k = new PART_ns::Key();
for (unsigned long i = 0; i < conf.init_keys; i++) {
if (conf.key_type == Integer) {
long kk = benchmark->nextInitIntKey();
k->Init(kk, sizeof(uint64_t), kk);
art->insert(k, tinfo);
art->insert(k);
} else if (conf.key_type == String) {
std::string s = benchmark->nextInitStrKey();
k->Init((char *)s.c_str(), sizeof(uint64_t),
(char *)s.c_str());
art->insert(k, tinfo);
art->insert(k);
}
}
printf("init insert finished\n");
Expand Down
Loading

0 comments on commit 163121b

Please sign in to comment.