Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Fixes #1164 - Peloton connects to nonexistent database#1224

Open
eribeiro wants to merge 8 commits intocmu-db:masterfrom
eribeiro:1164-inexistent-db
Open

Fixes #1164 - Peloton connects to nonexistent database#1224
eribeiro wants to merge 8 commits intocmu-db:masterfrom
eribeiro:1164-inexistent-db

Conversation

@eribeiro
Copy link
Contributor

No description provided.

@coveralls
Copy link

coveralls commented Mar 25, 2018

Coverage Status

Coverage increased (+0.006%) to 76.973% when pulling 47f529d on eribeiro:1164-inexistent-db into a9d83a0 on cmu-db:master.

@schedutron
Copy link
Contributor

@eribeiro Thanks for the PR, I just forgot to inform you about doing a separate PR as I’m busy with a conference this week. However, please fix the undeclared identifier error for client. Then the code should compile fine.

@ChTimTsubasa
Copy link
Member

ChTimTsubasa commented Mar 26, 2018

I would review this when this PR is ready.

@eribeiro
Copy link
Contributor Author

eribeiro commented Mar 26, 2018

@schedutron @ChTimTsubasa My bad! I was rebasing with current master late last night and didn't see this "little" detail. Thanks for pointing out.

update: gonna fix the new test asap and then I think it will be ready to review. Thanks!

Copy link
Member

@ChTimTsubasa ChTimTsubasa left a comment

Choose a reason for hiding this comment

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

Should add JDBC test to see if the response is correct.

bool Catalog::CheckDatabaseExists(const std::string &database_name) {
auto pg_database = DatabaseCatalog::GetInstance();
auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
auto txn = txn_manager.BeginTransaction();
Copy link
Member

Choose a reason for hiding this comment

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

Instead of starting a txn inside Catalog, it would be better starting a new txn outside and pass it into the function. It would be more consistent with the form of other functions in Catalog.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right.

catalog::Catalog::GetInstance()->CreateDatabase("EMP_DB", txn);

exists = catalog::Catalog::GetInstance()->CheckDatabaseExists("EMP_DB");
EXPECT_EQ(true, exists);
Copy link
Member

Choose a reason for hiding this comment

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

This would be false as the transaction created at line 259 has not been committed yet and therefore, the new database would not be visible to others.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Snap! This is one of the reasons the tests are failing. Thanks for pointing out.

} else {
auto error_msg = "Database " + value + " doesn't exist";
auto error_code = "3D000"; // invalid_catalog_name
SendErrorResponse({
Copy link
Member

Choose a reason for hiding this comment

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

Have you compared the responses you sent here with the Postgres's response? You can try to capture the packet using Wireshark.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, I have captured Postgres' responses using wireshark. I can capture Peloton's and compare the two.

@tcm-marcel
Copy link
Contributor

@eribeiro Can you add the changes @ChTimTsubasa requested?

@eribeiro
Copy link
Contributor Author

eribeiro commented Apr 4, 2018

@tcm-marcel yes, gonna change the PR tomorrow. Thanks for the review @ChTimTsubasa!

@eribeiro
Copy link
Contributor Author

eribeiro commented Apr 4, 2018

@ChTimTsubasa Could you please give me some pointers about adding the JDBC test? Which file should I insert this new test? There's an automated way of testing the jdbc tests via CLI?

I see the script test_jdbc.sh should be run with something along these lines: ./test_jdbc.sh PelotonBasicTest localhost 15721. It run, but looks like it doesn't execute the test.

Copy link
Member

@ChTimTsubasa ChTimTsubasa left a comment

Choose a reason for hiding this comment

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

Can you add a test case under ./test/network/ to address your fix.

You might want to follow some other test cases in the same directory such as simple_query_test.cpp, but instead your test should just boot the peloton service and have two clients connect to the server. One client should connect to an existing database while another should connect to a non-existing database. Make sure they get correct response.

@eribeiro
Copy link
Contributor Author

eribeiro commented Apr 5, 2018

Ok, I am gonna add those tests asap. Btw, I was able to get the a basic jdbc tests running. Some observations below when running with the following JDBC URL: jdbc:postgresql://localhost:<port>/foo

  1. This is the stack trace on Postgres connecting to a non existent database (foo):
Exception in thread "main" org.postgresql.util.PSQLException: FATAL: database "foo" does not exist
	at org.postgresql.core.v3.ConnectionFactoryImpl.readStartupMessages(ConnectionFactoryImpl.java:730)
	at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:231)
	at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
	at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:211)
	at org.postgresql.Driver.makeConnection(Driver.java:407)
	at org.postgresql.Driver.connect(Driver.java:275)
	at java.sql.DriverManager.getConnection(DriverManager.java:664)
	at java.sql.DriverManager.getConnection(DriverManager.java:247)
	at PelotonBasicTest.makeConnection(PelotonBasicTest.java:149)
	at PelotonBasicTest.<init>(PelotonBasicTest.java:144)
	at PelotonBasicTest.SingleTest(PelotonBasicTest.java:807)
	at PelotonBasicTest.main(PelotonBasicTest.java:801)

  1. This is the stack trace of Peloton after the patch connecting to same non existent database:
Exception in thread "main" org.postgresql.util.PSQLException: FATAL: Database "foo" doesn't exist
	at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:451)
	at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:223)
	at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
	at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:211)
	at org.postgresql.Driver.makeConnection(Driver.java:407)
	at org.postgresql.Driver.connect(Driver.java:275)
	at java.sql.DriverManager.getConnection(DriverManager.java:664)
	at java.sql.DriverManager.getConnection(DriverManager.java:247)
	at PelotonBasicTest.makeConnection(PelotonBasicTest.java:149)
	at PelotonBasicTest.<init>(PelotonBasicTest.java:144)
	at PelotonBasicTest.SingleTest(PelotonBasicTest.java:807)
	at PelotonBasicTest.main(PelotonBasicTest.java:801)

