mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-24 18:50:49 +00:00
Implement totalBytes() for MergeTree/ReplicatedMergeTree
This commit is contained in:
parent
4a7ee947b2
commit
08d5872d90
@ -151,6 +151,11 @@ std::optional<UInt64> StorageMergeTree::totalRows() const
|
|||||||
return getTotalActiveSizeInRows();
|
return getTotalActiveSizeInRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<UInt64> StorageMergeTree::totalBytes() const
|
||||||
|
{
|
||||||
|
return getTotalActiveSizeInBytes();
|
||||||
|
}
|
||||||
|
|
||||||
BlockOutputStreamPtr StorageMergeTree::write(const ASTPtr & /*query*/, const Context & context)
|
BlockOutputStreamPtr StorageMergeTree::write(const ASTPtr & /*query*/, const Context & context)
|
||||||
{
|
{
|
||||||
return std::make_shared<MergeTreeBlockOutputStream>(*this, context.getSettingsRef().max_partitions_per_insert_block);
|
return std::make_shared<MergeTreeBlockOutputStream>(*this, context.getSettingsRef().max_partitions_per_insert_block);
|
||||||
|
@ -46,6 +46,7 @@ public:
|
|||||||
unsigned num_streams) override;
|
unsigned num_streams) override;
|
||||||
|
|
||||||
std::optional<UInt64> totalRows() const override;
|
std::optional<UInt64> totalRows() const override;
|
||||||
|
std::optional<UInt64> totalBytes() const override;
|
||||||
|
|
||||||
BlockOutputStreamPtr write(const ASTPtr & query, const Context & context) override;
|
BlockOutputStreamPtr write(const ASTPtr & query, const Context & context) override;
|
||||||
|
|
||||||
|
@ -2995,9 +2995,9 @@ Pipes StorageReplicatedMergeTree::read(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::optional<UInt64> StorageReplicatedMergeTree::totalRows() const
|
template <class Func>
|
||||||
|
void StorageReplicatedMergeTree::foreachCommittedParts(const Func & func) const
|
||||||
{
|
{
|
||||||
size_t res = 0;
|
|
||||||
auto max_added_blocks = getMaxAddedBlocks();
|
auto max_added_blocks = getMaxAddedBlocks();
|
||||||
auto lock = lockParts();
|
auto lock = lockParts();
|
||||||
for (auto & part : getDataPartsStateRange(DataPartState::Committed))
|
for (auto & part : getDataPartsStateRange(DataPartState::Committed))
|
||||||
@ -3009,8 +3009,21 @@ std::optional<UInt64> StorageReplicatedMergeTree::totalRows() const
|
|||||||
if (blocks_iterator == max_added_blocks.end() || part->info.max_block > blocks_iterator->second)
|
if (blocks_iterator == max_added_blocks.end() || part->info.max_block > blocks_iterator->second)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
res += part->rows_count;
|
func(part);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<UInt64> StorageReplicatedMergeTree::totalRows() const
|
||||||
|
{
|
||||||
|
UInt64 res = 0;
|
||||||
|
foreachCommittedParts([&res](auto & part) { res += part->rows_count; });
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<UInt64> StorageReplicatedMergeTree::totalBytes() const
|
||||||
|
{
|
||||||
|
UInt64 res = 0;
|
||||||
|
foreachCommittedParts([&res](auto & part) { res += part->getBytesOnDisk(); });
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,6 +96,7 @@ public:
|
|||||||
unsigned num_streams) override;
|
unsigned num_streams) override;
|
||||||
|
|
||||||
std::optional<UInt64> totalRows() const override;
|
std::optional<UInt64> totalRows() const override;
|
||||||
|
std::optional<UInt64> totalBytes() const override;
|
||||||
|
|
||||||
BlockOutputStreamPtr write(const ASTPtr & query, const Context & context) override;
|
BlockOutputStreamPtr write(const ASTPtr & query, const Context & context) override;
|
||||||
|
|
||||||
@ -287,6 +288,9 @@ private:
|
|||||||
/// True if replica was created for existing table with fixed granularity
|
/// True if replica was created for existing table with fixed granularity
|
||||||
bool other_replicas_fixed_granularity = false;
|
bool other_replicas_fixed_granularity = false;
|
||||||
|
|
||||||
|
template <class Func>
|
||||||
|
void foreachCommittedParts(const Func & func) const;
|
||||||
|
|
||||||
/** Creates the minimum set of nodes in ZooKeeper.
|
/** Creates the minimum set of nodes in ZooKeeper.
|
||||||
*/
|
*/
|
||||||
void createTableIfNotExists();
|
void createTableIfNotExists();
|
||||||
|
Loading…
Reference in New Issue
Block a user