This is an automated email from the ASF dual-hosted git repository.
bharat pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hadoop-ozone.git
The following commit(s) were added to refs/heads/master by this push:
new 78255dd HDDS-3476. Use persisted transaction info during OM startup
in OM StateMachine. (#986)
78255dd is described below
commit 78255ddc7053bb470c7663993d5ce0aecd635f2d
Author: Bharat Viswanadham <[email protected]>
AuthorDate: Thu Jun 11 13:05:50 2020 -0700
HDDS-3476. Use persisted transaction info during OM startup in OM
StateMachine. (#986)
---
.../java/org/apache/hadoop/ozone/OzoneConsts.java | 10 --
.../common/src/main/resources/ozone-default.xml | 9 --
.../apache/hadoop/hdds/utils/db/DBCheckpoint.java | 29 ------
.../hadoop/hdds/utils/db/RocksDBCheckpoint.java | 22 ----
.../org/apache/hadoop/ozone/om/OMConfigKeys.java | 4 +-
.../ozone/om/protocol/OzoneManagerHAProtocol.java | 39 -------
.../om/protocol/OzoneManagerServerProtocol.java | 28 -----
.../apache/hadoop/ozone/MiniOzoneChaosCluster.java | 4 +-
.../hadoop/ozone/TestOzoneConfigurationFields.java | 3 +-
.../hadoop/ozone/om/TestOMDbCheckpointServlet.java | 18 ----
.../hadoop/ozone/om/TestOMRatisSnapshots.java | 9 +-
.../apache/hadoop/ozone/om/TestOzoneManagerHA.java | 4 +-
.../ozone/om/TestOzoneManagerHAWithData.java | 26 ++---
.../snapshot/TestOzoneManagerSnapshotProvider.java | 28 ++++-
.../hadoop/ozone/om/OMDBCheckpointServlet.java | 28 -----
.../hadoop/ozone/om/OmMetadataManagerImpl.java | 20 +++-
.../org/apache/hadoop/ozone/om/OzoneManager.java | 105 ++++++++++---------
.../apache/hadoop/ozone/om/ha/OMNodeDetails.java | 6 +-
.../hadoop/ozone/om/ratis/OMRatisSnapshotInfo.java | 116 ++-------------------
.../hadoop/ozone/om/ratis/OMTransactionInfo.java | 13 +++
.../ozone/om/ratis/OzoneManagerRatisServer.java | 21 +++-
.../ozone/om/ratis/OzoneManagerStateMachine.java | 45 +++++---
.../om/ratis/utils/OzoneManagerRatisUtils.java | 67 ++++++++++++
.../om/snapshot/OzoneManagerSnapshotProvider.java | 34 ++----
.../ozone/om/ratis/TestOMRatisSnapshotInfo.java | 65 ------------
.../om/ratis/TestOzoneManagerRatisServer.java | 22 ++--
.../om/ratis/TestOzoneManagerStateMachine.java | 20 +++-
27 files changed, 304 insertions(+), 491 deletions(-)
diff --git
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneConsts.java
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneConsts.java
index 5a1f915..66d0e7f 100644
--- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneConsts.java
+++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneConsts.java
@@ -320,16 +320,6 @@ public final class OzoneConsts {
// Dummy OMNodeID for OM Clients to use for a non-HA OM setup
public static final String OM_NODE_ID_DUMMY = "omNodeIdDummy";
- // OM Ratis snapshot file to store the last applied index
- public static final String OM_RATIS_SNAPSHOT_INDEX = "ratisSnapshotIndex";
-
- public static final String OM_RATIS_SNAPSHOT_TERM = "ratisSnapshotTerm";
-
- // OM Http request parameter to be used while downloading DB checkpoint
- // from OM leader to follower
- public static final String OM_RATIS_SNAPSHOT_BEFORE_DB_CHECKPOINT =
- "snapshotBeforeCheckpoint";
-
public static final String JAVA_TMP_DIR = "java.io.tmpdir";
public static final String LOCALHOST = "localhost";
diff --git a/hadoop-hdds/common/src/main/resources/ozone-default.xml
b/hadoop-hdds/common/src/main/resources/ozone-default.xml
index 79f3bcb..0af1772 100644
--- a/hadoop-hdds/common/src/main/resources/ozone-default.xml
+++ b/hadoop-hdds/common/src/main/resources/ozone-default.xml
@@ -1663,15 +1663,6 @@
</property>
<property>
- <name>ozone.om.ratis.snapshot.auto.trigger.threshold</name>
- <value>400000</value>
- <tag>OZONE, DEBUG, OM, RATIS</tag>
- <description>The log index threshold after ratis will auto trigger
- snapshot on the OM state machine.
- </description>
- </property>
-
- <property>
<name>ozone.om.ratis.server.request.timeout</name>
<value>3s</value>
<tag>OZONE, OM, RATIS, MANAGEMENT</tag>
diff --git
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/DBCheckpoint.java
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/DBCheckpoint.java
index 625c9e4..34ab4a4 100644
---
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/DBCheckpoint.java
+++
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/DBCheckpoint.java
@@ -54,33 +54,4 @@ public interface DBCheckpoint {
* @throws IOException if I/O error happens
*/
void cleanupCheckpoint() throws IOException;
-
- /**
- * Set the OM Ratis snapshot index corresponding to the OM DB checkpoint.
- * The snapshot index is the latest snapshot index saved by ratis
- * snapshots. It is not guaranteed to be the last ratis index applied to
- * the OM DB state.
- * @param omRatisSnapshotIndex the saved ratis snapshot index
- */
- void setRatisSnapshotIndex(long omRatisSnapshotIndex);
-
- /**
- * Get the OM Ratis snapshot index corresponding to the OM DB checkpoint.
- * The ratis snapshot index indicates upto which index is definitely
- * included in the DB checkpoint. It is not guaranteed to be the last ratis
- * log index applied to the DB checkpoint.
- */
- long getRatisSnapshotIndex();
-
- /**
- * Set the Ratis snapshot term for the corresponding OM DB checkpoint.
- * @param omRatisSnapshotTerm
- */
- void setRatisSnapshotTerm(long omRatisSnapshotTerm);
-
- /**
- * Get the OM Ratis snapshot term corresponding to the OM DB checkpoint.
- * @return
- */
- long getRatisSnapshotTerm();
}
diff --git
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RocksDBCheckpoint.java
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RocksDBCheckpoint.java
index a0b771a..7ce7f37 100644
---
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RocksDBCheckpoint.java
+++
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RocksDBCheckpoint.java
@@ -38,8 +38,6 @@ public class RocksDBCheckpoint implements DBCheckpoint {
private long checkpointTimestamp = System.currentTimeMillis();
private long latestSequenceNumber = -1;
private long checkpointCreationTimeTaken = 0L;
- private long ratisSnapshotIndex = 0L;
- private long ratisSnapShotTerm = 0L;
public RocksDBCheckpoint(Path checkpointLocation) {
this.checkpointLocation = checkpointLocation;
@@ -81,24 +79,4 @@ public class RocksDBCheckpoint implements DBCheckpoint {
checkpointLocation.toString());
FileUtils.deleteDirectory(checkpointLocation.toFile());
}
-
- @Override
- public void setRatisSnapshotIndex(long omRatisSnapshotIndex) {
- this.ratisSnapshotIndex = omRatisSnapshotIndex;
- }
-
- @Override
- public long getRatisSnapshotIndex() {
- return ratisSnapshotIndex;
- }
-
- @Override
- public void setRatisSnapshotTerm(long omRatisSnapshotTermIndex) {
- this.ratisSnapShotTerm = omRatisSnapshotTermIndex;
- }
-
- @Override
- public long getRatisSnapshotTerm() {
- return ratisSnapShotTerm;
- }
}
\ No newline at end of file
diff --git
a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/OMConfigKeys.java
b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/OMConfigKeys.java
index 7800d2f..13ac462 100644
---
a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/OMConfigKeys.java
+++
b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/OMConfigKeys.java
@@ -133,12 +133,10 @@ public final class OMConfigKeys {
"ozone.om.ratis.log.purge.gap";
public static final int OZONE_OM_RATIS_LOG_PURGE_GAP_DEFAULT = 1000000;
- // OM Snapshot configurations
public static final String OZONE_OM_RATIS_SNAPSHOT_AUTO_TRIGGER_THRESHOLD_KEY
= "ozone.om.ratis.snapshot.auto.trigger.threshold";
public static final long
- OZONE_OM_RATIS_SNAPSHOT_AUTO_TRIGGER_THRESHOLD_DEFAULT
- = 400000;
+ OZONE_OM_RATIS_SNAPSHOT_AUTO_TRIGGER_THRESHOLD_DEFAULT = 400000;
// OM Ratis server configurations
public static final String OZONE_OM_RATIS_SERVER_REQUEST_TIMEOUT_KEY
diff --git
a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocol/OzoneManagerHAProtocol.java
b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocol/OzoneManagerHAProtocol.java
deleted file mode 100644
index a641358..0000000
---
a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocol/OzoneManagerHAProtocol.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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.hadoop.ozone.om.protocol;
-
-import org.apache.ratis.server.protocol.TermIndex;
-
-import java.io.IOException;
-
-/**
- * Protocol to talk to OM HA. These methods are needed only called from
- * OmRequestHandler.
- */
-public interface OzoneManagerHAProtocol {
-
- /**
- * Store the snapshot index i.e. the raft log index, corresponding to the
- * last transaction applied to the OM RocksDB, in OM metadata dir on disk.
- * @return the snapshot term index which has both term and index.
- * @throws IOException
- */
- TermIndex saveRatisSnapshot() throws IOException;
-
-}
diff --git
a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocol/OzoneManagerServerProtocol.java
b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocol/OzoneManagerServerProtocol.java
deleted file mode 100644
index 6f58e2d..0000000
---
a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocol/OzoneManagerServerProtocol.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/**
- * 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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.hadoop.ozone.om.protocol;
-
-/**
- * This will be used in the OzoneManager Server, as few of the methods in
- * OzoneManagerHAProtocol need not be exposed to Om clients. This interface
- * extends both OzoneManagerHAProtocol and OzoneManagerProtocol.
- */
-public interface OzoneManagerServerProtocol extends OzoneManagerProtocol,
- OzoneManagerHAProtocol {
-}
diff --git
a/hadoop-ozone/fault-injection-test/mini-chaos-tests/src/test/java/org/apache/hadoop/ozone/MiniOzoneChaosCluster.java
b/hadoop-ozone/fault-injection-test/mini-chaos-tests/src/test/java/org/apache/hadoop/ozone/MiniOzoneChaosCluster.java
index c20677f..5a0b68d 100644
---
a/hadoop-ozone/fault-injection-test/mini-chaos-tests/src/test/java/org/apache/hadoop/ozone/MiniOzoneChaosCluster.java
+++
b/hadoop-ozone/fault-injection-test/mini-chaos-tests/src/test/java/org/apache/hadoop/ozone/MiniOzoneChaosCluster.java
@@ -233,10 +233,10 @@ public class MiniOzoneChaosCluster extends
MiniOzoneHAClusterImpl {
conf.setInt("hdds.scm.replication.event.timeout", 20 * 1000);
conf.setInt(OzoneConfigKeys.DFS_RATIS_SNAPSHOT_THRESHOLD_KEY, 100);
conf.setInt(OzoneConfigKeys.DFS_CONTAINER_RATIS_LOG_PURGE_GAP, 100);
+ conf.setInt(OMConfigKeys.OZONE_OM_RATIS_LOG_PURGE_GAP, 100);
conf.setInt(OMConfigKeys.
- OZONE_OM_RATIS_SNAPSHOT_AUTO_TRIGGER_THRESHOLD_KEY, 100);
- conf.setInt(OMConfigKeys.OZONE_OM_RATIS_LOG_PURGE_GAP, 100);
+ OZONE_OM_RATIS_SNAPSHOT_AUTO_TRIGGER_THRESHOLD_KEY, 100);
}
/**
diff --git
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/TestOzoneConfigurationFields.java
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/TestOzoneConfigurationFields.java
index b9ae815..cbd5db5 100644
---
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/TestOzoneConfigurationFields.java
+++
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/TestOzoneConfigurationFields.java
@@ -67,7 +67,8 @@ public class TestOzoneConfigurationFields extends
TestConfigurationFieldsBase {
OMConfigKeys.OZONE_OM_NODES_KEY,
OzoneConfigKeys.OZONE_ACL_AUTHORIZER_CLASS_NATIVE,
OzoneConfigKeys.OZONE_S3_AUTHINFO_MAX_LIFETIME_KEY,
- ReconServerConfigKeys.OZONE_RECON_SCM_DB_DIR
+ ReconServerConfigKeys.OZONE_RECON_SCM_DB_DIR,
+ OMConfigKeys.OZONE_OM_RATIS_SNAPSHOT_AUTO_TRIGGER_THRESHOLD_KEY
// TODO HDDS-2856
));
}
diff --git
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOMDbCheckpointServlet.java
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOMDbCheckpointServlet.java
index d21ebb4..15fd9aa 100644
---
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOMDbCheckpointServlet.java
+++
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOMDbCheckpointServlet.java
@@ -238,22 +238,4 @@ class TestDBCheckpoint implements DBCheckpoint {
public void cleanupCheckpoint() throws IOException {
FileUtils.deleteDirectory(checkpointFile.toFile());
}
-
- @Override
- public void setRatisSnapshotIndex(long omRatisSnapshotIndex) {
- }
-
- @Override
- public long getRatisSnapshotIndex() {
- return 0;
- }
-
- @Override
- public void setRatisSnapshotTerm(long omRatisSnapshotTermIndex) {
- }
-
- @Override
- public long getRatisSnapshotTerm() {
- return 0;
- }
}
\ No newline at end of file
diff --git
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOMRatisSnapshots.java
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOMRatisSnapshots.java
index eeaaede..cccdb7c 100644
---
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOMRatisSnapshots.java
+++
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOMRatisSnapshots.java
@@ -30,6 +30,7 @@ import org.apache.hadoop.ozone.client.OzoneBucket;
import org.apache.hadoop.ozone.client.OzoneClientFactory;
import org.apache.hadoop.ozone.client.OzoneVolume;
import org.apache.hadoop.ozone.client.VolumeArgs;
+import org.apache.hadoop.ozone.om.ratis.OMTransactionInfo;
import org.apache.hadoop.ozone.om.ratis.OzoneManagerRatisServer;
import org.apache.commons.lang3.RandomStringUtils;
@@ -79,10 +80,10 @@ public class TestOMRatisSnapshots {
clusterId = UUID.randomUUID().toString();
scmId = UUID.randomUUID().toString();
omServiceId = "om-service-test1";
+ conf.setInt(OMConfigKeys.OZONE_OM_RATIS_LOG_PURGE_GAP, LOG_PURGE_GAP);
conf.setLong(
OMConfigKeys.OZONE_OM_RATIS_SNAPSHOT_AUTO_TRIGGER_THRESHOLD_KEY,
SNAPSHOT_THRESHOLD);
- conf.setInt(OMConfigKeys.OZONE_OM_RATIS_LOG_PURGE_GAP, LOG_PURGE_GAP);
cluster = (MiniOzoneHAClusterImpl) MiniOzoneCluster.newHABuilder(conf)
.setClusterId(clusterId)
.setScmId(scmId)
@@ -150,7 +151,11 @@ public class TestOMRatisSnapshots {
}
// Get the latest db checkpoint from the leader OM.
- TermIndex leaderOMTermIndex = leaderOM.saveRatisSnapshot();
+ OMTransactionInfo omTransactionInfo =
+ OMTransactionInfo.readTransactionInfo(leaderOM.getMetadataManager());
+ TermIndex leaderOMTermIndex =
+ TermIndex.newTermIndex(omTransactionInfo.getCurrentTerm(),
+ omTransactionInfo.getTransactionIndex());
long leaderOMSnaphsotIndex = leaderOMTermIndex.getIndex();
long leaderOMSnapshotTermIndex = leaderOMTermIndex.getTerm();
diff --git
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOzoneManagerHA.java
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOzoneManagerHA.java
index 868f74c..daca5c3 100644
---
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOzoneManagerHA.java
+++
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOzoneManagerHA.java
@@ -68,11 +68,11 @@ public abstract class TestOzoneManagerHA {
private String scmId;
private String omServiceId;
private static int numOfOMs = 3;
- private static final long SNAPSHOT_THRESHOLD = 50;
private static final int LOG_PURGE_GAP = 50;
/* Reduce max number of retries to speed up unit test. */
private static final int OZONE_CLIENT_FAILOVER_MAX_ATTEMPTS = 5;
private static final int IPC_CLIENT_CONNECT_MAX_RETRIES = 4;
+ private static final long SNAPSHOT_THRESHOLD = 50;
@Rule
public ExpectedException exception = ExpectedException.none();
@@ -135,10 +135,10 @@ public abstract class TestOzoneManagerHA {
IPC_CLIENT_CONNECT_MAX_RETRIES);
/* Reduce IPC retry interval to speed up unit test. */
conf.setInt(IPC_CLIENT_CONNECT_RETRY_INTERVAL_KEY, 200);
+ conf.setInt(OMConfigKeys.OZONE_OM_RATIS_LOG_PURGE_GAP, LOG_PURGE_GAP);
conf.setLong(
OMConfigKeys.OZONE_OM_RATIS_SNAPSHOT_AUTO_TRIGGER_THRESHOLD_KEY,
SNAPSHOT_THRESHOLD);
- conf.setInt(OMConfigKeys.OZONE_OM_RATIS_LOG_PURGE_GAP, LOG_PURGE_GAP);
cluster = (MiniOzoneHAClusterImpl) MiniOzoneCluster.newHABuilder(conf)
.setClusterId(clusterId)
.setScmId(scmId)
diff --git
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOzoneManagerHAWithData.java
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOzoneManagerHAWithData.java
index a23cd0b..107ebfc 100644
---
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOzoneManagerHAWithData.java
+++
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOzoneManagerHAWithData.java
@@ -38,6 +38,7 @@ import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
+import java.io.IOException;
import java.net.ConnectException;
import java.util.ArrayList;
import java.util.HashMap;
@@ -442,8 +443,12 @@ public class TestOzoneManagerHAWithData extends
TestOzoneManagerHA {
}
GenericTestUtils.waitFor(() -> {
- if (ozoneManager.getRatisSnapshotIndex() > 0) {
- return true;
+ try {
+ if (ozoneManager.getRatisSnapshotIndex() > 0) {
+ return true;
+ }
+ } catch (IOException ex) {
+ fail("test failed during transactionInfo read");
}
return false;
}, 1000, 100000);
@@ -466,8 +471,12 @@ public class TestOzoneManagerHAWithData extends
TestOzoneManagerHA {
}
GenericTestUtils.waitFor(() -> {
- if (ozoneManager.getRatisSnapshotIndex() > 0) {
- return true;
+ try {
+ if (ozoneManager.getRatisSnapshotIndex() > 0) {
+ return true;
+ }
+ } catch (IOException ex) {
+ fail("test failed during transactionInfo read");
}
return false;
}, 1000, 100000);
@@ -541,7 +550,7 @@ public class TestOzoneManagerHAWithData extends
TestOzoneManagerHA {
followerOM1.restart();
// Get the latest snapshotIndex from the leader OM.
- long leaderOMSnaphsotIndex = leaderOM.saveRatisSnapshot().getIndex();
+ long leaderOMSnaphsotIndex = leaderOM.getRatisSnapshotIndex();
// The recently started OM should be lagging behind the leader OM.
long followerOMLastAppliedIndex =
@@ -570,13 +579,6 @@ public class TestOzoneManagerHAWithData extends
TestOzoneManagerHA {
Assert.assertTrue(followerOM1lastAppliedIndex >
leaderOMSnaphsotIndex);
- // The follower OMs should be in sync. There can be a small lag between
- // leader OM and follower OMs as txns are applied first on leader OM.
- long followerOM2lastAppliedIndex = followerOM1.getOmRatisServer()
- .getLastAppliedTermIndex().getIndex();
- Assert.assertEquals(followerOM1lastAppliedIndex,
- followerOM2lastAppliedIndex);
-
}
@Test
diff --git
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/snapshot/TestOzoneManagerSnapshotProvider.java
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/snapshot/TestOzoneManagerSnapshotProvider.java
index 9d3276d..d77f4d9 100644
---
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/snapshot/TestOzoneManagerSnapshotProvider.java
+++
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/snapshot/TestOzoneManagerSnapshotProvider.java
@@ -31,9 +31,11 @@ import org.apache.hadoop.ozone.client.OzoneVolume;
import org.apache.hadoop.ozone.client.VolumeArgs;
import org.apache.hadoop.ozone.om.OMConfigKeys;
import org.apache.hadoop.ozone.om.OmFailoverProxyUtil;
+import org.apache.hadoop.ozone.om.OmMetadataManagerImpl;
import org.apache.hadoop.ozone.om.OzoneManager;
import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.hadoop.ozone.om.ratis.OMTransactionInfo;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
@@ -111,18 +113,18 @@ public class TestOzoneManagerSnapshotProvider {
.getFailoverProxyProvider(objectStore.getClientProxy())
.getCurrentProxyOMNodeId();
- OzoneManager ozoneManager = cluster.getOzoneManager(leaderOMNodeId);
+ OzoneManager leaderOM = cluster.getOzoneManager(leaderOMNodeId);
// Get a follower OM
- String followerNodeId = ozoneManager.getPeerNodes().get(0).getOMNodeId();
+ String followerNodeId = leaderOM.getPeerNodes().get(0).getOMNodeId();
OzoneManager followerOM = cluster.getOzoneManager(followerNodeId);
// Download latest checkpoint from leader OM to follower OM
DBCheckpoint omSnapshot = followerOM.getOmSnapshotProvider()
.getOzoneManagerDBSnapshot(leaderOMNodeId);
- long leaderSnapshotIndex = ozoneManager.getRatisSnapshotIndex();
- long downloadedSnapshotIndex = omSnapshot.getRatisSnapshotIndex();
+ long leaderSnapshotIndex = leaderOM.getRatisSnapshotIndex();
+ long downloadedSnapshotIndex = getDownloadSnapshotIndex(omSnapshot);
// The snapshot index downloaded from leader OM should match the ratis
// snapshot index on the leader OM
@@ -130,4 +132,22 @@ public class TestOzoneManagerSnapshotProvider {
"not match its ratis snapshot index",
leaderSnapshotIndex, downloadedSnapshotIndex);
}
+
+ private long getDownloadSnapshotIndex(DBCheckpoint dbCheckpoint)
+ throws Exception {
+
+ OzoneConfiguration configuration = new OzoneConfiguration(conf);
+ configuration.set(OMConfigKeys.OZONE_OM_DB_DIRS,
+ dbCheckpoint.getCheckpointLocation().getParent().toString());
+
+ OmMetadataManagerImpl omMetadataManager =
+ new OmMetadataManagerImpl(configuration);
+
+ long transactionIndex =
+ OMTransactionInfo.readTransactionInfo(omMetadataManager)
+ .getTransactionIndex();
+ omMetadataManager.stop();
+ return transactionIndex;
+
+ }
}
\ No newline at end of file
diff --git
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OMDBCheckpointServlet.java
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OMDBCheckpointServlet.java
index ac5d869..25e2755 100644
---
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OMDBCheckpointServlet.java
+++
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OMDBCheckpointServlet.java
@@ -47,11 +47,7 @@ import
org.apache.commons.compress.compressors.CompressorOutputStream;
import org.apache.commons.compress.compressors.CompressorStreamFactory;
import org.apache.commons.compress.utils.IOUtils;
import org.apache.commons.lang3.StringUtils;
-import static
org.apache.hadoop.ozone.OzoneConsts.OM_RATIS_SNAPSHOT_BEFORE_DB_CHECKPOINT;
-import static org.apache.hadoop.ozone.OzoneConsts.OM_RATIS_SNAPSHOT_INDEX;
-import static org.apache.hadoop.ozone.OzoneConsts.OM_RATIS_SNAPSHOT_TERM;
import static
org.apache.hadoop.ozone.OzoneConsts.OZONE_DB_CHECKPOINT_REQUEST_FLUSH;
-import org.apache.ratis.server.protocol.TermIndex;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -120,30 +116,6 @@ public class OMDBCheckpointServlet extends HttpServlet {
flush = Boolean.valueOf(flushParam);
}
- boolean takeRatisSnapshot = false;
- String snapshotBeforeCheckpointParam =
- request.getParameter(OM_RATIS_SNAPSHOT_BEFORE_DB_CHECKPOINT);
- if (StringUtils.isNotEmpty(snapshotBeforeCheckpointParam)) {
- takeRatisSnapshot = Boolean.valueOf(snapshotBeforeCheckpointParam);
- }
-
- if (takeRatisSnapshot) {
- // If OM follower is downloading the checkpoint, we should save a
- // ratis snapshot first. This step also included flushing the OM DB.
- // Hence, we can set flush to false.
-
- // We need to set both snapshot term index and snapshot index.
- flush = false;
- TermIndex lastAppliedTermIndex = om.saveRatisSnapshot();
-
- // Ratis snapshot index and term index is used when downloading DB
- // checkpoint to OM follower.
- response.setHeader(OM_RATIS_SNAPSHOT_INDEX,
- String.valueOf(lastAppliedTermIndex.getIndex()));
- response.setHeader(OM_RATIS_SNAPSHOT_TERM,
- String.valueOf(lastAppliedTermIndex.getTerm()));
- }
-
checkpoint = omDbStore.getCheckpoint(flush);
if (checkpoint == null || checkpoint.getCheckpointLocation() == null) {
LOG.error("Unable to process metadata snapshot request. " +
diff --git
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java
index 39a093a..452afaa 100644
---
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java
+++
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java
@@ -78,6 +78,7 @@ import static
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_OPEN_KEY_EXPIRE_THRE
import static
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_OPEN_KEY_EXPIRE_THRESHOLD_SECONDS_DEFAULT;
import static org.apache.hadoop.ozone.OzoneConsts.OM_DB_NAME;
import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX;
+
import org.eclipse.jetty.util.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -155,6 +156,7 @@ public class OmMetadataManagerImpl implements
OMMetadataManager {
private boolean isRatisEnabled;
public OmMetadataManagerImpl(OzoneConfiguration conf) throws IOException {
+
this.lock = new OzoneManagerLock(conf);
this.openKeyExpireThresholdMS = 1000L * conf.getInt(
OZONE_OPEN_KEY_EXPIRE_THRESHOLD_SECONDS,
@@ -259,16 +261,24 @@ public class OmMetadataManagerImpl implements
OMMetadataManager {
rocksDBConfiguration.setSyncOption(true);
}
- DBStoreBuilder dbStoreBuilder = DBStoreBuilder.newBuilder(configuration,
- rocksDBConfiguration).setName(OM_DB_NAME)
- .setPath(Paths.get(metaDir.getPath()));
+ this.store = loadDB(configuration, metaDir);
- this.store = addOMTablesAndCodecs(dbStoreBuilder).build();
initializeOmTables();
}
}
- protected DBStoreBuilder addOMTablesAndCodecs(DBStoreBuilder builder) {
+ public static DBStore loadDB(OzoneConfiguration configuration, File metaDir)
+ throws IOException {
+ RocksDBConfiguration rocksDBConfiguration =
+ configuration.getObject(RocksDBConfiguration.class);
+ DBStoreBuilder dbStoreBuilder = DBStoreBuilder.newBuilder(configuration,
+ rocksDBConfiguration).setName(OM_DB_NAME)
+ .setPath(Paths.get(metaDir.getPath()));
+ DBStore dbStore = addOMTablesAndCodecs(dbStoreBuilder).build();
+ return dbStore;
+ }
+
+ protected static DBStoreBuilder addOMTablesAndCodecs(DBStoreBuilder builder)
{
return builder.addTable(USER_TABLE)
.addTable(VOLUME_TABLE)
diff --git
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
index 9f556f8..a791d28 100644
---
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
+++
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
@@ -125,10 +125,12 @@ import
org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo;
import org.apache.hadoop.ozone.om.helpers.S3SecretValue;
import org.apache.hadoop.ozone.om.helpers.ServiceInfo;
import org.apache.hadoop.ozone.om.helpers.ServiceInfoEx;
-import org.apache.hadoop.ozone.om.protocol.OzoneManagerServerProtocol;
+import org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol;
import org.apache.hadoop.ozone.om.protocolPB.OzoneManagerProtocolPB;
import org.apache.hadoop.ozone.om.ratis.OMRatisSnapshotInfo;
+import org.apache.hadoop.ozone.om.ratis.OMTransactionInfo;
import org.apache.hadoop.ozone.om.ratis.OzoneManagerRatisServer;
+import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerRatisUtils;
import org.apache.hadoop.ozone.om.snapshot.OzoneManagerSnapshotProvider;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
import
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.DBUpdatesRequest;
@@ -221,7 +223,7 @@ import org.slf4j.LoggerFactory;
*/
@InterfaceAudience.LimitedPrivate({"HDFS", "CBLOCK", "OZONE", "HBASE"})
public final class OzoneManager extends ServiceRuntimeInfoImpl
- implements OzoneManagerServerProtocol, OMMXBean, Auditor {
+ implements OzoneManagerProtocol, OMMXBean, Auditor {
public static final Logger LOG =
LoggerFactory.getLogger(OzoneManager.class);
@@ -411,8 +413,7 @@ public final class OzoneManager extends
ServiceRuntimeInfoImpl
}
instantiateServices();
- this.omRatisSnapshotInfo = new OMRatisSnapshotInfo(
- omStorage.getCurrentDir());
+ this.omRatisSnapshotInfo = new OMRatisSnapshotInfo();
initializeRatisServer();
if (isRatisEnabled) {
// Create Ratis storage dir
@@ -1235,20 +1236,9 @@ public final class OzoneManager extends
ServiceRuntimeInfoImpl
}
@VisibleForTesting
- public long getRatisSnapshotIndex() {
- return omRatisSnapshotInfo.getIndex();
- }
-
- @Override
- public TermIndex saveRatisSnapshot() throws IOException {
- TermIndex snapshotIndex = omRatisServer.getLastAppliedTermIndex();
-
- // Flush the OM state to disk
- metadataManager.getStore().flush();
-
- omRatisSnapshotInfo.saveRatisSnapshotToDisk(snapshotIndex);
-
- return snapshotIndex;
+ public long getRatisSnapshotIndex() throws IOException {
+ return OMTransactionInfo.readTransactionInfo(metadataManager)
+ .getTransactionIndex();
}
/**
@@ -3021,29 +3011,30 @@ public final class OzoneManager extends
ServiceRuntimeInfoImpl
DBCheckpoint omDBcheckpoint = getDBCheckpointFromLeader(leaderId);
Path newDBlocation = omDBcheckpoint.getCheckpointLocation();
+ LOG.info("Downloaded checkpoint from Leader {}, in to the location {}",
+ leaderId, newDBlocation);
+
// Check if current ratis log index is smaller than the downloaded
- // snapshot index. If yes, proceed by stopping the ratis server so that
- // the OM state can be re-initialized. If no, then do not proceed with
- // installSnapshot.
- long lastAppliedIndex = omRatisServer.getLastAppliedTermIndex().getIndex();
- long checkpointSnapshotIndex = omDBcheckpoint.getRatisSnapshotIndex();
- long checkpointSnapshotTermIndex =
- omDBcheckpoint.getRatisSnapshotTerm();
- if (checkpointSnapshotIndex <= lastAppliedIndex) {
- LOG.error("Failed to install checkpoint from OM leader: {}. The last " +
- "applied index: {} is greater than or equal to the checkpoint's"
- + " " +
- "snapshot index: {}. Deleting the downloaded checkpoint {}",
- leaderId,
- lastAppliedIndex, checkpointSnapshotIndex,
+ // checkpoint transaction index. If yes, proceed by stopping the ratis
+ // server so that the OM state can be re-initialized. If no, then do not
+ // proceed with installSnapshot.
+
+ OMTransactionInfo omTransactionInfo = null;
+
+ Path dbDir = newDBlocation.getParent();
+ if (dbDir == null) {
+ LOG.error("Incorrect DB location path {} received from checkpoint.",
newDBlocation);
- try {
- FileUtils.deleteFully(newDBlocation);
- } catch (IOException e) {
- LOG.error("Failed to fully delete the downloaded DB checkpoint {} " +
- "from OM leader {}.", newDBlocation,
- leaderId, e);
- }
+ return null;
+ }
+
+ try {
+ omTransactionInfo =
+ OzoneManagerRatisUtils.getTransactionInfoFromDownloadedSnapshot(
+ configuration, dbDir);
+ } catch (Exception ex) {
+ LOG.error("Failed during opening downloaded snapshot from " +
+ "{} to obtain transaction index", newDBlocation, ex);
return null;
}
@@ -3056,6 +3047,23 @@ public final class OzoneManager extends
ServiceRuntimeInfoImpl
// append log entries to the ratis server.
omRatisServer.getOmStateMachine().pause();
+ //TODO: un-pause SM if any failures and retry?
+
+ long lastAppliedIndex = omRatisServer.getLastAppliedTermIndex().getIndex();
+
+ boolean canProceed =
+ OzoneManagerRatisUtils.verifyTransactionInfo(omTransactionInfo,
+ lastAppliedIndex, leaderId, newDBlocation);
+
+ // If downloaded DB has transaction info less than current one, return.
+ if (!canProceed) {
+ return null;
+ }
+
+ long leaderIndex = omTransactionInfo.getTransactionIndex();
+ long leaderTerm = omTransactionInfo.getCurrentTerm();
+
+
File dbBackup;
try {
dbBackup = replaceOMDBWithCheckpoint(lastAppliedIndex, newDBlocation);
@@ -3069,9 +3077,8 @@ public final class OzoneManager extends
ServiceRuntimeInfoImpl
// Restart (unpause) the state machine and update its last applied index
// to the installed checkpoint's snapshot index.
try {
- reloadOMState(checkpointSnapshotIndex, checkpointSnapshotTermIndex);
- omRatisServer.getOmStateMachine().unpause(checkpointSnapshotIndex,
- checkpointSnapshotTermIndex);
+ reloadOMState(leaderIndex, leaderTerm);
+ omRatisServer.getOmStateMachine().unpause(leaderIndex, leaderTerm);
} catch (IOException e) {
LOG.error("Failed to reload OM state with new DB checkpoint.", e);
return null;
@@ -3086,12 +3093,11 @@ public final class OzoneManager extends
ServiceRuntimeInfoImpl
// TODO: We should only return the snpashotIndex to the leader.
// Should be fixed after RATIS-586
- TermIndex newTermIndex =
TermIndex.newTermIndex(checkpointSnapshotTermIndex,
- checkpointSnapshotIndex);
-
+ TermIndex newTermIndex = TermIndex.newTermIndex(leaderTerm, leaderIndex);
return newTermIndex;
}
+
/**
* Download the latest OM DB checkpoint from the leader OM.
*
@@ -3156,8 +3162,8 @@ public final class OzoneManager extends
ServiceRuntimeInfoImpl
* All the classes which use/ store MetadataManager should also be updated
* with the new MetadataManager instance.
*/
- void reloadOMState(long newSnapshotIndex,
- long newSnapShotTermIndex) throws IOException {
+ void reloadOMState(long newSnapshotIndex, long newSnapshotTermIndex)
+ throws IOException {
instantiateServices();
@@ -3179,9 +3185,8 @@ public final class OzoneManager extends
ServiceRuntimeInfoImpl
saveOmMetrics();
// Update OM snapshot index with the new snapshot index (from the new OM
- // DB state) and save the snapshot index to disk
- omRatisSnapshotInfo.saveRatisSnapshotToDisk(
- TermIndex.newTermIndex(newSnapShotTermIndex, newSnapshotIndex));
+ // DB state).
+ omRatisSnapshotInfo.updateTermIndex(newSnapshotTermIndex,
newSnapshotIndex);
}
public static Logger getLogger() {
diff --git
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ha/OMNodeDetails.java
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ha/OMNodeDetails.java
index b00191d..3fe8735 100644
---
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ha/OMNodeDetails.java
+++
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ha/OMNodeDetails.java
@@ -25,7 +25,7 @@ import org.apache.hadoop.net.NetUtils;
import java.net.InetAddress;
import java.net.InetSocketAddress;
-import static
org.apache.hadoop.ozone.OzoneConsts.OM_RATIS_SNAPSHOT_BEFORE_DB_CHECKPOINT;
+import static
org.apache.hadoop.ozone.OzoneConsts.OZONE_DB_CHECKPOINT_REQUEST_FLUSH;
import static
org.apache.hadoop.ozone.OzoneConsts.OZONE_OM_DB_CHECKPOINT_HTTP_ENDPOINT;
/**
@@ -165,12 +165,12 @@ public final class OMNodeDetails {
if (httpPolicy.isHttpEnabled()) {
if (StringUtils.isNotEmpty(httpAddress)) {
return "http://" + httpAddress + OZONE_OM_DB_CHECKPOINT_HTTP_ENDPOINT
- + "?" + OM_RATIS_SNAPSHOT_BEFORE_DB_CHECKPOINT + "=true";
+ + "?" + OZONE_DB_CHECKPOINT_REQUEST_FLUSH + "=true";
}
} else {
if (StringUtils.isNotEmpty(httpsAddress)) {
return "https://" + httpsAddress + OZONE_OM_DB_CHECKPOINT_HTTP_ENDPOINT
- + "?" + OM_RATIS_SNAPSHOT_BEFORE_DB_CHECKPOINT + "=true";
+ + "?" + OZONE_DB_CHECKPOINT_REQUEST_FLUSH + "=true";
}
}
return null;
diff --git
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OMRatisSnapshotInfo.java
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OMRatisSnapshotInfo.java
index 483adbf..b893414 100644
---
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OMRatisSnapshotInfo.java
+++
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OMRatisSnapshotInfo.java
@@ -22,18 +22,10 @@ import org.apache.ratis.server.storage.FileInfo;
import org.apache.ratis.statemachine.SnapshotInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.yaml.snakeyaml.DumperOptions;
-import org.yaml.snakeyaml.Yaml;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
import java.util.List;
-import static org.apache.hadoop.ozone.OzoneConsts.OM_RATIS_SNAPSHOT_INDEX;
+import static org.apache.hadoop.ozone.OzoneConsts.TRANSACTION_INFO_SPLIT_KEY;
/**
* This class captures the snapshotIndex and term of the latest snapshot in
@@ -49,81 +41,15 @@ public class OMRatisSnapshotInfo implements SnapshotInfo {
private volatile long term = 0;
private volatile long snapshotIndex = -1;
- private final File ratisSnapshotFile;
-
- public OMRatisSnapshotInfo(File ratisDir) throws IOException {
- ratisSnapshotFile = new File(ratisDir, OM_RATIS_SNAPSHOT_INDEX);
- loadRatisSnapshotIndex();
- }
-
public void updateTerm(long newTerm) {
term = newTerm;
}
- private void updateTermIndex(long newTerm, long newIndex) {
+ public void updateTermIndex(long newTerm, long newIndex) {
this.term = newTerm;
this.snapshotIndex = newIndex;
}
- /**
- * Load the snapshot index and term from the snapshot file on disk,
- * if it exists.
- * @throws IOException
- */
- private void loadRatisSnapshotIndex() throws IOException {
- if (ratisSnapshotFile.exists()) {
- RatisSnapshotYaml ratisSnapshotYaml = readRatisSnapshotYaml();
- updateTermIndex(ratisSnapshotYaml.term, ratisSnapshotYaml.snapshotIndex);
- }
- }
-
- /**
- * Read and parse the snapshot yaml file.
- */
- private RatisSnapshotYaml readRatisSnapshotYaml() throws IOException {
- try (FileInputStream inputFileStream = new FileInputStream(
- ratisSnapshotFile)) {
- Yaml yaml = new Yaml();
- try {
- return yaml.loadAs(inputFileStream, RatisSnapshotYaml.class);
- } catch (Exception e) {
- throw new IOException("Unable to parse RatisSnapshot yaml file.", e);
- }
- }
- }
-
- /**
- * Update and persist the snapshot index and term to disk.
- * @param lastAppliedTermIndex new snapshot index to be persisted to disk.
- * @throws IOException
- */
- public void saveRatisSnapshotToDisk(TermIndex lastAppliedTermIndex)
- throws IOException {
- updateTermIndex(lastAppliedTermIndex.getTerm(),
- lastAppliedTermIndex.getIndex());
- writeRatisSnapshotYaml();
- LOG.info("Saved Ratis Snapshot on the OM with snapshotIndex {}",
- lastAppliedTermIndex);
- }
-
- /**
- * Write snapshot details to disk in yaml format.
- */
- private void writeRatisSnapshotYaml() throws IOException {
- DumperOptions options = new DumperOptions();
- options.setPrettyFlow(true);
- options.setDefaultFlowStyle(DumperOptions.FlowStyle.FLOW);
- Yaml yaml = new Yaml(options);
-
- RatisSnapshotYaml ratisSnapshotYaml = new RatisSnapshotYaml(term,
- snapshotIndex);
-
- try (Writer writer = new OutputStreamWriter(
- new FileOutputStream(ratisSnapshotFile), "UTF-8")) {
- yaml.dump(ratisSnapshotYaml, writer);
- }
- }
-
@Override
public TermIndex getTermIndex() {
return TermIndex.newTermIndex(term, snapshotIndex);
@@ -144,36 +70,12 @@ public class OMRatisSnapshotInfo implements SnapshotInfo {
return null;
}
- /**
- * Ratis Snapshot details to be written to the yaml file.
- */
- public static class RatisSnapshotYaml {
- private long term;
- private long snapshotIndex;
-
- public RatisSnapshotYaml() {
- // Needed for snake-yaml introspection.
- }
-
- RatisSnapshotYaml(long term, long snapshotIndex) {
- this.term = term;
- this.snapshotIndex = snapshotIndex;
- }
-
- public void setTerm(long term) {
- this.term = term;
- }
-
- public long getTerm() {
- return this.term;
- }
-
- public void setSnapshotIndex(long index) {
- this.snapshotIndex = index;
- }
-
- public long getSnapshotIndex() {
- return this.snapshotIndex;
- }
+ @Override
+ public String toString() {
+ StringBuilder stringBuilder = new StringBuilder();
+ stringBuilder.append(term);
+ stringBuilder.append(TRANSACTION_INFO_SPLIT_KEY);
+ stringBuilder.append(snapshotIndex);
+ return stringBuilder.toString();
}
}
diff --git
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OMTransactionInfo.java
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OMTransactionInfo.java
index 712659f..2441751 100644
---
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OMTransactionInfo.java
+++
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OMTransactionInfo.java
@@ -20,9 +20,12 @@ package org.apache.hadoop.ozone.om.ratis;
import com.google.common.base.Preconditions;
import org.apache.hadoop.hdds.StringUtils;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import java.io.IOException;
import java.util.Objects;
+import static org.apache.hadoop.ozone.OzoneConsts.TRANSACTION_INFO_KEY;
import static org.apache.hadoop.ozone.OzoneConsts.TRANSACTION_INFO_SPLIT_KEY;
/**
@@ -116,6 +119,16 @@ public final class OMTransactionInfo {
}
/**
+ * Return transaction info persisted in OM DB.
+ * @param metadataManager
+ * @return
+ * @throws IOException
+ */
+ public static OMTransactionInfo readTransactionInfo(
+ OMMetadataManager metadataManager) throws IOException {
+ return metadataManager.getTransactionInfoTable().get(TRANSACTION_INFO_KEY);
+ }
+ /**
* Builder to build {@link OMTransactionInfo}.
*/
public static class Builder {
diff --git
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerRatisServer.java
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerRatisServer.java
index 191ab00..2a98db6 100644
---
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerRatisServer.java
+++
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerRatisServer.java
@@ -342,7 +342,8 @@ public final class OzoneManagerRatisServer {
/**
* Initializes and returns OzoneManager StateMachine.
*/
- private OzoneManagerStateMachine getStateMachine(ConfigurationSource conf) {
+ private OzoneManagerStateMachine getStateMachine(ConfigurationSource conf)
+ throws IOException {
return new OzoneManagerStateMachine(this,
TracingUtil.isTracingEnabled(conf));
}
@@ -528,14 +529,24 @@ public final class OzoneManagerRatisServer {
this.roleCheckInitialDelayMs = leaderElectionMinTimeout
.toLong(TimeUnit.MILLISECONDS);
+ // Set auto trigger snapshot. We don't need to configure auto trigger
+ // threshold in OM, as last applied index is flushed during double buffer
+ // flush automatically. (But added this property internally, so that this
+ // helps during testing, when want to trigger snapshots frequently, and
+ // which will purge logs when purge gap condition is satisfied and which
+ // will trigger installSnapshot when logs are cleaned up.)
+ // The transaction info value in OM DB is used as
+ // snapshot value after restart.
+
+ RaftServerConfigKeys.Snapshot.setAutoTriggerEnabled(
+ properties, true);
+
long snapshotAutoTriggerThreshold = conf.getLong(
OMConfigKeys.OZONE_OM_RATIS_SNAPSHOT_AUTO_TRIGGER_THRESHOLD_KEY,
OMConfigKeys.OZONE_OM_RATIS_SNAPSHOT_AUTO_TRIGGER_THRESHOLD_DEFAULT);
- RaftServerConfigKeys.Snapshot.setAutoTriggerEnabled(
- properties, true);
- RaftServerConfigKeys.Snapshot.setAutoTriggerThreshold(
- properties, snapshotAutoTriggerThreshold);
+ RaftServerConfigKeys.Snapshot.setAutoTriggerThreshold(properties,
+ snapshotAutoTriggerThreshold);
return properties;
}
diff --git
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerStateMachine.java
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerStateMachine.java
index 33ac961..1ff383a 100644
---
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerStateMachine.java
+++
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerStateMachine.java
@@ -99,13 +99,13 @@ public class OzoneManagerStateMachine extends
BaseStateMachine {
public OzoneManagerStateMachine(OzoneManagerRatisServer ratisServer,
- boolean isTracingEnabled) {
+ boolean isTracingEnabled) throws IOException {
this.omRatisServer = ratisServer;
this.isTracingEnabled = isTracingEnabled;
this.ozoneManager = omRatisServer.getOzoneManager();
this.snapshotInfo = ozoneManager.getSnapshotInfo();
- updateLastAppliedIndexWithSnaphsotIndex();
+ loadSnapshotInfoFromDB();
this.ozoneManagerDoubleBuffer = new OzoneManagerDoubleBuffer.Builder()
.setOmMetadataManager(ozoneManager.getMetadataManager())
@@ -138,7 +138,13 @@ public class OzoneManagerStateMachine extends
BaseStateMachine {
}
@Override
+ public void reinitialize() throws IOException {
+ loadSnapshotInfoFromDB();
+ }
+
+ @Override
public SnapshotInfo getLatestSnapshot() {
+ LOG.info("Latest Snapshot Info {}", snapshotInfo);
return snapshotInfo;
}
@@ -164,7 +170,6 @@ public class OzoneManagerStateMachine extends
BaseStateMachine {
// with some information like its peers and termIndex). So, calling
// updateLastApplied updates lastAppliedTermIndex.
computeAndUpdateLastAppliedIndex(index, currentTerm, null, false);
- snapshotInfo.updateTerm(currentTerm);
}
/**
@@ -338,20 +343,22 @@ public class OzoneManagerStateMachine extends
BaseStateMachine {
}
/**
- * Take OM Ratis snapshot. Write the snapshot index to file. Snapshot index
- * is the log index corresponding to the last applied transaction on the OM
- * State Machine.
+ * Take OM Ratis snapshot is a dummy operation as when double buffer
+ * flushes the lastAppliedIndex is flushed to DB and that is used as
+ * snapshot index.
*
* @return the last applied index on the state machine which has been
* stored in the snapshot file.
*/
@Override
public long takeSnapshot() throws IOException {
- LOG.info("Saving Ratis snapshot on the OM.");
- if (ozoneManager != null) {
- return ozoneManager.saveRatisSnapshot().getIndex();
- }
- return 0;
+ LOG.info("Current Snapshot Index {}", getLastAppliedTermIndex());
+ TermIndex lastTermIndex = getLastAppliedTermIndex();
+ long lastAppliedIndex = lastTermIndex.getIndex();
+ snapshotInfo.updateTermIndex(lastTermIndex.getTerm(),
+ lastAppliedIndex);
+ ozoneManager.getMetadataManager().getStore().flush();
+ return lastAppliedIndex;
}
/**
@@ -515,13 +522,21 @@ public class OzoneManagerStateMachine extends
BaseStateMachine {
}
}
- public void updateLastAppliedIndexWithSnaphsotIndex() {
+ public void loadSnapshotInfoFromDB() throws IOException {
// This is done, as we have a check in Ratis for not throwing
// LeaderNotReadyException, it checks stateMachineIndex >= raftLog
// nextIndex (placeHolderIndex).
- setLastAppliedTermIndex(TermIndex.newTermIndex(snapshotInfo.getTerm(),
- snapshotInfo.getIndex()));
- LOG.info("LastAppliedIndex set from SnapShotInfo {}",
+ OMTransactionInfo omTransactionInfo =
+ OMTransactionInfo.readTransactionInfo(
+ ozoneManager.getMetadataManager());
+ if (omTransactionInfo != null) {
+ setLastAppliedTermIndex(TermIndex.newTermIndex(
+ omTransactionInfo.getCurrentTerm(),
+ omTransactionInfo.getTransactionIndex()));
+ snapshotInfo.updateTermIndex(omTransactionInfo.getCurrentTerm(),
+ omTransactionInfo.getTransactionIndex());
+ }
+ LOG.info("LastAppliedIndex is set from TransactionInfo from OM DB as {}",
getLastAppliedTermIndex());
}
diff --git
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/utils/OzoneManagerRatisUtils.java
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/utils/OzoneManagerRatisUtils.java
index 9f19907..ddbda17 100644
---
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/utils/OzoneManagerRatisUtils.java
+++
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/utils/OzoneManagerRatisUtils.java
@@ -18,7 +18,13 @@
package org.apache.hadoop.ozone.om.ratis.utils;
import com.google.common.base.Preconditions;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.utils.db.DBStore;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.ozone.om.OmMetadataManagerImpl;
+import org.apache.hadoop.ozone.om.OzoneManager;
import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.om.ratis.OMTransactionInfo;
import org.apache.hadoop.ozone.om.request.bucket.OMBucketCreateRequest;
import org.apache.hadoop.ozone.om.request.bucket.OMBucketDeleteRequest;
import org.apache.hadoop.ozone.om.request.bucket.OMBucketSetPropertyRequest;
@@ -61,9 +67,14 @@ import
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMReque
import
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OzoneObj.ObjectType;
import
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.Status;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.Type;
+import org.apache.ratis.util.FileUtils;
import org.rocksdb.RocksDBException;
import java.io.IOException;
+import java.nio.file.Path;
+
+import static org.apache.hadoop.ozone.OzoneConsts.TRANSACTION_INFO_KEY;
+import static
org.apache.hadoop.ozone.om.OmMetadataManagerImpl.TRANSACTION_INFO_TABLE;
/**
* Utility class used by OzoneManager HA.
@@ -212,4 +223,60 @@ public final class OzoneManagerRatisUtils {
}
}
}
+
+ /**
+ * Obtain Transaction info from downloaded snapshot DB.
+ * @param tempConfig
+ * @return OMTransactionInfo
+ * @throws Exception
+ */
+ public static OMTransactionInfo getTransactionInfoFromDownloadedSnapshot(
+ OzoneConfiguration tempConfig, Path dbDir) throws Exception {
+ DBStore dbStore =
+ OmMetadataManagerImpl.loadDB(tempConfig, dbDir.toFile());
+
+ Table<String, OMTransactionInfo> transactionInfoTable =
+ dbStore.getTable(TRANSACTION_INFO_TABLE,
+ String.class, OMTransactionInfo.class);
+
+ OMTransactionInfo omTransactionInfo =
+ transactionInfoTable.get(TRANSACTION_INFO_KEY);
+ dbStore.close();
+ OzoneManager.LOG.info("Downloaded checkpoint with OMTransactionInfo {}",
+ omTransactionInfo);
+ return omTransactionInfo;
+ }
+
+ /**
+ * Verify transaction info with provided lastAppliedIndex.
+ *
+ * If transaction info transaction Index is less than or equal to
+ * lastAppliedIndex, return false, else return true.
+ * @param omTransactionInfo
+ * @param lastAppliedIndex
+ * @param leaderId
+ * @param newDBlocation
+ * @return boolean
+ */
+ public static boolean verifyTransactionInfo(
+ OMTransactionInfo omTransactionInfo,
+ long lastAppliedIndex,
+ String leaderId, Path newDBlocation) {
+ if (omTransactionInfo.getTransactionIndex() <= lastAppliedIndex) {
+ OzoneManager.LOG.error("Failed to install checkpoint from OM leader: {}"
+
+ ". The last applied index: {} is greater than or equal to the " +
+ "checkpoint's applied index: {}. Deleting the downloaded " +
+ "checkpoint {}", leaderId, lastAppliedIndex,
+ omTransactionInfo.getTransactionIndex(), newDBlocation);
+ try {
+ FileUtils.deleteFully(newDBlocation);
+ } catch (IOException e) {
+ OzoneManager.LOG.error("Failed to fully delete the downloaded DB " +
+ "checkpoint {} from OM leader {}.", newDBlocation, leaderId, e);
+ }
+ return false;
+ }
+
+ return true;
+ }
}
diff --git
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/OzoneManagerSnapshotProvider.java
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/OzoneManagerSnapshotProvider.java
index 8fcf4e9..52fe253 100644
---
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/OzoneManagerSnapshotProvider.java
+++
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/OzoneManagerSnapshotProvider.java
@@ -42,8 +42,8 @@ import org.apache.hadoop.ozone.om.ha.OMNodeDetails;
import static java.net.HttpURLConnection.HTTP_CREATED;
import static java.net.HttpURLConnection.HTTP_OK;
import org.apache.commons.io.FileUtils;
-import static org.apache.hadoop.ozone.OzoneConsts.OM_RATIS_SNAPSHOT_INDEX;
-import static org.apache.hadoop.ozone.OzoneConsts.OM_RATIS_SNAPSHOT_TERM;
+
+import static org.apache.hadoop.ozone.OzoneConsts.OM_DB_NAME;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_HTTP_AUTH_TYPE;
import static
org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_SNAPSHOT_PROVIDER_CONNECTION_TIMEOUT_DEFAULT;
import static
org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_SNAPSHOT_PROVIDER_CONNECTION_TIMEOUT_KEY;
@@ -112,16 +112,16 @@ public class OzoneManagerSnapshotProvider {
*/
public DBCheckpoint getOzoneManagerDBSnapshot(String leaderOMNodeID)
throws IOException {
- String snapshotFileName = OM_SNAPSHOT_DB + "_" +
System.currentTimeMillis();
- File targetFile = new File(omSnapshotDir, snapshotFileName + ".tar.gz");
+ String snapshotTime = Long.toString(System.currentTimeMillis());
+ String snapshotFileName = Paths.get(omSnapshotDir.getAbsolutePath(),
+ snapshotTime, OM_DB_NAME).toFile().getAbsolutePath();
+ File targetFile = new File(snapshotFileName + ".tar.gz");
String omCheckpointUrl = peerNodesMap.get(leaderOMNodeID)
.getOMDBCheckpointEnpointUrl(httpPolicy);
LOG.info("Downloading latest checkpoint from Leader OM {}. Checkpoint " +
"URL: {}", leaderOMNodeID, omCheckpointUrl);
- final long[] snapshotIndex = new long[1];
- final long[] snapshotTerm = new long[1];
SecurityUtil.doAsCurrentUser(() -> {
HttpURLConnection httpURLConnection = (HttpURLConnection)
connectionFactory.openConnection(new URL(omCheckpointUrl),
@@ -133,36 +133,22 @@ public class OzoneManagerSnapshotProvider {
"OM to download latest checkpoint. Checkpoint URL: " +
omCheckpointUrl + ". ErrorCode: " + errorCode);
}
- snapshotIndex[0] = httpURLConnection.getHeaderFieldLong(
- OM_RATIS_SNAPSHOT_INDEX, -1);
- if (snapshotIndex[0] == -1) {
- throw new IOException("The HTTP response header " +
- OM_RATIS_SNAPSHOT_INDEX + " is missing.");
- }
- snapshotTerm[0] = httpURLConnection.getHeaderFieldLong(
- OM_RATIS_SNAPSHOT_TERM, -1);
- if (snapshotTerm[0] == -1) {
- throw new IOException("The HTTP response header " +
- OM_RATIS_SNAPSHOT_TERM + " is missing.");
- }
try (InputStream inputStream = httpURLConnection.getInputStream()) {
FileUtils.copyInputStreamToFile(inputStream, targetFile);
}
return null;
});
+
// Untar the checkpoint file.
- Path untarredDbDir = Paths.get(omSnapshotDir.getAbsolutePath(),
- snapshotFileName);
+ Path untarredDbDir = Paths.get(snapshotFileName);
FileUtil.unTar(targetFile, untarredDbDir.toFile());
FileUtils.deleteQuietly(targetFile);
- LOG.info("Sucessfully downloaded latest checkpoint with snapshot " +
- "index {} from leader OM: {}", snapshotIndex[0], leaderOMNodeID);
+ LOG.info("Sucessfully downloaded latest checkpoint from leader OM: {}",
+ leaderOMNodeID);
RocksDBCheckpoint omCheckpoint = new RocksDBCheckpoint(untarredDbDir);
- omCheckpoint.setRatisSnapshotIndex(snapshotIndex[0]);
- omCheckpoint.setRatisSnapshotTerm(snapshotTerm[0]);
return omCheckpoint;
}
diff --git
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/ratis/TestOMRatisSnapshotInfo.java
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/ratis/TestOMRatisSnapshotInfo.java
deleted file mode 100644
index c000cd2..0000000
---
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/ratis/TestOMRatisSnapshotInfo.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/**
- * 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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.hadoop.ozone.om.ratis;
-
-import org.apache.ratis.server.protocol.TermIndex;
-import org.junit.Assert;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-
-import java.io.File;
-import java.util.Random;
-
-/**
- * Tests {@link org.apache.hadoop.ozone.om.ratis.OMRatisSnapshotInfo}.
- */
-public class TestOMRatisSnapshotInfo {
-
- @Rule
- public TemporaryFolder folder = new TemporaryFolder();
-
- @Test
- public void testSaveAndLoadSnapshotInfo() throws Exception {
- File rootDir = folder.newFolder();
- OMRatisSnapshotInfo omRatisSnapshotInfo = new OMRatisSnapshotInfo(rootDir);
-
- // Initially term and index should be 0 and -1
- Assert.assertEquals(0, omRatisSnapshotInfo.getTerm());
- Assert.assertEquals(-1, omRatisSnapshotInfo.getIndex());
-
- Random random = new Random();
- int snapshotIndex = random.nextInt(50);
- int termIndex = random.nextInt(10);
-
- // Save snapshotInfo to disk
- omRatisSnapshotInfo.saveRatisSnapshotToDisk(
- TermIndex.newTermIndex(termIndex, snapshotIndex));
-
- Assert.assertEquals(termIndex, omRatisSnapshotInfo.getTerm());
- Assert.assertEquals(snapshotIndex, omRatisSnapshotInfo.getIndex());
-
- // Load the snapshot file into new SnapshotInfo
- OMRatisSnapshotInfo newSnapshotInfo = new OMRatisSnapshotInfo(rootDir);
-
- // Verify that the snapshot file loaded properly
- Assert.assertEquals(termIndex, newSnapshotInfo.getTerm());
- Assert.assertEquals(snapshotIndex, newSnapshotInfo.getIndex());
- }
-
-}
diff --git
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/ratis/TestOzoneManagerRatisServer.java
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/ratis/TestOzoneManagerRatisServer.java
index a8ad5e9..f22f3db 100644
---
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/ratis/TestOzoneManagerRatisServer.java
+++
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/ratis/TestOzoneManagerRatisServer.java
@@ -41,6 +41,7 @@ import
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.ratis.protocol.RaftGroupId;
import org.apache.ratis.server.protocol.TermIndex;
+import org.apache.ratis.statemachine.SnapshotInfo;
import org.apache.ratis.util.LifeCycle;
import org.junit.After;
import org.junit.Assert;
@@ -51,6 +52,7 @@ import org.junit.rules.TemporaryFolder;
import org.mockito.Mockito;
import org.slf4j.LoggerFactory;
+import static org.apache.hadoop.ozone.OzoneConsts.TRANSACTION_INFO_KEY;
import static org.junit.Assert.assertFalse;
import static org.mockito.Mockito.when;
@@ -102,9 +104,7 @@ public class TestOzoneManagerRatisServer {
omMetadataManager = new OmMetadataManagerImpl(ozoneConfiguration);
when(ozoneManager.getMetadataManager()).thenReturn(omMetadataManager);
initialTermIndex = TermIndex.newTermIndex(0, 0);
- when(ozoneManager.saveRatisSnapshot()).thenReturn(initialTermIndex);
- OMRatisSnapshotInfo omRatisSnapshotInfo = new OMRatisSnapshotInfo(
- folder.newFolder());
+ OMRatisSnapshotInfo omRatisSnapshotInfo = new OMRatisSnapshotInfo();
when(ozoneManager.getSnapshotInfo()).thenReturn(omRatisSnapshotInfo);
omRatisServer = OzoneManagerRatisServer.newOMRatisServer(conf,
ozoneManager,
omNodeDetails, Collections.emptyList());
@@ -130,12 +130,20 @@ public class TestOzoneManagerRatisServer {
@Test
public void testLoadSnapshotInfoOnStart() throws Exception {
// Stop the Ratis server and manually update the snapshotInfo.
- TermIndex oldSnaphsotIndex = ozoneManager.saveRatisSnapshot();
- ozoneManager.getSnapshotInfo().saveRatisSnapshotToDisk(oldSnaphsotIndex);
+ omRatisServer.getOmStateMachine().loadSnapshotInfoFromDB();
omRatisServer.stop();
+
+ SnapshotInfo snapshotInfo =
+ omRatisServer.getOmStateMachine().getLatestSnapshot();
+
TermIndex newSnapshotIndex = TermIndex.newTermIndex(
- oldSnaphsotIndex.getTerm(), oldSnaphsotIndex.getIndex() + 100);
- ozoneManager.getSnapshotInfo().saveRatisSnapshotToDisk(newSnapshotIndex);
+ snapshotInfo.getTerm(), snapshotInfo.getIndex() + 100);
+
+ omMetadataManager.getTransactionInfoTable().put(TRANSACTION_INFO_KEY,
+ new OMTransactionInfo.Builder()
+ .setCurrentTerm(snapshotInfo.getTerm())
+ .setTransactionIndex(snapshotInfo.getIndex() + 100)
+ .build());
// Start new Ratis server. It should pick up and load the new SnapshotInfo
omRatisServer = OzoneManagerRatisServer.newOMRatisServer(conf,
ozoneManager,
diff --git
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/ratis/TestOzoneManagerStateMachine.java
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/ratis/TestOzoneManagerStateMachine.java
index b3ff9f8..5a60f7c 100644
---
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/ratis/TestOzoneManagerStateMachine.java
+++
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/ratis/TestOzoneManagerStateMachine.java
@@ -16,10 +16,16 @@
*/
package org.apache.hadoop.ozone.om.ratis;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.ozone.om.OMConfigKeys;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.OmMetadataManagerImpl;
import org.apache.hadoop.ozone.om.OzoneManager;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
import org.mockito.Mockito;
import java.util.ArrayList;
@@ -32,18 +38,30 @@ import static org.mockito.Mockito.when;
*/
public class TestOzoneManagerStateMachine {
+ @Rule
+ public TemporaryFolder tempDir = new TemporaryFolder();
+
private OzoneManagerStateMachine ozoneManagerStateMachine;
@Before
- public void setup() {
+ public void setup() throws Exception {
OzoneManagerRatisServer ozoneManagerRatisServer =
Mockito.mock(OzoneManagerRatisServer.class);
OzoneManager ozoneManager = Mockito.mock(OzoneManager.class);
+ OzoneConfiguration conf = new OzoneConfiguration();
+ conf.set(OMConfigKeys.OZONE_OM_DB_DIRS,
+ tempDir.newFolder().getAbsolutePath().toString());
+
+ OMMetadataManager omMetadataManager = new OmMetadataManagerImpl(conf);
+
+ when(ozoneManager.getMetadataManager()).thenReturn(omMetadataManager);
+
when(ozoneManagerRatisServer.getOzoneManager()).thenReturn(ozoneManager);
when(ozoneManager.getSnapshotInfo()).thenReturn(
Mockito.mock(OMRatisSnapshotInfo.class));
ozoneManagerStateMachine =
new OzoneManagerStateMachine(ozoneManagerRatisServer, false);
+ ozoneManagerStateMachine.notifyIndexUpdate(0, 0);
}
@Test
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]