You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@geode.apache.org by GitBox <gi...@apache.org> on 2022/05/30 00:27:07 UTC
[GitHub] [geode] nabarunnag opened a new pull request, #7740: GEODE-10106: Use queueConnection snapshot for if
nabarunnag opened a new pull request, #7740:
URL: https://github.com/apache/geode/pull/7740
* Using queueConnection snapshot for multiple if checks
* As it is a volatile variable, the value may become null mid checks.
<!-- Thank you for submitting a contribution to Apache Geode. -->
<!-- In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:
-->
### For all changes:
- [ ] Is there a JIRA ticket associated with this PR? Is it referenced in the commit message?
- [ ] Has your PR been rebased against the latest commit within the target branch (typically `develop`)?
- [ ] Is your initial contribution a single, squashed commit?
- [ ] Does `gradlew build` run cleanly?
- [ ] Have you written or updated unit tests to verify your changes?
- [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
<!-- Note:
Please ensure that once the PR is submitted, check Concourse for build issues and
submit an update to your PR as soon as possible. If you need help, please send an
email to dev@geode.apache.org.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] pivotal-jbarrett commented on a diff in pull request #7740: GEODE-10106: Use queueConnection snapshot for if
Posted by GitBox <gi...@apache.org>.
pivotal-jbarrett commented on code in PR #7740:
URL: https://github.com/apache/geode/pull/7740#discussion_r887358938
##########
geode-core/src/main/java/org/apache/geode/cache/client/internal/QueueManagerImpl.java:
##########
@@ -966,6 +965,16 @@ public void recoverPrimary(Set<ServerLocation> excludedServers) {
}
}
+ private boolean isPrimaryRecoveryNeeded(final ConnectionList queueConnectionList) {
Review Comment:
If you make this static you could easily create unit tests that could test all the paths in this method.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] nabarunnag merged pull request #7740: GEODE-10106: Use queueConnection snapshot for if
Posted by GitBox <gi...@apache.org>.
nabarunnag merged PR #7740:
URL: https://github.com/apache/geode/pull/7740
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] nabarunnag commented on a diff in pull request #7740: GEODE-10106: Use queueConnection snapshot for if
Posted by GitBox <gi...@apache.org>.
nabarunnag commented on code in PR #7740:
URL: https://github.com/apache/geode/pull/7740#discussion_r888380716
##########
geode-core/src/main/java/org/apache/geode/cache/client/internal/QueueManagerImpl.java:
##########
@@ -966,6 +965,17 @@ public void recoverPrimary(Set<ServerLocation> excludedServers) {
}
}
+ @VisibleForTesting
+ public static boolean isPrimaryRecoveryNeeded(final ConnectionList queueConnectionList) {
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] nabarunnag commented on a diff in pull request #7740: GEODE-10106: Use queueConnection snapshot for if
Posted by GitBox <gi...@apache.org>.
nabarunnag commented on code in PR #7740:
URL: https://github.com/apache/geode/pull/7740#discussion_r887543290
##########
geode-core/src/main/java/org/apache/geode/cache/client/internal/QueueManagerImpl.java:
##########
@@ -966,6 +965,16 @@ public void recoverPrimary(Set<ServerLocation> excludedServers) {
}
}
+ private boolean isPrimaryRecoveryNeeded(final ConnectionList queueConnectionList) {
Review Comment:
@pivotal-jbarrett done, all branches are covered now.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] pivotal-jbarrett commented on a diff in pull request #7740: GEODE-10106: Use queueConnection snapshot for if
Posted by GitBox <gi...@apache.org>.
pivotal-jbarrett commented on code in PR #7740:
URL: https://github.com/apache/geode/pull/7740#discussion_r887574681
##########
geode-core/src/main/java/org/apache/geode/cache/client/internal/QueueManagerImpl.java:
##########
@@ -966,6 +965,17 @@ public void recoverPrimary(Set<ServerLocation> excludedServers) {
}
}
+ @VisibleForTesting
+ public static boolean isPrimaryRecoveryNeeded(final ConnectionList queueConnectionList) {
Review Comment:
For unit tests in the same package this doesn't need to be public. Then you can also drop the annotation.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] nabarunnag commented on a diff in pull request #7740: GEODE-10106: Use queueConnection snapshot for if
Posted by GitBox <gi...@apache.org>.
nabarunnag commented on code in PR #7740:
URL: https://github.com/apache/geode/pull/7740#discussion_r887320991
##########
geode-core/src/main/java/org/apache/geode/cache/client/internal/QueueManagerImpl.java:
##########
@@ -862,8 +862,9 @@ public void recoverPrimary(Set<ServerLocation> excludedServers) {
return;
}
final boolean isDebugEnabled = logger.isDebugEnabled();
- if (queueConnections != null && queueConnections.getPrimary() != null
- && !queueConnections.getPrimary().isDestroyed()) {
+ ConnectionList snapshot = queueConnections;
Review Comment:
@pivotal-jbarrett I just cherry-pick the fix from another method in the same class. I will get it refactored
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] pivotal-jbarrett commented on a diff in pull request #7740: GEODE-10106: Use queueConnection snapshot for if
Posted by GitBox <gi...@apache.org>.
pivotal-jbarrett commented on code in PR #7740:
URL: https://github.com/apache/geode/pull/7740#discussion_r887249683
##########
geode-core/src/main/java/org/apache/geode/cache/client/internal/QueueManagerImpl.java:
##########
@@ -862,8 +862,9 @@ public void recoverPrimary(Set<ServerLocation> excludedServers) {
return;
}
final boolean isDebugEnabled = logger.isDebugEnabled();
- if (queueConnections != null && queueConnections.getPrimary() != null
- && !queueConnections.getPrimary().isDestroyed()) {
+ ConnectionList snapshot = queueConnections;
Review Comment:
I really don't like the name snapshot. It isn't a snapshot since the contents of the queue can change. It is the current reference to the queue. For volatiles I prefer either a local prefix, like `localQueueConnctions`, or just shadowing the member like:
```java
final ConnectionList queueConnections = this.queueConnections;
```
It can be made slightly more clear the intent with a little refactor.
```java
final ConnectionList queueConnections = getQueueConnections();
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] pivotal-jbarrett commented on a diff in pull request #7740: GEODE-10106: Use queueConnection snapshot for if
Posted by GitBox <gi...@apache.org>.
pivotal-jbarrett commented on code in PR #7740:
URL: https://github.com/apache/geode/pull/7740#discussion_r887255651
##########
geode-core/src/main/java/org/apache/geode/cache/client/internal/QueueManagerImpl.java:
##########
@@ -862,8 +862,9 @@ public void recoverPrimary(Set<ServerLocation> excludedServers) {
return;
}
final boolean isDebugEnabled = logger.isDebugEnabled();
- if (queueConnections != null && queueConnections.getPrimary() != null
- && !queueConnections.getPrimary().isDestroyed()) {
+ ConnectionList snapshot = queueConnections;
Review Comment:
Alternatively:
```java
if (primaryNotDestroyed(queueConnections)) {
...
}
...
static boolean primaryNotDestroyed(final ConnectionList connectionList) {
if (null != connectionList) {
final Connection primaryConnection = connectionList.getPrimary();
if (null != primaryConnection) {
return !primaryConnection.isDestroyed();
}
}
return false;
}
```
Now this new method is unit testable and guaranteed to be a non-volatile reference.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org