This is an automated email from the ASF dual-hosted git repository.
adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new 7212465c0bb HDDS-8271. Do not close OM DB when a WAL file vanishes
during getUpdatesSince (#11709)
7212465c0bb is described below
commit 7212465c0bb19615708c144238317db51c2a696d
Author: Aleksei Ieshin <[email protected]>
AuthorDate: Sat Oct 24 18:32:52 2026 +1100
HDDS-8271. Do not close OM DB when a WAL file vanishes during
getUpdatesSince (#11709)
---
.../apache/hadoop/hdds/utils/db/RocksDatabase.java | 45 +++++-
.../utils/db/TestRocksDatabaseGetUpdatesSince.java | 164 +++++++++++++++++++++
2 files changed, 207 insertions(+), 2 deletions(-)
diff --git
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RocksDatabase.java
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RocksDatabase.java
index 635efd584aa..e7db2cf635d 100644
---
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RocksDatabase.java
+++
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RocksDatabase.java
@@ -39,6 +39,7 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Supplier;
+import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.hadoop.hdds.StringUtils;
@@ -77,6 +78,8 @@
public final class RocksDatabase implements Closeable {
static final Logger LOG = LoggerFactory.getLogger(RocksDatabase.class);
+ private static final Pattern VANISHED_WAL_FILE =
Pattern.compile("/\\d+\\.log: No such file or directory");
+
public static final String ESTIMATE_NUM_KEYS = "rocksdb.estimate-num-keys";
static {
@@ -780,13 +783,51 @@ public String getProperty(ColumnFamily family, String key)
public ManagedTransactionLogIterator getUpdatesSince(long sequenceNumber)
throws RocksDatabaseException {
try (UncheckedAutoCloseable ignored = acquire()) {
- return managed(db.get().getUpdatesSince(sequenceNumber));
+ return getUpdatesSinceRetryingWalRace(sequenceNumber);
} catch (RocksDBException e) {
- closeOnError(e);
+ if (!isVanishedWalFile(e)) {
+ closeOnError(e);
+ }
throw toRocksDatabaseException(this, "getUpdatesSince " +
sequenceNumber, e);
}
}
+ private ManagedTransactionLogIterator getUpdatesSinceRetryingWalRace(long
sequenceNumber)
+ throws RocksDBException {
+ try {
+ return getUpdatesSinceFromRocksDB(sequenceNumber);
+ } catch (RocksDBException e) {
+ if (!isVanishedWalFile(e)) {
+ throw e;
+ }
+ LOG.warn("getUpdatesSince {} raced with WAL archive/purge, retrying
once", sequenceNumber, e);
+ return getUpdatesSinceFromRocksDB(sequenceNumber);
+ }
+ }
+
+ @VisibleForTesting
+ ManagedTransactionLogIterator getUpdatesSinceFromRocksDB(long
sequenceNumber) throws RocksDBException {
+ return managed(db.get().getUpdatesSince(sequenceNumber));
+ }
+
+ /**
+ * A WAL file was archived or purged while RocksDB was listing or opening
it; this does not affect recovery.
+ * The message is matched because rocksdbjni's Status.SubCode has no
PathNotFound.
+ */
+ @VisibleForTesting
+ static boolean isVanishedWalFile(RocksDBException e) {
+ if (e.getStatus() == null) {
+ return false;
+ }
+ switch (e.getStatus().getCode()) {
+ case IOError:
+ final String state = e.getStatus().getState();
+ return state != null && VANISHED_WAL_FILE.matcher(state).find();
+ default:
+ return false;
+ }
+ }
+
public long getLatestSequenceNumber() throws RocksDatabaseException {
try (UncheckedAutoCloseable ignored = acquire()) {
return db.get().getLatestSequenceNumber();
diff --git
a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestRocksDatabaseGetUpdatesSince.java
b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestRocksDatabaseGetUpdatesSince.java
new file mode 100644
index 00000000000..0997b019255
--- /dev/null
+++
b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestRocksDatabaseGetUpdatesSince.java
@@ -0,0 +1,164 @@
+/*
+ * 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.hadoop.hdds.utils.db;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.Mockito.doCallRealMethod;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import java.io.File;
+import java.util.Collections;
+import java.util.stream.Stream;
+import org.apache.hadoop.hdds.StringUtils;
+import org.apache.hadoop.hdds.utils.db.managed.ManagedColumnFamilyOptions;
+import org.apache.hadoop.hdds.utils.db.managed.ManagedTransactionLogIterator;
+import org.apache.hadoop.hdds.utils.db.managed.ManagedWriteOptions;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.rocksdb.RocksDB;
+import org.rocksdb.RocksDBException;
+import org.rocksdb.Status;
+
+/**
+ * Tests that {@link RocksDatabase#getUpdatesSince(long)} does not close the DB
+ * when a WAL file vanishes while RocksDB lists or opens the WALs (HDDS-8271).
+ */
+public class TestRocksDatabaseGetUpdatesSince {
+
+ private static final String ARCHIVED_WAL_VANISHED =
+ "while stat a file for size: /data/om/db/om.db/archive/000123.log: No
such file or directory";
+ private static final String LIVE_WAL_VANISHED =
+ "while stat a file for size: /data/om/db/om.db/000123.log: No such file
or directory";
+ private static final String ARCHIVED_WAL_VANISHED_ON_OPEN =
+ "While opening a file for sequentially reading:
/data/om/db/om.db/archive/000123.log: No such file or directory";
+
+ private TableConfig defaultTable;
+ private RocksDatabase db;
+
+ @BeforeEach
+ public void setUp(@TempDir File tempDir) throws Exception {
+ defaultTable = new
TableConfig(StringUtils.bytes2String(RocksDB.DEFAULT_COLUMN_FAMILY),
+ new ManagedColumnFamilyOptions());
+ db = spy(RocksDatabase.open(tempDir, TestRDBStore.newManagedDBOptions(),
new ManagedWriteOptions(),
+ Collections.singleton(defaultTable), false));
+ }
+
+ @AfterEach
+ public void tearDown() {
+ db.close();
+ defaultTable.close();
+ }
+
+ static Stream<RocksDBException> vanishedWalErrors() {
+ return Stream.of(ARCHIVED_WAL_VANISHED, LIVE_WAL_VANISHED,
ARCHIVED_WAL_VANISHED_ON_OPEN)
+ .map(TestRocksDatabaseGetUpdatesSince::ioError);
+ }
+
+ static Stream<RocksDBException> otherErrors() {
+ return Stream.concat(
+ Stream.of(
+ "while stat a file for size: /data/om/db/om.db/000123.log:
Input/output error",
+ "While appending to file: /data/om/db/om.db/000123.log: No space
left on device",
+ "while stat a file for size: /data/om/db/om.db/000123.sst: No such
file or directory",
+ "While opening a file for sequentially reading:
/data/om/db/om.db/MANIFEST-000001: "
+ + "No such file or directory",
+ "While opening a file for sequentially reading:
/data/om/db/om.db/archive/000123.log: Permission denied")
+ .map(TestRocksDatabaseGetUpdatesSince::ioError),
+ Stream.of(ARCHIVED_WAL_VANISHED, LIVE_WAL_VANISHED,
ARCHIVED_WAL_VANISHED_ON_OPEN)
+ .map(message -> rocksDBException(Status.Code.Corruption,
message)));
+ }
+
+ @ParameterizedTest
+ @MethodSource("vanishedWalErrors")
+ public void classifiesVanishedWal(RocksDBException e) {
+ assertTrue(RocksDatabase.isVanishedWalFile(e));
+ }
+
+ @ParameterizedTest
+ @MethodSource("otherErrors")
+ public void doesNotClassifyOtherErrors(RocksDBException e) {
+ assertFalse(RocksDatabase.isVanishedWalFile(e));
+ }
+
+ @Test
+ public void doesNotClassifyMissingStatus() {
+ assertFalse(RocksDatabase.isVanishedWalFile(new
RocksDBException(ARCHIVED_WAL_VANISHED)));
+ }
+
+ @ParameterizedTest
+ @MethodSource("vanishedWalErrors")
+ public void retriesOnceAndKeepsDbOpenWhenWalVanishes(RocksDBException e)
throws Exception {
+
doThrow(e).doCallRealMethod().when(db).getUpdatesSinceFromRocksDB(anyLong());
+
+ try (ManagedTransactionLogIterator iterator = db.getUpdatesSince(0)) {
+ assertNotNull(iterator);
+ }
+ assertFalse(db.isClosed());
+ verify(db, times(2)).getUpdatesSinceFromRocksDB(0);
+ }
+
+ @ParameterizedTest
+ @MethodSource("vanishedWalErrors")
+ public void keepsDbOpenWhenRetryFailsTheSameWay(RocksDBException e) throws
Exception {
+ doThrow(e).when(db).getUpdatesSinceFromRocksDB(anyLong());
+
+ assertThrows(RocksDatabaseException.class, () -> db.getUpdatesSince(0));
+ assertFalse(db.isClosed());
+ verify(db, times(2)).getUpdatesSinceFromRocksDB(0);
+ }
+
+ @ParameterizedTest
+ @MethodSource("otherErrors")
+ public void closesDbWithoutRetryOnOtherErrors(RocksDBException e) throws
Exception {
+ doThrow(e).when(db).getUpdatesSinceFromRocksDB(anyLong());
+
+ assertThrows(RocksDatabaseException.class, () -> db.getUpdatesSince(0));
+ assertTrue(db.isClosed());
+ verify(db, times(1)).getUpdatesSinceFromRocksDB(0);
+ }
+
+ @Test
+ public void doesNotRetryWhenRocksDBSucceeds() throws Exception {
+ doCallRealMethod().when(db).getUpdatesSinceFromRocksDB(anyLong());
+
+ try (ManagedTransactionLogIterator iterator = db.getUpdatesSince(0)) {
+ assertNotNull(iterator);
+ }
+ assertFalse(db.isClosed());
+ verify(db, times(1)).getUpdatesSinceFromRocksDB(0);
+ }
+
+ private static RocksDBException ioError(String message) {
+ return rocksDBException(Status.Code.IOError, message);
+ }
+
+ private static RocksDBException rocksDBException(Status.Code code, String
message) {
+ return new RocksDBException(message, new Status(code, Status.SubCode.None,
message));
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]