Avoid locking as late as possible
Former-commit-id: acc894fe41d4e8869f28928cb0feffa1792c11c4
This commit is contained in:
parent
ac55fe6dac
commit
4360d1ab3d
@ -11,9 +11,11 @@ public:
|
||||
|
||||
void arm(client *c) // if a client is passed, then the client is already locked
|
||||
{
|
||||
if (m_fArmed)
|
||||
return;
|
||||
|
||||
if (c != nullptr)
|
||||
{
|
||||
serverAssert(!m_fArmed);
|
||||
serverAssert(c->lock.fOwnLock());
|
||||
|
||||
if (!aeTryAcquireLock(true /*fWeak*/)) // avoid locking the client if we can
|
||||
|
@ -3586,9 +3586,6 @@ int processCommand(client *c, int callFlags) {
|
||||
|
||||
incrementMvccTstamp();
|
||||
|
||||
if (!locker.isArmed())
|
||||
locker.arm(c);
|
||||
|
||||
/* Handle the maxmemory directive.
|
||||
*
|
||||
* Note that we do not want to reclaim memory if we are here re-entering
|
||||
@ -3596,6 +3593,7 @@ int processCommand(client *c, int callFlags) {
|
||||
* condition, to avoid mixing the propagation of scripts with the
|
||||
* propagation of DELs due to eviction. */
|
||||
if (g_pserver->maxmemory && !g_pserver->lua_timedout) {
|
||||
locker.arm(c);
|
||||
int out_of_memory = freeMemoryIfNeededAndSafe() == C_ERR;
|
||||
/* freeMemoryIfNeeded may flush replica output buffers. This may result
|
||||
* into a replica, that may be the active client, to be freed. */
|
||||
@ -3615,6 +3613,9 @@ int processCommand(client *c, int callFlags) {
|
||||
|
||||
/* Don't accept write commands if there are problems persisting on disk
|
||||
* and if this is a master instance. */
|
||||
if (c->cmd->flags & CMD_WRITE || c->cmd->proc == pingCommand)
|
||||
{
|
||||
locker.arm(c);
|
||||
int deny_write_type = writeCommandsDeniedByDiskError();
|
||||
if (deny_write_type != DISK_ERROR_TYPE_NONE &&
|
||||
listLength(g_pserver->masters) == 0 &&
|
||||
@ -3654,6 +3655,7 @@ int processCommand(client *c, int callFlags) {
|
||||
addReply(c, shared.roslaveerr);
|
||||
return C_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/* Only allow a subset of commands in the context of Pub/Sub if the
|
||||
* connection is in RESP2 mode. With RESP3 there are no limits. */
|
||||
@ -3667,6 +3669,9 @@ int processCommand(client *c, int callFlags) {
|
||||
return C_OK;
|
||||
}
|
||||
|
||||
if (listLength(g_pserver->masters))
|
||||
{
|
||||
locker.arm(c);
|
||||
/* Only allow commands with flag "t", such as INFO, SLAVEOF and so on,
|
||||
* when replica-serve-stale-data is no and we are a replica with a broken
|
||||
* link with master. */
|
||||
@ -3678,6 +3683,7 @@ int processCommand(client *c, int callFlags) {
|
||||
addReply(c, shared.masterdownerr);
|
||||
return C_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/* Loading DB? Return an error if the command has not the
|
||||
* CMD_LOADING flag. */
|
||||
@ -3711,6 +3717,7 @@ int processCommand(client *c, int callFlags) {
|
||||
queueMultiCommand(c);
|
||||
addReply(c,shared.queued);
|
||||
} else {
|
||||
locker.arm(c);
|
||||
call(c,callFlags);
|
||||
c->woff = g_pserver->master_repl_offset;
|
||||
if (listLength(g_pserver->ready_keys))
|
||||
|
Loading…
x
Reference in New Issue
Block a user