Skip to content

Commit

Permalink
Merge branch 'master' into avoidDeleteFailure
Browse files Browse the repository at this point in the history
  • Loading branch information
olapiv authored Nov 22, 2024
2 parents 1f3c932 + 9324c0c commit 5836973
Show file tree
Hide file tree
Showing 37 changed files with 1,461 additions and 530 deletions.
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"
}
}
46 changes: 30 additions & 16 deletions .github/workflows/build_test_push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@ jobs:

- run: brew install protobuf

- name: Build
- name: Build Slash
run: cd pink/third/slash/slash && make

- name: Build Pink
run: cd pink && make static_lib

build-and-run-redis-benchmark:
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_VERSION: 24.10.0
RONDB_TARBALL_URI: https://repo.hops.works/master/rondb-24.10.0-linux-glibc2.28-x86_64.tar.gz
RONDB_DOCKER_DIR: /tmp/rondb-docker
RONDB_TARBALL_FILE: rondb.tar.gz
RONDB_PATH: /tmp/rondb
IMAGE_NAME: rondis:latest
CONTAINER_NAME: rondis
Expand All @@ -35,31 +41,33 @@ jobs:
with:
fetch-depth: 0

- name: Clone rondb-docker
run: git clone -b release-0.7 https://github.com/logicalclocks/rondb-docker.git $RONDB_DOCKER_DIR

- name: Download RonDB
run: |
wget $RONDB_TARBALL_URI -O $RONDB_DOCKER_DIR/$RONDB_TARBALL_FILE
mkdir -p $RONDB_PATH
tar xfz $RONDB_DOCKER_DIR/$RONDB_TARBALL_FILE -C $RONDB_PATH --strip-components=1
- name: Run rondb-docker
env:
RONDB_DOCKER_DIR: /tmp/rondb-docker
run: |
path_now=$(pwd)
git clone -b release-0.7 https://github.com/logicalclocks/rondb-docker.git $RONDB_DOCKER_DIR
cd $RONDB_DOCKER_DIR && ./build_run_docker.sh -d \
cd $RONDB_DOCKER_DIR
# The script expects a relative path to the tarball
./build_run_docker.sh -d \
--rondb-tarball-path ./$RONDB_TARBALL_FILE \
--rondb-version $RONDB_VERSION \
--size small \
--num-mgm-nodes 1 \
--node-groups 1 \
--replication-factor 1 \
--num-mysql-nodes 1 \
--num-rest-api-nodes 0 \
--num-benchmarking-nodes 0
cd $path_now
- name: Build Rondis image
run: docker build -t $IMAGE_NAME .

- name: Download RonDB
run: |
wget $RONDB_TARBALL_URI -O /tmp/temp_tarball.tar.gz
mkdir -p $RONDB_PATH
tar xfz /tmp/temp_tarball.tar.gz -C $RONDB_PATH --strip-components=1
- name: Create Rondis environment
run: |
docker run -d \
Expand All @@ -79,7 +87,7 @@ jobs:
run: |
docker exec -i mysqld_1 bash -c "mysql -uroot -e 'CREATE DATABASE redis;'"
for sql_file in pink/rondis/sql/*.sql; do
cat "$sql_file" | docker exec -i mysqld_1 mysql -uroot
cat "$sql_file" | docker exec -i mysqld_1 mysql -uroot --database=redis
done
- name: Connect Docker network
Expand All @@ -93,17 +101,23 @@ jobs:
docker exec -w $DOCKER_WORK_DIR -e LD_LIBRARY_PATH=/tmp/rondb/lib \
-t $CONTAINER_NAME pink/rondis/rondis 6379 mgmd_1:1186 2 > $LOCAL_RONDIS_LOG &
# Takes a few seconds before all connections are setup and started properly
- name: Wait for Rondis server to start properly
run: sleep 5

# Running this multiple times to check for memory leaks and that overwrites/updates/deletes work
- name: Run tests multiple times
run: |
for i in {1..50}; do
docker exec -w $DOCKER_WORK_DIR -i $CONTAINER_NAME bash -c \
"pink/rondis/tests/get_set.sh $((i % 3))"
docker exec -w $DOCKER_WORK_DIR -i $CONTAINER_NAME bash -c \
"pink/rondis/tests/hget_hset.sh $((i % 5)) $((i % 3))"
echo "Success in run $i"
done
- 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,incr,hget,hset,hincr -r 100 -P 10 --threads 3"

- name: Show Rondis logs
if: always()
Expand Down
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;

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
46 changes: 18 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,23 @@ 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);
}

void set_length(char *buf, Uint32 key_len)
{
Uint8 *ptr = (Uint8 *)buf;
ptr[0] = (Uint8)(key_len & 255);
ptr[1] = (Uint8)(key_len >> 8);
}

Uint32 get_length(char *buf)
{
Uint8 *ptr = (Uint8 *)buf;
Uint8 low = ptr[0];
Uint8 high = ptr[1];
Uint32 len32 = Uint32(low) + Uint32(256) * Uint32(high);
return len32;
}
11 changes: 10 additions & 1 deletion pink/rondis/common.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
#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"

#define FOREIGN_KEY_RESTRICT_ERROR 256
#define RESTRICT_VALUE_ROWS_ERROR 6000

#define RONDB_INTERNAL_ERROR 2
#define READ_ERROR 626

int write_formatted(char *buffer, int bufferSize, const char *format, ...);
void assign_ndb_err_to_response(std::string *response, const char *app_str, NdbError error);
void assign_generic_err_to_response(std::string *response, const char *app_str);
void set_length(char* buf, Uint32 key_len);
Uint32 get_length(char* buf);

// NDB API error messages
#define FAILED_GET_DICT "Failed to get NdbDict"
#define FAILED_CREATE_TABLE_OBJECT "Failed to create table object"
#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_HSET_KEY "Failed to find 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 +36,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
Loading

0 comments on commit 5836973

Please sign in to comment.