提交 bf832b3e 编写于 作者: V Vitaliy Lyudvichenko

Fixed OPTIMIZE after RENAME of replicated table. [#CLICKHOUSE-2]

上级 5536bf20
#include "ReplicatedMergeTreeAddress.h"
#include <IO/ReadBufferFromString.h>
#include <IO/WriteBufferFromString.h>
#include <IO/Operators.h>
namespace DB
{
void ReplicatedMergeTreeAddress::writeText(WriteBuffer & out) const
{
out
<< "host: " << escape << host << '\n'
<< "port: " << replication_port << '\n'
<< "tcp_port: " << queries_port << '\n'
<< "database: " << escape << database << '\n'
<< "table: " << escape << table << '\n';
}
void ReplicatedMergeTreeAddress::readText(ReadBuffer & in)
{
in
>> "host: " >> escape >> host >> "\n"
>> "port: " >> replication_port >> "\n"
>> "tcp_port: " >> queries_port >> "\n"
>> "database: " >> escape >> database >> "\n"
>> "table: " >> escape >> table >> "\n";
}
String ReplicatedMergeTreeAddress::toString() const
{
WriteBufferFromOwnString out;
writeText(out);
return out.str();
}
void ReplicatedMergeTreeAddress::fromString(const String & str)
{
ReadBufferFromString in(str);
readText(in);
}
}
#pragma once
#include <Core/Types.h>
#include <IO/ReadBuffer.h>
#include <IO/ReadBufferFromString.h>
#include <IO/WriteBuffer.h>
#include <IO/WriteBufferFromString.h>
#include <IO/Operators.h>
namespace DB
......@@ -18,44 +17,19 @@ struct ReplicatedMergeTreeAddress
String database;
String table;
ReplicatedMergeTreeAddress() {}
ReplicatedMergeTreeAddress(const String & str)
ReplicatedMergeTreeAddress() = default;
explicit ReplicatedMergeTreeAddress(const String & str)
{
fromString(str);
}
void writeText(WriteBuffer & out) const
{
out
<< "host: " << escape << host << '\n'
<< "port: " << replication_port << '\n'
<< "tcp_port: " << queries_port << '\n'
<< "database: " << escape << database << '\n'
<< "table: " << escape << table << '\n';
}
void writeText(WriteBuffer & out) const;
void readText(ReadBuffer & in)
{
in
>> "host: " >> escape >> host >> "\n"
>> "port: " >> replication_port >> "\n"
>> "tcp_port: " >> queries_port >> "\n"
>> "database: " >> escape >> database >> "\n"
>> "table: " >> escape >> table >> "\n";
}
void readText(ReadBuffer & in);
String toString() const
{
WriteBufferFromOwnString out;
writeText(out);
return out.str();
}
String toString() const;
void fromString(const String & str)
{
ReadBufferFromString in(str);
readText(in);
}
void fromString(const String & str);
};
}
......@@ -292,16 +292,10 @@ void ReplicatedMergeTreeRestartingThread::updateQuorumIfWeHavePart()
void ReplicatedMergeTreeRestartingThread::activateReplica()
{
auto host_port = storage.context.getInterserverIOAddress();
auto zookeeper = storage.getZooKeeper();
/// How other replicas can access this.
ReplicatedMergeTreeAddress address;
address.host = host_port.first;
address.replication_port = host_port.second;
address.queries_port = storage.context.getTCPPort();
address.database = storage.database_name;
address.table = storage.table_name;
/// How other replicas can access this one.
ReplicatedMergeTreeAddress address = storage.getReplicatedMergeTreeAddress();
String is_active_path = storage.replica_path + "/is_active";
......
......@@ -3004,6 +3004,10 @@ void StorageReplicatedMergeTree::rename(const String & new_path_to_db, const Str
table_name = new_table_name;
full_path = new_full_path;
/// Update table name in zookeeper
auto zookeeper = getZooKeeper();
zookeeper->set(replica_path + "/host", getReplicatedMergeTreeAddress().toString());
/// TODO: You can update names of loggers.
}
......@@ -3766,4 +3770,17 @@ void StorageReplicatedMergeTree::clearBlocksInPartition(
LOG_TRACE(log, "Deleted " << to_delete_futures.size() << " deduplication block IDs in partition ID " << partition_id);
}
ReplicatedMergeTreeAddress StorageReplicatedMergeTree::getReplicatedMergeTreeAddress() const
{
auto host_port = context.getInterserverIOAddress();
ReplicatedMergeTreeAddress res;
res.host = host_port.first;
res.replication_port = host_port.second;
res.queries_port = context.getTCPPort();
res.database = database_name;
res.table = table_name;
return res;
}
}
......@@ -17,6 +17,7 @@
#include <Storages/MergeTree/AbandonableLockInZooKeeper.h>
#include <Storages/MergeTree/BackgroundProcessingPool.h>
#include <Storages/MergeTree/DataPartsExchange.h>
#include <Storages/MergeTree/ReplicatedMergeTreeAddress.h>
#include <DataTypes/DataTypesNumber.h>
#include <Common/randomSeed.h>
#include <Common/ZooKeeper/ZooKeeper.h>
......@@ -451,6 +452,9 @@ private:
void clearBlocksInPartition(
zkutil::ZooKeeper & zookeeper, const String & partition_id, Int64 min_block_num, Int64 max_block_num);
/// Info about how other replicas can access this one.
ReplicatedMergeTreeAddress getReplicatedMergeTreeAddress() const;
protected:
/** If not 'attach', either creates a new table in ZK, or adds a replica to an existing table.
*/
......
......@@ -61,11 +61,3 @@ ALTER TABLE test.clear_column1 CLEAR COLUMN s IN PARTITION '200002';
ALTER TABLE test.clear_column1 CLEAR COLUMN s IN PARTITION '200012', CLEAR COLUMN i IN PARTITION '200012';
-- Drop empty partition also Ok
ALTER TABLE test.clear_column1 DROP PARTITION '200012', DROP PARTITION '200011';
-- check optimize for non-leader replica (it is not related with CLEAR COLUMN)
OPTIMIZE TABLE test.clear_column1;
OPTIMIZE TABLE test.clear_column2;
DROP TABLE IF EXISTS test.clear_column1;
DROP TABLE IF EXISTS test.clear_column2;
DROP TABLE IF EXISTS test.clear_column1;
DROP TABLE IF EXISTS test.clear_column2;
CREATE TABLE test.clear_column1 (p Int64, i Int64, v UInt64) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/test/clear_column', '1', v) PARTITION BY p ORDER BY i;
CREATE TABLE test.clear_column2 (p Int64, i Int64, v UInt64) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/test/clear_column', '2', v) PARTITION BY p ORDER BY i;
INSERT INTO test.clear_column1 VALUES (0, 1, 0);
INSERT INTO test.clear_column1 VALUES (0, 1, 1);
OPTIMIZE TABLE test.clear_column1;
OPTIMIZE TABLE test.clear_column2;
SELECT * FROM test.clear_column1;
RENAME TABLE test.clear_column2 TO test.clear_column3;
INSERT INTO test.clear_column1 VALUES (0, 1, 2);
OPTIMIZE TABLE test.clear_column3;
SELECT * FROM test.clear_column1;
DROP TABLE IF EXISTS test.clear_column1;
DROP TABLE IF EXISTS test.clear_column2;
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册