Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions zookeeper-jute/src/main/resources/zookeeper.jute
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ module org.apache.zookeeper.data {
long ephemeralOwner; // owner id if ephemeral, 0 otw
long pzxid; // last modified children
}
class PathWithStat {
ustring path;
org.apache.zookeeper.data.Stat stat;
}

class ClientInfo {
ustring authScheme; // Authentication scheme
Expand Down Expand Up @@ -162,6 +166,13 @@ module org.apache.zookeeper.proto {
ustring path;
boolean watch;
}
class GetChildrenPaginatedRequest {
ustring path;
int maxReturned;
long minCzxid;
int czxidOffset;
boolean watch;
}
class CheckVersionRequest {
ustring path;
int version;
Expand Down Expand Up @@ -233,6 +244,12 @@ module org.apache.zookeeper.proto {
vector<ustring> children;
org.apache.zookeeper.data.Stat stat;
}
class GetChildrenPaginatedResponse {
vector<ustring> children;
org.apache.zookeeper.data.Stat stat;
long nextPageCzxid;
int nextPageCzxidOffset;
}
class GetACLResponse {
vector<org.apache.zookeeper.data.ACL> acl;
org.apache.zookeeper.data.Stat stat;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.zookeeper;

import java.util.LinkedList;
import java.util.List;
import java.util.NoSuchElementException;

/**
* Iterator over children nodes of a given path.
* <p>
* Note: the final collection of children may not be strongly consistent with the server.
* If there are concurrent writes to the children during iteration, the final collection could
* miss some children or contain some duplicate children.
*
* @see ZooKeeper#getAllChildrenPaginated(String, boolean)
*/
class ChildrenBatchIterator implements RemoteIterator<String> {

private final ZooKeeper zooKeeper;
private final String path;
private final Watcher watcher;
private final int batchSize;
private final LinkedList<String> childrenQueue;
private final PaginationNextPage nextPage;
private long nextBatchMinZxid;
private int nextBatchZxidOffset;


ChildrenBatchIterator(ZooKeeper zooKeeper, String path, Watcher watcher, int batchSize, long minZxid)
throws KeeperException, InterruptedException {
this.zooKeeper = zooKeeper;
this.path = path;
this.watcher = watcher;
this.batchSize = batchSize;
this.nextBatchZxidOffset = 0;
this.nextBatchMinZxid = minZxid;

this.childrenQueue = new LinkedList<>();
this.nextPage = new PaginationNextPage();

batchGetChildren();
}

@Override
public boolean hasNext() {
// next() never lets childrenQueue empty unless we iterated over all children
return !childrenQueue.isEmpty();
}

@Override
public String next() throws KeeperException, InterruptedException {
if (!hasNext()) {
throw new NoSuchElementException("No more children");
}

// If we're down to the last element, backfill before returning it
if (childrenQueue.size() == 1 && nextBatchMinZxid != ZooDefs.GetChildrenPaginated.lastPageMinCzxid) {
batchGetChildren();
}

return childrenQueue.pop();
}

/**
* Prepare minZxid and zxidOffset for the next batch request
*/
private void updateOffsetsForNextBatch() {
nextBatchMinZxid = nextPage.getMinCzxid();
nextBatchZxidOffset = nextPage.getMinCzxidOffset();
}

private void batchGetChildren() throws KeeperException, InterruptedException {
List<String> childrenBatch =
zooKeeper.getChildren(path, watcher, batchSize, nextBatchMinZxid, nextBatchZxidOffset, null, nextPage);
childrenQueue.addAll(childrenBatch);
updateOffsetsForNextBatch();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.zookeeper;

import org.apache.yetus.audience.InterfaceAudience;

/**
* Represents the info used to fetch the next page of data for pagination.
*/
@InterfaceAudience.Public
public class PaginationNextPage {
private long minCzxid;
private int minCzxidOffset;

public long getMinCzxid() {
return minCzxid;
}

public void setMinCzxid(long minCzxid) {
this.minCzxid = minCzxid;
}

public int getMinCzxidOffset() {
return minCzxidOffset;
}

public void setMinCzxidOffset(int minCzxidOffset) {
this.minCzxidOffset = minCzxidOffset;
}

@Override
public String toString() {
return "PaginationNextPage{"
+ "minCzxid=" + minCzxid
+ ", minCzxidOffset=" + minCzxidOffset
+ '}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.zookeeper;

import java.util.NoSuchElementException;

/**
* An iterator over a collection whose elements need to be fetched remotely.
*/
public interface RemoteIterator<E> {

/**
* Returns true if the iterator has more elements.
*
* @return true if the iterator has more elements, false otherwise.
*/
boolean hasNext();

/**
* Returns the next element in the iteration.
*
* @return the next element in the iteration.
* @throws InterruptedException if the thread is interrupted
* @throws KeeperException if an error is encountered server-side
* @throws NoSuchElementException if the iteration has no more elements
*/
E next() throws InterruptedException, KeeperException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ public interface OpCode {

int multiRead = 22;

int getChildrenPaginated = 71;

int auth = 100;

int setWatches = 101;
Expand Down Expand Up @@ -161,6 +163,13 @@ public interface AddWatchModes {
int persistentRecursive = 1; // matches AddWatchMode.PERSISTENT_RECURSIVE
}

@InterfaceAudience.Public
public interface GetChildrenPaginated {
// Represents the current fetched page is the final page, no more children left to fetch.
long lastPageMinCzxid = -1L;
int lastPageCzxidOffset = -1;
}

public static final String[] opNames = {"notification", "create", "delete", "exists", "getData", "setData", "getACL", "setACL", "getChildren", "getChildren2", "getMaxChildren", "setMaxChildren", "ping", "reconfig", "getConfig"};

}
Loading