Commit da2541f6 authored by Yuqi Zhang's avatar Yuqi Zhang
Browse files

renames of macros

parent 9249b983
......@@ -31,7 +31,7 @@
* */
// Add one additional arg to rargv type robj*. Will NOT delete the obj.
#define RARGV_ADD(obj) \
#define _RARGV_ADD(obj) \
do \
{ \
if (!c->rargv) INIT_RARGV; \
......@@ -44,24 +44,30 @@
c->rargc++; \
} while (0)
// Add one additional arg to rargv, type sds. Will DELETE the sds.
#define RARGV_ADD_SDS(str) RARGV_ADD(createObject(OBJ_STRING, str))
// Add one additional arg to rargv, type sds. Take the ownership of the sds.
#define RARGV_ADD_SDS(str) _RARGV_ADD(createObject(OBJ_STRING, str))
// Check the argc and the container type. You may use this at the start of the prepare phase.
#define CHECK_ARGC_AND_CONTAINER_TYPE(_type, _max) \
do \
{ \
if (c->argc > _max || c->argc < 2) \
{ \
addReply(c, shared.syntaxerr); \
return; \
} \
robj *o = lookupKeyRead(c->db, c->argv[1]); \
if (o != NULL && o->type != _type) \
{ \
addReply(c, shared.wrongtypeerr); \
return; \
} \
#define CHECK_ARGC(_max) \
do \
{ \
if (c->argc > _max || c->argc < 2) \
{ \
addReply(c, shared.syntaxerr); \
return; \
} \
} while (0)
#define CHECK_CONTAINER_TYPE(_type) \
do \
{ \
robj *_o = lookupKeyRead(c->db, c->argv[1]); \
if (_o != NULL && _o->type != _type) \
{ \
addReply(c, shared.wrongtypeerr); \
return; \
} \
} while (0)
// Check the type of the arg, int / double.
......@@ -91,18 +97,20 @@
* CRDT_BEGIN
* CRDT_PREPARE
* // Do the prepare phase, such as:
* // - check correctness of 1. the format of the command from the cliend and
* 2. the type of the targeted CRDT using CHECK_ARGC_AND_CONTAINER_TYPE macro
* // - check correctness of
* 1. the format of the command from the cliend and
* 2. the type of the targeted CRDT
* using CHECK_ARGC, CHECK_CONTAINER_TYPE,
* CHECK_ARG_TYPE_INT and CHECK_ARG_TYPE_DOUBLE macros
* // - check the precondition of the prepare phase, read the local state
* // - add additional parameters to broadcast using RARGV_ADD or RARGV_ADD_SDS macros
* // - add additional parameters to broadcast using RARGV_ADD_SDS macro
* // Will automatically reply an "OK" message to the client if
* // the prepare phase ends successfully.
* CRDT_EFFECT
* // Get the parameters from c->rargv, c->rargc is the number of paremeters.
* // The order of the parameters in c->rargv is: The parameters of the initial client
* // calling this command, then the additional parameters from the prepare phase,
* // in the order of calling
* // RARGV_ADD or RARGV_ADD_SDS macros.
* // in the order of calling RARGV_ADD_SDS macros.
* // Trust the correctness of these parameters. Here we do no further check.
*
* // Then do the effect phase of the command according to the algorithm.
......
......@@ -259,7 +259,8 @@ void ozaddCommand(client *c)
*/
CRDT_BEGIN
CRDT_PREPARE
CHECK_ARGC_AND_CONTAINER_TYPE(OBJ_ZSET, 4);
CHECK_ARGC(4);
CHECK_CONTAINER_TYPE(OBJ_ZSET);
CHECK_ARG_TYPE_DOUBLE(c->argv[3]);
oze *e = GET_OZE(argv, 1);
if (LOOKUP(e))
......@@ -296,7 +297,8 @@ void ozincrbyCommand(client *c)
*/
CRDT_BEGIN
CRDT_PREPARE
CHECK_ARGC_AND_CONTAINER_TYPE(OBJ_ZSET, 4);
CHECK_ARGC(4);
CHECK_CONTAINER_TYPE(OBJ_ZSET);
CHECK_ARG_TYPE_DOUBLE(c->argv[3]);
oze *e = GET_OZE(argv, 0);
if (e == NULL || !LOOKUP(e))
......@@ -342,7 +344,8 @@ void ozremCommand(client *c)
*/
CRDT_BEGIN
CRDT_PREPARE
CHECK_ARGC_AND_CONTAINER_TYPE(OBJ_ZSET, 3);
CHECK_ARGC(3);
CHECK_CONTAINER_TYPE(OBJ_ZSET);
oze *e = GET_OZE(argv, 0);
if (e == NULL || !LOOKUP(e))
{
......
......@@ -387,7 +387,8 @@ void rlinsertCommand(client *c)
{
CRDT_BEGIN
CRDT_PREPARE
CHECK_ARGC_AND_CONTAINER_TYPE(OBJ_HASH, 9);
CHECK_ARGC(9);
CHECK_CONTAINER_TYPE(OBJ_HASH);
for (int i = 5; i < 9; ++i)
CHECK_ARG_TYPE_INT(c->argv[i]);
rle *pre = GET_RLE(c->db, c->argv[1], c->argv[2], 0);
......@@ -449,7 +450,8 @@ void rlupdateCommand(client *c)
{
CRDT_BEGIN
CRDT_PREPARE
CHECK_ARGC_AND_CONTAINER_TYPE(OBJ_HASH, 5);
CHECK_ARGC(5);
CHECK_CONTAINER_TYPE(OBJ_HASH);
CHECK_ARG_TYPE_INT(c->argv[4]);
rle *e = GET_RLE(c->db, c->argv[1], c->argv[2], 0);
if (e == NULL || !LOOKUP(e))
......@@ -480,7 +482,8 @@ void rlremCommand(client *c)
{
CRDT_BEGIN
CRDT_PREPARE
CHECK_ARGC_AND_CONTAINER_TYPE(OBJ_HASH, 3);
CHECK_ARGC(3);
CHECK_CONTAINER_TYPE(OBJ_HASH);
rle *e = GET_RLE(c->db, c->argv[1], c->argv[2], 0);
if (e == NULL || !LOOKUP(e))
{
......
......@@ -147,7 +147,8 @@ void rwflinsertCommand(client *c)
{
CRDT_BEGIN
CRDT_PREPARE
CHECK_ARGC_AND_CONTAINER_TYPE(OBJ_HASH, 9);
CHECK_ARGC(9);
CHECK_CONTAINER_TYPE(OBJ_HASH);
for (int i = 5; i < 9; ++i)
CHECK_ARG_TYPE_INT(c->argv[i]);
rwfle *pre = GET_RWFLE(argv, 0);
......@@ -261,7 +262,8 @@ void rwflupdateCommand(client *c)
{
CRDT_BEGIN
CRDT_PREPARE
CHECK_ARGC_AND_CONTAINER_TYPE(OBJ_HASH, 5);
CHECK_ARGC(5);
CHECK_CONTAINER_TYPE(OBJ_HASH);
CHECK_ARG_TYPE_INT(c->argv[4]);
rwfle *e = GET_RWFLE(argv, 0);
PREPARE_PRECOND_NON_ADD(e);
......@@ -296,7 +298,8 @@ void rwflremCommand(client *c)
{
CRDT_BEGIN
CRDT_PREPARE
CHECK_ARGC_AND_CONTAINER_TYPE(OBJ_HASH, 3);
CHECK_ARGC(3);
CHECK_CONTAINER_TYPE(OBJ_HASH);
rwfle *e = GET_RWFLE(argv, 0);
PREPARE_PRECOND_NON_ADD(e);
ADD_CR_RMV(e);
......
......@@ -54,7 +54,8 @@ void rwfzaddCommand(client *c)
{
CRDT_BEGIN
CRDT_PREPARE
CHECK_ARGC_AND_CONTAINER_TYPE(OBJ_ZSET, 4);
CHECK_ARGC(4);
CHECK_CONTAINER_TYPE(OBJ_ZSET);
CHECK_ARG_TYPE_DOUBLE(c->argv[3]);
rwfze *e = GET_RWFZE(argv, 1);
PREPARE_PRECOND_ADD(e);
......@@ -81,7 +82,8 @@ void rwfzincrbyCommand(client *c)
{
CRDT_BEGIN
CRDT_PREPARE
CHECK_ARGC_AND_CONTAINER_TYPE(OBJ_ZSET, 4);
CHECK_ARGC(4);
CHECK_CONTAINER_TYPE(OBJ_ZSET);
CHECK_ARG_TYPE_DOUBLE(c->argv[3]);
rwfze *e = GET_RWFZE(argv, 0);
PREPARE_PRECOND_NON_ADD(e);
......@@ -108,7 +110,8 @@ void rwfzremCommand(client *c)
{
CRDT_BEGIN
CRDT_PREPARE
CHECK_ARGC_AND_CONTAINER_TYPE(OBJ_ZSET, 3);
CHECK_ARGC(3);
CHECK_CONTAINER_TYPE(OBJ_ZSET);
rwfze *e = GET_RWFZE(argv, 0);
PREPARE_PRECOND_NON_ADD(e);
ADD_CR_RMV(e);
......
......@@ -362,7 +362,8 @@ void rzaddCommand(client *c)
{
CRDT_BEGIN
CRDT_PREPARE
CHECK_ARGC_AND_CONTAINER_TYPE(OBJ_ZSET, 4);
CHECK_ARGC(4);
CHECK_CONTAINER_TYPE(OBJ_ZSET);
CHECK_ARG_TYPE_DOUBLE(c->argv[3]);
rze *e = GET_RZE(argv, 1);
if (LOOKUP(e))
......@@ -394,7 +395,8 @@ void rzincrbyCommand(client *c)
{
CRDT_BEGIN
CRDT_PREPARE
CHECK_ARGC_AND_CONTAINER_TYPE(OBJ_ZSET, 4);
CHECK_ARGC(4);
CHECK_CONTAINER_TYPE(OBJ_ZSET);
CHECK_ARG_TYPE_DOUBLE(c->argv[3]);
rze *e = GET_RZE(argv, 0);
if (e == NULL || !LOOKUP(e))
......@@ -426,7 +428,8 @@ void rzremCommand(client *c)
{
CRDT_BEGIN
CRDT_PREPARE
CHECK_ARGC_AND_CONTAINER_TYPE(OBJ_ZSET, 3);
CHECK_ARGC(3);
CHECK_CONTAINER_TYPE(OBJ_ZSET);
rze *e = GET_RZE(argv, 0);
if (e == NULL || !LOOKUP(e))
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment