Skip to content

Commit

Permalink
[FLASH-1026] Synchronization between drop table and remove region (#538)
Browse files Browse the repository at this point in the history
  • Loading branch information
JaySon-Huang authored Mar 23, 2020
1 parent 8ece150 commit cdf2c9d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions dbms/src/Interpreters/InterpreterDropQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ BlockIO InterpreterDropQuery::execute()
ErrorCodes::TABLE_WAS_NOT_DROPPED);
}

table.first->shutdown();

/// If table was already dropped by anyone, an exception will be thrown
auto table_lock = table.first->lockForAlter(__PRETTY_FUNCTION__);

table.first->shutdown();

String current_table_name = table.first->getTableName();

if (drop.detach)
Expand Down
13 changes: 8 additions & 5 deletions dbms/src/Storages/DeltaMerge/DeltaMergeStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,15 @@ void DeltaMergeStore::shutdown()
{
bool v = false;
if (!shutdown_called.compare_exchange_strong(v, true))
return ;
return;

LOG_DEBUG(log, "Shutdown DeltaMerge Store start [" << db_name << "." << table_name << "]");
background_pool.removeTask(gc_handle);
gc_handle = nullptr;

background_pool.removeTask(background_task_handle);
background_task_handle = nullptr;
LOG_DEBUG(log, "Shutdown DeltaMerge Store start [" << db_name << "." << table_name << "]");
}

DMContextPtr DeltaMergeStore::newDMContext(const Context & db_context, const DB::Settings & db_settings)
Expand Down Expand Up @@ -811,6 +813,9 @@ void DeltaMergeStore::checkSegmentUpdate(const DMContextPtr & dm_context, const
auto try_add_background_task = [&](const BackgroundTask & task) {
if (background_tasks.length() <= std::max(id_to_segment.size() * 2, background_pool.getNumberOfThreads() * 5))
{
if (shutdown_called.load(std::memory_order_relaxed))
return;

// Prevent too many tasks.
background_tasks.addTask(task, thread_type, log);
background_task_handle->wake();
Expand Down Expand Up @@ -997,15 +1002,13 @@ bool DeltaMergeStore::handleBackgroundTask()
left = segmentMergeDelta(*task.dm_context, task.segment, false);
type = ThreadType::BG_MergeDelta;
break;
case Compact:
{
case Compact: {
task.segment->getDelta()->compact(*task.dm_context);
left = task.segment;
type = ThreadType::BG_Compact;
break;
}
case Flush:
{
case Flush: {
task.segment->getDelta()->flush(*task.dm_context);
left = task.segment;
type = ThreadType::BG_Flush;
Expand Down

0 comments on commit cdf2c9d

Please sign in to comment.