Author: frm
Date: Thu Oct 20 15:47:20 2016
New Revision: 1765838
URL: http://svn.apache.org/viewvc?rev=1765838&view=rev
Log:
OAK-4958 - Decrease the timeout when reading a segment on the primary
Added:
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/server/FileStoreUtil.java
(with props)
Modified:
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/server/DefaultStandbyReferencesReader.java
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/server/DefaultStandbySegmentReader.java
Modified:
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/server/DefaultStandbyReferencesReader.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/server/DefaultStandbyReferencesReader.java?rev=1765838&r1=1765837&r2=1765838&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/server/DefaultStandbyReferencesReader.java
(original)
+++
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/server/DefaultStandbyReferencesReader.java
Thu Oct 20 15:47:20 2016
@@ -18,14 +18,12 @@
package org.apache.jackrabbit.oak.segment.standby.server;
import static com.google.common.collect.Lists.newArrayList;
+import static
org.apache.jackrabbit.oak.segment.standby.server.FileStoreUtil.readSegmentWithRetry;
import java.util.List;
import java.util.UUID;
-import java.util.concurrent.TimeUnit;
import org.apache.jackrabbit.oak.segment.Segment;
-import org.apache.jackrabbit.oak.segment.SegmentId;
-import org.apache.jackrabbit.oak.segment.SegmentNotFoundException;
import org.apache.jackrabbit.oak.segment.file.FileStore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -36,7 +34,7 @@ class DefaultStandbyReferencesReader imp
private final FileStore store;
- public DefaultStandbyReferencesReader(FileStore store) {
+ DefaultStandbyReferencesReader(FileStore store) {
this.store = store;
}
@@ -47,7 +45,7 @@ class DefaultStandbyReferencesReader imp
long msb = uuid.getMostSignificantBits();
long lsb = uuid.getLeastSignificantBits();
- Segment segment = readSegment(store.newSegmentId(msb, lsb));
+ Segment segment = readSegmentWithRetry(store, store.newSegmentId(msb,
lsb));
if (segment == null) {
return null;
@@ -62,26 +60,4 @@ class DefaultStandbyReferencesReader imp
return references;
}
- private Segment readSegment(SegmentId id) {
-
- for (int i = 0; i < 10; i++) {
- try {
- return store.readSegment(id);
- } catch (SegmentNotFoundException e) {
- log.warn("Unable to read segment, waiting...", e);
- }
-
- try {
- TimeUnit.MILLISECONDS.sleep(2000);
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- return null;
- }
- }
-
- log.warn("Unable to read segment %s", id);
-
- return null;
- }
-
}
Modified:
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/server/DefaultStandbySegmentReader.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/server/DefaultStandbySegmentReader.java?rev=1765838&r1=1765837&r2=1765838&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/server/DefaultStandbySegmentReader.java
(original)
+++
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/server/DefaultStandbySegmentReader.java
Thu Oct 20 15:47:20 2016
@@ -17,14 +17,13 @@
package org.apache.jackrabbit.oak.segment.standby.server;
+import static
org.apache.jackrabbit.oak.segment.standby.server.FileStoreUtil.readSegmentWithRetry;
+
import java.io.IOException;
import java.util.UUID;
-import java.util.concurrent.TimeUnit;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.apache.jackrabbit.oak.segment.Segment;
-import org.apache.jackrabbit.oak.segment.SegmentId;
-import org.apache.jackrabbit.oak.segment.SegmentNotFoundException;
import org.apache.jackrabbit.oak.segment.file.FileStore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -45,7 +44,7 @@ class DefaultStandbySegmentReader implem
long msb = uuid.getMostSignificantBits();
long lsb = uuid.getLeastSignificantBits();
- Segment segment = readSegment(store.newSegmentId(msb, lsb));
+ Segment segment = readSegmentWithRetry(store, store.newSegmentId(msb,
lsb));
if (segment == null) {
return null;
@@ -60,23 +59,4 @@ class DefaultStandbySegmentReader implem
}
}
- private Segment readSegment(SegmentId id) {
- for (int i = 0; i < 10; i++) {
- try {
- return store.readSegment(id);
- } catch (SegmentNotFoundException e) {
- log.warn("Unable to read segment, waiting...", e);
- }
-
- try {
- TimeUnit.MILLISECONDS.sleep(2000);
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- return null;
- }
- }
-
- return null;
- }
-
}
Added:
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/server/FileStoreUtil.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/server/FileStoreUtil.java?rev=1765838&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/server/FileStoreUtil.java
(added)
+++
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/server/FileStoreUtil.java
Thu Oct 20 15:47:20 2016
@@ -0,0 +1,50 @@
+/*
+ * 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.jackrabbit.oak.segment.standby.server;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.jackrabbit.oak.segment.Segment;
+import org.apache.jackrabbit.oak.segment.SegmentId;
+import org.apache.jackrabbit.oak.segment.SegmentNotFoundException;
+import org.apache.jackrabbit.oak.segment.file.FileStore;
+
+class FileStoreUtil {
+
+ FileStoreUtil() {
+ // Prevent instantiation
+ }
+
+ static Segment readSegmentWithRetry(FileStore store, SegmentId id) {
+ for (int i = 0; i < 10; i++) {
+ try {
+ return store.readSegment(id);
+ } catch (SegmentNotFoundException e) {
+ // Ignore this exception and wait
+ }
+ try {
+ TimeUnit.MILLISECONDS.sleep(125);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ return null;
+ }
+ }
+ return null;
+ }
+
+}
Propchange:
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/server/FileStoreUtil.java
------------------------------------------------------------------------------
svn:eol-style = native