I see that if I don't provide the database name after the slash (jdbc:postgresql://localhost:15721/) then Peloton returns a empty value for the database name. Any idea of why this is happening?

Exception in thread "main" org.postgresql.util.PSQLException: Database "" doesn't exist
	at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:451)
	at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:223)
	at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
	at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:211)
	at org.postgresql.Driver.makeConnection(Driver.java:407)
	at org.postgresql.Driver.connect(Driver.java:275)
	at java.sql.DriverManager.getConnection(DriverManager.java:664)
	at java.sql.DriverManager.getConnection(DriverManager.java:247)
	at PelotonBasicTest.makeConnection(PelotonBasicTest.java:149)
	at PelotonBasicTest.<init>(PelotonBasicTest.java:144)
	at PelotonBasicTest.SingleTest(PelotonBasicTest.java:807)
	at PelotonBasicTest.main(PelotonBasicTest.java:801)

@ChTimTsubasa
Copy link
Member

The exception looks like that you are implementing the database check correctly. Can you try some test cases with "default_database", which is the default existing database?

@eribeiro
Copy link
Contributor Author

eribeiro commented Apr 6, 2018

@ChTimTsubasa Firstly, thanks for the patience and support. Well, I have added a quite simple test -- simple_connection_test.cpp -- in test/network directory. It tries two connections with a invalid and a valid database name. Please, let me know what I can improve on this file. There is a need for JDBC test?

But I must say that I was unable to register it as a valid test so I resorted to a quick-and-dirty hack of renaming to an already registered name and then I could test it. Could you tell me how can I register a new test file to execute via ctest?

Thanks!

Copy link
Member

@ChTimTsubasa ChTimTsubasa left a comment

Choose a reason for hiding this comment

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

The test case looks good. No need to worry about not having a registered test. You cannot do that because of Singleton. That is not your problem.

I think this PR is good and ready to merge.

@pervazea pervazea removed the accepted label Apr 9, 2018
@pervazea pervazea self-requested a review April 9, 2018 15:30
} catch (const std::exception &e) {
auto msg = e.what();
LOG_INFO("[SimpleConnectionTest] Exception occurred: %s", msg);
EXPECT_TRUE(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

You are catching the exception here, but not checking if it is the expected failure type?
You should check that the failure is the expected failure.

server.SetPort(port);
server.SetupServer();
} catch (peloton::ConnectionException &exception) {
LOG_INFO("[LaunchServer] exception when launching server");
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens here if the server generates an exception?

@pervazea
Copy link
Contributor

pervazea commented Apr 9, 2018

I don't understand the comment about "not being able to register a test". How did you try to add the new test?

@pmenon
Copy link
Member

pmenon commented May 21, 2018

@eribeiro What is the status of this?

@edwardoliveira
Copy link

@pmenon Hi,

TL;DR: it is stalled. :(

The code works(ed), but it lacks the last (?) round of review since I've got swamped by work commitments.

I can try to resume work on it if it is already relevant, but if anyone else would like to adopt this PR feel free to do so, no problem. Afaik, it is almost ready to commit once the tests are in place and conflicts resolved. :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants