-
Notifications
You must be signed in to change notification settings - Fork 587
HDDS-3411. Switch Recon SQL DB to Derby. #839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1d822d7
HDDS-3411. Switch Recon SQL DB to Derby.
17f56a7
Fix integration test failure.
83a85a6
Rat check.
fed115d
Merge remote-tracking branch 'upstream/master' into HDDS-3411-master
d61cbd8
Merge remote-tracking branch 'upstream/master' into HDDS-3411-master
e22f090
Address review comments, move SQL DB configs to Java based.
523f50b
trigger new CI check
fa85ecd
Fix TestOzoneConfigurationFields integration test failure.
98ebd26
Merge branch 'master' into HDDS-3411-master
avijayanhwx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...op-ozone/recon-codegen/src/main/java/org/hadoop/ozone/recon/codegen/ReconSqlDbConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * 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.hadoop.ozone.recon.codegen; | ||
|
|
||
| import org.apache.hadoop.hdds.conf.Config; | ||
| import org.apache.hadoop.hdds.conf.ConfigGroup; | ||
| import org.apache.hadoop.hdds.conf.ConfigTag; | ||
| import org.apache.hadoop.hdds.conf.ConfigType; | ||
|
|
||
| /** | ||
| * The configuration class for the Recon SQL DB. | ||
| */ | ||
| @ConfigGroup(prefix = "ozone.recon.sql.db") | ||
| public class ReconSqlDbConfig { | ||
avijayanhwx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @Config(key = "jooq.dialect", | ||
| type = ConfigType.STRING, | ||
| defaultValue = "", | ||
| 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 " + | ||
| "to https://www.jooq.org/javadoc/latest/org" + | ||
| ".jooq/org/jooq/SQLDialect.html to specify different dialect." | ||
| ) | ||
| private String sqlDbDialect; | ||
|
|
||
| public String getSqlDbDialect() { | ||
| return sqlDbDialect; | ||
| } | ||
|
|
||
| public void setSqlDbDialect(String sqlDbDialect) { | ||
| this.sqlDbDialect = sqlDbDialect; | ||
| } | ||
| } | ||
97 changes: 97 additions & 0 deletions
97
hadoop-ozone/recon-codegen/src/main/java/org/hadoop/ozone/recon/codegen/SqlDbUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| /* | ||
| * 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.hadoop.ozone.recon.codegen; | ||
|
|
||
| import static org.jooq.impl.DSL.count; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.OutputStream; | ||
| import java.sql.Connection; | ||
| import java.sql.DriverManager; | ||
| import java.sql.SQLException; | ||
| import java.util.function.BiPredicate; | ||
|
|
||
| import org.jooq.exception.DataAccessException; | ||
| import org.jooq.impl.DSL; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** | ||
| * Constants and Helper functions for Recon SQL related stuff. | ||
| */ | ||
| public final class SqlDbUtils { | ||
|
|
||
| public final static String DERBY_DRIVER_CLASS = | ||
| "org.apache.derby.jdbc.EmbeddedDriver"; | ||
| public final static String SQLITE_DRIVER_CLASS = "org.sqlite.JDBC"; | ||
| public final static String DERBY_DISABLE_LOG_METHOD = | ||
| SqlDbUtils.class.getName() + ".disableDerbyLogFile"; | ||
|
|
||
| private static final Logger LOG = | ||
| LoggerFactory.getLogger(SqlDbUtils.class); | ||
|
|
||
| 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() { | ||
| public void write(int b) throws IOException { | ||
| // Ignore all log messages | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Helper function to check if table exists through JOOQ. | ||
| */ | ||
| public static final BiPredicate<Connection, String> TABLE_EXISTS_CHECK = | ||
| (conn, tableName) -> { | ||
| try { | ||
| DSL.using(conn).select(count()).from(tableName).execute(); | ||
| } catch (DataAccessException ex) { | ||
| LOG.info(ex.getMessage()); | ||
| return false; | ||
| } | ||
| LOG.info("{} table already exists, skipping creation.", tableName); | ||
| return true; | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.