Skip to content

Commit 2ef0b7d

Browse files
RONDB-768: Added support for HSET, HGET, HINCR and rewrite of SET handling, removed FOREIGN KEY
1 parent eec0e23 commit 2ef0b7d

16 files changed

+935
-377
lines changed

pink/rondis/common.cc

+16
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,19 @@ void assign_generic_err_to_response(
2525
std::cout << buf;
2626
response->assign(buf);
2727
}
28+
29+
void set_length(char *buf, Uint32 key_len)
30+
{
31+
Uint8 *ptr = (Uint8 *)buf;
32+
ptr[0] = (Uint8)(key_len & 255);
33+
ptr[1] = (Uint8)(key_len >> 8);
34+
}
35+
36+
Uint32 get_length(char *buf)
37+
{
38+
Uint8 *ptr = (Uint8 *)buf;
39+
Uint8 low = ptr[0];
40+
Uint8 high = ptr[1];
41+
Uint32 len32 = Uint32(low) + Uint32(256) * Uint32(high);
42+
return len32;
43+
}

pink/rondis/common.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88

99
#define REDIS_DB_NAME "redis"
1010

11-
#define FOREIGN_KEY_RESTRICT_ERROR 256
11+
#define RESTRICT_VALUE_ROWS_ERROR 6000
1212

1313
#define RONDB_INTERNAL_ERROR 2
1414
#define READ_ERROR 626
1515

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

2022
// NDB API error messages
2123
#define FAILED_GET_DICT "Failed to get NdbDict"
@@ -24,6 +26,7 @@ void assign_generic_err_to_response(std::string *response, const char *app_str);
2426
#define FAILED_EXEC_TXN "Failed to execute transaction"
2527
#define FAILED_READ_KEY "Failed to read key"
2628
#define FAILED_INCR_KEY "Failed to increment key"
29+
#define FAILED_HSET_KEY "Failed to find key"
2730
#define FAILED_INCR_KEY_MULTI_ROW "Failed to increment key, multi-row value"
2831
#define FAILED_GET_OP "Failed to get NdbOperation object"
2932
#define FAILED_DEFINE_OP "Failed to define RonDB operation"

pink/rondis/rondb.cc

+41-1
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,45 @@ int rondb_redis_handler(const pink::RedisCmdArgsType &argv,
197197
assign_generic_err_to_response(response, error_message);
198198
}
199199
}
200+
else if (strcasecmp(command, "HGET") == 0)
201+
{
202+
if (argv.size() == 3)
203+
{
204+
rondb_hget_command(ndb, argv, response);
205+
}
206+
else
207+
{
208+
char error_message[256];
209+
snprintf(error_message, sizeof(error_message), REDIS_WRONG_NUMBER_OF_ARGS, argv[0].c_str());
210+
assign_generic_err_to_response(response, error_message);
211+
}
212+
}
213+
else if (strcasecmp(command, "HSET") == 0)
214+
{
215+
if (argv.size() == 4)
216+
{
217+
rondb_hset_command(ndb, argv, response);
218+
}
219+
else
220+
{
221+
char error_message[256];
222+
snprintf(error_message, sizeof(error_message), REDIS_WRONG_NUMBER_OF_ARGS, argv[0].c_str());
223+
assign_generic_err_to_response(response, error_message);
224+
}
225+
}
226+
else if (strcasecmp(command, "HINCR") == 0)
227+
{
228+
if (argv.size() == 3)
229+
{
230+
rondb_hincr_command(ndb, argv, response);
231+
}
232+
else
233+
{
234+
char error_message[256];
235+
snprintf(error_message, sizeof(error_message), REDIS_WRONG_NUMBER_OF_ARGS, argv[0].c_str());
236+
assign_generic_err_to_response(response, error_message);
237+
}
238+
}
200239
else
201240
{
202241
unsupported_command(argv, response);
@@ -209,7 +248,8 @@ int rondb_redis_handler(const pink::RedisCmdArgsType &argv,
209248
If this limit is reached, the Ndb object will not create any new ones.
210249
Hence, better to catch these cases early.
211250
*/
212-
print_args(argv);
251+
printf("Failed to stop transaction\n");
252+
//print_args(argv);
213253
printf("Number of transactions started: %lld\n", ndb->getClientStat(ndb->TransStartCount));
214254
printf("Number of transactions closed: %lld\n", ndb->getClientStat(ndb->TransCloseCount));
215255
exit(1);

pink/rondis/sql/HSET_key.sql

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CREATE TABLE hset_keys(
2+
redis_key VARBINARY(3000) NOT NULL,
3+
redis_key_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
4+
PRIMARY KEY (redis_key) USING HASH,
5+
UNIQUE KEY (redis_key_id) USING HASH
6+
) ENGINE NDB,
7+
COMMENT = "NDB_TABLE=PARTITION_BALANCE=RP_BY_LDM_X_8";

pink/rondis/sql/STRING_key.sql

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
CREATE TABLE redis.string_keys(
1+
CREATE TABLE string_keys(
22
-- Redis actually supports a max key size of 512MiB,
33
-- but we choose not to support that here
4+
redis_key_id BIGINT UNSIGNED NOT NULL,
45
redis_key VARBINARY(3000) NOT NULL,
56
-- This is to save space when referencing the key in the value table
67
rondb_key BIGINT UNSIGNED AUTO_INCREMENT NULL,
@@ -14,10 +15,10 @@ CREATE TABLE redis.string_keys(
1415
num_rows INT UNSIGNED NOT NULL,
1516
value_start VARBINARY(26500) NOT NULL,
1617
-- Redis supports get/set of seconds/milliseconds
17-
expiry_date INT UNSIGNED,
18+
expiry_date INT UNSIGNED NOT NULL,
1819
-- Easier to sort and delete keys this way
1920
KEY expiry_index(expiry_date),
20-
PRIMARY KEY (redis_key) USING HASH,
21+
PRIMARY KEY (redis_key_id, redis_key) USING HASH,
2122
UNIQUE KEY (rondb_key) USING HASH
2223
) ENGINE NDB -- Each CHAR will use 1 byte
2324
CHARSET = latin1 COMMENT = "NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM_X_8";

pink/rondis/sql/STRING_value.sql

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
CREATE TABLE redis.string_values(
1+
CREATE TABLE string_values(
22
rondb_key BIGINT UNSIGNED NOT NULL,
33
ordinal INT UNSIGNED NOT NULL,
44
value VARBINARY(29500) NOT NULL,
5-
PRIMARY KEY (rondb_key, ordinal),
6-
FOREIGN KEY (rondb_key) REFERENCES redis.string_keys(rondb_key) ON UPDATE RESTRICT ON DELETE CASCADE
5+
PRIMARY KEY (rondb_key, ordinal)
76
) ENGINE NDB,
8-
COMMENT = "NDB_TABLE=PARTITION_BALANCE=RP_BY_LDM_X_8" PARTITION BY KEY (rondb_key);
7+
COMMENT = "NDB_TABLE=PARTITION_BALANCE=RP_BY_LDM_X_8";

0 commit comments

Comments
 (0)