Skip to content

Commit

Permalink
ZOOKEEPER-2892: Improve lazy initialize and close stream for `PrepReq…
Browse files Browse the repository at this point in the history
…uestProcessor`

Improve lazy initialize and close stream for `PrepRequestProcessor`

* Delay the initialization of `ChangeRecord` and `ReconfigRequest` variables
* Close the `ByteArrayOutputStream` I/O stream

hanm PTAL

Author: asdf2014 <benedictjin2016@gmail.com>

Reviewers: hanm@apache.org, andor@apache.org

Closes #361 from asdf2014/ZOOKEEPER-2892
  • Loading branch information
asdf2014 authored and anmolnar committed Feb 7, 2019
1 parent 8a2a1b5 commit c418b44
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -375,14 +375,14 @@ protected void pRequest2Txn(int type, long zxid, Request request,
case OpCode.deleteContainer: {
String path = new String(request.request.array());
String parentPath = getParentPathAndValidate(path);
ChangeRecord parentRecord = getRecordForPath(parentPath);
ChangeRecord nodeRecord = getRecordForPath(path);
if (nodeRecord.childCount > 0) {
throw new KeeperException.NotEmptyException(path);
}
if (EphemeralType.get(nodeRecord.stat.getEphemeralOwner()) == EphemeralType.NORMAL) {
throw new KeeperException.BadVersionException(path);
}
ChangeRecord parentRecord = getRecordForPath(parentPath);
request.setTxn(new DeleteTxn(path));
parentRecord = parentRecord.duplicate(request.getHdr().getZxid());
parentRecord.childCount--;
Expand All @@ -398,8 +398,8 @@ protected void pRequest2Txn(int type, long zxid, Request request,
String path = deleteRequest.getPath();
String parentPath = getParentPathAndValidate(path);
ChangeRecord parentRecord = getRecordForPath(parentPath);
ChangeRecord nodeRecord = getRecordForPath(path);
checkACL(zks, request.cnxn, parentRecord.acl, ZooDefs.Perms.DELETE, request.authInfo, path, null);
ChangeRecord nodeRecord = getRecordForPath(path);
checkAndIncVersion(nodeRecord.stat.getVersion(), deleteRequest.getVersion(), path);
if (nodeRecord.childCount > 0) {
throw new KeeperException.NotEmptyException(path);
Expand Down Expand Up @@ -436,7 +436,6 @@ protected void pRequest2Txn(int type, long zxid, Request request,
}

zks.sessionTracker.checkSession(request.sessionId, request.getOwner());
ReconfigRequest reconfigRequest = (ReconfigRequest)record;
LeaderZooKeeperServer lzks;
try {
lzks = (LeaderZooKeeperServer)zks;
Expand All @@ -449,6 +448,7 @@ protected void pRequest2Txn(int type, long zxid, Request request,
if (lastSeenQV.getVersion()!=lzks.self.getQuorumVerifier().getVersion()) {
throw new KeeperException.ReconfigInProgress();
}
ReconfigRequest reconfigRequest = (ReconfigRequest)record;
long configId = reconfigRequest.getCurConfigId();

if (configId != -1 && configId!=lzks.self.getLastSeenQuorumVerifier().getVersion()){
Expand Down Expand Up @@ -825,12 +825,12 @@ protected void pRequest(Request request) throws RequestProcessorException {
//FIXME: I don't want to have to serialize it here and then
// immediately deserialize in next processor. But I'm
// not sure how else to get the txn stored into our list.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos);
txn.serialize(boa, "request") ;
ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray());

txns.add(new Txn(type, bb.array()));
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos);
txn.serialize(boa, "request");
ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray());
txns.add(new Txn(type, bb.array()));
}
}

request.setHdr(new TxnHeader(request.sessionId, request.cxid, zxid,
Expand Down Expand Up @@ -956,10 +956,10 @@ private List<ACL> fixupACL(String path, List<Id> authInfo, List<ACL> acls)
// check for well formed ACLs
// This resolves https://issues.apache.org/jira/browse/ZOOKEEPER-1877
List<ACL> uniqacls = removeDuplicates(acls);
List<ACL> rv = new LinkedList<ACL>();
if (uniqacls == null || uniqacls.size() == 0) {
throw new KeeperException.InvalidACLException(path);
}
List<ACL> rv = new LinkedList<ACL>();
for (ACL a: uniqacls) {
LOG.debug("Processing ACL: {}", a);
if (a == null) {
Expand Down

0 comments on commit c418b44

Please sign in to comment.