|
3 | 3 | #include <Core/UUID.h> |
4 | 4 | #include <Databases/TablesDependencyGraph.h> |
5 | 5 | #include <Interpreters/Context_fwd.h> |
| 6 | +#include <Interpreters/DDLGuard.h> |
6 | 7 | #include <Interpreters/StorageID.h> |
7 | 8 | #include <Parsers/IAST_fwd.h> |
8 | 9 | #include <Storages/IStorage_fwd.h> |
@@ -37,45 +38,6 @@ using Databases = std::map<String, std::shared_ptr<IDatabase>>; |
37 | 38 | using DiskPtr = std::shared_ptr<IDisk>; |
38 | 39 | using TableNamesSet = std::unordered_set<QualifiedTableName>; |
39 | 40 |
|
40 | | -/// Allows executing DDL query only in one thread. |
41 | | -/// Puts an element into the map, locks tables's mutex, counts how much threads run parallel query on the table, |
42 | | -/// when counter is 0 erases element in the destructor. |
43 | | -/// If the element already exists in the map, waits when ddl query will be finished in other thread. |
44 | | -class DDLGuard |
45 | | -{ |
46 | | -public: |
47 | | - struct Entry |
48 | | - { |
49 | | - std::unique_ptr<std::mutex> mutex; |
50 | | - UInt32 counter; |
51 | | - }; |
52 | | - |
53 | | - /// Element name -> (mutex, counter). |
54 | | - /// NOTE: using std::map here (and not std::unordered_map) to avoid iterator invalidation on insertion. |
55 | | - using Map = std::map<String, Entry>; |
56 | | - |
57 | | - DDLGuard( |
58 | | - Map & map_, |
59 | | - SharedMutex & db_mutex_, |
60 | | - std::unique_lock<std::mutex> guards_lock_, |
61 | | - const String & elem, |
62 | | - const String & database_name); |
63 | | - ~DDLGuard(); |
64 | | - |
65 | | - /// Unlocks table name, keeps holding read lock for database name |
66 | | - void releaseTableLock() noexcept; |
67 | | - |
68 | | -private: |
69 | | - Map & map; |
70 | | - SharedMutex & db_mutex; |
71 | | - Map::iterator it; |
72 | | - std::unique_lock<std::mutex> guards_lock; |
73 | | - std::unique_lock<std::mutex> table_lock; |
74 | | - bool table_lock_removed = false; |
75 | | - bool is_database_guard = false; |
76 | | -}; |
77 | | - |
78 | | -using DDLGuardPtr = std::unique_ptr<DDLGuard>; |
79 | 41 |
|
80 | 42 | class FutureSetFromSubquery; |
81 | 43 | using FutureSetFromSubqueryPtr = std::shared_ptr<FutureSetFromSubquery>; |
|
0 commit comments