mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 01:25:21 +00:00
fix test
This commit is contained in:
parent
b5d1c4e657
commit
9a36a509fe
@ -309,21 +309,23 @@ Sessions with Ephemerals (1):
|
||||
/clickhouse/task_queue/ddl
|
||||
```
|
||||
|
||||
- `csnp`: Schedule a snapshot creation task. Return `Snapshot creation scheduled with last committed log index xxx.` if successfully scheduled or `Fail to scheduled snapshot creation task.` if failed.
|
||||
- `csnp`: Schedule a snapshot creation task. Return the last committed log index of the scheduled snapshot if successfully scheduled or `Fail to scheduled snapshot creation task.` if failed.
|
||||
|
||||
```
|
||||
Snapshot creation scheduled with last committed log index 100.
|
||||
100
|
||||
```
|
||||
|
||||
- `lgif`: Keeper log information. `last_log_idx` : my last log index in log store; `last_log_term` : my last log term; `last_committed_log_idx` : my last committed log index in state machine; `leader_committed_log_idx` : leader's committed log index from my perspective; `target_committed_log_idx` : target log index should be committed to; `last_snapshot_idx` : the largest committed log index in last snapshot.
|
||||
- `lgif`: Keeper log information. `first_log_idx` : my first log index in log store; `first_log_term` : my first log term; `last_log_idx` : my last log index in log store; `last_log_term` : my last log term; `last_committed_log_idx` : my last committed log index in state machine; `leader_committed_log_idx` : leader's committed log index from my perspective; `target_committed_log_idx` : target log index should be committed to; `last_snapshot_idx` : the largest committed log index in last snapshot.
|
||||
|
||||
```
|
||||
last_log_idx : 101
|
||||
last_log_term : 1
|
||||
last_committed_log_idx : 100
|
||||
leader_committed_log_idx : 101
|
||||
target_committed_log_idx : 101
|
||||
last_snapshot_idx : 50
|
||||
first_log_idx 1
|
||||
first_log_term 1
|
||||
last_log_idx 101
|
||||
last_log_term 1
|
||||
last_committed_log_idx 100
|
||||
leader_committed_log_idx 101
|
||||
target_committed_log_idx 101
|
||||
last_snapshot_idx 50
|
||||
```
|
||||
|
||||
## [experimental] Migration from ZooKeeper {#migration-from-zookeeper}
|
||||
|
@ -481,20 +481,29 @@ String ApiVersionCommand::run()
|
||||
String CreateSnapshotCommand::run()
|
||||
{
|
||||
auto log_index = keeper_dispatcher.createSnapshot();
|
||||
return log_index > 0 ? "Snapshot creation scheduled with last committed log index " + std::to_string(log_index) + "."
|
||||
: "Fail to scheduled snapshot creation task.";
|
||||
return log_index > 0 ? std::to_string(log_index) : "Fail to scheduled snapshot creation task.";
|
||||
}
|
||||
|
||||
String LogInfoCommand::run()
|
||||
{
|
||||
KeeperLogInfo log_info = keeper_dispatcher.getKeeperLogInfo();
|
||||
StringBuffer ret;
|
||||
print(ret, "last_log_idx", log_info.last_log_idx);
|
||||
print(ret, "last_log_term", log_info.last_log_term);
|
||||
print(ret, "last_committed_log_idx", log_info.last_committed_log_idx);
|
||||
print(ret, "leader_committed_log_idx", log_info.leader_committed_log_idx);
|
||||
print(ret, "target_committed_log_idx", log_info.target_committed_log_idx);
|
||||
print(ret, "last_snapshot_idx", log_info.last_snapshot_idx);
|
||||
|
||||
auto append = [&ret] (String key, uint64_t value) -> void
|
||||
{
|
||||
writeText(key, ret);
|
||||
writeText('\t', ret);
|
||||
writeText(std::to_string(value), ret);
|
||||
writeText('\n', ret);
|
||||
};
|
||||
append("first_log_idx", log_info.first_log_idx);
|
||||
append("first_log_term", log_info.first_log_idx);
|
||||
append("last_log_idx", log_info.last_log_idx);
|
||||
append("last_log_term", log_info.last_log_term);
|
||||
append("last_committed_log_idx", log_info.last_committed_log_idx);
|
||||
append("leader_committed_log_idx", log_info.leader_committed_log_idx);
|
||||
append("target_committed_log_idx", log_info.target_committed_log_idx);
|
||||
append("last_snapshot_idx", log_info.last_snapshot_idx);
|
||||
return ret.str();
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@ using FourLetterCommandPtr = std::shared_ptr<DB::IFourLetterCommand>;
|
||||
/// Just like zookeeper Four Letter Words commands, CH Keeper responds to a small set of commands.
|
||||
/// Each command is composed of four letters, these commands are useful to monitor and issue system problems.
|
||||
/// The feature is based on Zookeeper 3.5.9, details is in https://zookeeper.apache.org/doc/r3.5.9/zookeeperAdmin.html#sc_zkCommands.
|
||||
/// Also we add some additional commands such as csnp, lgif etc.
|
||||
struct IFourLetterCommand
|
||||
{
|
||||
public:
|
||||
@ -342,12 +343,14 @@ struct CreateSnapshotCommand : public IFourLetterCommand
|
||||
};
|
||||
|
||||
/** Raft log information:
|
||||
* last_log_idx : 101
|
||||
* last_log_term : 1
|
||||
* last_committed_idx : 100
|
||||
* leader_committed_log_idx : 101
|
||||
* target_committed_log_idx : 101
|
||||
* last_snapshot_idx : 50
|
||||
* first_log_idx 1
|
||||
* first_log_term 1
|
||||
* last_log_idx 101
|
||||
* last_log_term 1
|
||||
* last_committed_idx 100
|
||||
* leader_committed_log_idx 101
|
||||
* target_committed_log_idx 101
|
||||
* last_snapshot_idx 50
|
||||
*/
|
||||
struct LogInfoCommand : public IFourLetterCommand
|
||||
{
|
||||
|
@ -50,6 +50,12 @@ struct Keeper4LWInfo
|
||||
/// Keeper log information for 4lw commands
|
||||
struct KeeperLogInfo
|
||||
{
|
||||
/// My first log index in log store.
|
||||
uint64_t first_log_idx;
|
||||
|
||||
/// My first log term.
|
||||
uint64_t first_log_term;
|
||||
|
||||
/// My last log index in log store.
|
||||
uint64_t last_log_idx;
|
||||
|
||||
|
@ -114,7 +114,6 @@ KeeperServer::KeeperServer(
|
||||
, is_recovering(config.getBool("keeper_server.force_recovery", false))
|
||||
, keeper_context{std::make_shared<KeeperContext>()}
|
||||
, create_snapshot_on_exit(config.getBool("keeper_server.create_snapshot_on_exit", true))
|
||||
, last_manual_snapshot_log_idx(0)
|
||||
{
|
||||
if (coordination_settings->quorum_reads)
|
||||
LOG_WARNING(log, "Quorum reads enabled, Keeper will work slower.");
|
||||
@ -920,8 +919,11 @@ uint64_t KeeperServer::createSnapshot()
|
||||
KeeperLogInfo KeeperServer::getKeeperLogInfo()
|
||||
{
|
||||
KeeperLogInfo log_info;
|
||||
log_info.first_log_idx = state_manager->load_log_store()->start_index();
|
||||
log_info.first_log_term = state_manager->load_log_store()->term_at(log_info.first_log_idx);
|
||||
log_info.last_log_idx = raft_instance->get_last_log_idx();
|
||||
log_info.last_log_term = raft_instance->get_last_log_term();
|
||||
log_info.last_committed_log_idx = raft_instance->get_committed_log_idx();
|
||||
log_info.leader_committed_log_idx = raft_instance->get_leader_committed_log_idx();
|
||||
log_info.target_committed_log_idx = raft_instance->get_target_committed_log_idx();
|
||||
log_info.last_snapshot_idx = raft_instance->get_last_snapshot_idx();
|
||||
|
@ -598,19 +598,46 @@ def test_cmd_wchp(started_cluster):
|
||||
destroy_zk_client(zk)
|
||||
|
||||
|
||||
def test_cmd_snapshot(started_cluster):
|
||||
def test_cmd_csnp(started_cluster):
|
||||
zk = None
|
||||
try:
|
||||
wait_nodes()
|
||||
zk = get_fake_zk(node1.name, timeout=30.0)
|
||||
data = keeper_utils.send_4lw_cmd(cluster, node1, cmd="csnp")
|
||||
try:
|
||||
int(data)
|
||||
assert True
|
||||
except ValueError:
|
||||
assert False
|
||||
finally:
|
||||
destroy_zk_client(zk)
|
||||
|
||||
|
||||
def test_cmd_lgif(started_cluster):
|
||||
zk = None
|
||||
try:
|
||||
wait_nodes()
|
||||
clear_znodes()
|
||||
reset_node_stats()
|
||||
|
||||
zk = get_fake_zk(node1.name, timeout=30.0)
|
||||
do_some_action(zk, create_cnt=100)
|
||||
|
||||
create = send_4lw_cmd(cmd="csnp")
|
||||
assert create == "Snapshot creation scheduled."
|
||||
data = keeper_utils.send_4lw_cmd(cluster, node1, cmd="lgif")
|
||||
print(data)
|
||||
reader = csv.reader(data.split("\n"), delimiter="\t")
|
||||
result = {}
|
||||
|
||||
check = send_4lw_cmd(cmd="snpd")
|
||||
assert check == "Yes" or check == "No"
|
||||
for row in reader:
|
||||
if len(row) != 0:
|
||||
result[row[0]] = row[1]
|
||||
|
||||
assert int(result["first_log_idx"]) == 1
|
||||
assert int(result["first_log_term"]) == 1
|
||||
assert int(result["last_log_idx"]) >= 1
|
||||
assert int(result["last_log_term"]) == 1
|
||||
assert int(result["last_committed_log_idx"]) >= 1
|
||||
assert int(result["leader_committed_log_idx"]) >= 1
|
||||
assert int(result["target_committed_log_idx"]) >= 1
|
||||
assert int(result["last_snapshot_idx"]) >= 1
|
||||
finally:
|
||||
destroy_zk_client(zk)
|
||||
|
Loading…
Reference in New Issue
Block a user