This is an automated email from the ASF dual-hosted git repository.
smengcl pushed a commit to branch ozone-2.2
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/ozone-2.2 by this push:
new c8f5a03eeb8 HDDS-17144. ozone repair tools fail to load RocksDB
OPTIONS written by a newer RocksDB version (#11632)
c8f5a03eeb8 is described below
commit c8f5a03eeb84793b21e7db6e2e060a2c301df3a8
Author: Siyao Meng <[email protected]>
AuthorDate: Tue Oct 20 20:08:46 2026 -0700
HDDS-17144. ozone repair tools fail to load RocksDB OPTIONS written by a
newer RocksDB version (#11632)
Co-authored-by: Claude Opus 5.5 <[email protected]>
(cherry picked from commit df04bc0e309f625a7dcdcd60790a42f34e2743d9)
---
.../hdds/utils/db/managed/ManagedRocksDB.java | 6 +-
.../hdds/utils/db/managed/TestManagedRocksDB.java | 126 +++++++++++++++++++++
2 files changed, 131 insertions(+), 1 deletion(-)
diff --git
a/hadoop-hdds/managed-rocksdb/src/main/java/org/apache/hadoop/hdds/utils/db/managed/ManagedRocksDB.java
b/hadoop-hdds/managed-rocksdb/src/main/java/org/apache/hadoop/hdds/utils/db/managed/ManagedRocksDB.java
index 3401469f682..dc34a811aca 100644
---
a/hadoop-hdds/managed-rocksdb/src/main/java/org/apache/hadoop/hdds/utils/db/managed/ManagedRocksDB.java
+++
b/hadoop-hdds/managed-rocksdb/src/main/java/org/apache/hadoop/hdds/utils/db/managed/ManagedRocksDB.java
@@ -90,7 +90,10 @@ public static ManagedRocksDB open(
* Open a RocksDB option with the latest options. Other than {@link
ManagedConfigOptions} and
* path, the other options and handles should be empty since it will be
populated with
* loadLatestOptions. Nevertheless, the caller is still responsible in
cleaning up / closing the resources.
- * @param configOptions Config options.
+ * <p>
+ * Unknown options are ignored if the OPTIONS file was written by a newer
RocksDB version, e.g. after a downgrade.
+ * RocksDB still rejects unknown options in OPTIONS files written by the
same or an older version.
+ * @param configOptions Config options. {@code ignore_unknown_options} is
set to true.
* @param options DBOptions. This would be modified based on the latest
options.
* @param path DB path.
* @param columnFamilyDescriptors Column family descriptors. These would be
modified based on the latest options.
@@ -104,6 +107,7 @@ public static ManagedRocksDB openWithLatestOptions(
final List<ColumnFamilyDescriptor> columnFamilyDescriptors,
final List<ColumnFamilyHandle> columnFamilyHandles)
throws RocksDBException {
+ configOptions.setIgnoreUnknownOptions(true);
// Preserve all the previous DB options
OptionsUtil.loadLatestOptions(configOptions, path, options,
columnFamilyDescriptors);
return new ManagedRocksDB(
diff --git
a/hadoop-hdds/managed-rocksdb/src/test/java/org/apache/hadoop/hdds/utils/db/managed/TestManagedRocksDB.java
b/hadoop-hdds/managed-rocksdb/src/test/java/org/apache/hadoop/hdds/utils/db/managed/TestManagedRocksDB.java
new file mode 100644
index 00000000000..8ed058a8000
--- /dev/null
+++
b/hadoop-hdds/managed-rocksdb/src/test/java/org/apache/hadoop/hdds/utils/db/managed/TestManagedRocksDB.java
@@ -0,0 +1,126 @@
+/*
+ * 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.managed;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Stream;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+import org.rocksdb.ColumnFamilyDescriptor;
+import org.rocksdb.ColumnFamilyHandle;
+import org.rocksdb.RocksDB;
+import org.rocksdb.RocksDBException;
+
+/**
+ * Tests for {@link ManagedRocksDB#openWithLatestOptions}.
+ */
+public class TestManagedRocksDB {
+ static {
+ ManagedRocksObjectUtils.loadRocksDBLibrary();
+ }
+
+ private static final byte[] KEY = "key".getBytes(UTF_8);
+ private static final byte[] VALUE = "value".getBytes(UTF_8);
+
+ @Test
+ public void testOpenWithOptionsFromNewerRocksDBVersion(@TempDir Path dir)
throws Exception {
+ createDB(dir);
+ // Simulate an OPTIONS file written by a newer RocksDB, e.g. after a
downgrade.
+ addUnknownOptionToLatestOptionsFile(dir, true);
+
+ List<ColumnFamilyDescriptor> descriptors = new ArrayList<>();
+ List<ColumnFamilyHandle> handles = new ArrayList<>();
+ try (ManagedConfigOptions configOptions = new ManagedConfigOptions();
+ ManagedDBOptions dbOptions = new ManagedDBOptions();
+ ManagedRocksDB db = ManagedRocksDB.openWithLatestOptions(
+ configOptions, dbOptions, dir.toString(), descriptors, handles)) {
+ try {
+ assertArrayEquals(VALUE, db.get().get(KEY));
+ } finally {
+ handles.forEach(ColumnFamilyHandle::close);
+ }
+ } finally {
+ descriptors.forEach(d -> d.getOptions().close());
+ }
+ }
+
+ @Test
+ public void testOpenWithUnknownOptionFromSameRocksDBVersion(@TempDir Path
dir) throws Exception {
+ createDB(dir);
+ // An unknown option in an OPTIONS file from the same RocksDB version
still means corruption.
+ addUnknownOptionToLatestOptionsFile(dir, false);
+
+ List<ColumnFamilyDescriptor> descriptors = new ArrayList<>();
+ try (ManagedConfigOptions configOptions = new ManagedConfigOptions();
+ ManagedDBOptions dbOptions = new ManagedDBOptions()) {
+ assertThrows(RocksDBException.class, () ->
ManagedRocksDB.openWithLatestOptions(
+ configOptions, dbOptions, dir.toString(), descriptors, new
ArrayList<>()));
+ } finally {
+ descriptors.forEach(d -> d.getOptions().close());
+ }
+ }
+
+ private static void createDB(Path dir) throws RocksDBException {
+ List<ColumnFamilyHandle> handles = new ArrayList<>();
+ try (ManagedColumnFamilyOptions cfOptions = new
ManagedColumnFamilyOptions();
+ ManagedDBOptions dbOptions = new ManagedDBOptions()) {
+ dbOptions.setCreateIfMissing(true);
+ try (ManagedRocksDB db = ManagedRocksDB.open(dbOptions, dir.toString(),
+ Collections.singletonList(new
ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY, cfOptions)), handles)) {
+ try {
+ db.get().put(KEY, VALUE);
+ } finally {
+ handles.forEach(ColumnFamilyHandle::close);
+ }
+ }
+ }
+ }
+
+ /**
+ * Adds an unknown option to the default column family in the latest OPTIONS
file.
+ * If {@code newerVersion}, also marks the file as written by RocksDB 99.0.0.
+ */
+ private static void addUnknownOptionToLatestOptionsFile(Path dir, boolean
newerVersion) throws IOException {
+ Path optionsFile;
+ try (Stream<Path> files = Files.list(dir)) {
+ optionsFile = files.filter(p ->
p.getFileName().toString().matches("OPTIONS-[0-9]+"))
+ .max(Path::compareTo)
+ .orElseThrow(() -> new IOException("No OPTIONS file in " + dir));
+ }
+ List<String> lines = new ArrayList<>();
+ for (String line : Files.readAllLines(optionsFile, UTF_8)) {
+ if (newerVersion && line.trim().startsWith("rocksdb_version=")) {
+ line = " rocksdb_version=99.0.0";
+ }
+ lines.add(line);
+ if (line.startsWith("[CFOptions \"default\"]")) {
+ lines.add(" option_from_a_newer_rocksdb=1");
+ }
+ }
+ Files.write(optionsFile, lines, UTF_8);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]