try fix flaky tests and refine code style

This commit is contained in:
Han Fei 2022-05-28 17:25:33 +08:00
parent 0d5448a621
commit 0f71231574
3 changed files with 53 additions and 42 deletions

View File

@ -59,19 +59,19 @@ struct ZkNodeCache
index++;
if (!children.contains(child_name))
{
String subPath = "/" + boost::algorithm::join(std::vector<String>(nodes.begin(), nodes.begin() + index), "/");
bool chExist = false;
String sub_path = "/" + boost::algorithm::join(std::vector<String>(nodes.begin(), nodes.begin() + index), "/");
bool ch_exist = false;
if (exists)
{
// If this node doesn't exists, neither will its child.
chExist = zookeeper->exists(subPath);
ch_exist = zookeeper->exists(sub_path);
}
children[child_name] = std::make_shared<ZkNodeCache>(subPath, chExist);
children[child_name] = std::make_shared<ZkNodeCache>(sub_path, ch_exist);
}
children[child_name]->insert(nodes, zookeeper, value_to_set, index);
}
void generate_requests(Coordination::Requests & requests)
void generateRequests(Coordination::Requests & requests)
{
// If the node doesn't exists, we should generate create request.
// If the node exists, we should generate set request.
@ -119,7 +119,7 @@ public:
String path = block.getByPosition(2).column->getDataAt(i).toString();
// We don't expect a "name" contains a path.
if (name.find("/") != std::string::npos)
if (name.find('/') != std::string::npos)
{
throw Exception("column name should not contains \'/\'", ErrorCodes::BAD_ARGUMENTS);
}
@ -129,7 +129,7 @@ public:
// Remove all the empty node. for path '/a//b///c/d/' we get <a b c d>
for (int j = int(path_vec.size()) - 1; j >= 0; j--)
{
if (path_vec[j] == "")
if (path_vec[j].empty())
path_vec.erase(path_vec.begin() + j);
}
path_vec.push_back(name);
@ -140,7 +140,7 @@ public:
void onFinish() override
{
Coordination::Requests requests;
cache.generate_requests(requests);
cache.generateRequests(requests);
zookeeper->multi(requests);
}
};

View File

@ -1,25 +1,25 @@
/1-insert-testc c
/1-insert-testc/c c
/1-insert-testc/c/c c
/1-insert-testc/c/c d
/1-insert-testc/c/c e
/1-insert-testc/c/c f
/1-insert-testc/c/c kk
/1-insert-testc/c/c/c c
/1-insert-testc/c/c/c/c c
/1-insert-testc/c/c/c/c/c c
/1-insert-testc/c/c/c/c/c/c c 9
/1-insert-testc/c/c/c/c/c/c/c c 10
/1-insert-testc/c/c/d e 10
/1-insert-testc/c/c/d f 11
/1-insert-testc/c/c/d g 12
/1-insert-testc/c/c/e g 13
/1-insert-testc/c/c/f g 14
/1-insert-testc/c/c/kk g 15
/default/1-insert-testc c
/default/1-insert-testc/c c
/default/1-insert-testc/c/c c
/default/1-insert-testc/c/c d
/default/1-insert-testc/c/c e
/default/1-insert-testc/c/c f
/default/1-insert-testc/c/c kk
/default/1-insert-testc/c/c/c c
/default/1-insert-testc/c/c/c/c c
/default/1-insert-testc/c/c/c/c/c c
/default/1-insert-testc/c/c/c/c/c/c c 9
/default/1-insert-testc/c/c/c/c/c/c/c c 10
/default/1-insert-testc/c/c/d e 10
/default/1-insert-testc/c/c/d f 11
/default/1-insert-testc/c/c/d g 12
/default/1-insert-testc/c/c/e g 13
/default/1-insert-testc/c/c/f g 14
/default/1-insert-testc/c/c/kk g 14
-------------------------
/2-insert-testx testc x
/2-insert-testx testz z
/2-insert-testz c
/2-insert-testz/c cd
/2-insert-testz/c/cd dd
/2-insert-testz/c/cd/dd testc y
/default/2-insert-testx testc x
/default/2-insert-testx testz z
/default/2-insert-testz c
/default/2-insert-testz/c cd
/default/2-insert-testz/c/cd dd
/default/2-insert-testz/c/cd/dd testc y

View File

@ -2,25 +2,36 @@
set allow_unrestricted_reads_from_keeper = 'true';
-- test recursive create and big transaction
insert into system.zookeeper (name, path, value) values ('c', '/1-insert-testc/c/c/c/c/c/c', 11), ('e', '/1-insert-testc/c/c/d', 10), ('c', '/1-insert-testc/c/c/c/c/c/c/c', 10), ('c', '/1-insert-testc/c/c/c/c/c/c', 9), ('f', '/1-insert-testc/c/c/d', 11), ('g', '/1-insert-testc/c/c/d', 12), ('g', '/1-insert-testc/c/c/e', 13), ('g', '/1-insert-testc/c/c/f', 14), ('g', '/1-insert-testc/c/c/kk', 14);
-- insert same value, suppose to have no side effects
insert into system.zookeeper (name, path, value) values ('c', '/1-insert-testc/c/c/c/c/c/c', 11), ('e', '/1-insert-testc/c/c/d', 10), ('c', '/1-insert-testc/c/c/c/c/c/c/c', 10), ('c', '/1-insert-testc/c/c/c/c/c/c', 9), ('f', '/1-insert-testc/c/c/d', 11), ('g', '/1-insert-testc/c/c/d', 12), ('g', '/1-insert-testc/c/c/e', 13), ('g', '/1-insert-testc/c/c/f', 14), ('g', '/1-insert-testc/c/c/kk', 15);
drop table if exists test_zkinsert;
SELECT * FROM (SELECT path, name, value FROM system.zookeeper ORDER BY path, name) WHERE path LIKE '/1-insert-test%';
create table test_zkinsert (
name String,
path String,
value String
) ENGINE Memory;
-- test recursive create and big transaction
insert into test_zkinsert (name, path, value) values ('c', '/1-insert-testc/c/c/c/c/c/c', 11), ('e', '/1-insert-testc/c/c/d', 10), ('c', '/1-insert-testc/c/c/c/c/c/c/c', 10), ('c', '/1-insert-testc/c/c/c/c/c/c', 9), ('f', '/1-insert-testc/c/c/d', 11), ('g', '/1-insert-testc/c/c/d', 12), ('g', '/1-insert-testc/c/c/e', 13), ('g', '/1-insert-testc/c/c/f', 14), ('g', '/1-insert-testc/c/c/kk', 14);
-- insert same value, suppose to have no side effects
insert into system.zookeeper (name, path, value) SELECT name, '/' || currentDatabase() || path, value from test_zkinsert;
SELECT * FROM (SELECT path, name, value FROM system.zookeeper ORDER BY path, name) WHERE path LIKE '/' || currentDatabase() || '/1-insert-test%';
SELECT '-------------------------';
-- test inserting into root path
insert into system.zookeeper (name, path, value) values ('testc', '/2-insert-testx', 'x');
insert into system.zookeeper (name, path, value) values ('testz', '/2-insert-testx', 'y');
insert into system.zookeeper (name, path, value) values ('testc', '2-insert-testz//c/cd/dd//', 'y');
insert into system.zookeeper (name, value, path) values ('testz', 'z', '/2-insert-testx');
insert into test_zkinsert (name, path, value) values ('testc', '/2-insert-testx', 'x');
insert into test_zkinsert (name, path, value) values ('testz', '/2-insert-testx', 'y');
insert into test_zkinsert (name, path, value) values ('testc', '/2-insert-testz//c/cd/dd//', 'y');
insert into test_zkinsert (name, value, path) values ('testz', 'z', '/2-insert-testx');
SELECT * FROM (SELECT path, name, value FROM system.zookeeper ORDER BY path, name) WHERE path LIKE '/2-insert-test%';
insert into system.zookeeper (name, path, value) SELECT name, '/' || currentDatabase() || path, value from test_zkinsert;
SELECT * FROM (SELECT path, name, value FROM system.zookeeper ORDER BY path, name) WHERE path LIKE '/' || currentDatabase() || '/2-insert-test%';
-- test exceptions
insert into system.zookeeper (name, path, value) values ('a/b/c', '/', 'y'); -- { serverError 36 }
insert into system.zookeeper (name, path, value) values ('/', '/a/b/c', 'z'); -- { serverError 36 }
set allow_unrestricted_reads_from_keeper = 'false';
drop table if exists test_zkinsert;