mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 01:25:21 +00:00
Add event for tracking data parts lock
This commit is contained in:
parent
e67c002cb0
commit
415b3826e0
@ -258,6 +258,7 @@ The server successfully detected this situation and will download merged part fr
|
||||
M(RWLockReadersWaitMilliseconds, "Total time spent waiting for a read lock to be acquired (in a heavy RWLock).") \
|
||||
M(RWLockWritersWaitMilliseconds, "Total time spent waiting for a write lock to be acquired (in a heavy RWLock).") \
|
||||
M(DNSError, "Total count of errors in DNS resolution") \
|
||||
M(PartsLockMicroseconds, "Total time spent holding data parts lock in MergeTree tables") \
|
||||
\
|
||||
M(RealTimeMicroseconds, "Total (wall clock) time spent in processing (queries and other tasks) threads (note that this is a sum).") \
|
||||
M(UserTimeMicroseconds, "Total time spent in processing (queries and other tasks) threads executing CPU instructions in user mode. This include time CPU pipeline was stalled due to main memory access, cache misses, branch mispredictions, hyper-threading, etc.") \
|
||||
|
@ -128,6 +128,7 @@ namespace ProfileEvents
|
||||
extern const Event RejectedMutations;
|
||||
extern const Event DelayedMutations;
|
||||
extern const Event DelayedMutationsMilliseconds;
|
||||
extern const Event PartsLockMicroseconds;
|
||||
}
|
||||
|
||||
namespace CurrentMetrics
|
||||
@ -309,6 +310,12 @@ void MergeTreeData::initializeDirectoriesAndFormatVersion(const std::string & re
|
||||
}
|
||||
}
|
||||
|
||||
DataPartsLock::~DataPartsLock()
|
||||
{
|
||||
if (watch.has_value())
|
||||
ProfileEvents::increment(ProfileEvents::PartsLockMicroseconds, watch->elapsedMicroseconds());
|
||||
}
|
||||
|
||||
MergeTreeData::MergeTreeData(
|
||||
const StorageID & table_id_,
|
||||
const StorageInMemoryMetadata & metadata_,
|
||||
@ -6244,14 +6251,14 @@ void MergeTreeData::Transaction::clear()
|
||||
precommitted_parts.clear();
|
||||
}
|
||||
|
||||
MergeTreeData::DataPartsVector MergeTreeData::Transaction::commit(MergeTreeData::DataPartsLock * acquired_parts_lock)
|
||||
MergeTreeData::DataPartsVector MergeTreeData::Transaction::commit(DataPartsLock * acquired_parts_lock)
|
||||
{
|
||||
DataPartsVector total_covered_parts;
|
||||
|
||||
if (!isEmpty())
|
||||
{
|
||||
auto settings = data.getSettings();
|
||||
auto parts_lock = acquired_parts_lock ? MergeTreeData::DataPartsLock() : data.lockParts();
|
||||
auto parts_lock = acquired_parts_lock ? DataPartsLock() : data.lockParts();
|
||||
auto * owing_parts_lock = acquired_parts_lock ? acquired_parts_lock : &parts_lock;
|
||||
|
||||
for (const auto & part : precommitted_parts)
|
||||
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
#include <base/defines.h>
|
||||
#include <Common/SimpleIncrement.h>
|
||||
#include <Common/SharedMutex.h>
|
||||
@ -40,7 +41,6 @@
|
||||
#include <boost/multi_index/global_fun.hpp>
|
||||
#include <boost/range/iterator_range_core.hpp>
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
@ -84,6 +84,19 @@ namespace ErrorCodes
|
||||
extern const int LOGICAL_ERROR;
|
||||
}
|
||||
|
||||
struct DataPartsLock
|
||||
{
|
||||
std::unique_lock<std::mutex> lock;
|
||||
std::optional<Stopwatch> watch;
|
||||
DataPartsLock() = default;
|
||||
|
||||
explicit DataPartsLock(std::mutex & data_parts_mutex_)
|
||||
: lock(data_parts_mutex_)
|
||||
, watch(Stopwatch(CLOCK_MONOTONIC))
|
||||
{}
|
||||
|
||||
~DataPartsLock();
|
||||
};
|
||||
|
||||
/// Data structure for *MergeTree engines.
|
||||
/// Merge tree is used for incremental sorting of data.
|
||||
@ -220,7 +233,6 @@ public:
|
||||
using MutableDataParts = std::set<MutableDataPartPtr, LessDataPart>;
|
||||
using DataPartsVector = std::vector<DataPartPtr>;
|
||||
|
||||
using DataPartsLock = std::unique_lock<std::mutex>;
|
||||
DataPartsLock lockParts() const { return DataPartsLock(data_parts_mutex); }
|
||||
|
||||
using OperationDataPartsLock = std::unique_lock<std::mutex>;
|
||||
@ -240,7 +252,7 @@ public:
|
||||
public:
|
||||
Transaction(MergeTreeData & data_, MergeTreeTransaction * txn_);
|
||||
|
||||
DataPartsVector commit(MergeTreeData::DataPartsLock * acquired_parts_lock = nullptr);
|
||||
DataPartsVector commit(DataPartsLock * acquired_parts_lock = nullptr);
|
||||
|
||||
void addPart(MutableDataPartPtr & part);
|
||||
|
||||
|
@ -113,7 +113,7 @@ void MergeTreeWriteAheadLog::rotate(const std::unique_lock<std::mutex> &)
|
||||
MergeTreeData::MutableDataPartsVector MergeTreeWriteAheadLog::restore(
|
||||
const StorageMetadataPtr & metadata_snapshot,
|
||||
ContextPtr context,
|
||||
std::unique_lock<std::mutex> & parts_lock,
|
||||
DataPartsLock & parts_lock,
|
||||
bool readonly)
|
||||
{
|
||||
std::unique_lock lock(write_mutex);
|
||||
|
@ -11,6 +11,7 @@ namespace DB
|
||||
{
|
||||
|
||||
class MergeTreeData;
|
||||
struct DataPartsLock;
|
||||
|
||||
/** WAL stores addditions and removals of data parts in in-memory format.
|
||||
* Format of data in WAL:
|
||||
@ -64,7 +65,7 @@ public:
|
||||
std::vector<MergeTreeMutableDataPartPtr> restore(
|
||||
const StorageMetadataPtr & metadata_snapshot,
|
||||
ContextPtr context,
|
||||
std::unique_lock<std::mutex> & parts_lock,
|
||||
DataPartsLock & parts_lock,
|
||||
bool readonly);
|
||||
|
||||
using MinMaxBlockNumber = std::pair<Int64, Int64>;
|
||||
|
Loading…
Reference in New Issue
Block a user