ClickHouse/dbms/src/Common/ActionLock.h
Vitaliy Lyudvichenko c888903488
Add query ALTER TABLE t1 [REPLACE|ATTACH] PARTITION FROM t2
* Add ATTACH PARTITION FROM table for MergeTree. [#CLICKHOUSE-3546]

* Implemented replicated case on non-leader replica. [#CLICKHOUSE-3546]

* Disable merges in the dropping range. [#CLICKHOUSE-3546]

* DROP PARTITION is atomic and simpler now. [#CLICKHOUSE-3546]

* Implemented more SYSTEM queries. [#CLICKHOUSE-2931] [#CLICKHOUSE-3546]

SYSTEM queries:
RESTART REPLICAS
SYNC REPLICA db.name
STOP MERGES [db.name]
START MERGES [db.name]
STOP FETCHES [db.name]
START FETCHES [db.name]
STOP REPLICATED SENDS [db.name]
START REPLICATED SENDS [db.name]
STOP REPLICATION QUEUES [db.name]
START REPLICATION QUEUES [db.name]

* Fixed a bunch of bugs in REPLACE PARTITION. [#CLICKHOUSE-3546]

* Add tests for REPLACE PARTITION and SYSTEM. [#CLICKHOUSE-3546]

* Add system.part_log logging. [#CLICKHOUSE-3546]

* Fixed long wait in SYNC REPLICA. [#CLICKHOUSE-3546]

* Add requested changes. [#CLICKHOUSE-3546]

Fixed clickhouse-client bad return code.

* Add requested chenges. [#CLICKHOUSE-3546]

* Add requested chenges. [#CLICKHOUSE-3546]
2018-05-21 16:49:54 +03:00

47 lines
964 B
C++

#pragma once
#include <memory>
#include <atomic>
#include <Core/Types.h>
namespace DB
{
class ActionBlocker;
using StorageActionBlockType = size_t;
/// Blocks related action while a ActionLock instance exists
/// ActionBlocker could be destroyed before the lock, in this case ActionLock will safely do nothing in its destructor
class ActionLock
{
public:
ActionLock() = default;
explicit ActionLock(const ActionBlocker & blocker);
ActionLock(ActionLock && other);
ActionLock & operator=(ActionLock && other);
ActionLock(const ActionLock & other) = delete;
ActionLock & operator=(const ActionLock & other) = delete;
bool expired() const
{
return counter_ptr.expired();
}
~ActionLock()
{
if (auto counter = counter_ptr.lock())
--(*counter);
}
private:
using Counter = std::atomic<int>;
using CounterWeakPtr = std::weak_ptr<Counter>;
CounterWeakPtr counter_ptr;
};
}