stefan-egli commented on a change in pull request #453:
URL: https://github.com/apache/jackrabbit-oak/pull/453#discussion_r781049236
##########
File path:
oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecoveryAgent.java
##########
@@ -142,9 +143,29 @@ public int recover(int clusterId, long waitUntil)
ClusterNodeInfoDocument nodeInfo =
missingLastRevUtil.getClusterNodeInfo(clusterId);
if (nodeInfo != null) {
+ // Check our own lease before running recovery for another
+ // clusterId (OAK-9656)
+ long now = revisionContext.getClock().getTime();
+ ClusterNodeInfoDocument me = null;
+ if (clusterId != revisionContext.getClusterId()) {
+ // Get leaseEnd from our own cluster node info, unless
+ // we are doing recovery on startup for the clusterId
+ // we want to acquire. Then it's fine to go ahead with
+ // an expired lease.
+ me =
missingLastRevUtil.getClusterNodeInfo(revisionContext.getClusterId());
+ }
+ if (me != null && me.isRecoveryNeeded(now)) {
Review comment:
Since `me` is only used within the above
```if (clusterId != revisionContext.getClusterId()) {```
block, this block here could be moved 1 line up into that block. That could
make it slightly easier to read - since the scope it then smaller. wdyt?
##########
File path:
oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/RecoveryWithIncorrectClockTest.java
##########
@@ -0,0 +1,98 @@
+/*
+ * 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.plugins.document;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore;
+import org.apache.jackrabbit.oak.stats.Clock;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static
org.apache.jackrabbit.oak.plugins.document.Collection.CLUSTER_NODES;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.lessThan;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class RecoveryWithIncorrectClockTest {
+
+ @Rule
+ public DocumentMKBuilderProvider builderProvider = new
DocumentMKBuilderProvider();
+
+ private final DocumentStore store = new MemoryDocumentStore();
+ private final FailingDocumentStore s1 = new FailingDocumentStore(store);
+
+ private final Clock clock = new Clock.Virtual();
+
+ private DocumentNodeStore ns1;
+
+ private DocumentNodeStore ns2;
+
+ @Before
+ public void before() throws Exception {
+ clock.waitUntil(System.currentTimeMillis());
+ Revision.setClock(clock);
+ ClusterNodeInfo.setClock(clock);
+ ns1 = createDocumentNodeStore(1, s1);
+ ns2 = createDocumentNodeStore(2, store);
+ }
+
+ @AfterClass
+ public static void after() {
+ Revision.resetClockToDefault();
+ ClusterNodeInfo.resetClockToDefault();
+ }
+
+ @Test
+ public void recover() throws Exception {
+ // prevent ns1 from writing anything. This will also prevent any
+ // further updates to clusterNodes entry 1
+ s1.fail().after(0).eternally();
+
+ long now = clock.getTime();
+ // simulate a sudden jump of time to the system clock
+ clock.waitUntil(now + TimeUnit.HOURS.toMillis(1));
+ long ahead = clock.getTime();
+ // ns2 now sees an expired lease for clusterId 1
+ LastRevRecoveryAgent agent = ns2.getLastRevRecoveryAgent();
+ try {
+ assertTrue(agent.isRecoveryNeeded());
+ agent.performRecoveryIfNeeded();
+ } catch (DocumentStoreException e) {
+ // this is expected. any of the above LastRevRecoveryAgent calls
+ // can and should fail because the lease for ns2 expired
Review comment:
does that mean both lines in the `try/catch` block can fail? in that
case, wouldn't it make sense to put each one in an individual `try/catch` block
(as otherwise you're not testing that both lines fail)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]