Merge pull request #16409 from azat/drop-distributed-fix

Fix DROP TABLE for Distributed (racy with INSERT)
This commit is contained in:
tavplubix 2020-10-28 14:10:32 +03:00 committed by GitHub
commit cd70dc82cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -80,7 +80,6 @@ namespace ErrorCodes
extern const int TYPE_MISMATCH; extern const int TYPE_MISMATCH;
extern const int TOO_MANY_ROWS; extern const int TOO_MANY_ROWS;
extern const int UNABLE_TO_SKIP_UNUSED_SHARDS; extern const int UNABLE_TO_SKIP_UNUSED_SHARDS;
extern const int LOGICAL_ERROR;
} }
namespace ActionLocks namespace ActionLocks
@ -600,15 +599,22 @@ void StorageDistributed::shutdown()
monitors_blocker.cancelForever(); monitors_blocker.cancelForever();
std::lock_guard lock(cluster_nodes_mutex); std::lock_guard lock(cluster_nodes_mutex);
LOG_DEBUG(log, "Joining background threads for async INSERT");
cluster_nodes_data.clear(); cluster_nodes_data.clear();
LOG_DEBUG(log, "Background threads for async INSERT joined");
} }
void StorageDistributed::drop() void StorageDistributed::drop()
{ {
// shutdown() should be already called // Some INSERT in-between shutdown() and drop() can call
// and by the same reason we cannot use truncate() here, since // requireDirectoryMonitor() again, so call shutdown() to clear them, but
// cluster_nodes_data already cleaned // when the drop() (this function) executed none of INSERT is allowed in
if (!cluster_nodes_data.empty()) // parallel.
throw Exception("drop called before shutdown", ErrorCodes::LOGICAL_ERROR); //
// And second time shutdown() should be fast, since none of
// DirectoryMonitor should do anything, because ActionBlocker is canceled
// (in shutdown()).
shutdown();
// Distributed table w/o sharding_key does not allows INSERTs // Distributed table w/o sharding_key does not allows INSERTs
if (relative_data_path.empty()) if (relative_data_path.empty())