-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
Execute actions under permit in primary mode only #42241
Changes from 8 commits
15fc6e1
ec689bb
d6bd1b8
bb46faa
df499c1
923e700
4fd9b37
ff90a28
fea358b
799f731
b348429
f38d926
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,6 @@ | |
package org.elasticsearch.index.shard; | ||
|
||
import com.carrotsearch.hppc.ObjectLongMap; | ||
|
||
import org.apache.logging.log4j.Logger; | ||
import org.apache.logging.log4j.message.ParameterizedMessage; | ||
import org.apache.lucene.index.CheckIndex; | ||
|
@@ -2496,7 +2495,7 @@ public void acquirePrimaryOperationPermit(ActionListener<Releasable> onPermitAcq | |
verifyNotClosed(); | ||
assert shardRouting.primary() : "acquirePrimaryOperationPermit should only be called on primary shard: " + shardRouting; | ||
|
||
indexShardOperationPermits.acquire(onPermitAcquired, executorOnDelay, false, debugInfo); | ||
indexShardOperationPermits.acquire(wrapPrimaryOperationPermitListener(onPermitAcquired), executorOnDelay, false, debugInfo); | ||
} | ||
|
||
/** | ||
|
@@ -2507,7 +2506,27 @@ public void acquireAllPrimaryOperationsPermits(final ActionListener<Releasable> | |
verifyNotClosed(); | ||
assert shardRouting.primary() : "acquireAllPrimaryOperationsPermits should only be called on primary shard: " + shardRouting; | ||
|
||
asyncBlockOperations(onPermitAcquired, timeout.duration(), timeout.timeUnit()); | ||
asyncBlockOperations(wrapPrimaryOperationPermitListener(onPermitAcquired), timeout.duration(), timeout.timeUnit()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change verifies the primary mode after acquiring permits. I think we should verify the primary mode before acquiring permits? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have to verify after otherwise our check could be invalidated by the time that we acquire the permit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, I missed the relocation situation. Thanks for the explanation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No problem. 😄 LGTM to you then? |
||
} | ||
|
||
/** | ||
* Wraps the action to run on a primary after acquiring permit. This wrapping is used to check if the shard is in primary mode before | ||
* executing the action. | ||
* | ||
* @param listener the listener to wrap | ||
* @return the wrapped listener | ||
*/ | ||
private ActionListener<Releasable> wrapPrimaryOperationPermitListener(final ActionListener<Releasable> listener) { | ||
return ActionListener.delegateFailure( | ||
listener, | ||
(l, r) -> { | ||
if (replicationTracker.isPrimaryMode() == false) { | ||
r.close(); | ||
l.onFailure(new IllegalStateException("shard is not in primary mode")); | ||
} else { | ||
l.onResponse(r); | ||
} | ||
}); | ||
} | ||
|
||
private void asyncBlockOperations(ActionListener<Releasable> onPermitAcquired, long timeout, TimeUnit timeUnit) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this should become a dedicated exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to a dedicated exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed 799f731.