Skip to content

Commit

Permalink
Merge branch 'master' into jonmv/ZOOKEEPER-4541
Browse files Browse the repository at this point in the history
  • Loading branch information
jonmv authored Oct 17, 2022
2 parents 14fcc41 + 90f813e commit 961aa17
Show file tree
Hide file tree
Showing 40 changed files with 587 additions and 330 deletions.
20 changes: 8 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,25 @@ matrix:
- os: linux
arch: arm64
jdk: openjdk11
install: |
f=$(which javac)
while [[ -L $f ]]; do f=$(readlink $f); done
export JAVA_HOME=${f%/bin/*}
- os: linux
arch: s390x
jdk: openjdk11
addons:
apt:
update: true
packages:
- maven
- libcppunit-dev

cache:
directories:
- "$HOME/.m2"

addons:
apt:
update: true
packages:
- libcppunit-dev

install:
- if [ "${TRAVIS_CPU_ARCH}" == "arm64" ]; then
sudo apt-get install maven;
fi
- maven
- libcppunit-dev

script: mvn clean apache-rat:check verify -DskipTests spotbugs:check checkstyle:check -Pfull-build

Expand Down
2 changes: 1 addition & 1 deletion dev/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# under the License.
#

FROM maven:3.6.3-jdk-8
FROM maven:3.8.4-jdk-8

RUN apt-get update
RUN apt-get install -y \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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.io.IOException;
import java.nio.charset.StandardCharsets;
import org.apache.jute.InputArchive;
import org.apache.jute.OutputArchive;
import org.apache.jute.Record;

public class DeleteContainerRequest implements Record {
private String path;

public DeleteContainerRequest() {
}

public DeleteContainerRequest(String path) {
this.path = path;
}

public String getPath() {
return path;
}

@Override
public void serialize(OutputArchive archive, String tag) throws IOException {
archive.writeBuffer(path.getBytes(StandardCharsets.UTF_8), "path");
}

@Override
public void deserialize(InputArchive archive, String tag) throws IOException {
byte[] bytes = archive.readBuffer("path");
path = new String(bytes, StandardCharsets.UTF_8);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.apache.jute.Record;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.MultiOperationRecord;
Expand Down Expand Up @@ -58,7 +57,7 @@ public static void addAuditLog(Request request, ProcessTxnResult txnResult, bool
if (!ZKAuditProvider.isAuditEnabled()) {
return;
}
String op = null;
String op;
//For failed transaction rc.path is null
String path = txnResult.path;
String acls = null;
Expand All @@ -69,8 +68,7 @@ public static void addAuditLog(Request request, ProcessTxnResult txnResult, bool
case ZooDefs.OpCode.create2:
case ZooDefs.OpCode.createContainer:
op = AuditConstants.OP_CREATE;
CreateRequest createRequest = new CreateRequest();
deserialize(request, createRequest);
CreateRequest createRequest = request.readRequestRecord(CreateRequest::new);
createMode = getCreateMode(createRequest);
if (failedTxn) {
path = createRequest.getPath();
Expand All @@ -80,23 +78,20 @@ public static void addAuditLog(Request request, ProcessTxnResult txnResult, bool
case ZooDefs.OpCode.deleteContainer:
op = AuditConstants.OP_DELETE;
if (failedTxn) {
DeleteRequest deleteRequest = new DeleteRequest();
deserialize(request, deleteRequest);
DeleteRequest deleteRequest = request.readRequestRecord(DeleteRequest::new);
path = deleteRequest.getPath();
}
break;
case ZooDefs.OpCode.setData:
op = AuditConstants.OP_SETDATA;
if (failedTxn) {
SetDataRequest setDataRequest = new SetDataRequest();
deserialize(request, setDataRequest);
SetDataRequest setDataRequest = request.readRequestRecord(SetDataRequest::new);
path = setDataRequest.getPath();
}
break;
case ZooDefs.OpCode.setACL:
op = AuditConstants.OP_SETACL;
SetACLRequest setACLRequest = new SetACLRequest();
deserialize(request, setACLRequest);
SetACLRequest setACLRequest = request.readRequestRecord(SetACLRequest::new);
acls = ZKUtil.aclToString(setACLRequest.getAcl());
if (failedTxn) {
path = setACLRequest.getPath();
Expand Down Expand Up @@ -125,10 +120,6 @@ public static void addAuditLog(Request request, ProcessTxnResult txnResult, bool
}
}

private static void deserialize(Request request, Record record) throws IOException {
request.readRequestRecord(record);
}

private static Result getResult(ProcessTxnResult rc, boolean failedTxn) {
if (failedTxn) {
return Result.FAILURE;
Expand Down Expand Up @@ -191,8 +182,7 @@ private static Map<String, String> getCreateModes(Request request)
if (!ZKAuditProvider.isAuditEnabled()) {
return createModes;
}
MultiOperationRecord multiRequest = new MultiOperationRecord();
deserialize(request, multiRequest);
MultiOperationRecord multiRequest = request.readRequestRecord(MultiOperationRecord::new);
for (Op op : multiRequest) {
if (op.getType() == ZooDefs.OpCode.create || op.getType() == ZooDefs.OpCode.create2
|| op.getType() == ZooDefs.OpCode.createContainer) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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
*uuuuu
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "/RequuuAS 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.server;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.function.Supplier;
import org.apache.jute.Record;

public class ByteBufferRequestRecord implements RequestRecord {

private final ByteBuffer request;

private volatile Record record;

public ByteBufferRequestRecord(ByteBuffer request) {
this.request = request;
}

@SuppressWarnings("unchecked")
@Override
public <T extends Record> T readRecord(Supplier<T> constructor) throws IOException {
if (record != null) {
return (T) record;
}

record = constructor.get();
request.rewind();
ByteBufferInputStream.byteBuffer2Record(request, record);
request.rewind();
return (T) record;
}

@Override
public byte[] readBytes() {
request.rewind();
int len = request.remaining();
byte[] b = new byte[len];
request.get(b);
request.rewind();
return b;
}

@Override
public int limit() {
return request.limit();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@

package org.apache.zookeeper.server;

import static java.nio.charset.StandardCharsets.UTF_8;
import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.zookeeper.DeleteContainerRequest;
import org.apache.zookeeper.ZooDefs;
import org.apache.zookeeper.common.Time;
import org.slf4j.Logger;
Expand Down Expand Up @@ -129,8 +128,8 @@ public void checkContainers() throws InterruptedException {
for (String containerPath : getCandidates()) {
long startMs = Time.currentElapsedTime();

ByteBuffer path = ByteBuffer.wrap(containerPath.getBytes(UTF_8));
Request request = new Request(null, 0, 0, ZooDefs.OpCode.deleteContainer, path, null);
DeleteContainerRequest record = new DeleteContainerRequest(containerPath);
Request request = new Request(null, 0, 0, ZooDefs.OpCode.deleteContainer, RequestRecord.fromRecord(record), null);
try {
LOG.info("Attempting to delete candidate container: {}", containerPath);
postDeleteRequest(request);
Expand Down
Loading

0 comments on commit 961aa17

Please sign in to comment.