@@ -2878,40 +2878,46 @@ public List<String> getAllChildrenPaginated(String path, boolean watch)
28782878 return childrenPaginated ;
28792879 }
28802880
2881- Set <String > childrenSet = new HashSet <>(childrenPaginated );
2882- getChildrenRemainingPages (path , watcher , nextPage , childrenSet );
2881+ Set <String > childrenSet = getChildrenRemainingPages (path , watcher , nextPage , childrenPaginated );
28832882
28842883 return new ArrayList <>(childrenSet );
28852884 }
28862885
2887- private void getChildrenRemainingPages (String path ,
2886+ private Set < String > getChildrenRemainingPages (String path ,
28882887 Watcher watcher ,
28892888 PaginationNextPage nextPage ,
2890- Set <String > childrenSet ) throws KeeperException , InterruptedException {
2889+ List <String > childrenPage )
2890+ throws KeeperException , InterruptedException {
2891+ Set <String > allChildrenSet = new HashSet <>(childrenPage );
28912892 int retryCount = 0 ;
2893+
28922894 do {
2893- List <String > childrenPaginated ;
28942895 long minCzxid = nextPage .getMinCzxid ();
28952896 if (nextPage .getMinCzxidOffset () == 0 ) {
2896- childrenPaginated = getChildren (path , watcher , Integer .MAX_VALUE , minCzxid ,
2897+ childrenPage = getChildren (path , watcher , Integer .MAX_VALUE , minCzxid ,
28972898 nextPage .getMinCzxidOffset (), null , nextPage );
28982899 } else {
28992900 // If a child with the same czxid is returned in the previous page, and then deleted
29002901 // on the server, the children not in the previous page but offset is less than czxidOffset
29012902 // would be missed in the next page. Use the last child in the previous page to determine whether or not
29022903 // the deletion case happens. If it happens, retry fetching the page starting from offset 0.
2903- childrenPaginated = getChildren (path , watcher , Integer .MAX_VALUE , minCzxid ,
2904+ String lastChild = childrenPage .isEmpty () ? "" : childrenPage .get (childrenPage .size () - 1 );
2905+ childrenPage = getChildren (path , watcher , Integer .MAX_VALUE , minCzxid ,
29042906 nextPage .getMinCzxidOffset () - 1 , null , nextPage );
2905- if (!childrenPaginated .isEmpty () && !childrenSet .contains (childrenPaginated .get (0 ))) {
2906- if (retryCount ++ >= 3 ) {
2907+ if (!lastChild .equals (childrenPage .get (0 ))) {
2908+ if (retryCount ++ >= 5 ) {
2909+ LOG .warn ("Failed to fetch children pages because of znode deletion and retries exceeding 5" );
29072910 throw KeeperException .create (Code .OPERATIONTIMEOUT );
29082911 }
2909- LOG .info ("Retry fetching children for minZxid = {}, retries = {}" , minCzxid , retryCount );
2910- childrenPaginated = getChildren (path , watcher , Integer .MAX_VALUE , minCzxid , 0 , null , nextPage );
2912+ LOG .info ("Due to znode deletion, retry fetching children from offset 0 for minCzxid={}, retries={}" ,
2913+ minCzxid , retryCount );
2914+ childrenPage = getChildren (path , watcher , Integer .MAX_VALUE , minCzxid , 0 , null , nextPage );
29112915 }
29122916 }
2913- childrenSet .addAll (childrenPaginated );
2917+ allChildrenSet .addAll (childrenPage );
29142918 } while (nextPage .getMinCzxid () != ZooDefs .GetChildrenPaginated .lastPageMinCzxid );
2919+
2920+ return allChildrenSet ;
29152921 }
29162922
29172923 private void updateNextPage (PaginationNextPage nextPage , long minCzxId , int czxIdOffset ) {
0 commit comments