Skip to content
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

Merged
merged 22 commits into from
Aug 18, 2021

Conversation

Torch3333
Copy link
Contributor

@Torch3333 Torch3333 commented Aug 10, 2021

This completes the implementation of the JDBCStorageAdmin and refactor integration test to rely on it.
cf. https://scalar-labs.atlassian.net/browse/DLT-9371

@Torch3333 Torch3333 added the enhancement New feature or request label Aug 10, 2021
@Torch3333 Torch3333 self-assigned this Aug 10, 2021
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 {
Copy link
Contributor Author

@Torch3333 Torch3333 Aug 11, 2021

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 {
Copy link
Contributor Author

@Torch3333 Torch3333 Aug 11, 2021

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.

Comment on lines 155 to 161
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);
}
}
Copy link
Contributor Author

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.

@Torch3333 Torch3333 changed the title WIP Add create, truncate and delete table implementation to JDBCAdmin Add create, truncate and delete table implementation to JDBCAdmin Aug 11, 2021
@Torch3333 Torch3333 marked this pull request as ready for review August 11, 2021 04:40
Copy link
Collaborator

@brfrn169 brfrn169 left a 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!

@Torch3333 Torch3333 requested a review from brfrn169 August 12, 2021 08:06
Copy link
Collaborator

@brfrn169 brfrn169 left a 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!

@Torch3333 Torch3333 requested a review from brfrn169 August 13, 2021 02:04
brfrn169
brfrn169 previously approved these changes Aug 13, 2021
Copy link
Collaborator

@brfrn169 brfrn169 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you!

Copy link
Contributor

@feeblefakie feeblefakie left a 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.

createTableInternal(connection, namespace, table, metadata);
createIndex(connection, namespace, table, metadata);
} catch (SQLException e) {
connection.rollback();
Copy link
Contributor

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?

Copy link
Contributor Author

@Torch3333 Torch3333 Aug 13, 2021

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-26e58dccc9f536e4794af12538f00972936415bb04ba1b0d5d1f6b903f55e2d5R169

Are 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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Thank you!

@Torch3333 Torch3333 requested a review from feeblefakie August 17, 2021 01:41
feeblefakie
feeblefakie previously approved these changes Aug 17, 2021
Copy link
Contributor

@feeblefakie feeblefakie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you!

brfrn169
brfrn169 previously approved these changes Aug 17, 2021
Copy link
Collaborator

@brfrn169 brfrn169 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you!

@Torch3333
Copy link
Contributor Author

Please wait before merging this, I want to clarify something first with @brfrn169

Vincent Guilpain added 2 commits August 17, 2021 14:48
…ked by passing the namespacePrefix concatenated to the namespace
…:scalar-labs/scalardb into add_create_truncate_delete_to_jdbc_admin
@Torch3333 Torch3333 dismissed stale reviews from brfrn169 and feeblefakie via c6c997b August 17, 2021 05:49
@Torch3333 Torch3333 requested a review from brfrn169 August 17, 2021 05:51
@Torch3333
Copy link
Contributor Author

@brfrn169
@feeblefakie
I found out that was an inconsistency in the code where one of the JDBCTableMetadataManager method was called by concatenating "namespacePrefix + namespace" while only the "namespace" value should be passed.
Sorry for this, please have a look again 🙇

…aManager.java


Simplify method usage

Co-authored-by: Toshihiro Suzuki <[email protected]>
Copy link
Collaborator

@brfrn169 brfrn169 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you!

@Torch3333
Copy link
Contributor Author

Circle-ci integration-test-for-jdbc-oracle is failing. I am investigating it.

@brfrn169
Copy link
Collaborator

brfrn169 commented Aug 17, 2021

@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.

@brfrn169
Copy link
Collaborator

It looks like the last Oracle integration finished as the usual time 👍

Copy link
Contributor

@feeblefakie feeblefakie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you!

@brfrn169 brfrn169 merged commit cd92e6b into master Aug 18, 2021
@brfrn169 brfrn169 deleted the add_create_truncate_delete_to_jdbc_admin branch August 18, 2021 06:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants