-
Notifications
You must be signed in to change notification settings - Fork 25.2k
log messages from allocation commands #25955
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
Changes from 12 commits
d13d904
7fc7e91
fe12f4f
30b1d7c
459da7b
4ae5e1e
c140fb5
8b1a14c
50a292c
c409959
7c4256b
33d62f8
b9db126
3a40d56
9f69454
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 |
---|---|---|
|
@@ -38,6 +38,7 @@ | |
import org.elasticsearch.index.shard.ShardNotFoundException; | ||
|
||
import java.io.IOException; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Allocates an unassigned empty primary shard to a specific node. Use with extreme care as this will result in data loss. | ||
|
@@ -72,6 +73,11 @@ public String name() { | |
return NAME; | ||
} | ||
|
||
@Override | ||
public Optional<String> getMessage() { | ||
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. Question, why did you do it here and not as part of the 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. My thinking was that we didn't want to change the wire format of RerouteExplanation by adding the message to it (I think Yannick mentioned this), so here seemed like an okay place to generate the message. Do you mean putting this message into one of the field of the Decision that the RerouteExplanation is constructed with? E.g. public RerouteExplanation execute(RoutingAllocation allocation, boolean explain) {
// ...
return new RerouteExplanation(this, allocation.decision(Decision.YES, name() + " (allocation command)", "allocated an empty primary for ... rest of the message"));
} 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. I was was thinking about adding a message field to RerouteExplanation it self. The write thing is not a big deal IMO |
||
return Optional.of("Allocated an empty primary for [" + index + "][" + shardId + "] on node [" + node + "]"); | ||
} | ||
|
||
public static AllocateEmptyPrimaryAllocationCommand fromXContent(XContentParser parser) throws IOException { | ||
return new Builder().parse(parser).build(); | ||
} | ||
|
@@ -115,19 +121,22 @@ public RerouteExplanation execute(RoutingAllocation allocation, boolean explain) | |
} | ||
|
||
if (shardRouting.recoverySource().getType() != RecoverySource.Type.EMPTY_STORE && acceptDataLoss == false) { | ||
return explainOrThrowRejectedCommand(explain, allocation, | ||
"allocating an empty primary for [" + index + "][" + shardId + "] can result in data loss. Please confirm by setting the accept_data_loss parameter to true"); | ||
String dataLossWarning = "allocating an empty primary for [" + index + "][" + shardId + "] can result in data loss. Please confirm " + | ||
"by setting the accept_data_loss parameter to true"; | ||
return explainOrThrowRejectedCommand(explain, allocation, dataLossWarning); | ||
} | ||
|
||
UnassignedInfo unassignedInfoToUpdate = null; | ||
if (shardRouting.unassignedInfo().getReason() != UnassignedInfo.Reason.FORCED_EMPTY_PRIMARY) { | ||
unassignedInfoToUpdate = new UnassignedInfo(UnassignedInfo.Reason.FORCED_EMPTY_PRIMARY, | ||
"force empty allocation from previous reason " + shardRouting.unassignedInfo().getReason() + ", " + shardRouting.unassignedInfo().getMessage(), | ||
String unassignedInfoMessage = "force empty allocation from previous reason " + shardRouting.unassignedInfo().getReason() + | ||
", " + shardRouting.unassignedInfo().getMessage(); | ||
unassignedInfoToUpdate = new UnassignedInfo(UnassignedInfo.Reason.FORCED_EMPTY_PRIMARY, unassignedInfoMessage, | ||
shardRouting.unassignedInfo().getFailure(), 0, System.nanoTime(), System.currentTimeMillis(), false, | ||
shardRouting.unassignedInfo().getLastAllocationStatus()); | ||
} | ||
|
||
initializeUnassignedShard(allocation, routingNodes, routingNode, shardRouting, unassignedInfoToUpdate, StoreRecoverySource.EMPTY_STORE_INSTANCE); | ||
initializeUnassignedShard(allocation, routingNodes, routingNode, shardRouting, unassignedInfoToUpdate, | ||
StoreRecoverySource.EMPTY_STORE_INSTANCE); | ||
|
||
return new RerouteExplanation(this, allocation.decision(Decision.YES, name() + " (allocation command)", "ignore deciders")); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ | |
import org.elasticsearch.index.shard.ShardNotFoundException; | ||
|
||
import java.io.IOException; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Allocates an unassigned stale primary shard to a specific node. Use with extreme care as this will result in data loss. | ||
|
@@ -70,6 +71,11 @@ public String name() { | |
return NAME; | ||
} | ||
|
||
@Override | ||
public Optional<String> getMessage() { | ||
return Optional.of("Allocated a stale primary for [" + index + "][" + shardId + "] on node [" + node + "]"); | ||
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. log messages always start in lower case. Also I wonder if we should give this (and AllocateEmptyPrimaryAllocationCommand) a stronger wording, e.g. "force-allocated a stale primary ...", to make it clearer that this action has been explicitly forced by the user, not the system. 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. That's a good idea, will make it more clear that it came from a command |
||
} | ||
|
||
public static AllocateStalePrimaryAllocationCommand fromXContent(XContentParser parser) throws IOException { | ||
return new Builder().parse(parser).build(); | ||
} | ||
|
@@ -113,8 +119,9 @@ public RerouteExplanation execute(RoutingAllocation allocation, boolean explain) | |
} | ||
|
||
if (acceptDataLoss == false) { | ||
return explainOrThrowRejectedCommand(explain, allocation, | ||
"allocating an empty primary for [" + index + "][" + shardId + "] can result in data loss. Please confirm by setting the accept_data_loss parameter to true"); | ||
String dataLossWarning = "allocating an empty primary for [" + index + "][" + shardId + "] can result in data loss. Please " + | ||
"confirm by setting the accept_data_loss parameter to true"; | ||
return explainOrThrowRejectedCommand(explain, allocation, dataLossWarning); | ||
} | ||
|
||
if (shardRouting.recoverySource().getType() != RecoverySource.Type.EXISTING_STORE) { | ||
|
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.
Should this go into a
finally
block in case an exception is thrown ingetMessages
?Uh oh!
There was an error while loading. Please reload this page.
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.
Sounds good to me. If that were to happen without
finally
, would an error response with the exception be returned somewhere "upstream", or would the request handling just time out?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 presume that the error would be logged and the connection would hang until the client timed out (just a guess)
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.
ActionListener#wrap protects against this: