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 6 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
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
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
5 changes: 1 addition & 4 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
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, multi-row value"
olapiv marked this conversation as resolved.
Show resolved Hide resolved
#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
13 changes: 13 additions & 0 deletions pink/rondis/rondb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,19 @@ int rondb_redis_handler(const pink::RedisCmdArgsType &argv,
assign_generic_err_to_response(response, error_message);
}
}
else if (argv[0] == "INCR")
{
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: ");
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
Loading