Permalink
Browse files

Cleaned parameter and fixed bug in use of getcwd().

1 parent d152f52 commit ca36d9e9a5ad95f7bea904a1f2324ef9ece8b41c @goossaert committed May 14, 2015
View
@@ -25,7 +25,8 @@ BINDIR=$(PREFIX)/bin
INCLUDEDIR=$(PREFIX)/include/kingdb
LIBDIR=$(PREFIX)/lib
-CFLAGS=-std=c++11 -MMD -MP -c
+GCC_WALL=-Waddress -Warray-bounds=1 -Wc++11-compat -Wc++14-compat -Wchar-subscripts -Wenum-compare -Wimplicit-int -Wimplicit-function-declaration -Wcomment -Wformat -Wmain -Wmaybe-uninitialized -Wmissing-braces -Wnonnull -Wopenmp-simd -Wparentheses -Wpointer-sign -Wreorder -Wreturn-type -Wsequence-point -Wsign-compare -Wstrict-aliasing -Wstrict-overflow=1 -Wswitch -Wtrigraphs -Wuninitialized -Wunknown-pragmas -Wunused-function -Wunused-label -Wunused-value -Wunused-variable -Wvolatile-register-var
+CFLAGS=-Wall -std=c++11 -MMD -MP -c
all: CFLAGS += -O2
all: $(SOURCES) $(LIBRARY) $(EXECUTABLE) $(CLIENT_EMB) $(TEST_COMPRESSION) $(TEST_DB)
View
@@ -47,6 +47,7 @@ KingDB has no external dependencies and has been tested on:
- Mac OS X 10.9.5 with Apple LLVM version 6.0 (clang-600.0.51)
- Linux Ubuntu 14.04 x64 with GCC 4.9.2
+- Linux Ubuntu 15.04 x64 with GCC 4.9.2-10ubuntu13
- Linux CentOS 6.5 x86\_64 with GCC 4.9.2
If you are using GCC, update the Makefile and add \-fno\-builtin\-memcmp in the CFLAGS, and if you have tcmalloc on your system, add \-ltcmalloc to the LDFLAGS. This will give you a nice performance speed\-up.
View
@@ -46,6 +46,7 @@ KingDB has no external dependencies and has been tested on:
- Mac OS X 10.9.5 with Apple LLVM version 6.0 (clang-600.0.51)
- Linux Ubuntu 14.04 x64 with GCC 4.9.2
+- Linux Ubuntu 15.04 x64 with GCC 4.9.2-10ubuntu13
- Linux CentOS 6.5 x86\_64 with GCC 4.9.2
Because KingDB uses C++11, you need GCC >=4.9.2 or Clang >=3.3. The following commands will compile KingDB as a static library, and will install it on your computer. This will also install the `kingserver` program.
View
@@ -28,6 +28,7 @@ KingServer has no external dependencies and has been tested on:
- Mac OS X 10.9.5 with Apple LLVM version 6.0 (clang-600.0.51)
- Linux Ubuntu 14.04 x64 with GCC 4.9.2
+- Linux Ubuntu 15.04 x64 with GCC 4.9.2-10ubuntu13
- Linux CentOS 6.5 x86\_64 with GCC 4.9.2
Because KingServer uses C++11, you need GCC >=4.9.2 or Clang >=3.3. The following commands will compile KingServer and will install the `kingserver` program.
@@ -78,7 +79,7 @@ As long as your point the client to right IP and port where KingServer listens,
It would be tedious to have to specify all the options on the command line all the time. KingServer allows you to use a configuration file to set values for all options. Such a file would look like this:
# hash can be used to add comments
- server.size-buffer-recv 8kb
+ server.recv-socket-buffer-size 8kb
server.interface.memcached-port 11211
server.num-threads 500
@@ -185,7 +186,7 @@ Default value: info (String)
Target of the logs, can be 'stderr' to log to stderr, or any custom string that will be used as the 'ident' parameter for syslog.
Default value: kingdb (String)
-`--server.size-buffer-recv`
+`--server.recv-socket-buffer-size`
Size of the buffer used to receive data from the network. Each thread of the server has one such buffer.
Default value: 64KB (Unsigned 64-bit integer)
@@ -136,7 +136,7 @@ class MultipartReader {
char* data_left = value_.data() + offset_output_;
- size_t step = 1024*1024;
+ size_t step = 1024*1024; // TODO: make this a parameter at some point?
size_t size_current = offset_output_ + step < size_left ? step : size_left - offset_output_;
if (read_options_.verify_checksums) {
crc32_.stream(data_left, size_current);
View
@@ -32,7 +32,6 @@ void NetworkTask::Run(std::thread::id tid, uint64_t id) {
char *buffer_send = new char[server_options_.internal__size_buffer_send];
ByteArray buffer;
ByteArray key;
- int size_key = 0;
log::trace("NetworkTask", "ENTER");
// TODO-7: replace the memory allocation performed for 'key' and 'buffer' by a
// pool of pre-allocated buffers
@@ -52,20 +51,19 @@ void NetworkTask::Run(std::thread::id tid, uint64_t id) {
is_command_get = false;
is_command_put = false;
is_command_delete = false;
- size_key = 0;
}
if (is_new_buffer) {
log::trace("NetworkTask", "is_new_buffer");
bytes_received_buffer = 0;
- buffer = ByteArray::NewAllocatedMemoryByteArray(server_options_.size_buffer_recv);
+ buffer = ByteArray::NewAllocatedMemoryByteArray(server_options_.recv_socket_buffer_size);
log::trace("NetworkTask", "allocated");
}
log::trace("NetworkTask", "Calling recv()");
bytes_received_last = recv(sockfd_,
buffer.data() + bytes_received_buffer,
- server_options_.size_buffer_recv - bytes_received_buffer,
+ server_options_.recv_socket_buffer_size - bytes_received_buffer,
0);
if (bytes_received_last <= 0) {
log::trace("NetworkTask", "recv()'d 0 bytes: breaking");
@@ -143,7 +141,7 @@ void NetworkTask::Run(std::thread::id tid, uint64_t id) {
// Loop and get more data from the network if the buffer is not full and all the data
// hasn't arrived yet
if ( bytes_received_total < bytes_expected
- && bytes_received_buffer < server_options_.size_buffer_recv) {
+ && bytes_received_buffer < server_options_.recv_socket_buffer_size) {
// TODO: what if the \r\n is on the two last messages, i.e. \n is the
// first character of the last message?
log::trace("NetworkTask", "force looping to get the rest of the data");
@@ -38,6 +38,10 @@ void crash_signal_handler(int sig) {
int daemonize() {
// Adapted from Michael Kerrisk's becomeDaemon()
+
+ kdb::FileUtil::kingdb_getcwd(); // cache the current working directory
+ // before the fork() happens, otherwise
+ // getcwd() returns "/" on Mac OS X.
// Become background process
switch (fork()) {
@@ -731,12 +731,12 @@ class HSTableManager {
// storing functions) still work?
// There are three categories of entries:
- // - Small entries: sizes within [0, server.size_buffer_recv)
- // - Medium entries: sizes within [server.size_buffer_recv, hstable.maximum_size)
+ // - Small entries: sizes within [0, server.recv_socket_buffer_size)
+ // - Medium entries: sizes within [server.recv_socket_buffer_size, hstable.maximum_size)
// - Large entries: sizes greater than hstable.maximum_size
//
// When using the storage engine through a network interface, medium and
- // large entries are split into parts of size at most server.size_buffer_recv,
+ // large entries are split into parts of size at most server.recv_socket_buffer_size,
// making them "multipart" entries.
// Small entries do not need to be split, and are therefore "self-contained".
// Parts are held into "orders", which hold extra metadata needed
@@ -749,10 +749,10 @@ class HSTableManager {
// When using the storage engine embedded in another program, orders can be
// on any size, and because it is embedded, the data can be sent as is to
// the storage engine, potentially in a very large buffer, larger than
- // the size of server.size_buffer_recv contrained when on a network. Because the
- // logic in the storage engine expects first and last parts, a large
- // order that is at the same time a first *and* a last part could cause
- // an issue: the order could be treated only as a first part,
+ // the size of server.recv_socket_buffer_size contrained when on a network.
+ // Because the logic in the storage engine expects first and last parts,
+ // a large order that is at the same time a first *and* a last part could
+ // cause an issue: the order could be treated only as a first part,
// and the operations triggered by the arrival of the last part
// may not be done. To solve that problem, and because compression
// and hash functions take input of limited sizes anyway, the constant
@@ -67,7 +67,7 @@ class StorageEngine {
sequence_snapshot_ = 0;
stop_requested_ = false;
is_closed_ = false;
- fs_free_space_ = 0;
+ fs_free_space_ = db_options_.storage__minimum_free_space_accept_orders;
file_manager_ = std::make_shared<FileManager>();
if (!is_read_only_) {
thread_index_ = std::thread(&StorageEngine::ProcessingLoopIndex, this);
@@ -16,7 +16,9 @@
#include <sstream>
#include <csignal>
+#ifdef DEBUG
#include <gperftools/profiler.h>
+#endif
#include "interface/database.h"
#include "util/status.h"
View
@@ -38,6 +38,10 @@ class FileUtil {
}
static std::string kingdb_getcwd() {
+ static char *path = nullptr;
+ if (path != nullptr) {
+ return path;
+ }
char *buffer = nullptr;
int size = 64;
do {
@@ -48,9 +52,8 @@ class FileUtil {
size *= 2;
delete[] buffer;
} while(true);
- std::string cwd(buffer);
- delete[] buffer;
- return cwd;
+ path = buffer;
+ return path;
}
// NOTE: Pre-allocating disk space is very tricky: fallocate() and
View
@@ -152,7 +152,7 @@ class FileManager {
}
int MaxNumFiles() {
- return 2048; // TODO: make this is an internal parameter
+ return 2048; // TODO: make this is an internal parameter at some point?
}
private:
View
@@ -225,15 +225,14 @@ struct ServerOptions {
uint32_t interface__memcached_port;
uint32_t listen_backlog;
uint32_t num_threads;
- uint64_t size_buffer_recv;
+ uint64_t recv_socket_buffer_size;
- // TODO: change size-buffer-recv to recv-socket-buffer-size ?
// TODO: add a max-connections parameter?
static void AddParametersToConfigParser(ServerOptions& server_options, ConfigParser& parser) {
parser.AddParameter(new kdb::UnsignedInt64Parameter(
- "server.size-buffer-recv", "64KB", &server_options.size_buffer_recv, false,
+ "server.recv-socket-buffer-size", "64KB", &server_options.recv_socket_buffer_size, false,
"Size of the buffer used to receive data from the network. Each thread of the server has one such buffer."));
parser.AddParameter(new kdb::UnsignedInt32Parameter(
"server.listen-backlog", "150", &server_options.listen_backlog, false,

0 comments on commit ca36d9e

Please sign in to comment.