Allow noop PutUser updates (#35843)

When assertions are enabled, a Put User action that have no effect (a
noop update) would trigger an assertion failure and shutdown the node.

This change accepts "noop" as an update result, and adds more
diagnostics to the assertion failure message.
This commit is contained in:
Tim Vernum 2018-11-27 15:08:53 +11:00 committed by GitHub
parent 3435fc4613
commit a18b219f79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -17,6 +17,7 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import java.io.IOException;
import java.util.Arrays;
import java.util.Map;
import static org.elasticsearch.action.ValidateActions.addValidationError;
@ -180,4 +181,18 @@ public class PutUserRequest extends ActionRequest implements UserRequest, WriteR
}
out.writeBytesReference(charBytesRef);
}
@Override
public String toString() {
return "PutUserRequest{" +
"username='" + username + '\'' +
", roles=" + Arrays.toString(roles) +
", fullName='" + fullName + '\'' +
", email='" + email + '\'' +
", metadata=" + metadata +
", passwordHash=" + (passwordHash == null ? "<null>" : "<not-null>") +
", enabled=" + enabled +
", refreshPolicy=" + refreshPolicy +
'}';
}
}

View File

@ -341,7 +341,9 @@ public class NativeUsersStore {
new ActionListener<UpdateResponse>() {
@Override
public void onResponse(UpdateResponse updateResponse) {
assert updateResponse.getResult() == DocWriteResponse.Result.UPDATED;
assert updateResponse.getResult() == DocWriteResponse.Result.UPDATED
|| updateResponse.getResult() == DocWriteResponse.Result.NOOP
: "Expected 'UPDATED' or 'NOOP' result [" + updateResponse + "] for request [" + putUserRequest + "]";
clearRealmCache(putUserRequest.username(), listener, false);
}