fix order of destruction of table locks and child streams

Incorrect order could lead to a very rare `mutex lock failed: Invalid argument`
error when MergeTree table was dropped and its parts were deleted defore the destruction
of streams that were reading from that parts.
This commit is contained in:
Alexey Zatelepin 2019-03-06 15:25:59 +03:00
parent 6e852288ff
commit bc30ed92d4

View File

@ -242,6 +242,10 @@ public:
void enableExtremes() { enabled_extremes = true; } void enableExtremes() { enabled_extremes = true; }
protected: protected:
/// Order is important: `table_locks` must be destroyed after `children` so that tables from
/// which child streams read are protected by the locks during the lifetime of the child streams.
TableStructureReadLocks table_locks;
BlockInputStreams children; BlockInputStreams children;
std::shared_mutex children_mutex; std::shared_mutex children_mutex;
@ -268,8 +272,6 @@ protected:
} }
private: private:
TableStructureReadLocks table_locks;
bool enabled_extremes = false; bool enabled_extremes = false;
/// The limit on the number of rows/bytes has been exceeded, and you need to stop execution on the next `read` call, as if the thread has run out. /// The limit on the number of rows/bytes has been exceeded, and you need to stop execution on the next `read` call, as if the thread has run out.