-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
106 changed files
with
2,534 additions
and
1,055 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
rocksdb_server | ||
create_db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
SKYLOFT_DIR ?= | ||
ROCKSDB_SRC ?= | ||
|
||
CFLAGS = -I$(SKYLOFT_DIR)/include -DSKYLOFT | ||
SKYLOFT_LIBS = $(SKYLOFT_DIR)/lib/libskyloft.a $(SKYLOFT_DIR)/lib/libutils.a | ||
SKYLOFT_LDFLAGS = -T $(SKYLOFT_DIR)/lib/libos.ld -lnuma | ||
SKYLOFT_LDFLAGS += $(shell pkg-config --libs libdpdk) | ||
|
||
CFLAGS += -I$(ROCKSDB_SRC)/include/rocksdb/ | ||
ROCKSDB_LIBS = $(ROCKSDB_SRC)/librocksdb.a | ||
ROCKSDB_LDFLAGS = -lpthread -ldl -lz -lbz2 -lsnappy -lzstd -lstdc++ -lm | ||
|
||
ifneq ($(DEBUG),) | ||
CFLAGS += -DDEBUG -rdynamic -O0 -ggdb | ||
LDFLAGS += -rdynamic | ||
else | ||
CFLAGS += -DNDEBUG -O3 | ||
endif | ||
|
||
CC = gcc | ||
CXX = g++ | ||
LD = gcc | ||
|
||
rocksdb_server_src = rocksdb_server.cc | ||
rocksdb_server_obj = $(rocksdb_server_src:.cc=.o) | ||
|
||
create_db_src = create_db.cc | ||
create_db_obj = $(create_db_src:.cc=.o) | ||
|
||
src = $(rocksdb_server_src) $(create_db_src) | ||
obj = $(rocksdb_server_obj) $(create_db_obj) | ||
|
||
# must be first | ||
all: rocksdb_server create_db | ||
|
||
$(ROCKSDB_LIBS): | ||
make -j -C rocksdb static_lib | ||
|
||
rocksdb_server: $(rocksdb_server_obj) $(SKYLOFT_LIBS) $(ROCKSDB_LIBS) | ||
$(LD) -o $@ $^ $(SKYLOFT_LDFLAGS) $(ROCKSDB_LDFLAGS) | ||
|
||
create_db: $(create_db_obj) $(ROCKSDB_LIBS) | ||
$(LD) -o $@ $^ $(ROCKSDB_LDFLAGS) | ||
|
||
%.o: %.c | ||
$(CC) $(CFLAGS) -c $< -o $@ | ||
|
||
%.o: %.cc | ||
$(CXX) $(CFLAGS) -c $< -o $@ | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -f $(obj) rocksdb_server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#include <assert.h> | ||
#include <random> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include "c.h" | ||
|
||
#include <unistd.h> // sysconf() - get CPU count | ||
|
||
const char DBPath[] = "/tmp/my_db"; | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
rocksdb_t *db; | ||
rocksdb_backup_engine_t *be; | ||
rocksdb_options_t *options = rocksdb_options_create(); | ||
|
||
rocksdb_slicetransform_t *prefix_extractor = rocksdb_slicetransform_create_fixed_prefix(8); | ||
rocksdb_options_set_prefix_extractor(options, prefix_extractor); | ||
rocksdb_options_set_plain_table_factory(options, 0, 10, 0.75, 3); | ||
|
||
// Optimize RocksDB. This is the easiest way to | ||
// get RocksDB to perform well | ||
long cpus = sysconf(_SC_NPROCESSORS_ONLN); // get # of online cores | ||
rocksdb_options_increase_parallelism(options, (int)(cpus)); | ||
rocksdb_options_optimize_level_style_compaction(options, 512 * 1024 * 1024); | ||
// create the DB if it's not already present | ||
rocksdb_options_set_create_if_missing(options, 1); | ||
|
||
// open DB | ||
char *err = NULL; | ||
db = rocksdb_open(options, DBPath, &err); | ||
if (err) { | ||
printf("Failed to open DB: %s\n", err); | ||
exit(1); | ||
} | ||
|
||
// Setup RNG | ||
std::random_device rd; | ||
std::mt19937_64 e2(rd()); | ||
std::uniform_int_distribution<long long int> dist(std::llround(std::pow(2, 64))); | ||
|
||
// Put key-value | ||
rocksdb_writeoptions_t *writeoptions = rocksdb_writeoptions_create(); | ||
const char *value = "value"; | ||
for (int i = 0; i < 5000; i++) { | ||
char key[10]; | ||
// char value[64]; | ||
snprintf(key, sizeof(key), "key%d", i); | ||
// snprintf(value, sizeof(value), "%lld", dist(e2)); | ||
rocksdb_put(db, writeoptions, key, strlen(key), value, strlen(value) + 1, &err); | ||
assert(!err); | ||
} | ||
|
||
// Get value | ||
rocksdb_readoptions_t *readoptions = rocksdb_readoptions_create(); | ||
for (int i = 0; i < 10000; i++) { | ||
size_t len; | ||
char key[10]; | ||
snprintf(key, sizeof(key), "key%d", i); | ||
char *returned_value = rocksdb_get(db, readoptions, key, strlen(key), &len, &err); | ||
if (err) { | ||
printf("GET failed: %s\n", err); | ||
break; | ||
} | ||
printf("key: %s, Returned value: %s\n", key, returned_value); | ||
if (i < 5000) { | ||
assert(strcmp(returned_value, "value") == 0); | ||
free(returned_value); | ||
} else { | ||
assert(!returned_value); | ||
} | ||
} | ||
|
||
// cleanup | ||
rocksdb_writeoptions_destroy(writeoptions); | ||
// rocksdb_readoptions_destroy(readoptions); | ||
rocksdb_options_destroy(options); | ||
rocksdb_close(db); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.