Skip to content

Commit 9dc4f02

Browse files
committed
Revert "Merge pull request #45493 from azat/fix-detach"
This reverts commit a182a6b, reversing changes made to c47a29a.
1 parent ac1e726 commit 9dc4f02

File tree

7 files changed

+10
-19
lines changed

7 files changed

+10
-19
lines changed

src/Databases/DatabaseOnDisk.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,14 +379,14 @@ void DatabaseOnDisk::renameTable(
379379
if (dictionary && table && !table->isDictionary())
380380
throw Exception(ErrorCodes::INCORRECT_QUERY, "Use RENAME/EXCHANGE TABLE (instead of RENAME/EXCHANGE DICTIONARY) for tables");
381381

382-
table_lock = table->lockExclusively(
383-
local_context->getCurrentQueryId(), local_context->getSettingsRef().lock_acquire_timeout);
384-
385382
detachTable(local_context, table_name);
386383

387384
UUID prev_uuid = UUIDHelpers::Nil;
388385
try
389386
{
387+
table_lock = table->lockExclusively(
388+
local_context->getCurrentQueryId(), local_context->getSettingsRef().lock_acquire_timeout);
389+
390390
table_metadata_path = getObjectMetadataPath(table_name);
391391
attach_query = parseQueryFromMetadata(log, local_context, table_metadata_path);
392392
auto & create = attach_query->as<ASTCreateQuery &>();

src/Databases/DatabasesCommon.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ StoragePtr DatabaseWithOwnTablesBase::detachTableUnlocked(const String & table_n
236236
backQuote(database_name), backQuote(table_name));
237237
res = it->second;
238238
tables.erase(it);
239-
res->is_detached = true;
240239

241240
auto table_id = res->getStorageID();
242241
if (table_id.hasUUID())
@@ -273,10 +272,6 @@ void DatabaseWithOwnTablesBase::attachTableUnlocked(const String & table_name, c
273272
DatabaseCatalog::instance().removeUUIDMapping(table_id.uuid);
274273
throw Exception(ErrorCodes::TABLE_ALREADY_EXISTS, "Table {} already exists.", table_id.getFullTableName());
275274
}
276-
277-
/// It is important to reset is_detached here since in case of RENAME in
278-
/// non-Atomic database the is_detached is set to true before RENAME.
279-
table->is_detached = false;
280275
}
281276

282277
void DatabaseWithOwnTablesBase::shutdown()

src/Databases/MySQL/DatabaseMySQL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ void DatabaseMySQL::detachTablePermanently(ContextPtr, const String & table_name
448448
remove_or_detach_tables.erase(table_name);
449449
throw;
450450
}
451-
table_iter->second.second->is_detached = true;
451+
table_iter->second.second->is_dropped = true;
452452
}
453453

454454
void DatabaseMySQL::dropTable(ContextPtr local_context, const String & table_name, bool /*sync*/)

src/Interpreters/InterpreterDropQuery.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,6 @@ BlockIO InterpreterDropQuery::executeToTemporaryTable(const String & table_name,
287287
table->drop();
288288
table->is_dropped = true;
289289
}
290-
else if (kind == ASTDropQuery::Kind::Detach)
291-
{
292-
table->is_detached = true;
293-
}
294290
}
295291
}
296292

src/Storages/IStorage.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ TableLockHolder IStorage::lockForShare(const String & query_id, const std::chron
5050
{
5151
TableLockHolder result = tryLockTimed(drop_lock, RWLockImpl::Read, query_id, acquire_timeout);
5252

53-
if (is_dropped || is_detached)
53+
if (is_dropped)
5454
{
5555
auto table_id = getStorageID();
56-
throw Exception(ErrorCodes::TABLE_IS_DROPPED, "Table {}.{} is dropped or detached", table_id.database_name, table_id.table_name);
56+
throw Exception(ErrorCodes::TABLE_IS_DROPPED, "Table {}.{} is dropped", table_id.database_name, table_id.table_name);
5757
}
5858
return result;
5959
}
@@ -62,7 +62,7 @@ TableLockHolder IStorage::tryLockForShare(const String & query_id, const std::ch
6262
{
6363
TableLockHolder result = tryLockTimed(drop_lock, RWLockImpl::Read, query_id, acquire_timeout);
6464

65-
if (is_dropped || is_detached)
65+
if (is_dropped)
6666
{
6767
// Table was dropped while acquiring the lock
6868
result = nullptr;
@@ -81,7 +81,7 @@ IStorage::AlterLockHolder IStorage::lockForAlter(const std::chrono::milliseconds
8181
"Possible deadlock avoided. Client should retry.",
8282
getStorageID().getFullTableName(), acquire_timeout.count());
8383

84-
if (is_dropped || is_detached)
84+
if (is_dropped)
8585
throw Exception(ErrorCodes::TABLE_IS_DROPPED, "Table {} is dropped or detached", getStorageID());
8686

8787
return lock;
@@ -93,7 +93,7 @@ TableExclusiveLockHolder IStorage::lockExclusively(const String & query_id, cons
9393
TableExclusiveLockHolder result;
9494
result.drop_lock = tryLockTimed(drop_lock, RWLockImpl::Write, query_id, acquire_timeout);
9595

96-
if (is_dropped || is_detached)
96+
if (is_dropped)
9797
throw Exception(ErrorCodes::TABLE_IS_DROPPED, "Table {} is dropped or detached", getStorageID());
9898

9999
return result;

src/Storages/IStorage.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,6 @@ class IStorage : public std::enable_shared_from_this<IStorage>, public TypePromo
562562
virtual void onActionLockRemove(StorageActionBlockType /* action_type */) {}
563563

564564
std::atomic<bool> is_dropped{false};
565-
std::atomic<bool> is_detached{false};
566565

567566
/// Does table support index for IN sections
568567
virtual bool supportsIndexForIn() const { return false; }

src/Storages/LiveView/StorageLiveView.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ void StorageLiveView::drop()
470470
DatabaseCatalog::instance().removeViewDependency(select_table_id, table_id);
471471

472472
std::lock_guard lock(mutex);
473+
is_dropped = true;
473474
condition.notify_all();
474475
}
475476

0 commit comments

Comments
 (0)