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

PHOENIX-6776 :- Abort scans of closed connections at ScanningResultIterator #1517

Merged
merged 9 commits into from
Oct 28, 2022

Conversation

lokiore
Copy link
Contributor

@lokiore lokiore commented Oct 7, 2022

Added isClosing property in PhoenixConnection as well, as we change isClose status after closing all the underline objects (Iterators, scanners, statements).

@Override
public void run() {
try {
ResultSet resultSet = conn.createStatement().executeQuery(
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't this thread need to loop or wait on the other thread to close the connection first? What if Thread t gets scheduled to run to completion (hence failure) before t1 does anything?

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 checked the time for completing query was more that 1500ms, but true that was on local, will add wait for proper conn closing thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

Another option to consider is whether you can do a synchronous test by, for example, mocking a Connection to always return isClosing = true, isClosed = false, and verifying that ScanningResultIterator does what you expect (runs its close logic)

Fixing the asynchronous logic to be deterministic through locking as you suggest also works.

Copy link
Contributor

Choose a reason for hiding this comment

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

@lokiore - The Thread.sleep calls still make this non-deterministic, don't they?

Copy link
Contributor

Choose a reason for hiding this comment

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

@lokiore, in general we do not want to use thread sleep as we can only guess the required sleep time and it changes from one system to another. This can make the test flapping. You can implement this test without having threads. In PhoenixConnection, you can define a testing only method to set the connection state to closing. After getting the connection, set the connection state closing using this method. Then you run the test code without creating threads and without closing the connection.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @gjacoby126 @kadirozde for suggesting, I have made changes Please take a look, Thanks

Copy link
Contributor

@gjacoby126 gjacoby126 left a comment

Choose a reason for hiding this comment

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

Thanks for the test fix. Just one tiny nit left and then I think this is ready to go.

@@ -190,4 +209,9 @@ public String toString() {
public ResultScanner getScanner() {
return scanner;
}

@VisibleForTesting
public static void setIsScannerClosedForceFully(boolean throwException) {
Copy link
Contributor

Choose a reason for hiding this comment

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

tiny nit: "forcefully" is one word so only the first F should be capitalized

@lokiore lokiore requested review from gjacoby126 and kadirozde and removed request for gjacoby126 and kadirozde October 28, 2022 17:37
@lokiore
Copy link
Contributor Author

lokiore commented Oct 28, 2022

I am trying to re-request review from both @gjacoby126 and @kadirozde but somehow it is removing one when I add other 😓, please take a look, Thanks!!

Copy link
Contributor

@gjacoby126 gjacoby126 left a comment

Choose a reason for hiding this comment

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

+1, thanks @lokiore

int amount = -50000 + i;
String s = "UPSERT INTO LONG_BUG (ID, AMOUNT) VALUES( " + i + ", " + amount + ")";
conn.createStatement().execute(s);
conn.commit();
Copy link
Contributor

Choose a reason for hiding this comment

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

It will be faster if you move this commit out of the loop

Copy link
Contributor

Choose a reason for hiding this comment

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

Also we should not need to add 5000 rows for this test after the recent changes. Let's reduce it to say 100.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pushed the change Thanks for pointing.

@@ -1374,6 +1381,11 @@ public void setTableResultIteratorFactory(TableResultIteratorFactory factory) {
this.tableResultIteratorFactory = factory;
}

@VisibleForTesting
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comment for this method is that it is only used for testing?

Copy link
Contributor

@kadirozde kadirozde left a comment

Choose a reason for hiding this comment

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

+1, Thank you!

@kadirozde kadirozde merged commit 24887be into apache:master Oct 28, 2022
lokiore added a commit to lokiore/phoenix that referenced this pull request Nov 9, 2022
…erator (apache#1517)

Co-authored-by: Lokesh Khurana <lokesh.khurana@salesforce.com>
tkhurana pushed a commit that referenced this pull request Nov 9, 2022
…erator (#1517) (#1525)

Co-authored-by: Lokesh Khurana <lokesh.khurana@salesforce.com>
@mnpoonia
Copy link
Contributor

@lokiore This change is causing regression in IndexScrutiny tool which in turn is causing tests to fail
See https://issues.apache.org/jira/browse/PHOENIX-6828

asfgit pushed a commit that referenced this pull request Nov 21, 2022
asfgit pushed a commit that referenced this pull request Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants