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 9cecdf6e9b6 HDDS-16668. Migrate Recon SQL DB from Derby to SQLite
(#11650)
9cecdf6e9b6 is described below
commit 9cecdf6e9b6bc58fa8304aaf766dcd815b3493e6
Author: Siyao Meng <[email protected]>
AuthorDate: Sun Nov 15 13:00:18 2026 -0800
HDDS-16668. Migrate Recon SQL DB from Derby to SQLite (#11650)
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.../common/src/main/resources/ozone-default.xml | 5 +-
.../hadoop/ozone/local/LocalOzoneCluster.java | 5 -
hadoop-ozone/dist/src/main/license/bin/LICENSE.txt | 1 -
hadoop-ozone/dist/src/main/license/jar-report.txt | 1 -
.../apache/hadoop/ozone/recon/ReconService.java | 5 -
.../TestReconContainerHealthSummaryEndToEnd.java | 6 +-
.../ozone/recon/TestReconWithOzoneManager.java | 34 +++++-
hadoop-ozone/recon-codegen/pom.xml | 8 +-
.../ozone/recon/codegen/JooqCodeGenerator.java | 27 ++---
.../recon/schema/ContainerSchemaDefinition.java | 6 +-
.../recon/schema/SchemaVersionTableDefinition.java | 8 +-
.../org/apache/ozone/recon/schema/SqlDbUtils.java | 70 +++--------
hadoop-ozone/recon/pom.xml | 4 -
.../hadoop/ozone/recon/ReconControllerModule.java | 7 ++
.../hadoop/ozone/recon/ReconSchemaManager.java | 11 +-
.../org/apache/hadoop/ozone/recon/ReconServer.java | 14 ++-
.../hadoop/ozone/recon/ReconSqlDbConfig.java | 16 ++-
.../persistence/ContainerHealthSchemaManager.java | 37 +++---
.../persistence/DefaultDataSourceProvider.java | 4 +-
.../recon/persistence/DerbyDataSourceProvider.java | 59 ----------
.../recon/persistence/JooqPersistenceModule.java | 2 +-
.../recon/tasks/ContainerKeyMapperHelper.java | 2 +-
.../apache/hadoop/ozone/recon/TestReconUtils.java | 15 +++
.../recon/persistence/AbstractReconSqlDBTest.java | 20 ++--
.../TestReconInternalSchemaDefinition.java | 5 +-
.../persistence/TestReconWithDifferentSqlDBs.java | 85 +-------------
.../TestSchemaVersionTableDefinition.java | 7 +-
.../persistence/TestStatsSchemaDefinition.java | 9 +-
... TestUnhealthyContainersSqlitePerformance.java} | 128 +++------------------
.../TestUtilizationSchemaDefinition.java | 19 +--
.../TestReconTaskStatusTableUpgradeAction.java | 7 +-
.../recon/upgrade/TestReconVersionManager.java | 2 +-
pom.xml | 6 -
33 files changed, 199 insertions(+), 436 deletions(-)
diff --git a/hadoop-hdds/common/src/main/resources/ozone-default.xml
b/hadoop-hdds/common/src/main/resources/ozone-default.xml
index 01ed7033d77..8b7ea051231 100644
--- a/hadoop-hdds/common/src/main/resources/ozone-default.xml
+++ b/hadoop-hdds/common/src/main/resources/ozone-default.xml
@@ -3577,9 +3577,10 @@
<value>10000</value>
<tag>OZONE, RECON</tag>
<description>
- Number of rows Derby returns per JDBC round-trip when streaming unhealthy
+ Number of rows the Recon SQL DB returns per JDBC round-trip when
streaming unhealthy
container records during a CSV export. Higher values reduce round-trip
overhead at the cost of slightly more memory per fetch batch.
+ SQLite, the default Recon SQL DB, ignores this setting.
</description>
</property>
<property>
@@ -4757,7 +4758,7 @@
<tag>OZONE, RECON, PERFORMANCE</tag>
<description>
Maximum threshold number of entries to hold in memory for File Size
Count task in hashmap before flushing to
- recon derby DB
+ Recon DB
</description>
</property>
diff --git
a/hadoop-ozone/cli-local/src/main/java/org/apache/hadoop/ozone/local/LocalOzoneCluster.java
b/hadoop-ozone/cli-local/src/main/java/org/apache/hadoop/ozone/local/LocalOzoneCluster.java
index 55255115254..14e34e74285 100644
---
a/hadoop-ozone/cli-local/src/main/java/org/apache/hadoop/ozone/local/LocalOzoneCluster.java
+++
b/hadoop-ozone/cli-local/src/main/java/org/apache/hadoop/ozone/local/LocalOzoneCluster.java
@@ -145,7 +145,6 @@
import org.apache.hadoop.ozone.om.OzoneManager;
import org.apache.hadoop.ozone.recon.ConfigurationProvider;
import org.apache.hadoop.ozone.recon.ReconServer;
-import org.apache.hadoop.ozone.recon.ReconSqlDbConfig;
import org.apache.hadoop.ozone.s3.Gateway;
import org.apache.hadoop.ozone.s3.OzoneConfigurationHolder;
import org.apache.ratis.util.function.CheckedSupplier;
@@ -747,10 +746,6 @@ private int configureRecon(OzoneConfiguration conf,
PersistedPortState persisted
conf.setIfUnset(OZONE_RECON_OM_SNAPSHOT_DB_DIR, reconDir.toString());
conf.setIfUnset(OZONE_RECON_SCM_DB_DIR, reconDir.toString());
- ReconSqlDbConfig dbConfig = conf.getObject(ReconSqlDbConfig.class);
- dbConfig.setJdbcUrl("jdbc:derby:" +
reconDir.resolve("ozone_recon_derby.db"));
- conf.setFromObject(dbConfig);
-
int reconHttpPort = reservePort(portAllocator, persistedPorts,
RECON_HTTP_PORT_KEY, config.getReconPort());
int reconHttpsPort = reservePort(portAllocator, persistedPorts,
RECON_HTTPS_PORT_KEY, 0);
int reconDatanodePort = reservePort(portAllocator, persistedPorts,
RECON_DATANODE_PORT_KEY, 0);
diff --git a/hadoop-ozone/dist/src/main/license/bin/LICENSE.txt
b/hadoop-ozone/dist/src/main/license/bin/LICENSE.txt
index adb097bfa2b..fcd75355c5e 100644
--- a/hadoop-ozone/dist/src/main/license/bin/LICENSE.txt
+++ b/hadoop-ozone/dist/src/main/license/bin/LICENSE.txt
@@ -362,7 +362,6 @@ Apache License 2.0
org.apache.commons:commons-text
org.apache.curator:curator-client
org.apache.curator:curator-framework
- org.apache.derby:derby
org.apache.hadoop:hadoop-annotations
org.apache.hadoop:hadoop-auth
org.apache.hadoop:hadoop-common
diff --git a/hadoop-ozone/dist/src/main/license/jar-report.txt
b/hadoop-ozone/dist/src/main/license/jar-report.txt
index b0ea8913455..78777d220d1 100644
--- a/hadoop-ozone/dist/src/main/license/jar-report.txt
+++ b/hadoop-ozone/dist/src/main/license/jar-report.txt
@@ -36,7 +36,6 @@ share/ozone/lib/commons-validator.jar
share/ozone/lib/converter-jackson.jar
share/ozone/lib/curator-client.jar
share/ozone/lib/curator-framework.jar
-share/ozone/lib/derby.jar
share/ozone/lib/disruptor.jar
share/ozone/lib/dnsjava.jar
share/ozone/lib/error_prone_annotations.jar
diff --git
a/hadoop-ozone/integration-test-recon/src/test/java/org/apache/hadoop/ozone/recon/ReconService.java
b/hadoop-ozone/integration-test-recon/src/test/java/org/apache/hadoop/ozone/recon/ReconService.java
index bedfb70e457..b51a3462f4c 100644
---
a/hadoop-ozone/integration-test-recon/src/test/java/org/apache/hadoop/ozone/recon/ReconService.java
+++
b/hadoop-ozone/integration-test-recon/src/test/java/org/apache/hadoop/ozone/recon/ReconService.java
@@ -90,11 +90,6 @@ private void configureRecon(OzoneConfiguration conf) {
conf.set(OZONE_RECON_OM_SNAPSHOT_DB_DIR, dir.getAbsolutePath());
conf.set(OZONE_RECON_SCM_DB_DIR, dir.getAbsolutePath());
- ReconSqlDbConfig dbConfig = conf.getObject(ReconSqlDbConfig.class);
- dbConfig.setJdbcUrl("jdbc:derby:" + dir.getAbsolutePath()
- + "/ozone_recon_derby.db");
- conf.setFromObject(dbConfig);
-
conf.set(OZONE_RECON_TASK_SAFEMODE_WAIT_THRESHOLD, "10s");
setReconAddress(conf);
diff --git
a/hadoop-ozone/integration-test-recon/src/test/java/org/apache/hadoop/ozone/recon/TestReconContainerHealthSummaryEndToEnd.java
b/hadoop-ozone/integration-test-recon/src/test/java/org/apache/hadoop/ozone/recon/TestReconContainerHealthSummaryEndToEnd.java
index af60f46a60b..d61d0256de2 100644
---
a/hadoop-ozone/integration-test-recon/src/test/java/org/apache/hadoop/ozone/recon/TestReconContainerHealthSummaryEndToEnd.java
+++
b/hadoop-ozone/integration-test-recon/src/test/java/org/apache/hadoop/ozone/recon/TestReconContainerHealthSummaryEndToEnd.java
@@ -76,7 +76,7 @@
* <ol>
* <li><b>Container State Summary</b> — per lifecycle-state counts (OPEN,
CLOSING,
* QUASI_CLOSED, CLOSED) are identical between SCM and Recon after a
full sync.</li>
- * <li><b>Container Health Summary</b> — UNHEALTHY_CONTAINERS derby table
counts in
+ * <li><b>Container Health Summary</b> — UNHEALTHY_CONTAINERS SQL table
counts in
* Recon match exactly the health states classified by SCM's
ReplicationManager
* after both process the same container replica state.</li>
* </ol>
@@ -312,7 +312,7 @@ public void
testContainerStateSummaryMatchesBetweenSCMAndRecon()
/**
* Validates that Container Health Summary counts match exactly between SCM's
- * {@link ReplicationManagerReport} and Recon's UNHEALTHY_CONTAINERS derby
+ * {@link ReplicationManagerReport} and Recon's UNHEALTHY_CONTAINERS SQL
* table after both process the same injected container states.
*
* <p>The test also explicitly validates the lifecycle-state boundary that
@@ -361,7 +361,7 @@ public void
testContainerHealthSummaryMatchesBetweenSCMAndRecon()
ReplicationManagerReport scmReport =
scm.getReplicationManager().getContainerReport();
- // Run Recon RM (writes to UNHEALTHY_CONTAINERS derby table).
+ // Run Recon RM (writes to UNHEALTHY_CONTAINERS SQL table).
reconScm.getReplicationManager().processAll();
ReconHealthRecords records = loadReconHealthRecords(reconCm);
diff --git
a/hadoop-ozone/integration-test-recon/src/test/java/org/apache/hadoop/ozone/recon/TestReconWithOzoneManager.java
b/hadoop-ozone/integration-test-recon/src/test/java/org/apache/hadoop/ozone/recon/TestReconWithOzoneManager.java
index 44e8c8f2296..89d011db890 100644
---
a/hadoop-ozone/integration-test-recon/src/test/java/org/apache/hadoop/ozone/recon/TestReconWithOzoneManager.java
+++
b/hadoop-ozone/integration-test-recon/src/test/java/org/apache/hadoop/ozone/recon/TestReconWithOzoneManager.java
@@ -30,7 +30,6 @@
import static
org.apache.hadoop.ozone.recon.spi.impl.OzoneManagerServiceProviderImpl.OmSnapshotTaskName.OmSnapshotRequest;
import static
org.apache.hadoop.ozone.recon.spi.impl.ReconDBDefinition.REPLICA_HISTORY_V2;
import static
org.apache.hadoop.ozone.recon.spi.impl.ReconReplicaHistoryDBDefinition.METADATA;
-import static
org.apache.ozone.recon.codegen.JooqCodeGenerator.RECON_SCHEMA_NAME;
import static
org.apache.ozone.recon.schema.SchemaVersionTableDefinition.SCHEMA_VERSION_TABLE_NAME;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -40,6 +39,8 @@
import static org.slf4j.event.Level.INFO;
import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
@@ -532,7 +533,7 @@ public void
testReplicaHistoryMigrationOnUpgradeAndRestart() throws Exception {
legacy.flushLog(true);
history.flushLog(true);
}
- try (Connection connection = DriverManager.getConnection(jdbcUrl,
RECON_SCHEMA_NAME, "");
+ try (Connection connection = DriverManager.getConnection(jdbcUrl);
PreparedStatement statement = connection.prepareStatement(
"UPDATE " + SCHEMA_VERSION_TABLE_NAME + " SET
\"version_number\" = ?")) {
statement.setInt(1,
ReconVersion.UNHEALTHY_CONTAINERS_STATE_CONTAINER_ID_INDEX.serialize());
@@ -572,8 +573,35 @@ public void
testReplicaHistoryMigrationOnUpgradeAndRestart() throws Exception {
}
}
+ @Test
+ public void testUpgradeActionsRunOnNewSqlDbForExistingInstall() throws
Exception {
+ OzoneConfiguration conf = cluster.getConf();
+ String jdbcUrl = ReconGuiceServletContextListener.getGlobalInjector()
+ .getInstance(DataSourceConfiguration.class).getJdbcUrl();
+ String sqlDbFile = jdbcUrl.substring("jdbc:sqlite:".length());
+
+ try (LogCapturer logs =
LogCapturer.captureLogs(LoggerFactory.getLogger("org.apache"))) {
+ recon.stop();
+ // Same as the first start after the move from Derby: Recon is
initialized, but its SQL DB is new.
+ for (String suffix : new String[] {"", "-wal", "-shm"}) {
+ Files.deleteIfExists(Paths.get(sqlDbFile + suffix));
+ }
+
+ logs.clearOutput();
+ recon.start(conf);
+ assertEquals(ReconVersion.SOFTWARE_VERSION.serialize(),
getReconSchemaVersion(jdbcUrl));
+ assertThat(logs.getOutput())
+ .contains("Inserted initial apparent version '" +
ReconVersion.INITIAL_VERSION.serialize() + "'")
+ .contains("Updated apparent version to '" +
ReconVersion.TASK_STATUS_STATISTICS.serialize() + "'.");
+ } finally {
+ if (recon.getReconServer() == null) {
+ recon.start(conf);
+ }
+ }
+ }
+
private int getReconSchemaVersion(String jdbcUrl) throws SQLException {
- try (Connection connection = DriverManager.getConnection(jdbcUrl,
RECON_SCHEMA_NAME, "");
+ try (Connection connection = DriverManager.getConnection(jdbcUrl);
PreparedStatement statement = connection.prepareStatement(
"SELECT \"version_number\" FROM " + SCHEMA_VERSION_TABLE_NAME);
ResultSet result = statement.executeQuery()) {
diff --git a/hadoop-ozone/recon-codegen/pom.xml
b/hadoop-ozone/recon-codegen/pom.xml
index 86934c2e07a..a1e73c6ac2b 100644
--- a/hadoop-ozone/recon-codegen/pom.xml
+++ b/hadoop-ozone/recon-codegen/pom.xml
@@ -35,10 +35,6 @@
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
- <dependency>
- <groupId>org.apache.derby</groupId>
- <artifactId>derby</artifactId>
- </dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
@@ -63,6 +59,10 @@
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.xerial</groupId>
+ <artifactId>sqlite-jdbc</artifactId>
+ </dependency>
</dependencies>
<build>
diff --git
a/hadoop-ozone/recon-codegen/src/main/java/org/apache/ozone/recon/codegen/JooqCodeGenerator.java
b/hadoop-ozone/recon-codegen/src/main/java/org/apache/ozone/recon/codegen/JooqCodeGenerator.java
index 123dd97db1d..dd51c001cf1 100644
---
a/hadoop-ozone/recon-codegen/src/main/java/org/apache/ozone/recon/codegen/JooqCodeGenerator.java
+++
b/hadoop-ozone/recon-codegen/src/main/java/org/apache/ozone/recon/codegen/JooqCodeGenerator.java
@@ -28,7 +28,6 @@
import java.util.Set;
import javax.sql.DataSource;
import org.apache.commons.io.FileUtils;
-import org.apache.derby.jdbc.EmbeddedDataSource;
import org.apache.hadoop.util.Time;
import org.apache.ozone.recon.schema.ReconSchemaDefinition;
import org.apache.ozone.recon.schema.ReconSchemaGenerationModule;
@@ -44,6 +43,7 @@
import org.jooq.meta.jaxb.Target;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.sqlite.SQLiteDataSource;
/**
* Utility class that generates the Dao and Pojos for Recon schema. The
@@ -59,9 +59,8 @@ public class JooqCodeGenerator {
private static final String DB = Paths.get(
System.getProperty("java.io.tmpdir"),
- "recon-generated-schema-" + Time.monotonicNow()).toString();
- public static final String RECON_SCHEMA_NAME = "RECON";
- private static final String JDBC_URL = "jdbc:derby:" + DB;
+ "recon-generated-schema-" + Time.monotonicNow() + ".db").toString();
+ private static final String JDBC_URL = "jdbc:sqlite:" + DB;
private final Set<ReconSchemaDefinition> allDefinitions;
@Inject
@@ -85,15 +84,14 @@ private void generateSourceCode(String outputDir) throws
Exception {
Configuration configuration =
new Configuration()
.withJdbc(new Jdbc()
- .withDriver(SqlDbUtils.DERBY_DRIVER_CLASS)
+ .withDriver(SqlDbUtils.SQLITE_DRIVER_CLASS)
.withUrl(JDBC_URL))
.withGenerator(new Generator()
.withDatabase(new Database()
- .withName("org.jooq.meta.derby.DerbyDatabase")
+ .withName("org.jooq.meta.sqlite.SQLiteDatabase")
.withOutputSchemaToDefault(true)
.withIncludeTables(true)
- .withIncludePrimaryKeys(true)
- .withInputSchema(RECON_SCHEMA_NAME))
+ .withIncludePrimaryKeys(true))
.withGenerate(new Generate()
.withDaos(true)
.withEmptyCatalogs(true))
@@ -111,22 +109,15 @@ private void generateSourceCode(String outputDir) throws
Exception {
* Provider for embedded datasource.
*/
static class LocalDataSourceProvider implements Provider<DataSource> {
- private static EmbeddedDataSource dataSource;
+ private static final SQLiteDataSource DATA_SOURCE = new SQLiteDataSource();
static {
- try {
- SqlDbUtils.createNewDerbyDatabase(JDBC_URL, RECON_SCHEMA_NAME);
- } catch (Exception e) {
- LOG.error("Error creating Recon Derby DB.", e);
- }
- dataSource = new EmbeddedDataSource();
- dataSource.setDatabaseName(DB);
- dataSource.setUser(RECON_SCHEMA_NAME);
+ DATA_SOURCE.setUrl(JDBC_URL);
}
@Override
public DataSource get() {
- return dataSource;
+ return DATA_SOURCE;
}
static void cleanup() {
diff --git
a/hadoop-ozone/recon-codegen/src/main/java/org/apache/ozone/recon/schema/ContainerSchemaDefinition.java
b/hadoop-ozone/recon-codegen/src/main/java/org/apache/ozone/recon/schema/ContainerSchemaDefinition.java
index 4f1d6fcbbf1..eb753742259 100644
---
a/hadoop-ozone/recon-codegen/src/main/java/org/apache/ozone/recon/schema/ContainerSchemaDefinition.java
+++
b/hadoop-ozone/recon-codegen/src/main/java/org/apache/ozone/recon/schema/ContainerSchemaDefinition.java
@@ -88,15 +88,15 @@ private void createUnhealthyContainersTable() {
//
// 1. COUNT(*)/GROUP-BY filtered by state:
// WHERE container_state = ?
- // Derby uses the index prefix (container_state) — same efficiency as
the old
+ // The DB uses the index prefix (container_state) — same efficiency as
the old
// single-column idx_container_state.
//
// 2. Paginated reads filtered by state + cursor:
// WHERE container_state = ? AND container_id > ? ORDER BY
container_id ASC
- // With the old single-column index Derby had to:
+ // With the old single-column index the DB had to:
// a) Scan ALL rows for the state (e.g. 200K), then
// b) Sort them by container_id for every page call — O(n) per page.
- // With this composite index Derby jumps directly to (state, minId) and
reads
+ // With this composite index the DB jumps directly to (state, minId)
and reads
// the next LIMIT entries sequentially — O(1) per page, ~10–14× faster.
dslContext.createIndex("idx_state_container_id")
.on(DSL.table(UNHEALTHY_CONTAINERS_TABLE_NAME),
diff --git
a/hadoop-ozone/recon-codegen/src/main/java/org/apache/ozone/recon/schema/SchemaVersionTableDefinition.java
b/hadoop-ozone/recon-codegen/src/main/java/org/apache/ozone/recon/schema/SchemaVersionTableDefinition.java
index 59de2845e48..0925b82869b 100644
---
a/hadoop-ozone/recon-codegen/src/main/java/org/apache/ozone/recon/schema/SchemaVersionTableDefinition.java
+++
b/hadoop-ozone/recon-codegen/src/main/java/org/apache/ozone/recon/schema/SchemaVersionTableDefinition.java
@@ -42,7 +42,7 @@ public class SchemaVersionTableDefinition implements
ReconSchemaDefinition {
public static final String SCHEMA_VERSION_TABLE_NAME =
"RECON_SCHEMA_VERSION";
private final DataSource dataSource;
- private int softwareVersion;
+ private int freshInstallVersion;
@Inject
public SchemaVersionTableDefinition(DataSource dataSource) {
@@ -61,7 +61,7 @@ public void initializeSchema() throws SQLException {
createSchemaVersionTable(localDslContext);
if (isFreshInstall) {
- insertApparentVersion(localDslContext, softwareVersion);
+ insertApparentVersion(localDslContext, freshInstallVersion);
}
}
}
@@ -88,7 +88,7 @@ private void insertApparentVersion(DSLContext dslContext, int
apparentVersion) {
LOG.info("Inserted initial apparent version '{}' into SchemaVersion
table.", apparentVersion);
}
- public void setSoftwareVersion(int version) {
- this.softwareVersion = version;
+ public void setFreshInstallVersion(int version) {
+ this.freshInstallVersion = version;
}
}
diff --git
a/hadoop-ozone/recon-codegen/src/main/java/org/apache/ozone/recon/schema/SqlDbUtils.java
b/hadoop-ozone/recon-codegen/src/main/java/org/apache/ozone/recon/schema/SqlDbUtils.java
index 5e75bbe9413..5aac1dd5f8e 100644
---
a/hadoop-ozone/recon-codegen/src/main/java/org/apache/ozone/recon/schema/SqlDbUtils.java
+++
b/hadoop-ozone/recon-codegen/src/main/java/org/apache/ozone/recon/schema/SqlDbUtils.java
@@ -19,15 +19,14 @@
import static org.jooq.impl.DSL.count;
-import java.io.IOException;
-import java.io.OutputStream;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
-import java.sql.DriverManager;
+import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
+import java.util.Locale;
import java.util.function.BiPredicate;
import org.jooq.exception.DataAccessException;
import org.jooq.impl.DSL;
@@ -39,11 +38,7 @@
*/
public final class SqlDbUtils {
- public static final String DERBY_DRIVER_CLASS =
- "org.apache.derby.jdbc.EmbeddedDriver";
public static final String SQLITE_DRIVER_CLASS = "org.sqlite.JDBC";
- public static final String DERBY_DISABLE_LOG_METHOD =
- SqlDbUtils.class.getName() + ".disableDerbyLogFile";
private static final Logger LOG =
LoggerFactory.getLogger(SqlDbUtils.class);
@@ -66,38 +61,6 @@ public final class SqlDbUtils {
private SqlDbUtils() {
}
- /**
- * Create new Derby Database with URL and schema name.
- * @param jdbcUrl JDBC url.
- * @param schemaName Schema name
- * @throws ClassNotFoundException on not finding driver class.
- * @throws SQLException on SQL exception.
- */
- public static void createNewDerbyDatabase(String jdbcUrl, String schemaName)
- throws ClassNotFoundException, SQLException {
- System.setProperty("derby.stream.error.method",
- DERBY_DISABLE_LOG_METHOD);
- Class.forName(DERBY_DRIVER_CLASS);
- try (Connection connection = DriverManager.getConnection(jdbcUrl
- + ";user=" + schemaName
- + ";create=true")) {
- LOG.info("Created derby database at {}.", jdbcUrl);
- }
- }
-
- /**
- * Used to suppress embedded derby database logging.
- * @return No-Op output stream.
- */
- public static OutputStream disableDerbyLogFile() {
- return new OutputStream() {
- @Override
- public void write(int b) throws IOException {
- // Ignore all log messages
- }
- };
- }
-
/**
* Utility method to list all user-defined tables in the database.
*
@@ -118,7 +81,7 @@ public static List<String> listAllTables(Connection
connection) throws SQLExcept
}
/**
- * Checks whether a column exists in a Derby table via {@code
SYS.SYSCOLUMNS}.
+ * Checks whether a column exists in a table.
*
* @param conn the database connection
* @param tableName the table name (case-insensitive)
@@ -139,7 +102,7 @@ public static boolean columnExists(Connection conn, String
tableName, String col
}
/**
- * Checks whether a Derby column allows NULL values.
+ * Checks whether a column allows NULL values.
*
* @param conn the database connection
* @param tableName the table name (case-insensitive)
@@ -163,7 +126,8 @@ public static boolean isColumnNullable(Connection conn,
String tableName, String
}
/**
- * Checks whether a named constraint exists on a Derby table.
+ * Checks whether a named constraint exists on a SQLite table. SQLite keeps
+ * constraints only in the table's CREATE statement in {@code sqlite_master}.
*
* @param conn the database connection
* @param tableName the table name (case-insensitive)
@@ -172,23 +136,15 @@ public static boolean isColumnNullable(Connection conn,
String tableName, String
*/
public static boolean constraintExists(Connection conn, String tableName,
String constraintName)
throws SQLException {
- String sql = "SELECT 1 FROM SYS.SYSCONSTRAINTS c "
- + "INNER JOIN SYS.SYSTABLES t ON c.TABLEID = t.TABLEID "
- + "WHERE t.TABLENAME = ? AND c.CONSTRAINTNAME = ?";
- try (java.sql.PreparedStatement ps = conn.prepareStatement(sql)) {
- ps.setString(1, tableName.toUpperCase());
- ps.setString(2, constraintName);
+ String sql = "SELECT sql FROM sqlite_master WHERE type = 'table' AND name
= ? COLLATE NOCASE";
+ try (PreparedStatement ps = conn.prepareStatement(sql)) {
+ ps.setString(1, tableName);
try (ResultSet rs = ps.executeQuery()) {
- if (rs.next()) {
- return true;
+ if (!rs.next()) {
+ return false;
}
- }
- }
- try (java.sql.PreparedStatement ps = conn.prepareStatement(sql)) {
- ps.setString(1, tableName.toUpperCase());
- ps.setString(2, constraintName.toUpperCase());
- try (ResultSet rs = ps.executeQuery()) {
- return rs.next();
+ String createSql = rs.getString(1).replace("\"", "").replace("`",
"").toLowerCase(Locale.ROOT);
+ return createSql.contains("constraint " +
constraintName.toLowerCase(Locale.ROOT) + " ");
}
}
}
diff --git a/hadoop-ozone/recon/pom.xml b/hadoop-ozone/recon/pom.xml
index f5f29eda223..0fc6335d327 100644
--- a/hadoop-ozone/recon/pom.xml
+++ b/hadoop-ozone/recon/pom.xml
@@ -118,10 +118,6 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
- <dependency>
- <groupId>org.apache.derby</groupId>
- <artifactId>derby</artifactId>
- </dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-auth</artifactId>
diff --git
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/ReconControllerModule.java
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/ReconControllerModule.java
index 8347744a969..5b5aca17450 100644
---
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/ReconControllerModule.java
+++
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/ReconControllerModule.java
@@ -231,12 +231,19 @@ StorageContainerLocationInternalInterface getSCMProtocol(
}
@Provides
+ @Singleton
DataSourceConfiguration getDataSourceConfiguration(
final OzoneConfiguration ozoneConfiguration) {
ReconSqlDbConfig sqlDbConfig =
ozoneConfiguration.getObject(ReconSqlDbConfig.class);
+ if (StringUtils.startsWith(sqlDbConfig.getJdbcUrl(), "jdbc:derby:")) {
+ LOG.warn("Derby is no longer supported for the Recon SQL DB. Ignoring
the configured {} and using the SQLite "
+ + "defaults.", sqlDbConfig.getJdbcUrl());
+ sqlDbConfig.setJdbcUrl(ReconSqlDbConfig.DEFAULT_JDBC_URL);
+ }
+
// ${ozone.recon.db.dir} is left unresolved when the key is not set, so
resolve it with the same fallback
// (ozone.metadata.dirs) as the other Recon DBs.
String reconDbDirPlaceholder = "${" + OZONE_RECON_DB_DIR + "}";
diff --git
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/ReconSchemaManager.java
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/ReconSchemaManager.java
index dbfa66551cf..f369c1337da 100644
---
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/ReconSchemaManager.java
+++
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/ReconSchemaManager.java
@@ -44,6 +44,15 @@ public ReconSchemaManager(Set<ReconSchemaDefinition>
reconSchemaDefinitions) {
@VisibleForTesting
public void createReconSchema() {
+ createReconSchema(ReconVersion.SOFTWARE_VERSION);
+ }
+
+ /**
+ * Create the Recon SQL tables.
+ *
+ * @param freshInstallVersion version recorded when the SQL DB is new
+ */
+ public void createReconSchema(ReconVersion freshInstallVersion) {
try {
// Initialize the schema version table first
reconSchemaDefinitions.stream()
@@ -51,7 +60,7 @@ public void createReconSchema() {
.findFirst()
.ifPresent(schemaDefinition -> {
SchemaVersionTableDefinition schemaVersionTable =
(SchemaVersionTableDefinition) schemaDefinition;
-
schemaVersionTable.setSoftwareVersion(ReconVersion.SOFTWARE_VERSION.serialize());
+
schemaVersionTable.setFreshInstallVersion(freshInstallVersion.serialize());
try {
schemaVersionTable.initializeSchema();
} catch (SQLException e) {
diff --git
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/ReconServer.java
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/ReconServer.java
index d015de32dc9..4364ee6ae40 100644
---
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/ReconServer.java
+++
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/ReconServer.java
@@ -23,12 +23,14 @@
import static
org.apache.hadoop.hdds.utils.HddsServerUtil.getScmSecurityClientWithMaxRetry;
import static org.apache.hadoop.ozone.common.Storage.StorageState.INITIALIZED;
import static
org.apache.hadoop.ozone.conf.OzoneServiceConfig.DEFAULT_SHUTDOWN_HOOK_PRIORITY;
+import static
org.apache.hadoop.ozone.recon.ReconServerConfigKeys.OZONE_RECON_DB_DIR;
import static org.apache.hadoop.security.UserGroupInformation.getCurrentUser;
import static org.apache.hadoop.util.ExitUtil.terminate;
import com.google.common.annotations.VisibleForTesting;
import com.google.inject.Guice;
import com.google.inject.Injector;
+import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.concurrent.Callable;
@@ -60,6 +62,7 @@
import org.apache.hadoop.ozone.recon.spi.impl.ReconDBProvider;
import org.apache.hadoop.ozone.recon.spi.impl.ReconReplicaHistoryDBProvider;
import org.apache.hadoop.ozone.recon.tasks.ReconTaskController;
+import org.apache.hadoop.ozone.recon.upgrade.ReconVersion;
import org.apache.hadoop.ozone.recon.upgrade.ReconVersionManager;
import org.apache.hadoop.ozone.upgrade.UpgradeException;
import org.apache.hadoop.ozone.util.OzoneNetUtils;
@@ -138,6 +141,7 @@ public Void call() throws Exception {
ReconGuiceServletContextListener.setInjector(injector);
reconStorage = injector.getInstance(ReconStorageConfig.class);
+ boolean existingInstall = reconStorage.getState() == INITIALIZED;
loginReconUserIfSecurityEnabled(configuration);
@@ -167,7 +171,15 @@ public Void call() throws Exception {
injector.getInstance(ReconSchemaManager.class);
LOG.info("Creating Recon Schema.");
- reconSchemaManager.createReconSchema();
+ // A new SQL DB on an existing Recon (for example after the move from
Derby to SQLite) cannot tell which upgrade
+ // actions the derived data already has, so start from the initial
version to run all of them.
+ ReconVersion newSqlDbVersion = existingInstall ?
ReconVersion.INITIAL_VERSION : ReconVersion.SOFTWARE_VERSION;
+ reconSchemaManager.createReconSchema(newSqlDbVersion);
+ File legacyDerbyDb = new
File(injector.getInstance(ReconUtils.class).getReconDbDir(
+ injector.getInstance(OzoneConfiguration.class), OZONE_RECON_DB_DIR),
ReconSqlDbConfig.LEGACY_DERBY_DB_NAME);
+ if (legacyDerbyDb.exists()) {
+ LOG.info("Recon now uses SQLite. {} is no longer used and can be
deleted.", legacyDerbyDb);
+ }
LOG.debug("Recon schema creation done.");
ReconSafeModeManager reconSafeModeMgr =
injector.getInstance(ReconSafeModeManager.class);
diff --git
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/ReconSqlDbConfig.java
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/ReconSqlDbConfig.java
index e35e2665ecf..29ec0df4221 100644
---
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/ReconSqlDbConfig.java
+++
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/ReconSqlDbConfig.java
@@ -30,17 +30,23 @@
@ConfigGroup(prefix = "ozone.recon.sql.db")
public class ReconSqlDbConfig {
+ public static final String DEFAULT_DRIVER_CLASS = "org.sqlite.JDBC";
+ public static final String DEFAULT_JDBC_URL =
"jdbc:sqlite:${ozone.recon.db.dir}/ozone_recon_sqlite.db";
+ public static final String DEFAULT_SQL_DB_DIALECT = "SQLITE";
+ /** Derby DB written by Recon before the default moved to SQLite. */
+ public static final String LEGACY_DERBY_DB_NAME = "ozone_recon_derby.db";
+
@Config(key = "ozone.recon.sql.db.driver",
type = ConfigType.STRING,
- defaultValue = "org.apache.derby.jdbc.EmbeddedDriver",
+ defaultValue = DEFAULT_DRIVER_CLASS,
tags = {ConfigTag.STORAGE, ConfigTag.RECON, ConfigTag.OZONE},
- description = "Recon SQL DB driver class. Defaults to Derby."
+ description = "Recon SQL DB driver class. Defaults to SQLite."
)
private String driverClass;
@Config(key = "ozone.recon.sql.db.jdbc.url",
type = ConfigType.STRING,
- defaultValue = "jdbc:derby:${ozone.recon.db.dir}/ozone_recon_derby.db",
+ defaultValue = DEFAULT_JDBC_URL,
tags = {ConfigTag.STORAGE, ConfigTag.RECON, ConfigTag.OZONE},
description = "Ozone Recon SQL database jdbc url."
)
@@ -123,10 +129,10 @@ public class ReconSqlDbConfig {
@Config(key = "ozone.recon.sql.db.jooq.dialect",
type = ConfigType.STRING,
- defaultValue = "DERBY",
+ defaultValue = DEFAULT_SQL_DB_DIALECT,
tags = {ConfigTag.STORAGE, ConfigTag.RECON, ConfigTag.OZONE},
description = "Recon internally uses Jooq to talk to its SQL DB. By " +
- "default, we support Derby and Sqlite out of the box. Please refer "
+
+ "default, we support SQLite out of the box. Please refer " +
"to https://www.jooq.org/javadoc/latest/org" +
".jooq/org/jooq/SQLDialect.html to specify different dialect."
)
diff --git
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/persistence/ContainerHealthSchemaManager.java
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/persistence/ContainerHealthSchemaManager.java
index 15d3a1f4425..2e738dc07db 100644
---
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/persistence/ContainerHealthSchemaManager.java
+++
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/persistence/ContainerHealthSchemaManager.java
@@ -59,13 +59,11 @@ public class ContainerHealthSchemaManager {
* Maximum number of container IDs to include in a single
* {@code DELETE … WHERE container_id IN (…)} statement.
*
- * <p>Derby's SQL compiler translates each prepared statement into a Java
- * class. A large IN-predicate generates a deeply nested expression tree
- * whose compiled bytecode can exceed the JVM hard limit of 65,535 bytes
- * per method (ERROR XBCM4). Empirically, 5,000 IDs combined with the
- * 7-state container_state IN-predicate generates ~148 KB — more than
- * twice the limit. 1,000 IDs stays well under ~30 KB, providing a safe
- * 2× margin.</p>
+ * <p>Each ID is a bind parameter, and SQLite rejects a statement with more
+ * than {@code SQLITE_MAX_VARIABLE_NUMBER} parameters (250,000 in the
+ * sqlite-jdbc build). A scan cycle on a large cluster can touch more
+ * containers than that, so the IDs are chunked. 1,000 IDs per statement
+ * stays far below the limit and keeps each statement small.</p>
*/
static final int MAX_IN_CLAUSE_CHUNK_SIZE = 1_000;
@@ -156,12 +154,9 @@ private UnhealthyContainersRecord toJooqRecord(DSLContext
txContext,
* scan cycle (just like the SCM-sourced states); omitting it would leave
* stale REPLICA_MISMATCH records in the table after a mismatch is resolved.
*
- * <p><b>Derby bytecode limit:</b> Derby translates each SQL statement into
- * a Java class whose methods must each stay under the JVM 64 KB bytecode
- * limit. A single {@code IN} predicate with more than ~2,000 values (when
- * combined with the 7-state container_state filter) overflows this limit
- * and causes {@code ERROR XBCM4}. This method automatically partitions
- * {@code containerIds} into chunks of at most
+ * <p><b>Bind parameter limit:</b> each container ID is a bind parameter,
+ * and SQLite limits the number of parameters per statement. This method
+ * automatically partitions {@code containerIds} into chunks of at most
* {@value #MAX_IN_CLAUSE_CHUNK_SIZE}
* IDs so callers never need to worry about the limit, regardless of how
* many containers a scan cycle processes.
@@ -232,10 +227,8 @@ private int deleteScmStatesForContainers(DSLContext
dslContext,
* The key is a stable containerId + state tuple.
*
* <p>This method also chunks the container-id predicate internally to stay
- * within Derby's statement compilation limits. Large scan cycles in Recon
can
- * easily touch tens of thousands of containers, and expanding all IDs into a
- * single {@code IN (...)} predicate causes Derby to generate bytecode that
- * exceeds the JVM constant-pool / method-size limits.</p>
+ * within SQLite's bind parameter limit. On a large cluster a scan cycle can
+ * touch more containers than one {@code IN (...)} predicate allows.</p>
*/
public Map<ContainerStateKey, Long> getExistingInStateSinceByContainerIds(
List<Long> containerIds) {
@@ -372,7 +365,7 @@ public List<UnhealthyContainerRecord>
getUnhealthyContainers(
query.addOrderBy(orderField);
query.addLimit(limit);
- // Pre-buffer `limit` rows per JDBC round-trip instead of Derby's default
of 1 row.
+ // Only a hint: sqlite-jdbc ignores the fetch size.
query.fetchSize(limit);
try {
@@ -418,7 +411,7 @@ public void clearAllUnhealthyContainerRecords() {
/**
* Returns the count of unhealthy containers matching the given state.
*
- * <p>A full {@code SELECT COUNT(*)} is always executed against Derby.
+ * <p>A full {@code SELECT COUNT(*)} is always executed against the Recon
SQL DB.
* The {@code limit} parameter does not restrict the DB query — it only
* caps the returned value so the UI can display a bounded estimated
total.</p>
*
@@ -486,15 +479,15 @@ public Cursor<UnhealthyContainersRecord>
getUnhealthyContainersCursor(
}
// ORDER BY container_id ASC — matches composite index (state,
container_id),
- // so Derby walks it in order with no sort step.
+ // so the DB walks it in order with no sort step.
query.addOrderBy(UNHEALTHY_CONTAINERS.CONTAINER_ID.asc());
if (limit > 0) {
query.addLimit(limit);
}
- // Controls how many rows Derby returns per JDBC round-trip.
- // Configurable via ozone.recon.unhealthy.container.fetch.size (default
10,000).
+ // Rows returned per JDBC round-trip, configurable via
ozone.recon.unhealthy.container.fetch.size
+ // (default 10,000). sqlite-jdbc ignores it.
query.fetchSize(this.unhealthyContainersFetchSize);
return query.fetchLazy();
diff --git
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/persistence/DefaultDataSourceProvider.java
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/persistence/DefaultDataSourceProvider.java
index 4e21ae6359c..d7bf847f42e 100644
---
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/persistence/DefaultDataSourceProvider.java
+++
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/persistence/DefaultDataSourceProvider.java
@@ -47,9 +47,7 @@ public class DefaultDataSourceProvider implements
Provider<DataSource> {
public DataSource get() {
String jdbcUrl = configuration.getJdbcUrl();
LOG.info("JDBC Url for Recon : {} ", jdbcUrl);
- if (StringUtils.startsWith(jdbcUrl, "jdbc:derby:")) {
- return new DerbyDataSourceProvider(configuration).get();
- } else if (StringUtils.startsWith(jdbcUrl, "jdbc:sqlite:")) {
+ if (StringUtils.startsWith(jdbcUrl, "jdbc:sqlite:")) {
return new SqliteDataSourceProvider(configuration).get();
}
diff --git
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/persistence/DerbyDataSourceProvider.java
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/persistence/DerbyDataSourceProvider.java
deleted file mode 100644
index e0b413df517..00000000000
---
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/persistence/DerbyDataSourceProvider.java
+++ /dev/null
@@ -1,59 +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
- *
- * 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.ozone.recon.persistence;
-
-import static
org.apache.ozone.recon.codegen.JooqCodeGenerator.RECON_SCHEMA_NAME;
-import static org.apache.ozone.recon.schema.SqlDbUtils.createNewDerbyDatabase;
-
-import com.google.inject.Inject;
-import com.google.inject.Provider;
-import javax.sql.DataSource;
-import org.apache.derby.jdbc.EmbeddedDataSource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Provide a {@link javax.sql.DataSource} for the application.
- */
-public class DerbyDataSourceProvider implements Provider<DataSource> {
-
- private static final Logger LOG =
- LoggerFactory.getLogger(DerbyDataSourceProvider.class);
-
- private DataSourceConfiguration configuration;
-
- @Inject
- DerbyDataSourceProvider(DataSourceConfiguration configuration) {
- this.configuration = configuration;
- }
-
- @Override
- public DataSource get() {
- String jdbcUrl = configuration.getJdbcUrl();
- try {
- createNewDerbyDatabase(jdbcUrl, RECON_SCHEMA_NAME);
- } catch (Exception e) {
- LOG.error("Error creating Recon Derby DB.", e);
- }
- EmbeddedDataSource dataSource = new EmbeddedDataSource();
- String dbName = jdbcUrl.replaceFirst("^jdbc:derby:", "");
- dataSource.setDatabaseName(dbName);
- dataSource.setUser(RECON_SCHEMA_NAME);
- return dataSource;
- }
-}
diff --git
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/persistence/JooqPersistenceModule.java
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/persistence/JooqPersistenceModule.java
index fac555f72a2..a1f8c6a0897 100644
---
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/persistence/JooqPersistenceModule.java
+++
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/persistence/JooqPersistenceModule.java
@@ -43,7 +43,7 @@
public class JooqPersistenceModule extends AbstractModule {
private Provider<DataSourceConfiguration> configurationProvider;
- public static final SQLDialect DEFAULT_DIALECT = SQLDialect.DERBY;
+ public static final SQLDialect DEFAULT_DIALECT = SQLDialect.SQLITE;
public JooqPersistenceModule(
Provider<DataSourceConfiguration> configurationProvider) {
diff --git
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/ContainerKeyMapperHelper.java
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/ContainerKeyMapperHelper.java
index 3ce5e23c836..d942c771cf3 100644
---
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/ContainerKeyMapperHelper.java
+++
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/ContainerKeyMapperHelper.java
@@ -517,7 +517,7 @@ public static void handleKeyReprocess(String key,
}
}
}
- // Container count will be written once at the end of reprocess, not here
(Derby optimization)
+ // Container count will be written once at the end of reprocess, not here
}
public static boolean flushAndCommitContainerKeyInfoToDB(
diff --git
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/TestReconUtils.java
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/TestReconUtils.java
index 41910a4f316..938b35bafcc 100644
---
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/TestReconUtils.java
+++
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/TestReconUtils.java
@@ -94,6 +94,21 @@ public void testSqlDbJdbcUrlResolvesReconDbDirPlaceholder() {
assertEquals("SQLITE", dataSourceConfiguration.getSqlDialect());
}
+ @Test
+ public void testSqlDbDerbyConfigFallsBackToSqlite() {
+ OzoneConfiguration configuration = new OzoneConfiguration();
+ configuration.set(OZONE_METADATA_DIRS, temporaryFolder.toString());
+ configuration.set("ozone.recon.sql.db.driver",
"org.apache.derby.jdbc.EmbeddedDriver");
+ configuration.set("ozone.recon.sql.db.jdbc.url",
"jdbc:derby:/old/ozone_recon_derby.db");
+ configuration.set("ozone.recon.sql.db.jooq.dialect", "DERBY");
+
+ DataSourceConfiguration dataSourceConfiguration =
+ new
ReconControllerModule(null).getDataSourceConfiguration(configuration);
+
+ assertEquals("jdbc:sqlite:" + temporaryFolder + "/ozone_recon_sqlite.db",
dataSourceConfiguration.getJdbcUrl());
+ assertEquals(ReconSqlDbConfig.DEFAULT_SQL_DB_DIALECT,
dataSourceConfiguration.getSqlDialect());
+ }
+
@Test
public void testCreateTarFile(@TempDir File tempSnapshotDir)
throws Exception {
diff --git
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/persistence/AbstractReconSqlDBTest.java
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/persistence/AbstractReconSqlDBTest.java
index 61689b94cf8..6c039708b3b 100644
---
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/persistence/AbstractReconSqlDBTest.java
+++
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/persistence/AbstractReconSqlDBTest.java
@@ -17,7 +17,7 @@
package org.apache.hadoop.ozone.recon.persistence;
-import static org.apache.ozone.recon.schema.SqlDbUtils.DERBY_DRIVER_CLASS;
+import static org.apache.ozone.recon.schema.SqlDbUtils.SQLITE_DRIVER_CLASS;
import static org.junit.jupiter.api.Assertions.fail;
import com.google.inject.AbstractModule;
@@ -66,7 +66,7 @@ public void init(Path temporaryFolder) {
try {
FileSystemUtils.deleteRecursively(temporaryFolder.resolve("Config"));
configurationProvider =
- new DerbyDataSourceConfigurationProvider(Files.createDirectory(
+ new SqliteDataSourceConfigurationProvider(Files.createDirectory(
temporaryFolder.resolve("Config")).toFile());
} catch (IOException e) {
fail();
@@ -87,7 +87,7 @@ public void createReconSchemaForTest(@TempDir Path
temporaryFolder) throws IOExc
init(temporaryFolder);
injector = Guice.createInjector(getReconSqlDBModules());
dslContext = DSL.using(new DefaultConfiguration().set(
- injector.getInstance(DataSource.class)));
+ injector.getInstance(DataSource.class)).set(SQLDialect.SQLITE));
createSchema(injector);
}
@@ -162,14 +162,14 @@ protected <T> T getSchemaDefinition(Class<T> type) {
}
/**
- * Local Derby datasource provider.
+ * Local SQLite datasource provider.
*/
- public static class DerbyDataSourceConfigurationProvider implements
+ public static class SqliteDataSourceConfigurationProvider implements
Provider<DataSourceConfiguration> {
private final File tempDir;
- public DerbyDataSourceConfigurationProvider(File tempDir) {
+ public SqliteDataSourceConfigurationProvider(File tempDir) {
this.tempDir = tempDir;
}
@@ -178,13 +178,13 @@ public DataSourceConfiguration get() {
return new DataSourceConfiguration() {
@Override
public String getDriverClass() {
- return DERBY_DRIVER_CLASS;
+ return SQLITE_DRIVER_CLASS;
}
@Override
public String getJdbcUrl() {
- return "jdbc:derby:" + tempDir.getAbsolutePath() +
- File.separator + "derby_recon.db";
+ return "jdbc:sqlite:" + tempDir.getAbsolutePath() +
+ File.separator + "recon_sqlite.db";
}
@Override
@@ -209,7 +209,7 @@ public long getConnectionTimeout() {
@Override
public String getSqlDialect() {
- return SQLDialect.DERBY.toString();
+ return SQLDialect.SQLITE.toString();
}
@Override
diff --git
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/persistence/TestReconInternalSchemaDefinition.java
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/persistence/TestReconInternalSchemaDefinition.java
index 4e661fc1cfd..1c770faba0c 100644
---
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/persistence/TestReconInternalSchemaDefinition.java
+++
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/persistence/TestReconInternalSchemaDefinition.java
@@ -51,13 +51,14 @@ public void testSchemaCreated() throws Exception {
ResultSet resultSet = metaData.getColumns(null, null,
RECON_TASK_STATUS_TABLE_NAME, null);
+ // SQLite reports BIGINT columns as INTEGER and TIMESTAMP columns as
VARCHAR.
List<Pair<String, Integer>> expectedPairs = new ArrayList<>();
expectedPairs.add(new ImmutablePair<>("task_name", Types.VARCHAR));
expectedPairs.add(new ImmutablePair<>("last_updated_timestamp",
- Types.BIGINT));
+ Types.INTEGER));
expectedPairs.add(new ImmutablePair<>("last_updated_seq_number",
- Types.BIGINT));
+ Types.INTEGER));
expectedPairs.add(new ImmutablePair<>("last_task_run_status",
Types.INTEGER));
expectedPairs.add(new ImmutablePair<>("is_current_task_running",
diff --git
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/persistence/TestReconWithDifferentSqlDBs.java
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/persistence/TestReconWithDifferentSqlDBs.java
index d0a8a9b2c80..5aacc988158 100644
---
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/persistence/TestReconWithDifferentSqlDBs.java
+++
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/persistence/TestReconWithDifferentSqlDBs.java
@@ -18,7 +18,6 @@
package org.apache.hadoop.ozone.recon.persistence;
import static
org.apache.hadoop.ozone.recon.ReconControllerModule.ReconDaoBindingModule.RECON_DAO_LIST;
-import static org.apache.ozone.recon.schema.SqlDbUtils.SQLITE_DRIVER_CLASS;
import static org.apache.ozone.recon.schema.generated.Tables.RECON_TASK_STATUS;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -27,18 +26,17 @@
import static org.mockito.Mockito.when;
import com.google.inject.Provider;
-import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.stream.Stream;
+import
org.apache.hadoop.ozone.recon.persistence.AbstractReconSqlDBTest.SqliteDataSourceConfigurationProvider;
import
org.apache.hadoop.ozone.recon.tasks.updater.ReconTaskStatusUpdaterManager;
import org.apache.ozone.recon.schema.generated.tables.daos.ReconTaskStatusDao;
import org.apache.ozone.recon.schema.generated.tables.pojos.ReconTaskStatus;
import org.jooq.DSLContext;
-import org.jooq.SQLDialect;
import org.jooq.impl.DSL;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
@@ -55,8 +53,6 @@ public class TestReconWithDifferentSqlDBs {
public static Stream<Object> parametersSource() throws IOException {
return Stream.of(
- new AbstractReconSqlDBTest.DerbyDataSourceConfigurationProvider(
- Files.createTempDirectory(temporaryFolder,
"JunitDerbyDB").toFile()),
new
SqliteDataSourceConfigurationProvider(Files.createTempDirectory(temporaryFolder,
"JunitSQLDS").toFile()));
}
@@ -136,83 +132,4 @@ public void testSqliteSelectedByUrlScheme() throws
Exception {
reconSqlDB.createReconSchemaForTest(temporaryFolder);
assertThat(reconSqlDB.getDataSource()).isInstanceOf(SQLiteDataSource.class);
}
-
- /**
- * Local Sqlite datasource provider.
- */
- public static class SqliteDataSourceConfigurationProvider implements
- Provider<DataSourceConfiguration> {
-
- private final File tempDir;
-
- public SqliteDataSourceConfigurationProvider(File tempDir) {
- this.tempDir = tempDir;
- }
-
- @Override
- public DataSourceConfiguration get() {
- return new DataSourceConfiguration() {
- @Override
- public String getDriverClass() {
- return SQLITE_DRIVER_CLASS;
- }
-
- @Override
- public String getJdbcUrl() {
- return "jdbc:sqlite:" + tempDir.getAbsolutePath() +
- File.separator + "recon_sqlite.db";
- }
-
- @Override
- public String getUserName() {
- return null;
- }
-
- @Override
- public String getPassword() {
- return null;
- }
-
- @Override
- public boolean setAutoCommit() {
- return true;
- }
-
- @Override
- public long getConnectionTimeout() {
- return 10000;
- }
-
- @Override
- public String getSqlDialect() {
- return SQLDialect.SQLITE.toString();
- }
-
- @Override
- public Integer getMaxActiveConnections() {
- return 2;
- }
-
- @Override
- public long getMaxConnectionAge() {
- return 120;
- }
-
- @Override
- public long getMaxIdleConnectionAge() {
- return 120;
- }
-
- @Override
- public String getConnectionTestStatement() {
- return "SELECT 1";
- }
-
- @Override
- public long getIdleConnectionTestPeriod() {
- return 30;
- }
- };
- }
- }
}
diff --git
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/persistence/TestSchemaVersionTableDefinition.java
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/persistence/TestSchemaVersionTableDefinition.java
index 5db305044cc..c33b38bcb6c 100644
---
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/persistence/TestSchemaVersionTableDefinition.java
+++
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/persistence/TestSchemaVersionTableDefinition.java
@@ -62,10 +62,11 @@ public void testSchemaVersionTableCreation() throws
Exception {
ResultSet resultSet = metaData.getColumns(null, null,
SCHEMA_VERSION_TABLE_NAME, null);
+ // SQLite reports BIGINT columns as INTEGER and TIMESTAMP columns as
VARCHAR.
List<Pair<String, Integer>> expectedPairs = new ArrayList<>();
expectedPairs.add(new ImmutablePair<>("version_number", Types.INTEGER));
- expectedPairs.add(new ImmutablePair<>("applied_on", Types.TIMESTAMP));
+ expectedPairs.add(new ImmutablePair<>("applied_on", Types.VARCHAR));
List<Pair<String, Integer>> actualPairs = new ArrayList<>();
@@ -152,7 +153,7 @@ public void testFreshInstallScenario() throws Exception {
// Initialize the schema
SchemaVersionTableDefinition schemaVersionTable = new
SchemaVersionTableDefinition(getDataSource());
- schemaVersionTable.setSoftwareVersion(3);
+ schemaVersionTable.setFreshInstallVersion(3);
schemaVersionTable.initializeSchema();
// Verify that the SchemaVersionTable is created
@@ -235,7 +236,7 @@ public void testUpgradedClusterScenario() throws Exception {
// Initialize the schema
SchemaVersionTableDefinition schemaVersionTable = new
SchemaVersionTableDefinition(getDataSource());
- schemaVersionTable.setSoftwareVersion(3);
+ schemaVersionTable.setFreshInstallVersion(3);
schemaVersionTable.initializeSchema();
try (ReconVersionManager versionManager = new
ReconVersionManager(getDataSource())) {
diff --git
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/persistence/TestStatsSchemaDefinition.java
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/persistence/TestStatsSchemaDefinition.java
index f76d25a860c..c4db737fa3f 100644
---
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/persistence/TestStatsSchemaDefinition.java
+++
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/persistence/TestStatsSchemaDefinition.java
@@ -27,6 +27,7 @@
import java.sql.Types;
import java.time.Clock;
import java.time.LocalDateTime;
+import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.tuple.ImmutablePair;
@@ -52,12 +53,13 @@ public void testIfStatsSchemaCreated() throws Exception {
ResultSet resultSet = metaData.getColumns(null, null,
GLOBAL_STATS_TABLE_NAME, null);
+ // SQLite reports BIGINT columns as INTEGER and TIMESTAMP columns as
VARCHAR.
List<Pair<String, Integer>> expectedPairs = new ArrayList<>();
expectedPairs.add(new ImmutablePair<>("key", Types.VARCHAR));
- expectedPairs.add(new ImmutablePair<>("value", Types.BIGINT));
+ expectedPairs.add(new ImmutablePair<>("value", Types.INTEGER));
expectedPairs.add(new ImmutablePair<>("last_updated_timestamp",
- Types.TIMESTAMP));
+ Types.VARCHAR));
List<Pair<String, Integer>> actualPairs = new ArrayList<>();
@@ -85,7 +87,8 @@ public void testGlobalStatsCRUDOperations() throws Exception {
GlobalStatsDao dao = getDao(GlobalStatsDao.class);
- LocalDateTime now = LocalDateTime.now(Clock.systemUTC().getZone());
+ // SQLite keeps timestamps at millisecond precision.
+ LocalDateTime now =
LocalDateTime.now(Clock.systemUTC().getZone()).truncatedTo(ChronoUnit.MILLIS);
GlobalStats newRecord = new GlobalStats();
newRecord.setLastUpdatedTimestamp(now);
newRecord.setKey("key1");
diff --git
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/persistence/TestUnhealthyContainersDerbyPerformance.java
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/persistence/TestUnhealthyContainersSqlitePerformance.java
similarity index 88%
rename from
hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/persistence/TestUnhealthyContainersDerbyPerformance.java
rename to
hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/persistence/TestUnhealthyContainersSqlitePerformance.java
index 9a1ed52af7d..d6195fedc5c 100644
---
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/persistence/TestUnhealthyContainersDerbyPerformance.java
+++
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/persistence/TestUnhealthyContainersSqlitePerformance.java
@@ -38,7 +38,7 @@
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import
org.apache.hadoop.ozone.recon.ReconControllerModule.ReconDaoBindingModule;
import org.apache.hadoop.ozone.recon.ReconSchemaManager;
-import
org.apache.hadoop.ozone.recon.persistence.AbstractReconSqlDBTest.DerbyDataSourceConfigurationProvider;
+import
org.apache.hadoop.ozone.recon.persistence.AbstractReconSqlDBTest.SqliteDataSourceConfigurationProvider;
import
org.apache.hadoop.ozone.recon.persistence.ContainerHealthSchemaManager.UnhealthyContainerRecord;
import
org.apache.hadoop.ozone.recon.persistence.ContainerHealthSchemaManager.UnhealthyContainersSummary;
import org.apache.ozone.recon.schema.ContainerSchemaDefinition;
@@ -47,7 +47,6 @@
import
org.apache.ozone.recon.schema.generated.tables.daos.UnhealthyContainersDao;
import org.apache.ozone.test.tag.Slow;
import org.jooq.DSLContext;
-import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
@@ -59,7 +58,7 @@
import org.slf4j.LoggerFactory;
/**
- * Performance benchmark for the UNHEALTHY_CONTAINERS Derby table at 1 million
+ * Performance benchmark for the UNHEALTHY_CONTAINERS SQLite table at 1 million
* records scale.
*
* <h2>Data layout</h2>
@@ -76,24 +75,20 @@
*
* <h2>Performance settings applied in this test</h2>
* <ul>
- * <li><b>In-memory database</b>: The test uses an in-memory Derby database
- * ({@code jdbc:derby:memory:...}) to eliminate disk I/O and fsync
overhead
- * during the 1-million-row benchmark.</li>
- * <li><b>JDBC fetch size</b>: set to {@value #READ_PAGE_SIZE} on each query
- * so Derby pre-buffers a full page of rows per JDBC round-trip instead
- * of the default 1-row-at-a-time fetch.</li>
+ * <li><b>JDBC fetch size</b>: set to {@value #READ_PAGE_SIZE} on each query,
+ * but sqlite-jdbc ignores it and reads rows one at a time.</li>
* <li><b>Large page size</b>: {@value #READ_PAGE_SIZE} rows per SQL fetch
* reduces the number of SQL round-trips from 200 (@ 1 K rows) to 40
* (@ 5 K rows) per 200 K-row state scan.</li>
* <li><b>Large delete chunks</b>: {@value #DELETE_CHUNK_SIZE} IDs per
- * DELETE statement reduces Derby plan-compilation overhead from 100
+ * DELETE statement reduces plan-compilation overhead from 100
* statements to 20 for a 100 K-ID batch delete.</li>
* </ul>
*
* <h2>What is measured</h2>
* <ol>
* <li><b>Bulk INSERT throughput</b> – 1 M records via JOOQ batchInsert in
- * chunks of 1,000 inside a single Derby transaction.</li>
+ * chunks of 1,000 inside a single transaction.</li>
* <li><b>COUNT(*) by state</b> – index-covered aggregate, one per
state.</li>
* <li><b>GROUP BY summary</b> – single pass over the idx_container_state
* index to aggregate all states.</li>
@@ -109,7 +104,7 @@
*
* <h2>Design notes</h2>
* <ul>
- * <li>Derby is an embedded, single-file Java database — not designed for
+ * <li>SQLite is an embedded, single-file database — not designed for
* production-scale workloads. Performance numbers here document its
* baseline behaviour and will flag regressions, but should not be
* compared with PostgreSQL / MySQL numbers.</li>
@@ -122,10 +117,10 @@
*/
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
-public class TestUnhealthyContainersDerbyPerformance {
+public class TestUnhealthyContainersSqlitePerformance {
private static final Logger LOG =
- LoggerFactory.getLogger(TestUnhealthyContainersDerbyPerformance.class);
+ LoggerFactory.getLogger(TestUnhealthyContainersSqlitePerformance.class);
// -----------------------------------------------------------------------
// Dataset constants
@@ -179,18 +174,16 @@ public class TestUnhealthyContainersDerbyPerformance {
*
* <p>5,000 rows per page means only 40 SQL round-trips to scan 200,000
* records for a single state, compared to 200 trips at the old 1,000-row
- * page size. Combined with {@code query.fetchSize(READ_PAGE_SIZE)} this
- * cuts round-trip overhead by 80% while keeping per-page heap usage well
- * below 1 MB.</p>
+ * page size. This cuts round-trip overhead by 80% while keeping per-page
+ * heap usage well below 1 MB.</p>
*/
private static final int READ_PAGE_SIZE = 5_000;
// -----------------------------------------------------------------------
- // Performance thresholds (CI-safe; expected run times are significantly
faster
- // than the original file-based Derby baseline after switching to in-memory)
+ // Performance thresholds (CI-safe; expected run times are significantly
faster)
// -----------------------------------------------------------------------
- /** Maximum acceptable time to insert all TOTAL_RECORDS into Derby. */
+ /** Maximum acceptable time to insert all TOTAL_RECORDS. */
private static final long MAX_INSERT_SECONDS = 300;
/** Maximum acceptable time for a single COUNT(*)-by-state query. */
@@ -219,92 +212,21 @@ public class TestUnhealthyContainersDerbyPerformance {
private ContainerSchemaDefinition schemaDefinition;
// -----------------------------------------------------------------------
- // One-time setup: create Derby schema + insert 1 M records
+ // One-time setup: create SQLite schema + insert 1 M records
// -----------------------------------------------------------------------
- private String inMemoryDbName;
-
/**
- * Initialises the embedded in-memory Derby database and creates the Recon
schema.
+ * Initialises the SQLite database and creates the Recon schema.
* Data population is done in dedicated test methods.
- *
- * <p>Reuses {@link DerbyDataSourceConfigurationProvider} for all connection
settings
- * and overrides only {@code getJdbcUrl()} to use an in-memory Derby database
- * ({@code jdbc:derby:memory:...}), eliminating disk I/O and fsync overhead
across
- * the benchmark's insert, replace, and delete transactions.</p>
*/
@BeforeAll
public void setUpDatabase(@TempDir Path tempDir) throws Exception {
- inMemoryDbName = "reconPerf_" + java.util.UUID.randomUUID().toString();
- LOG.info("=== Derby Performance Benchmark — Setup ===");
+ LOG.info("=== SQLite Performance Benchmark — Setup ===");
LOG.info("Dataset: {} states × {} container IDs = {} total records",
TESTED_STATES.size(), CONTAINER_ID_RANGE, TOTAL_RECORDS);
File configDir = Files.createDirectory(tempDir.resolve("Config")).toFile();
- DataSourceConfiguration base = new
DerbyDataSourceConfigurationProvider(configDir).get();
-
- // Reuse DerbyDataSourceConfigurationProvider settings but point to an
in-memory DB.
- Provider<DataSourceConfiguration> configProvider = () -> new
DataSourceConfiguration() {
- @Override
- public String getDriverClass() {
- return base.getDriverClass();
- }
-
- @Override
- public String getJdbcUrl() {
- return "jdbc:derby:memory:" + inMemoryDbName;
- }
-
- @Override
- public String getUserName() {
- return base.getUserName();
- }
-
- @Override
- public String getPassword() {
- return base.getPassword();
- }
-
- @Override
- public boolean setAutoCommit() {
- return base.setAutoCommit();
- }
-
- @Override
- public long getConnectionTimeout() {
- return base.getConnectionTimeout();
- }
-
- @Override
- public String getSqlDialect() {
- return base.getSqlDialect();
- }
-
- @Override
- public Integer getMaxActiveConnections() {
- return base.getMaxActiveConnections();
- }
-
- @Override
- public long getMaxConnectionAge() {
- return base.getMaxConnectionAge();
- }
-
- @Override
- public long getMaxIdleConnectionAge() {
- return base.getMaxIdleConnectionAge();
- }
-
- @Override
- public String getConnectionTestStatement() {
- return base.getConnectionTestStatement();
- }
-
- @Override
- public long getIdleConnectionTestPeriod() {
- return base.getIdleConnectionTestPeriod();
- }
- };
+ Provider<DataSourceConfiguration> configProvider = new
SqliteDataSourceConfigurationProvider(configDir);
Injector injector = Guice.createInjector(
new JooqPersistenceModule(configProvider),
@@ -325,20 +247,6 @@ protected void configure() {
schemaManager = new ContainerHealthSchemaManager(schemaDefinition, new
OzoneConfiguration());
}
- @AfterAll
- public void tearDownDatabase() {
- if (inMemoryDbName != null) {
- try (java.sql.Connection conn = java.sql.DriverManager.getConnection(
- "jdbc:derby:memory:" + inMemoryDbName + ";drop=true")) {
- conn.isValid(1);
- } catch (java.sql.SQLException e) {
- if (!"08006".equals(e.getSQLState())) {
- LOG.warn("Unexpected SQLState while dropping in-memory Derby DB:
{}", e.getSQLState(), e);
- }
- }
- }
- }
-
// -----------------------------------------------------------------------
// Test 1 — Batch INSERT performance for 1M records
// -----------------------------------------------------------------------
@@ -550,7 +458,7 @@ public void testPaginatedReadByStatePerformance() {
/**
* Pages through all records for every tested state sequentially, effectively
- * reading all 1 million rows from Derby through the application layer.
+ * reading all 1 million rows from SQLite through the application layer.
* This measures aggregate read throughput across the entire dataset.
*/
@Test
diff --git
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/persistence/TestUtilizationSchemaDefinition.java
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/persistence/TestUtilizationSchemaDefinition.java
index 1369ff17b14..d948cdb2591 100644
---
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/persistence/TestUtilizationSchemaDefinition.java
+++
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/persistence/TestUtilizationSchemaDefinition.java
@@ -31,6 +31,7 @@
import java.sql.SQLException;
import java.sql.Types;
import java.time.LocalDateTime;
+import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.tuple.ImmutablePair;
@@ -63,14 +64,15 @@ public void testReconSchemaCreated() throws Exception {
ResultSet resultSet = metaData.getColumns(null, null,
CLUSTER_GROWTH_DAILY_TABLE_NAME, null);
+ // SQLite reports BIGINT columns as INTEGER and TIMESTAMP columns as
VARCHAR.
List<Pair<String, Integer>> expectedPairs = new ArrayList<>();
- expectedPairs.add(new ImmutablePair<>("timestamp", Types.TIMESTAMP));
+ expectedPairs.add(new ImmutablePair<>("timestamp", Types.VARCHAR));
expectedPairs.add(new ImmutablePair<>("datanode_id", Types.INTEGER));
expectedPairs.add(new ImmutablePair<>("datanode_host", Types.VARCHAR));
expectedPairs.add(new ImmutablePair<>("rack_id", Types.VARCHAR));
- expectedPairs.add(new ImmutablePair<>("available_size", Types.BIGINT));
- expectedPairs.add(new ImmutablePair<>("used_size", Types.BIGINT));
+ expectedPairs.add(new ImmutablePair<>("available_size", Types.INTEGER));
+ expectedPairs.add(new ImmutablePair<>("used_size", Types.INTEGER));
expectedPairs.add(new ImmutablePair<>("container_count", Types.INTEGER));
expectedPairs.add(new ImmutablePair<>("block_count", Types.INTEGER));
@@ -93,9 +95,9 @@ public void testReconSchemaCreated() throws Exception {
expectedPairsFileCount.add(
new ImmutablePair<>("bucket", Types.VARCHAR));
expectedPairsFileCount.add(
- new ImmutablePair<>("file_size", Types.BIGINT));
+ new ImmutablePair<>("file_size", Types.INTEGER));
expectedPairsFileCount.add(
- new ImmutablePair<>("count", Types.BIGINT));
+ new ImmutablePair<>("count", Types.INTEGER));
List<Pair<String, Integer>> actualPairsFileCount = new ArrayList<>();
while (resultSetFileCount.next()) {
@@ -114,9 +116,9 @@ public void testReconSchemaCreated() throws Exception {
List<Pair<String, Integer>> expectedPairsContainerCount = new
ArrayList<>();
expectedPairsContainerCount.add(
- new ImmutablePair<>("container_size", Types.BIGINT));
+ new ImmutablePair<>("container_size", Types.INTEGER));
expectedPairsContainerCount.add(
- new ImmutablePair<>("count", Types.BIGINT));
+ new ImmutablePair<>("count", Types.INTEGER));
List<Pair<String, Integer>> actualPairsContainerCount = new ArrayList<>();
while (resultSetContainerCount.next()) {
@@ -147,7 +149,8 @@ public void testClusterGrowthDailyCRUDOperations() throws
Exception {
}
ClusterGrowthDailyDao dao = getDao(ClusterGrowthDailyDao.class);
- LocalDateTime now = LocalDateTime.now();
+ // SQLite keeps timestamps at millisecond precision.
+ LocalDateTime now = LocalDateTime.now().truncatedTo(ChronoUnit.MILLIS);
ClusterGrowthDaily newRecord = new ClusterGrowthDaily();
newRecord.setTimestamp(now);
newRecord.setDatanodeId(10);
diff --git
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/upgrade/TestReconTaskStatusTableUpgradeAction.java
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/upgrade/TestReconTaskStatusTableUpgradeAction.java
index 0f0f2a71478..4471c973660 100644
---
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/upgrade/TestReconTaskStatusTableUpgradeAction.java
+++
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/upgrade/TestReconTaskStatusTableUpgradeAction.java
@@ -39,7 +39,6 @@
import org.apache.hadoop.ozone.recon.persistence.AbstractReconSqlDBTest;
import org.apache.ozone.recon.schema.ReconTaskSchemaDefinition;
import org.jooq.DSLContext;
-import org.jooq.SQLDialect;
import org.jooq.impl.DSL;
import org.jooq.impl.SQLDataType;
import org.junit.jupiter.api.BeforeEach;
@@ -65,11 +64,7 @@ public class TestReconTaskStatusTableUpgradeAction
@BeforeEach
public void setUp() throws SQLException {
dataSource = getDataSource();
- // Use the Derby dialect explicitly. The shared DSLContext from the base
- // class uses SQLDialect.DEFAULT, which renders Derby-incompatible DDL
- // (e.g. "DROP TABLE IF EXISTS" and "bigint null"); a Derby-dialect context
- // generates SQL that the embedded Derby database accepts.
- dslContext = DSL.using(dataSource, SQLDialect.DERBY);
+ dslContext = getDslContext();
upgradeAction = new ReconTaskStatusTableUpgradeAction();
createLegacyTaskStatusTable();
}
diff --git
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/upgrade/TestReconVersionManager.java
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/upgrade/TestReconVersionManager.java
index bd9e1715aa9..72fe1e08906 100644
---
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/upgrade/TestReconVersionManager.java
+++
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/upgrade/TestReconVersionManager.java
@@ -123,7 +123,7 @@ private Injector createTestInjector(String directoryPrefix)
throws IOException {
Path dbDir = Files.createTempDirectory(tempDir, directoryPrefix);
File configDir = Files.createDirectory(dbDir.resolve("Config")).toFile();
Provider<DataSourceConfiguration> configProvider =
- new
AbstractReconSqlDBTest.DerbyDataSourceConfigurationProvider(configDir);
+ new
AbstractReconSqlDBTest.SqliteDataSourceConfigurationProvider(configDir);
return Guice.createInjector(
new JooqPersistenceModule(configProvider),
new AbstractModule() {
diff --git a/pom.xml b/pom.xml
index e9f0128aebc..fc1103a8447 100644
--- a/pom.xml
+++ b/pom.xml
@@ -71,7 +71,6 @@
<cyclonedx.version>2.9.3</cyclonedx.version>
<declared.hdds.version>${hdds.version}</declared.hdds.version>
<declared.ozone.version>${ozone.version}</declared.ozone.version>
- <derby.version>10.14.2.0</derby.version>
<disruptor.version>3.4.4</disruptor.version>
<distMgmtSnapshotsId>apache.snapshots.https</distMgmtSnapshotsId>
<distMgmtSnapshotsName>Apache Development Snapshot
Repository</distMgmtSnapshotsName>
@@ -759,11 +758,6 @@
</exclusion>
</exclusions>
</dependency>
- <dependency>
- <groupId>org.apache.derby</groupId>
- <artifactId>derby</artifactId>
- <version>${derby.version}</version>
- </dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-annotations</artifactId>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]