Fixes #1164 - Peloton connects to nonexistent database#1224
Fixes #1164 - Peloton connects to nonexistent database#1224eribeiro wants to merge 8 commits intocmu-db:masterfrom eribeiro:1164-inexistent-db
Conversation
|
@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 |
|
I would review this when this PR is ready. |
|
@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! |
ChTimTsubasa
left a comment
There was a problem hiding this comment.
Should add JDBC test to see if the response is correct.
src/catalog/catalog.cpp
Outdated
| bool Catalog::CheckDatabaseExists(const std::string &database_name) { | ||
| auto pg_database = DatabaseCatalog::GetInstance(); | ||
| auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance(); | ||
| auto txn = txn_manager.BeginTransaction(); |
There was a problem hiding this comment.
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.
test/catalog/catalog_test.cpp
Outdated
| catalog::Catalog::GetInstance()->CreateDatabase("EMP_DB", txn); | ||
|
|
||
| exists = catalog::Catalog::GetInstance()->CheckDatabaseExists("EMP_DB"); | ||
| EXPECT_EQ(true, exists); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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({ |
There was a problem hiding this comment.
Have you compared the responses you sent here with the Postgres's response? You can try to capture the packet using Wireshark.
There was a problem hiding this comment.
Yup, I have captured Postgres' responses using wireshark. I can capture Peloton's and compare the two.
|
@eribeiro Can you add the changes @ChTimTsubasa requested? |
|
@tcm-marcel yes, gonna change the PR tomorrow. Thanks for the review @ChTimTsubasa! |
|
@ChTimTsubasa I see the script |
ChTimTsubasa
left a comment
There was a problem hiding this comment.
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.
|
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:
I see that if I don't provide the database name after the slash ( |
|
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? |
|
@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! |
ChTimTsubasa
left a comment
There was a problem hiding this comment.
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.
| } catch (const std::exception &e) { | ||
| auto msg = e.what(); | ||
| LOG_INFO("[SimpleConnectionTest] Exception occurred: %s", msg); | ||
| EXPECT_TRUE(true); |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
What happens here if the server generates an exception?
|
I don't understand the comment about "not being able to register a test". How did you try to add the new test? |
|
@eribeiro What is the status of this? |
|
@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. :) |
No description provided.