-
Notifications
You must be signed in to change notification settings - Fork 37
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
Add create, truncate and delete table implementation to JDBCAdmin #270
Conversation
…ate_truncate_delete_to_jdbc_admin # Conflicts: # core/src/integration-test/java/com/scalar/db/storage/jdbc/test/TestEnv.java
…ate_truncate_delete_to_jdbc_admin
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
import javax.sql.DataSource; | ||
import org.apache.commons.dbcp2.BasicDataSource; | ||
|
||
@SuppressFBWarnings("SQL_NONCONSTANT_STRING_PASSED_TO_EXECUTE") | ||
public class TestEnv implements Closeable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A lof of changes in the PR were due to the refactoring of this integration test class to now rely on the JdbcDatabaseAdmin
to insert test table.
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
import javax.annotation.concurrent.ThreadSafe; | ||
import org.apache.commons.dbcp2.BasicDataSource; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
@ThreadSafe | ||
public class JdbcDatabaseAdmin implements DistributedStorageAdmin { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the important changes are here.
public void dropTable(String namespace, String table) throws ExecutionException { | ||
throw new UnsupportedOperationException("implement later"); | ||
dropTableInternal(namespace, table); | ||
metadataManager.deleteTableMetadata(namespace, table); | ||
if (metadataManager.getTableNames(namespace).isEmpty()) { | ||
dropSchema(namespace); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the new method TableMetadataManager.getTablesNames()
because I needed a way to know if there was any tables associated with the given namespace. I figured this was more proper to rely on the MetadataManager
data than run specific sql queries to check if a namespace contains some tables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM overall! Thank you!
I left some comments and suggestions. Please check them when you get a chance!
core/src/main/java/com/scalar/db/storage/jdbc/JdbcDatabaseAdmin.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/scalar/db/storage/jdbc/JdbcDatabaseAdmin.java
Outdated
Show resolved
Hide resolved
…the end of JdbcTableMetadataManager.deleteMetadataTable()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I just left several comments. Please take a look!
core/src/integration-test/java/com/scalar/db/storage/jdbc/test/TestEnv.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/scalar/db/storage/jdbc/JdbcTableMetadataManager.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looking good! Thank you!
Left some questions and a minor suggestion.
core/src/main/java/com/scalar/db/storage/common/TableMetadataManager.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/scalar/db/storage/jdbc/JdbcDatabaseAdmin.java
Outdated
Show resolved
Hide resolved
createTableInternal(connection, namespace, table, metadata); | ||
createIndex(connection, namespace, table, metadata); | ||
} catch (SQLException e) { | ||
connection.rollback(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a question.
Are we supposed to call rollback
for DDL?
Here, it's called, but it seems like it is not called in other places like below.
https://github.com/scalar-labs/scalardb/pull/270/files#diff-26e58dccc9f536e4794af12538f00972936415bb04ba1b0d5d1f6b903f55e2d5R169
Are there any particular criteria when to call it and when to not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we supposed to call rollback for DDL?
I assumed rollback was supported for all kind of statements but it's not the case for DDL. Oracle and Mysql do not support DDL statement transaction rollback while Postgresql and Sqlserver do.
Here, it's called, but it seems like it is not called in other places like below.
https://github.com/scalar-labs/scalardb/pull/270/files#diff-26e58dccc9f536e4794af12538f00972936415bb04ba1b0d5d1f6b903f55e2d5R169Are there any particular criteria when to call it and when to not?
connection.rollback()
should only be called if connection.setAutoCommit(false)
was called beforehand.
By default, auto-commit is true so every statement executed will be auto-committed right after. If an errors occurs in this mode, it will be roll-backed transparently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you!
Please wait before merging this, I want to clarify something first with @brfrn169 |
…ked by passing the namespacePrefix concatenated to the namespace
…:scalar-labs/scalardb into add_create_truncate_delete_to_jdbc_admin
@brfrn169 |
core/src/main/java/com/scalar/db/storage/jdbc/JdbcTableMetadataManager.java
Outdated
Show resolved
Hide resolved
…aManager.java Simplify method usage Co-authored-by: Toshihiro Suzuki <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you!
Circle-ci integration-test-for-jdbc-oracle is failing. I am investigating it. |
@Torch3333 I re-ran the Oracle integration test and it was successful but it seems like it took more time than usual. I will run it again. |
It looks like the last Oracle integration finished as the usual time 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you!
This completes the implementation of the JDBCStorageAdmin and refactor integration test to rely on it.
cf. https://scalar-labs.atlassian.net/browse/DLT-9371