vinyl: don't start scheduler fiber until local recovery is complete
We must not schedule any background jobs during local recovery, because they may disrupt yet to be recovered data stored on disk. Since we start the scheduler fiber as soon as the engine is initialized, we have to pull some tricks to make sure it doesn't schedule any tasks: the scheduler fiber function yields immediately upon startup; we assume that it won't be woken up until local recovery is complete, because we don't set the memory limit until then. This looks rather flimsy, because the logic is spread among several seemingly unrelated functions: the scheduler fiber (vy_scheduler_f), the quota watermark callback (vy_env_quota_exceeded_cb), and the engine recovery callback (vinyl_engine_begin_initial_recovery), where we leave the memory limit unset until recovery is complete. The latter isn't even mentioned in comments, which makes the code difficult to follow. Think how everything would fall apart should we try to wake up the scheduler fiber somewhere else for some reason. This patch attempts to make the code more straightforward by postponing startup of the scheduler fiber until recovery completion. It also moves the comment explaining why we can't schedule tasks during local recovery from vy_env_quota_exceeded_cb to vinyl_engine_begin_initial_recovery, because this is where we actually omit the scheduler fiber startup. Note, since now the scheduler fiber goes straight to business once started, we can't start worker threads in the fiber function as we used to, because then workers threads would be running even if vinyl was unused. So we move this code to vy_worker_pool_get, which is called when a worker is actually needed to run a task.
Loading
Please register or sign in to comment