Skip to content

Commit

Permalink
Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
HaoyuHuang committed Jun 26, 2020
1 parent cea4e0d commit 0462ad8
Show file tree
Hide file tree
Showing 44 changed files with 295 additions and 413 deletions.
12 changes: 0 additions & 12 deletions AUTHORS

This file was deleted.

6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,11 @@ target_sources(leveldb
rdma/nova_msg_parser.h
novalsm/nic_server.cpp
novalsm/nic_server.h
novalsm/conn_worker.cpp
novalsm/conn_worker.h
novalsm/client_req_worker.cpp
novalsm/client_req_worker.h
common/nova_common.cpp
common/nova_common.h
rdma/nova_msg_callback.h
rdma/rdma_msg_callback.h
rdma/nova_rdma_rc_broker.cpp
rdma/nova_rdma_rc_broker.h
rdma/nova_rdma_broker.h
Expand Down
36 changes: 0 additions & 36 deletions CONTRIBUTING.md

This file was deleted.

17 changes: 0 additions & 17 deletions NEWS

This file was deleted.

14 changes: 0 additions & 14 deletions TODO

This file was deleted.

4 changes: 2 additions & 2 deletions benchmarks/rdma_write_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
#ifndef LEVELDB_RDMA_WRITE_CLIENT_H
#define LEVELDB_RDMA_WRITE_CLIENT_H

#include "rdma/nova_msg_callback.h"
#include "rdma/rdma_msg_callback.h"
#include "rdma/nova_rdma_broker.h"
#include "common/nova_mem_manager.h"

namespace nova {
class RDMAWRITEClient : public NovaMsgCallback {
class RDMAWRITEClient : public RDMAMsgCallback {
public:
RDMAWRITEClient(uint32_t write_size_kb,
uint32_t my_server_id);
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/rdma_write_server_worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include <semaphore.h>

#include "rdma/nova_msg_callback.h"
#include "rdma/rdma_msg_callback.h"
#include "rdma/nova_rdma_broker.h"
#include "stoc/persistent_stoc_file.h"
#include "common/nova_mem_manager.h"
Expand All @@ -34,7 +34,7 @@ namespace nova {

class RDMAWRITEDiskWorker;

class RDMAWRITEServerWorker : public NovaMsgCallback {
class RDMAWRITEServerWorker : public RDMAMsgCallback {
public:
RDMAWRITEServerWorker(uint32_t max_run_time, uint32_t write_size_kb,
bool is_local_disk_bench, bool eval_disk_horizontal_scalability, uint32_t server_id);
Expand Down
7 changes: 0 additions & 7 deletions build.sh

This file was deleted.

102 changes: 24 additions & 78 deletions common/nova_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,30 +205,30 @@ namespace nova {
/* Initial power multiplier for the hash table */
#define HASHPOWER_DEFAULT 16

class Semaphore {
public:
Semaphore(int count_ = 0)
: count(count_) {}

inline void notify() {
std::unique_lock<std::mutex> lock(mtx);
count++;
cv.notify_all();
}

inline void wait() {
std::unique_lock<std::mutex> lock(mtx);
while (count == 0) {
cv.wait(lock);
}
count--;
}

private:
std::mutex mtx;
std::condition_variable cv;
int count = 0;
};
// class Semaphore {
// public:
// Semaphore(int count_ = 0)
// : count(count_) {}
//
// inline void notify() {
// std::unique_lock<std::mutex> lock(mtx);
// count++;
// cv.notify_all();
// }
//
// inline void wait() {
// std::unique_lock<std::mutex> lock(mtx);
// while (count == 0) {
// cv.wait(lock);
// }
// count--;
// }
//
// private:
// std::mutex mtx;
// std::condition_variable cv;
// int count = 0;
// };


uint32_t fastrand();
Expand Down Expand Up @@ -431,47 +431,6 @@ namespace nova {
}
};

enum LeaseType : uint8_t {
ILEASE = 1,
QLEASE = 2
};

struct LeaseEntry {
uint8_t type = 0;
// worker_id | lease_id.
uint64_t lease_id = 0;
// client_id | session_id.
uint64_t session_id = 0;

bool empty() {
return lease_id == 0;
}

static uint64_t size() {
return sizeof(uint8_t) + sizeof(uint64_t) + sizeof(uint64_t);
}

static LeaseEntry chars_to_leaseitem(char *buf) {
LeaseEntry it{};
char *tmp = buf;
memcpy(&it.type, tmp, sizeof(uint8_t));
tmp += sizeof(uint8_t);
memcpy(&it.lease_id, tmp, sizeof(uint64_t));
tmp += sizeof(uint64_t);
memcpy(&it.session_id, tmp, sizeof(uint64_t));
return it;
}

static void leaseitem_to_chars(char *_base, const LeaseEntry &entry) {
char *buf = _base;
memcpy(buf, &entry.type, sizeof(uint8_t));
buf += sizeof(uint8_t);
memcpy(buf, &entry.lease_id, sizeof(uint64_t));
buf += sizeof(uint64_t);
memcpy(buf, &entry.session_id, sizeof(uint64_t));
}
};

// Memory layout:
// stale, refs, nkey, key, nval (string representation + 1), 'h', val, checksum.
// data points to the beginning of the backing array.
Expand Down Expand Up @@ -627,19 +586,6 @@ namespace nova {
}
};

// inline uint32_t
// LogRecordsSize(const leveldb::LevelDBLogRecord &log_record);
//
// inline uint32_t
// LogRecordsSize(const std::vector<leveldb::LevelDBLogRecord> &log_records);
//
// inline uint32_t
// EncodeLogRecord(char *buf,
// const leveldb::LevelDBLogRecord &log_record);
//
// inline uint32_t DecodeLogRecord(char *buf,
// leveldb::LevelDBLogRecord *log_record);

inline uint32_t
LogRecordSize(const leveldb::LevelDBLogRecord &record) {
uint32_t size = 0;
Expand Down
3 changes: 1 addition & 2 deletions common/nova_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ namespace nova {
uint64_t log_buf_size;
uint64_t max_stoc_file_size;
uint64_t sstable_size;
std::string stoc_file_path;
std::string stoc_files_path;

bool use_local_disk;
bool enable_subrange;
Expand Down Expand Up @@ -185,7 +185,6 @@ namespace nova {
int level;

int block_cache_mb;
int row_cache_mb;
bool enable_lookup_index;
bool enable_range_index;
uint32_t num_memtables;
Expand Down
2 changes: 1 addition & 1 deletion common/nova_mem_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// Created by Haoyu Huang on 4/8/19.
// Copyright (c) 2019 University of Southern California. All rights reserved.
//
// A slabclass memory manager.

#ifndef NOVA_MEM_MANAGER_H
#define NOVA_MEM_MANAGER_H
Expand Down
16 changes: 8 additions & 8 deletions db/db_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2634,15 +2634,15 @@ namespace leveldb {
uint32_t memtable_id) {
if (nova::NovaConfig::config->log_record_mode ==
nova::NovaLogRecordMode::LOG_RDMA && !options.local_write) {
auto dc = reinterpret_cast<leveldb::StoCBlockClient *>(options.stoc_client);
NOVA_ASSERT(dc);
dc->set_dbid(dbid_);
auto stoc = reinterpret_cast<leveldb::StoCBlockClient *>(options.stoc_client);
NOVA_ASSERT(stoc);
stoc->set_dbid(dbid_);
options.stoc_client->InitiateReplicateLogRecords(
nova::LogFileName(server_id_, dbid_, memtable_id),
options.thread_id, dbid_, memtable_id,
options.rdma_backing_mem, log_records,
options.replicate_log_record_states);
dc->Wait();
stoc->Wait();
}
}

Expand All @@ -2652,9 +2652,9 @@ namespace leveldb {
uint32_t memtable_id) {
if (nova::NovaConfig::config->log_record_mode ==
nova::NovaLogRecordMode::LOG_RDMA && !options.local_write) {
auto dc = reinterpret_cast<leveldb::StoCBlockClient *>(options.stoc_client);
NOVA_ASSERT(dc);
dc->set_dbid(dbid_);
auto stoc = reinterpret_cast<leveldb::StoCBlockClient *>(options.stoc_client);
NOVA_ASSERT(stoc);
stoc->set_dbid(dbid_);
LevelDBLogRecord log_record = {};
log_record.sequence_number = last_sequence;
log_record.key = key;
Expand All @@ -2666,7 +2666,7 @@ namespace leveldb {
options.thread_id, dbid_, memtable_id,
options.rdma_backing_mem, {log_record},
options.replicate_log_record_states);
dc->Wait();
stoc->Wait();
}
}

Expand Down
5 changes: 3 additions & 2 deletions db/lookup_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
//
// Created by Haoyu Huang on 5/19/20.
// Copyright (c) 2020 University of Southern California. All rights reserved.
//
// It assumes a fixed size lookup index. One may swap it with any implementation of concurrent hash map.
// TODO: Support cleaning up the lookup index to remove entries that point to obsolete memtable ids.

#ifndef LEVELDB_LOOKUP_INDEX_H
#define LEVELDB_LOOKUP_INDEX_H
Expand All @@ -29,12 +30,12 @@ namespace leveldb {
uint32_t Encode(char *buf);

void Decode(Slice *buf);

private:
uint32_t size_ = 0;
TableLocation *table_locator_ = nullptr;
};
}



#endif //LEVELDB_LOOKUP_INDEX_H
2 changes: 0 additions & 2 deletions db/range_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
#include "leveldb/slice.h"
#include "version_set.h"

#define MAX_LIVE_VERSIONS 100000

namespace leveldb {
struct RangeTables {
std::set<uint32_t> memtable_ids;
Expand Down
1 change: 1 addition & 0 deletions db/subrange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//
// Created by Haoyu Huang on 5/4/20.
// Copyright (c) 2020 University of Southern California. All rights reserved.
// It assumes keys are integers.
//

#include "leveldb/subrange.h"
Expand Down
1 change: 1 addition & 0 deletions db/subrange_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//
// Created by Haoyu Huang on 5/4/20.
// Copyright (c) 2020 University of Southern California. All rights reserved.
// It assumes keys are integers.
//

#ifndef LEVELDB_SUBRANGE_MANAGER_H
Expand Down
3 changes: 3 additions & 0 deletions db/version_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "table_cache.h"
#include "range_index.h"

// Maintain this many live memtables.
// The program exits when the number of memtables exceeds this threshold.
#define MAX_LIVE_MEMTABLES 100000

namespace leveldb {
Expand Down Expand Up @@ -216,6 +218,7 @@ namespace leveldb {
uint32_t Encode(char *buf);

void Decode(Slice *buf);

int refs_ = 0; // Number of live refs to this version

private:
Expand Down
Loading

0 comments on commit 0462ad8

Please sign in to comment.