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

Replace InMemoryPersistedState with GatewayMetaState in CoordinatorTests #36897

Merged
merged 10 commits into from
Jan 15, 2019

Conversation

andrershov
Copy link
Contributor

This PR replaces InMemoryPersistedState withGatewayMetaState in
CoordinatorTests.
When performing such a replacement the main question was: do we want to
emulate exceptions as we do today in MockPersistedState before
delegating to GatewayMetaState or do we want these exceptions to
propagate from the lower level, i.e. file system exceptions?
On the one hand, lower level exception propagation is already tested in
GatewayMetaStateTests, so this won't improve the coverage.
On the other hand, the benefit of low-level exceptions is to see how all these
components work in conjunction. Finally, we abandoned the idea of low-level
exceptions because we don't have a way to deal with IOError today in
CoordinatorTests, but hacking GatewayMetaState not to throw
IOError seems unnatural.
So MockPersistedState rarely throws an exception before delegating to
GatewayMetaState, which is not supposed to throw the exception.

This commit required two changes:

  1. Move GatewayMetaStateUT to upper-level from
    GatewayMetaStatePersistedStateTests, because otherwise it's not easy
    to construct GatewayMetaState instance in CoordinatorTests.
  2. Move addition of STATE_NOT_RECOVERED_BLOCK from GatewayMetaState
    constructor to GatewayMetaState.applyClusterUpdaters, because
    CoordinatorTests class assume that there is no such block and most of
    them fail.

Other classes can be migrated from InMemoryPersistedState to
GatewayMetaState as well if requested by reviewers.

@andrershov andrershov added >test Issues or PRs that are addressing/adding tests :Distributed Coordination/Cluster Coordination Cluster formation and cluster state publication, including cluster membership and fault detection. labels Dec 20, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-distributed

Copy link
Contributor

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

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

Looks good. I suggested a renaming and a nit. I'm going to run this for a few iterations on my CI machine to be sure before we merge it.

* Metadata upgrade is tested in {@link GatewayMetaStateTests} and different {@link ClusterStateUpdaters} in
* {@link ClusterStateUpdatersTests}.
*/
public class GatewayMetaStateUT extends GatewayMetaState {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe MockGatewayMetaState would be a better name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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


public GatewayMetaStateUT(Settings settings, NodeEnvironment nodeEnvironment,
NamedXContentRegistry xContentRegistry,
DiscoveryNode localNode) throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: funny indentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

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

Hmm, this change substantially adds to the time it takes to run these tests. I guess this is to be expected since we're hitting the disk and fsyncing and so on. I ran Gradle with these options:

:server:test -Dtests.class=org.elasticsearch.cluster.coordination.CoordinatorTests -Dtests.jvm.argline=-Dhppc.bitmixer=DETERMINISTIC -Dtests.iters=20 -Dtests.failfast=true

On master, the second time through this took 514 sec. On this branch, it took 891 sec, 73% longer. Maybe we should only use a proper persistence layer rarely?

@ywelsch
Copy link
Contributor

ywelsch commented Dec 20, 2018

+1 on using it rarely

@andrershov
Copy link
Contributor Author

@DaveCTurner I've addressed your comments and changed MockPersistedState to use GatewayMetaState rarely and use InMemoryPersistedState in other cases. Ready for the 2nd pass.

@andrershov
Copy link
Contributor Author

run gradle build tests 1

@andrershov
Copy link
Contributor Author

run gradle build tests 2

Copy link
Contributor

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

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

Just a couple more nits.

try {
persistedState = new MockPersistedState(settings, localNode);
} catch (IOException e) {
fail("Unable to create MockPersistedState");
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we would like to see the caught exception here:

Suggested change
fail("Unable to create MockPersistedState");
throw new AssertionError("Unable to create MockPersistedState", e);


MockPersistedState(Settings settings, DiscoveryNode localNode) throws IOException {
if (rarely()) {
NodeEnvironment nodeEnvironment = newNodeEnvironment();
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: too much indent here?

@andrershov
Copy link
Contributor Author

@DaveCTurner Can you please make the next pass? I've fixed nits and last merge with master introduced node restart in CoordinatorTests (40b303c), so now MockPersistedState supports restarts when GatewayMetaState is used.

Copy link
Contributor

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @andrershov. Could you add a version label before merging?

@andrershov
Copy link
Contributor Author

test this please

@ywelsch ywelsch mentioned this pull request Jan 14, 2019
61 tasks
Conflicts in CoordinatorTests.java
@andrershov
Copy link
Contributor Author

run gradle build tests 2

1 similar comment
@andrershov
Copy link
Contributor Author

run gradle build tests 2

@andrershov andrershov merged commit 42fd68e into elastic:master Jan 15, 2019
@jimczi jimczi added v7.0.0-beta1 and removed v7.0.0 labels Feb 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed Coordination/Cluster Coordination Cluster formation and cluster state publication, including cluster membership and fault detection. >test Issues or PRs that are addressing/adding tests v7.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants