1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
#pragma once
#include <Interpreters/IInterpreter.h>
#include <Parsers/IAST_fwd.h>
#include <Storages/IStorage_fwd.h>
#include <Interpreters/StorageID.h>
#include <Common/ActionLock.h>
#include <Disks/IVolume.h>
namespace Poco { class Logger; }
namespace DB
{
class Context;
class AccessRightsElements;
class ASTSystemQuery;
class IDatabase;
using DatabasePtr = std::shared_ptr<IDatabase>;
/** Implement various SYSTEM queries.
* Examples: SYSTEM SHUTDOWN, SYSTEM DROP MARK CACHE.
*
* Some commands are intended to stop/start background actions for tables and comes with two variants:
*
* 1. SYSTEM STOP MERGES table, SYSTEM START MERGES table
* - start/stop actions for specific table.
*
* 2. SYSTEM STOP MERGES, SYSTEM START MERGES
* - start/stop actions for all existing tables.
* Note that the actions for tables that will be created after this query will not be affected.
*/
class InterpreterSystemQuery : public IInterpreter, WithMutableContext
{
public:
InterpreterSystemQuery(const ASTPtr & query_ptr_, ContextMutablePtr context_);
BlockIO execute() override;
static void startStopActionInDatabase(StorageActionBlockType action_type, bool start,
const String & database_name, const DatabasePtr & database,
const ContextPtr & local_context, Poco::Logger * log);
private:
ASTPtr query_ptr;
Poco::Logger * log = nullptr;
StorageID table_id = StorageID::createEmpty(); /// Will be set up if query contains table name
VolumePtr volume_ptr;
/// Tries to get a replicated table and restart it
/// Returns pointer to a newly created table if the restart was successful
StoragePtr tryRestartReplica(const StorageID & replica, ContextMutablePtr context, bool need_ddl_guard = true);
void restartReplica(const StorageID & replica, ContextMutablePtr system_context);
void restartReplicas(ContextMutablePtr system_context);
void syncReplica(ASTSystemQuery & query);
void waitLoadingParts();
void syncReplicatedDatabase(ASTSystemQuery & query);
void syncTransactionLog();
void restoreReplica();
void dropReplica(ASTSystemQuery & query);
bool dropReplicaImpl(ASTSystemQuery & query, const StoragePtr & table);
void dropDatabaseReplica(ASTSystemQuery & query);
void flushDistributed(ASTSystemQuery & query);
[[noreturn]] void restartDisk(String & name);
AccessRightsElements getRequiredAccessForDDLOnCluster() const;
void startStopAction(StorageActionBlockType action_type, bool start);
};
}
|