MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / parseClientCommandBuffer

Function parseClientCommandBuffer

src/networking.cpp:2572–2620  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2570}
2571
2572void parseClientCommandBuffer(client *c) {
2573 if (!FClientReady(c))
2574 return;
2575
2576 while(c->qb_pos < sdslen(c->querybuf)) {
2577 /* Determine request type when unknown. */
2578 if (!c->reqtype) {
2579 if (c->querybuf[c->qb_pos] == '*') {
2580 c->reqtype = PROTO_REQ_MULTIBULK;
2581 } else {
2582 c->reqtype = PROTO_REQ_INLINE;
2583 }
2584 }
2585
2586 size_t cqueriesStart = c->vecqueuedcmd.size();
2587 if (c->reqtype == PROTO_REQ_INLINE) {
2588 if (processInlineBuffer(c) != C_OK) break;
2589 } else if (c->reqtype == PROTO_REQ_MULTIBULK) {
2590 if (processMultibulkBuffer(c) != C_OK) break;
2591 } else {
2592 serverPanic("Unknown request type");
2593 }
2594 if (!c->vecqueuedcmd.empty() && (c->vecqueuedcmd.back().argc <= 0 || c->vecqueuedcmd.back().argv == nullptr)) {
2595 c->vecqueuedcmd.pop_back();
2596 } else if (!c->vecqueuedcmd.empty()) {
2597 if (c->flags & CLIENT_MASTER) c->vecqueuedcmd.back().reploff = c->read_reploff - sdslen(c->querybuf) + c->qb_pos;
2598 serverAssert(c->vecqueuedcmd.back().reploff >= 0);
2599 }
2600
2601 /* Prefetch outside the lock for better perf */
2602 if (g_pserver->prefetch_enabled && (cserver.cthreads > 1 || g_pserver->m_pstorageFactory) && cqueriesStart < c->vecqueuedcmd.size() &&
2603 (g_pserver->m_pstorageFactory || aeLockContested(cserver.cthreads/2) || cserver.cthreads == 1) && !GlobalLocksAcquired()) {
2604 auto &query = c->vecqueuedcmd.back();
2605 if (query.argc > 0 && query.argc == query.argcMax) {
2606 c->db->prefetchKeysAsync(c, query);
2607 }
2608 }
2609 c->reqtype = 0;
2610 c->multibulklen = 0;
2611 c->bulklen = -1;
2612 c->reqtype = 0;
2613 }
2614
2615 /* Trim to pos */
2616 if (c->qb_pos) {
2617 sdsrange(c->querybuf,c->qb_pos,-1);
2618 c->qb_pos = 0;
2619 }
2620}
2621
2622bool FAsyncCommand(parsed_command &cmd)
2623{

Callers 2

processInputBufferFunction · 0.85
readQueryFromClientFunction · 0.85

Calls 10

FClientReadyFunction · 0.85
sdslenFunction · 0.85
processInlineBufferFunction · 0.85
processMultibulkBufferFunction · 0.85
aeLockContestedFunction · 0.85
GlobalLocksAcquiredFunction · 0.85
sdsrangeFunction · 0.85
prefetchKeysAsyncMethod · 0.80
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected