Perform GET command inline

Former-commit-id: 5623936d99e334ab103f3dc1541b145c125d0ee8
This commit is contained in:
John Sully 2021-03-23 03:44:20 +00:00
parent 44603c8227
commit c6fc1bcfe3
4 changed files with 55 additions and 35 deletions

View File

@ -2998,10 +2998,10 @@ int dbnumFromDb(redisDb *db)
serverPanic("invalid database pointer"); serverPanic("invalid database pointer");
} }
void redisDbPersistentData::prefetchKeysAsync(client *c, parsed_command &command) bool redisDbPersistentData::prefetchKeysAsync(client *c, parsed_command &command, bool fExecOK)
{ {
if (m_spstorage == nullptr) if (m_spstorage == nullptr)
return; return false;
AeLocker lock; AeLocker lock;
@ -3010,7 +3010,7 @@ void redisDbPersistentData::prefetchKeysAsync(client *c, parsed_command &command
getKeysResult result = GETKEYS_RESULT_INIT; getKeysResult result = GETKEYS_RESULT_INIT;
auto cmd = lookupCommand(szFromObj(command.argv[0])); auto cmd = lookupCommand(szFromObj(command.argv[0]));
if (cmd == nullptr) if (cmd == nullptr)
return; // Bad command? It's not for us to judge, just bail return false; // Bad command? It's not for us to judge, just bail
int numkeys = getKeysFromCommand(cmd, command.argv, command.argc, &result); int numkeys = getKeysFromCommand(cmd, command.argv, command.argc, &result);
for (int ikey = 0; ikey < numkeys; ++ikey) for (int ikey = 0; ikey < numkeys; ++ikey)
{ {
@ -3042,6 +3042,7 @@ void redisDbPersistentData::prefetchKeysAsync(client *c, parsed_command &command
} }
} }
if (!vecInserts.empty()) {
lock.arm(c); lock.arm(c);
for (auto &tuple : vecInserts) for (auto &tuple : vecInserts)
{ {
@ -3079,4 +3080,15 @@ void redisDbPersistentData::prefetchKeysAsync(client *c, parsed_command &command
sdsfree(sharedKey); // BUG but don't bother crashing sdsfree(sharedKey); // BUG but don't bother crashing
} }
} }
lock.disarm();
}
if (fExecOK && cmd->proc == getCommand && !vecInserts.empty()) {
robj *o = std::get<1>(vecInserts[0]);
if (o != nullptr) {
addReplyBulk(c, o);
return true;
}
}
return false;
} }

View File

@ -2343,7 +2343,7 @@ void parseClientCommandBuffer(client *c) {
} }
} }
size_t cqueries = c->vecqueuedcmd.size(); size_t cqueriesStart = c->vecqueuedcmd.size();
if (c->reqtype == PROTO_REQ_INLINE) { if (c->reqtype == PROTO_REQ_INLINE) {
if (processInlineBuffer(c) != C_OK) break; if (processInlineBuffer(c) != C_OK) break;
} else if (c->reqtype == PROTO_REQ_MULTIBULK) { } else if (c->reqtype == PROTO_REQ_MULTIBULK) {
@ -2359,10 +2359,12 @@ void parseClientCommandBuffer(client *c) {
} }
/* Prefetch if we have a storage provider and we're not in the global lock */ /* Prefetch if we have a storage provider and we're not in the global lock */
if (cqueries < c->vecqueuedcmd.size() && g_pserver->m_pstorageFactory != nullptr && !GlobalLocksAcquired()) { if (cqueriesStart < c->vecqueuedcmd.size() && g_pserver->m_pstorageFactory != nullptr && !GlobalLocksAcquired()) {
auto &query = c->vecqueuedcmd.back(); auto &query = c->vecqueuedcmd.back();
if (query.argc > 0 && query.argc == query.argcMax) { if (query.argc > 0 && query.argc == query.argcMax) {
c->db->prefetchKeysAsync(c, query); if (c->db->prefetchKeysAsync(c, query, c->vecqueuedcmd.size() == 1)) {
c->vecqueuedcmd.erase(c->vecqueuedcmd.begin());
}
} }
} }
c->reqtype = 0; c->reqtype = 0;

View File

@ -2168,6 +2168,9 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) {
aeAcquireLock(); aeAcquireLock();
} }
if (g_pserver->maxmemory && g_pserver->m_pstorageFactory)
freeMemoryIfNeededAndSafe(false, false);
/* If another threads unblocked one of our clients, and this thread has been idle /* If another threads unblocked one of our clients, and this thread has been idle
then beforeSleep won't have a chance to process the unblocking. So we also then beforeSleep won't have a chance to process the unblocking. So we also
process them here in the cron job to ensure they don't starve. process them here in the cron job to ensure they don't starve.
@ -2455,6 +2458,9 @@ int serverCronLite(struct aeEventLoop *eventLoop, long long id, void *clientData
aeAcquireLock(); aeAcquireLock();
} }
if (g_pserver->maxmemory && g_pserver->m_pstorageFactory)
freeMemoryIfNeededAndSafe(false, false);
int iel = ielFromEventLoop(eventLoop); int iel = ielFromEventLoop(eventLoop);
serverAssert(iel != IDX_EVENT_LOOP_MAIN); serverAssert(iel != IDX_EVENT_LOOP_MAIN);

View File

@ -1134,7 +1134,7 @@ public:
bool removeCachedValue(const char *key); bool removeCachedValue(const char *key);
void removeAllCachedValues(); void removeAllCachedValues();
void prefetchKeysAsync(client *c, struct parsed_command &command); bool prefetchKeysAsync(client *c, struct parsed_command &command, bool fExecOK);
bool FSnapshot() const { return m_spdbSnapshotHOLDER != nullptr; } bool FSnapshot() const { return m_spdbSnapshotHOLDER != nullptr; }