Update conditions required to terminate runaway queries
GPDB uses "runaway query termination" to kill memory-intensive sessions when the total memory usage goes beyond the "red zone" limit. The "red zone detector" identifies the session consuming the most memory memory. If that is also currently active (i.e not in ReadCommand()), it is selected as the "primary" runaway session. Otherwise the session consuming next most memory is selected as the "secondary" runaway session, since an idle session cannot clean itself up. Once selected, the sessions attempts cleanup by either calling elog(ERROR). However, under certain conditions e.g critical sections, the clean up must be ignored. If the primary runaway session is idle and another session is marked as secondary, we should not terminate the secondary session if it is executing an administrative command (e.g database restarts). This is handled by ignoring clean up for secondary runaway sessions executing as superuser. Also we want to avoid cancelling a session outside of an active transaction since it will not be able to free up any more resources. This commit refactors the logic in RunawayCleaner_StartCleanup() to only cancel the query under the conditions described above. Furthermore, it makes sure that superuser() is called only when executing a transaction. Otherwise that can lead to a PANIC if it needs to access the catalogue. Also update runaway cleaner unit tests to include both primary and secondary runaway scenarios and add a unit test for runaway clean up when called outside of a transaction.
Showing
想要评论请 注册 或 登录