MXS-1985: Add debug assertions to dcb_foreach

The dcb_foreach function is not safe to use from multiple threads at the
same time. This should be asserted by checking that the function is called
only from the main worker.

The addition of this assertion also implies that only administrative
operations should use the dcb_foreach function. To accommodate this
change, the KILL command iteration needs to be adjusted.
This commit is contained in:
Markus Mäkelä 2018-07-19 22:50:12 +03:00
parent 30ac15817f
commit 101dad74a7
No known key found for this signature in database
GPG Key ID: 72D48FCE664F7B19
2 changed files with 3 additions and 0 deletions

View File

@ -356,6 +356,8 @@ static inline void dcb_readq_set(DCB *dcb, GWBUF *buffer)
*
* @deprecated You should not use this function, use dcb_foreach_parallel instead
*
* @warning This must only be called from the main thread, otherwise deadlocks occur
*
* @param func Function to call. The function should return @c true to continue iteration
* and @c false to stop iteration earlier. The first parameter is a DCB and the second
* is the value of @c data that the user provided.

View File

@ -2937,6 +2937,7 @@ private:
bool dcb_foreach(bool(*func)(DCB *dcb, void *data), void *data)
{
ss_dassert(Worker::get_current() == Worker::get(0));
SerialDcbTask task(func, data);
Worker::execute_serially(task);
return task.more();