mirror of
https://github.com/fluencelabs/redis
synced 2025-06-22 21:41:32 +00:00
Safer handling of MULTI/EXEC on errors.
After the transcation starts with a MULIT, the previous behavior was to return an error on problems such as maxmemory limit reached. But still to execute the transaction with the subset of queued commands on EXEC. While it is true that the client was able to check for errors distinguish QUEUED by an error reply, MULTI/EXEC in most client implementations uses pipelining for speed, so all the commands and EXEC are sent without caring about replies. With this change: 1) EXEC fails if at least one command was not queued because of an error. The EXECABORT error is used. 2) A generic error is always reported on EXEC. 3) The client DISCARDs the MULTI state after a failed EXEC, otherwise pipelining multiple transactions would be basically impossible: After a failed EXEC the next transaction would be simply queued as the tail of the previous transaction.
This commit is contained in:
30
src/redis.h
30
src/redis.h
@ -169,19 +169,20 @@
|
||||
#define REDIS_AOF_WAIT_REWRITE 2 /* AOF waits rewrite to start appending */
|
||||
|
||||
/* Client flags */
|
||||
#define REDIS_SLAVE 1 /* This client is a slave server */
|
||||
#define REDIS_MASTER 2 /* This client is a master server */
|
||||
#define REDIS_MONITOR 4 /* This client is a slave monitor, see MONITOR */
|
||||
#define REDIS_MULTI 8 /* This client is in a MULTI context */
|
||||
#define REDIS_BLOCKED 16 /* The client is waiting in a blocking operation */
|
||||
#define REDIS_DIRTY_CAS 64 /* Watched keys modified. EXEC will fail. */
|
||||
#define REDIS_CLOSE_AFTER_REPLY 128 /* Close after writing entire reply. */
|
||||
#define REDIS_UNBLOCKED 256 /* This client was unblocked and is stored in
|
||||
server.unblocked_clients */
|
||||
#define REDIS_LUA_CLIENT 512 /* This is a non connected client used by Lua */
|
||||
#define REDIS_ASKING 1024 /* Client issued the ASKING command */
|
||||
#define REDIS_CLOSE_ASAP 2048 /* Close this client ASAP */
|
||||
#define REDIS_UNIX_SOCKET 4096 /* Client connected via Unix domain socket */
|
||||
#define REDIS_SLAVE (1<<0) /* This client is a slave server */
|
||||
#define REDIS_MASTER (1<<1) /* This client is a master server */
|
||||
#define REDIS_MONITOR (1<<2) /* This client is a slave monitor, see MONITOR */
|
||||
#define REDIS_MULTI (1<<3) /* This client is in a MULTI context */
|
||||
#define REDIS_BLOCKED (1<<4) /* The client is waiting in a blocking operation */
|
||||
#define REDIS_DIRTY_CAS (1<<5) /* Watched keys modified. EXEC will fail. */
|
||||
#define REDIS_CLOSE_AFTER_REPLY (1<<6) /* Close after writing entire reply. */
|
||||
#define REDIS_UNBLOCKED (1<<7) /* This client was unblocked and is stored in
|
||||
server.unblocked_clients */
|
||||
#define REDIS_LUA_CLIENT (1<<8) /* This is a non connected client used by Lua */
|
||||
#define REDIS_ASKING (1<<9) /* Client issued the ASKING command */
|
||||
#define REDIS_CLOSE_ASAP (1<<10)/* Close this client ASAP */
|
||||
#define REDIS_UNIX_SOCKET (1<<11) /* Client connected via Unix domain socket */
|
||||
#define REDIS_DIRTY_EXEC (1<<12) /* EXEC will fail for errors while queueing */
|
||||
|
||||
/* Client request types */
|
||||
#define REDIS_REQ_INLINE 1
|
||||
@ -425,7 +426,7 @@ struct sharedObjectsStruct {
|
||||
*colon, *nullbulk, *nullmultibulk, *queued,
|
||||
*emptymultibulk, *wrongtypeerr, *nokeyerr, *syntaxerr, *sameobjecterr,
|
||||
*outofrangeerr, *noscripterr, *loadingerr, *slowscripterr, *bgsaveerr,
|
||||
*masterdownerr, *roslaveerr,
|
||||
*masterdownerr, *roslaveerr, *execaborterr,
|
||||
*oomerr, *plus, *messagebulk, *pmessagebulk, *subscribebulk,
|
||||
*unsubscribebulk, *psubscribebulk, *punsubscribebulk, *del, *rpop, *lpop,
|
||||
*lpush,
|
||||
@ -845,6 +846,7 @@ void queueMultiCommand(redisClient *c);
|
||||
void touchWatchedKey(redisDb *db, robj *key);
|
||||
void touchWatchedKeysOnFlush(int dbid);
|
||||
void discardTransaction(redisClient *c);
|
||||
void flagTransaction(redisClient *c);
|
||||
|
||||
/* Redis object implementation */
|
||||
void decrRefCount(void *o);
|
||||
|
Reference in New Issue
Block a user