Skip to content

Unit Test getAllChildrenPaginated for transaction children deleted case #9

@huizhilu

Description

@huizhilu

Description

There is a retry logic for API getAllChildrenPaginated() when there is deletion in the transaction children(children created by a multi transaction operation) and the new page's start minCzxidOffset shifts. Current implementation uses the last child as a flag to represent if there is offset shifting.

} else {
// If a child with the same czxid is returned in the previous page, and then deleted
// on the server, the children not in the previous page but offset is less than czxidOffset
// would be missed in the next page. Use the last child in the previous page to determine whether or not
// the deletion case happens. If it happens, retry fetching the page starting from offset 0.
String lastChild = childrenPage.isEmpty() ? "" : childrenPage.get(childrenPage.size() - 1);
childrenPage = getChildren(path, watcher, Integer.MAX_VALUE, minCzxid,
nextPage.getMinCzxidOffset() - 1, null, nextPage);
if (!lastChild.equals(childrenPage.get(0))) {
if (retryCount++ >= 5) {
LOG.warn("Failed to fetch children pages because of znode deletion and retries exceeding 5");
throw KeeperException.create(Code.OPERATIONTIMEOUT);
}
LOG.info("Due to znode deletion, retry fetching children from offset 0 for minCzxid={}, retries={}",
minCzxid, retryCount);
childrenPage = getChildren(path, watcher, Integer.MAX_VALUE, minCzxid, 0, null, nextPage);
}
}
allChildrenSet.addAll(childrenPage);
} while (nextPage.getMinCzxid() != ZooDefs.GetChildrenPaginated.lastPageMinCzxid);

We want to add a unit test for the code logic. As we could not simulate the read/write race condition on the server, we will need to mock the states in the zookeeper api for the uni test.

Related to #8

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions