Skip to content

Commit

Permalink
OAK-5094 - Check for NPE when reading the remote head from primary
Browse files Browse the repository at this point in the history
Contribution by Timothee Maret.


git-svn-id: https://svn.apache.org/repos/asf/jackrabbit/oak/trunk@1769157 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
francescomari committed Nov 10, 2016
1 parent 01e883b commit a5f7421
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;

import javax.annotation.Nullable;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
Expand Down Expand Up @@ -172,6 +174,7 @@ private void closeGroup() {
}
}

@Nullable
String getHead() throws InterruptedException {
channel.writeAndFlush(new GetHeadRequest(clientId));

Expand All @@ -184,6 +187,7 @@ String getHead() throws InterruptedException {
return response.getHeadRecordId();
}

@Nullable
byte[] getSegment(String segmentId) throws InterruptedException {
channel.writeAndFlush(new GetSegmentRequest(clientId, segmentId));

Expand All @@ -196,6 +200,7 @@ byte[] getSegment(String segmentId) throws InterruptedException {
return response.getSegmentData();
}

@Nullable
byte[] getBlob(String blobId) throws InterruptedException {
channel.writeAndFlush(new GetBlobRequest(clientId, blobId));

Expand All @@ -208,6 +213,7 @@ byte[] getBlob(String blobId) throws InterruptedException {
return response.getBlobData();
}

@Nullable
Iterable<String> getReferences(String segmentId) throws InterruptedException {
channel.writeAndFlush(new GetReferencesRequest(clientId, segmentId));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.util.Set;
import java.util.UUID;

import javax.annotation.Nullable;

import com.google.common.base.Supplier;
import org.apache.jackrabbit.oak.segment.RecordId;
import org.apache.jackrabbit.oak.segment.Segment;
Expand Down Expand Up @@ -63,6 +65,10 @@ class StandbyClientSyncExecution {
void execute() throws Exception {
RecordId remoteHead = getHead();

if (remoteHead == null) {
throw new IllegalStateException("Unable to fetch remote head");
}

if (remoteHead.equals(store.getHead().getRecordId())) {
return;
}
Expand All @@ -77,8 +83,13 @@ void execute() throws Exception {
log.debug("updated head state successfully: {} in {}ms.", ok, System.currentTimeMillis() - t);
}

@Nullable
private RecordId getHead() throws Exception {
return RecordId.fromString(store, client.getHead());
String head = client.getHead();
if (head == null) {
return null;
}
return RecordId.fromString(store, head);
}

private SegmentNodeState newSegmentNodeState(RecordId id) {
Expand Down

0 comments on commit a5f7421

Please sign in to comment.