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

Function processEventsWhileBlocked

src/networking.cpp:4060–4104  ·  view source on GitHub ↗

This function is called by Redis in order to process a few events from * time to time while blocked into some not interruptible operation. * This allows to reply to clients with the -LOADING error while loading the * data set at startup or after a full resynchronization with the master * and so forth. * * It calls the event loop in order to process a few events. Specifically we * try to cal

Source from the content-addressed store, hash-verified

4058 *
4059 * The function returns the total number of events processed. */
4060void processEventsWhileBlocked(int iel) {
4061
4062 int eventsCount = 0;
4063 executeWithoutGlobalLock([&](){
4064 int iterations = 4; /* See the function top-comment. */
4065 try
4066 {
4067 ProcessingEventsWhileBlocked = 1;
4068 while (iterations--) {
4069 long long startval = g_pserver->events_processed_while_blocked;
4070 long long ae_events = aeProcessEvents(g_pserver->rgthreadvar[iel].el,
4071 AE_FILE_EVENTS|AE_DONT_WAIT|
4072 AE_CALL_BEFORE_SLEEP|AE_CALL_AFTER_SLEEP);
4073 /* Note that g_pserver->events_processed_while_blocked will also get
4074 * incremeted by callbacks called by the event loop handlers. */
4075 eventsCount += ae_events;
4076 long long events = eventsCount - startval;
4077 if (!events) break;
4078 }
4079 ProcessingEventsWhileBlocked = 0;
4080 }
4081 catch (...)
4082 {
4083 ProcessingEventsWhileBlocked = 0;
4084 throw;
4085 }
4086 });
4087
4088 // Try to complete any async rehashes (this would normally happen in dbCron, but that won't run here)
4089 for (int idb = 0; idb < cserver.dbnum; ++idb) {
4090 redisDb *db = g_pserver->db[idb];
4091 while (db->dictUnsafeKeyOnly()->asyncdata != nullptr) {
4092 if (!db->dictUnsafeKeyOnly()->asyncdata->done)
4093 break;
4094 dictCompleteRehashAsync(db->dictUnsafeKeyOnly()->asyncdata, false /*fFree*/);
4095 }
4096 }
4097 g_pserver->events_processed_while_blocked += eventsCount;
4098
4099 whileBlockedCron();
4100
4101 // If a different thread processed the shutdown we need to abort the lua command or we will hang
4102 if (serverTL->el->stop)
4103 throw ShutdownException();
4104}
4105

Callers 4

ProcessWhileBlockedMethod · 0.85
rdbLoadProgressCallbackFunction · 0.85
loadAppendOnlyFileFunction · 0.85
luaMaskCountHookFunction · 0.85

Calls 6

executeWithoutGlobalLockFunction · 0.85
aeProcessEventsFunction · 0.85
dictCompleteRehashAsyncFunction · 0.85
whileBlockedCronFunction · 0.85
ShutdownExceptionClass · 0.85
dictUnsafeKeyOnlyMethod · 0.80

Tested by

no test coverage detected