Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First functional INCR command #20

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
128a6fa
Merge pull request #1 from olapiv/mikaelMultiP
mronstro Nov 4, 2024
d968646
RONDB-765: First step to implementing INCR command
mikaelronstrom Nov 5, 2024
e0f9c05
RONDB-766: Fix compiler warnings
mikaelronstrom Nov 5, 2024
a265c5d
RONDB-761: First functional INCR command
mikaelronstrom Nov 6, 2024
4f768a4
RONDB-761: Improvements to INCR key
mikaelronstrom Nov 7, 2024
bf9c8fb
RONDB-761: Review comments
mikaelronstrom Nov 8, 2024
fa82c40
RONDB-761: Fixed mistake
mikaelronstrom Nov 8, 2024
8ad0fe3
Autoformatting
olapiv Nov 8, 2024
7fffcde
Bumped RonDB version
olapiv Nov 8, 2024
8a8c34e
Added INCR to Bash tests
olapiv Nov 8, 2024
816ebac
Moved interpreted code to separate file
olapiv Nov 8, 2024
67ffec5
Removed redundant headers
olapiv Nov 8, 2024
27fbeda
Merge pull request #2 from olapiv/mikaelFixes
mronstro Nov 8, 2024
a21b3fb
RONDB-761: Fixed breakout of interpreter code, case insensitive comma…
mikaelronstrom Nov 8, 2024
e7f0dea
Slash compiler warnings
olapiv Nov 11, 2024
c8c449d
Slash compiler warnings
olapiv Nov 11, 2024
0660f9d
Added command ECHO
olapiv Nov 11, 2024
2aac8d2
Added piped_key command in tests
olapiv Nov 12, 2024
e3886c7
Redis-benchmark: multiple clients, random keyspace, batched requests
olapiv Nov 12, 2024
b3265ff
Added $KEY to batched test
olapiv Nov 12, 2024
812495d
Added log
olapiv Nov 12, 2024
6b22057
FIX: Set "close_" to false by default
olapiv Nov 12, 2024
b9d77c2
Fix compiler warning
olapiv Nov 12, 2024
b536240
Added CONFIG parameter
olapiv Nov 12, 2024
3585961
Added comments/logs
olapiv Nov 12, 2024
e4be12f
Removed commented-out code
olapiv Nov 12, 2024
eec0e23
Run tests multi-threaded
olapiv Nov 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
}
},
"containerEnv": {
"RONDB_PATH": "/usr/src/app/rondb-22.10.5-linux-glibc2.28-arm64_v8",
"RONDB_PATH": "/usr/src/app/rondb-24.10.0-linux-glibc2.28-arm64_v8",
// This assumes that the RonDB tarball is placed the root of the workspace folder
"LD_LIBRARY_PATH": "/usr/src/app/rondb-22.10.5-linux-glibc2.28-arm64_v8/lib"
"LD_LIBRARY_PATH": "/usr/src/app/rondb-24.10.0-linux-glibc2.28-arm64_v8/lib"
}
}
4 changes: 2 additions & 2 deletions .github/workflows/build_test_push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
needs: [build-pink-macos]
runs-on: ubuntu-latest
env:
RONDB_TARBALL_URI: https://repo.hops.works/master/rondb-22.10.5-linux-glibc2.28-x86_64.tar.gz
RONDB_TARBALL_URI: https://repo.hops.works/master/rondb-24.10.0-linux-glibc2.28-x86_64.tar.gz
RONDB_PATH: /tmp/rondb
IMAGE_NAME: rondis:latest
CONTAINER_NAME: rondis
Expand Down Expand Up @@ -107,4 +107,4 @@ jobs:
run: cat $LOCAL_RONDIS_LOG

- name: Run Redis benchmark
run: docker exec -i $CONTAINER_NAME bash -c "redis-benchmark -t get,set -c 2"
run: docker exec -i $CONTAINER_NAME bash -c "redis-benchmark -t get,set -r 100 -P 10 --threads 3"
6 changes: 1 addition & 5 deletions pink/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ ifeq ($(NO_PB),1)
$(filter-out $(VERSION_CC) $(wildcard $(SRC_DIR)/pb_*), $(wildcard $(SRC_DIR)/*.cc))
endif


ifndef SLASH_PATH
$(warning Warning: missing slash path, using default)
SLASH_PATH=$(CURDIR)/third/slash
endif
SLASH_PATH=$(CURDIR)/third/slash
SLASH_INCLUDE_DIR=$(SLASH_PATH)
SLASH_LIBRARY=$(SLASH_PATH)/slash/lib/libslash.a

Expand Down
1 change: 1 addition & 0 deletions pink/include/pink_conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class PinkConn : public std::enable_shared_from_this<PinkConn> {
}

bool IsClose() { return close_; }
// This can be used by the application
void SetClose(bool close) { close_ = close; }

void set_last_interaction(const struct timeval &now) {
Expand Down
6 changes: 3 additions & 3 deletions pink/include/redis_conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class RedisConn: public PinkConn {
const int rbuf_max_len = REDIS_MAX_MESSAGE);
virtual ~RedisConn();

virtual ReadStatus GetRequest();
virtual WriteStatus SendReply();
virtual int WriteResp(const std::string& resp);
virtual ReadStatus GetRequest() override;
virtual WriteStatus SendReply() override;
virtual int WriteResp(const std::string& resp) override;
olapiv marked this conversation as resolved.
Show resolved Hide resolved

void TryResizeBuffer() override;
void SetHandleType(const HandleType& handle_type);
Expand Down
7 changes: 2 additions & 5 deletions pink/rondis/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ endif

all: rondis

ifndef PINK_PATH
$(warning Warning: missing pink path, using default)
PINK_PATH=$(CURDIR)/../..
endif
PINK_PATH=$(CURDIR)/../..
PINK_INCLUDE_DIR=$(PINK_PATH)
PINK_LIBRARY=$(PINK_PATH)/pink/lib/libpink.a

Expand Down Expand Up @@ -48,7 +45,7 @@ endif
LDFLAGS := $(DEP_LIBS) $(LDFLAGS)

# Use find to locate all .cc files in subdirectories
SOURCES = $(CURDIR)/rondis.cc $(CURDIR)/rondb.cc $(CURDIR)/common.cc $(CURDIR)/string/table_definitions.cc $(CURDIR)/string/commands.cc $(CURDIR)/string/db_operations.cc
SOURCES = $(CURDIR)/rondis.cc $(CURDIR)/rondb.cc $(CURDIR)/common.cc $(CURDIR)/string/table_definitions.cc $(CURDIR)/string/commands.cc $(CURDIR)/string/db_operations.cc $(CURDIR)/string/interpreted_code.cc
OBJECTS = $(SOURCES:.cc=.o)

# Target to build the executable "rondis"
Expand Down
30 changes: 2 additions & 28 deletions pink/rondis/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,13 @@

#include "common.h"

/**
* @brief Writes formatted data to a buffer.
*
* This function writes formatted data to the provided buffer using a format string
* and a variable number of arguments, similar to printf. It ensures that the
* formatted string does not exceed the specified buffer size.
*
* @param buffer A pointer to the buffer where the formatted string will be written.
* @param bufferSize The size of the buffer.
* @param format A format string that specifies how subsequent arguments are converted for output.
* @param ... Additional arguments specifying the data to be formatted.
* @return The number of characters written, excluding the null terminator. If the output
* is truncated due to the buffer size limit, the return value is the number of
* characters (excluding the null terminator) which would have been written if
* enough space had been available.
*/
int write_formatted(char *buffer, int bufferSize, const char *format, ...)
{
int len = 0;
va_list arguments;
va_start(arguments, format);
len = vsnprintf(buffer, bufferSize, format, arguments);
va_end(arguments);
return len;
}

void assign_ndb_err_to_response(
std::string *response,
const char *app_str,
NdbError error)
{
char buf[512];
write_formatted(buf, sizeof(buf), "-ERR %s; NDB(%u) %s\r\n", app_str, error.code, error.message);
snprintf(buf, sizeof(buf), "-ERR %s; NDB(%u) %s\r\n", app_str, error.code, error.message);
std::cout << buf;
response->assign(buf);
}
Expand All @@ -47,7 +21,7 @@ void assign_generic_err_to_response(
const char *app_str)
{
char buf[512];
write_formatted(buf, sizeof(buf), "-ERR %s\r\n", app_str);
snprintf(buf, sizeof(buf), "-ERR %s\r\n", app_str);
std::cout << buf;
response->assign(buf);
}
6 changes: 6 additions & 0 deletions pink/rondis/common.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include <ndbapi/NdbApi.hpp>
#include <ndbapi/Ndb.hpp>

#ifndef RONDIS_COMMON_H
#define RONDIS_COMMON_H

#define MAX_CONNECTIONS 2

#define REDIS_DB_NAME "redis"
Expand All @@ -20,6 +23,8 @@ void assign_generic_err_to_response(std::string *response, const char *app_str);
#define FAILED_CREATE_TXN_OBJECT "Failed to create transaction object"
#define FAILED_EXEC_TXN "Failed to execute transaction"
#define FAILED_READ_KEY "Failed to read key"
#define FAILED_INCR_KEY "Failed to increment key"
#define FAILED_INCR_KEY_MULTI_ROW "Failed to increment key, multi-row value"
#define FAILED_GET_OP "Failed to get NdbOperation object"
#define FAILED_DEFINE_OP "Failed to define RonDB operation"

Expand All @@ -28,3 +33,4 @@ void assign_generic_err_to_response(std::string *response, const char *app_str);
#define REDIS_WRONG_NUMBER_OF_ARGS "wrong number of arguments for '%s' command"
#define REDIS_NO_SUCH_KEY "$-1\r\n"
#define REDIS_KEY_TOO_LARGE "key is too large (3000 bytes max)"
#endif
69 changes: 61 additions & 8 deletions pink/rondis/rondb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "common.h"
#include "string/table_definitions.h"
#include "string/commands.h"
#include <strings.h>

/*
Ndb objects are not thread-safe. Hence, each worker thread / RonDB connection should
Expand Down Expand Up @@ -95,12 +96,22 @@ void print_args(const pink::RedisCmdArgsType &argv)
printf("\n");
}

void unsupported_command(const pink::RedisCmdArgsType &argv, std::string *response)
{
printf("Unsupported command: ");
print_args(argv);
char error_message[256];
snprintf(error_message, sizeof(error_message), REDIS_UNKNOWN_COMMAND, argv[0].c_str());
assign_generic_err_to_response(response, error_message);
}

int rondb_redis_handler(const pink::RedisCmdArgsType &argv,
std::string *response,
int worker_id)
{
// First check non-ndb commands
if (argv[0] == "ping")
const char *command = argv[0].c_str();
if (strcasecmp(command, "ping") == 0)
{
if (argv.size() != 1)
{
Expand All @@ -111,10 +122,43 @@ int rondb_redis_handler(const pink::RedisCmdArgsType &argv,
}
response->append("+PONG\r\n");
}
else if (argv[0] == "ECHO")
{
if (argv.size() != 2)
{
char error_message[256];
snprintf(error_message, sizeof(error_message), REDIS_WRONG_NUMBER_OF_ARGS, argv[0].c_str());
assign_generic_err_to_response(response, error_message);
return 0;
}

response->assign("$" + std::to_string(argv[1].length()) + "\r\n" + argv[1] + "\r\n");
}
else if (argv[0] == "CONFIG")
{
if (argv.size() != 3)
{
char error_message[256];
snprintf(error_message, sizeof(error_message), REDIS_WRONG_NUMBER_OF_ARGS, argv[0].c_str());
assign_generic_err_to_response(response, error_message);
return 0;
}
if (argv[1] == "GET")
{
*response += "*2\r\n";
*response += "$" + std::to_string(argv[2].length()) + "\r\n";
*response += argv[2] + "\r\n";
*response += "*0\r\n";
}
else
{
unsupported_command(argv, response);
}
}
else
{
Ndb *ndb = ndb_objects[worker_id];
if (argv[0] == "GET")
if (strcasecmp(command, "GET") == 0)
{
if (argv.size() == 2)
{
Expand All @@ -127,7 +171,7 @@ int rondb_redis_handler(const pink::RedisCmdArgsType &argv,
assign_generic_err_to_response(response, error_message);
}
}
else if (argv[0] == "SET")
else if (strcasecmp(command, "SET") == 0)
{
if (argv.size() == 3)
{
Expand All @@ -140,13 +184,22 @@ int rondb_redis_handler(const pink::RedisCmdArgsType &argv,
assign_generic_err_to_response(response, error_message);
}
}
else if (strcasecmp(command, "INCR") == 0)
{
if (argv.size() == 2)
{
rondb_incr_command(ndb, argv, response);
}
else
{
char error_message[256];
snprintf(error_message, sizeof(error_message), REDIS_WRONG_NUMBER_OF_ARGS, argv[0].c_str());
assign_generic_err_to_response(response, error_message);
}
}
else
{
printf("Unsupported command: ");
print_args(argv);
char error_message[256];
snprintf(error_message, sizeof(error_message), REDIS_UNKNOWN_COMMAND, argv[0].c_str());
assign_generic_err_to_response(response, error_message);
unsupported_command(argv, response);
}
if (ndb->getClientStat(ndb->TransStartCount) != ndb->getClientStat(ndb->TransCloseCount))
{
Expand Down
4 changes: 4 additions & 0 deletions pink/rondis/rondb.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include <ndbapi/NdbApi.hpp>
#include <ndbapi/Ndb.hpp>

#ifndef RONDIS_RONDB_H
#define RONDIS_RONDB_H

extern std::vector<Ndb *> ndb_objects;

int initialize_ndb_objects(const char *connect_string, int num_ndb_objects);
Expand All @@ -14,3 +17,4 @@ void rondb_end();
int rondb_redis_handler(const pink::RedisCmdArgsType &argv,
std::string *response,
int fd);
#endif
2 changes: 1 addition & 1 deletion pink/rondis/rondis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ static void SignalSetup()
int main(int argc, char *argv[])
{
int port = 6379;
char *connect_string = "localhost:13000";
const char *connect_string = "localhost:13000";
int worker_threads = 2;
if (argc != 4)
{
Expand Down
Loading