@@ -53,10 +53,10 @@ TableLockHolder IStorage::lockForShare(const String & query_id, const std::chron
5353{
5454 TableLockHolder result = tryLockTimed (drop_lock, RWLockImpl::Read, query_id, acquire_timeout);
5555
56- if (is_dropped)
56+ if (is_dropped || is_detached )
5757 {
5858 auto table_id = getStorageID ();
59- throw Exception (ErrorCodes::TABLE_IS_DROPPED, " Table {}.{} is dropped" , table_id.database_name , table_id.table_name );
59+ throw Exception (ErrorCodes::TABLE_IS_DROPPED, " Table {}.{} is dropped or detached " , table_id.database_name , table_id.table_name );
6060 }
6161 return result;
6262}
@@ -65,7 +65,7 @@ TableLockHolder IStorage::tryLockForShare(const String & query_id, const std::ch
6565{
6666 TableLockHolder result = tryLockTimed (drop_lock, RWLockImpl::Read, query_id, acquire_timeout);
6767
68- if (is_dropped)
68+ if (is_dropped || is_detached )
6969 {
7070 // Table was dropped while acquiring the lock
7171 result = nullptr ;
@@ -84,8 +84,11 @@ IStorage::AlterLockHolder IStorage::lockForAlter(const std::chrono::milliseconds
8484 " Possible deadlock avoided. Client should retry." ,
8585 getStorageID ().getFullTableName (), std::to_string (acquire_timeout.count ()));
8686
87- if (is_dropped)
88- throw Exception (" Table is dropped" , ErrorCodes::TABLE_IS_DROPPED);
87+ if (is_dropped || is_detached)
88+ {
89+ auto table_id = getStorageID ();
90+ throw Exception (ErrorCodes::TABLE_IS_DROPPED, " Table {}.{} is dropped or detached" , table_id.database_name , table_id.table_name );
91+ }
8992
9093 return lock;
9194}
@@ -96,8 +99,11 @@ TableExclusiveLockHolder IStorage::lockExclusively(const String & query_id, cons
9699 TableExclusiveLockHolder result;
97100 result.drop_lock = tryLockTimed (drop_lock, RWLockImpl::Write, query_id, acquire_timeout);
98101
99- if (is_dropped)
100- throw Exception (" Table is dropped" , ErrorCodes::TABLE_IS_DROPPED);
102+ if (is_dropped || is_detached)
103+ {
104+ auto table_id = getStorageID ();
105+ throw Exception (ErrorCodes::TABLE_IS_DROPPED, " Table {}.{} is dropped or detached" , table_id.database_name , table_id.table_name );
106+ }
101107
102108 return result;
103109}
0 commit comments