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

fix repository update with the same settings but different type #31458

Merged

Conversation

vladimirdolzhenko
Copy link
Contributor

No description provided.

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-distributed

@@ -349,7 +349,7 @@ private boolean registerRepository(RepositoryMetaData repositoryMetaData) throws
Repository previous = repositories.get(repositoryMetaData.name());
if (previous != null) {
RepositoryMetaData previousMetadata = previous.getMetadata();
if (!previousMetadata.type().equals(repositoryMetaData.type()) && previousMetadata.settings().equals(repositoryMetaData.settings())) {
if (previousMetadata.type().equals(repositoryMetaData.type()) && previousMetadata.settings().equals(repositoryMetaData.settings())) {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can just use RepositoryMetaData.equals() here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

make sense

return Collections.singletonList(TestFSRepositoryPlugin.class);
}

public static class TestFSRepositoryPlugin extends Plugin implements RepositoryPlugin {
Copy link
Member

Choose a reason for hiding this comment

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

You can use MockRepository.Plugin instead of adding a new type of repository

Copy link
Member

@tlrx tlrx left a comment

Choose a reason for hiding this comment

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

I left some comments


Client client = client();
Settings settings = ((InternalTestCluster) cluster()).getDefaultSettings();
Path location = randomRepoPath(settings);
Copy link
Member

Choose a reason for hiding this comment

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

Why not using randomPath() directly?

assertThat(getRepositoriesResponse2.repositories(), hasSize(1));
RepositoryMetaData repositoryMetaData2 = getRepositoriesResponse2.repositories().get(0);

assertThat(repositoryMetaData2.type(), equalTo(FAKE_FS_TYPE));
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if we should also check the Repository instance itself using internalCluster().getInstance(RepositoriesService.class).repository(name) and check if the instance is the same or has changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agree - make sense to add that kind of check

@vladimirdolzhenko
Copy link
Contributor Author

@tlrx thanks for your comments, could you pls have another look ?

Copy link
Member

@tlrx tlrx left a comment

Choose a reason for hiding this comment

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

I left more minor comments, thanks @vladimirdolzhenko for fixing this!

.setType(FsRepository.TYPE)
.setSettings(repoSettings)
.get();
assertThat(putRepositoryResponse1.isAcknowledged(), equalTo(true));
Copy link
Member

Choose a reason for hiding this comment

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

You can use assertAcked(client.admin().cluster().preparePutRepository(repositoryName)
.setType(FsRepository.TYPE)
.setSettings(repoSettings))


// update repository

boolean diffType = randomBoolean();
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we could make this more readable with:
final String updatedRepositoryType = randomBoolean() ? "mock" : FsRepository.TYPE

?

.setType(diffType ? "mock" : FsRepository.TYPE)
.setSettings(repoSettings)
.get();
assertThat(putRepositoryResponse2.isAcknowledged(), equalTo(true));
Copy link
Member

Choose a reason for hiding this comment

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

You can use assertAcked()

assertThat(repositoryMetaData2.type(), equalTo(diffType ? "mock" : FsRepository.TYPE));

Repository repository2 = repositoriesService.repository(repositoryName);
assertThat(repository2, instanceOf(diffType ? MockRepository.class : FsRepository.class));
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need to check the implementation class, instance should be enough.


assertThat(repositoryMetaData2.type(), equalTo(diffType ? "mock" : FsRepository.TYPE));

Repository repository2 = repositoriesService.repository(repositoryName);
Copy link
Member

Choose a reason for hiding this comment

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

Can you use more explicit name? (Also for getRepositoriesResponse1/2).

@vladimirdolzhenko
Copy link
Contributor Author

test this please

Copy link
Member

@tlrx tlrx left a comment

Choose a reason for hiding this comment

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

Another bunch of minor comments, sorry I didn't catch everything the first times.


Client client = client();
InternalTestCluster cluster = (InternalTestCluster) cluster();
RepositoriesService repositoriesService = cluster.getInstance(RepositoriesService.class);
Copy link
Member

Choose a reason for hiding this comment

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

Can you make this final? Also, I think you should use getDataOrMasterNodeInstances as the repository is only registered on master eligible and data nodes. The method getInstance() retrieves the instance from a random node and if it's not a data or master one it will not find the repository.

InternalTestCluster cluster = (InternalTestCluster) cluster();
RepositoriesService repositoriesService = cluster.getInstance(RepositoriesService.class);
Settings settings = cluster.getDefaultSettings();
Path location = randomRepoPath();
Copy link
Member

Choose a reason for hiding this comment

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

If it's not used afterwards, maybe we don't need a ref to the location. We could simply use .put("location", randomRepoPath())

.setSettings(repoSettings)
.get());

GetRepositoriesResponse originalRetRepositoriesResponse =
Copy link
Member

Choose a reason for hiding this comment

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

Nit: typo in originalRetRepositoriesResponse

}

public void testUpdateRepository() {
String repositoryName = "test-repo";
Copy link
Member

Choose a reason for hiding this comment

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

Can you make it final?

// update repository

boolean updated = randomBoolean();
String updatedRepositoryType = updated ? "mock" : FsRepository.TYPE;
Copy link
Member

Choose a reason for hiding this comment

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

updated and updatedRepositoryType can be final too

@vladimirdolzhenko
Copy link
Contributor Author

test this please

1 similar comment
@vladimirdolzhenko
Copy link
Contributor Author

test this please

Copy link
Member

@tlrx tlrx left a comment

Choose a reason for hiding this comment

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

LGTM - I left a more comments that I'd like to be addressed before merging but I don't think that it will require another review

cluster.getDataOrMasterNodeInstances(RepositoriesService.class).iterator().next();
final Settings settings = cluster.getDefaultSettings();

final Settings.Builder repoSettings = Settings.builder().put(settings).put("location", randomRepoPath());
Copy link
Member

Choose a reason for hiding this comment

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

You don't need to pass the default cluster settings here but location is enough for a FS repository

final Repository originalRepository = repositoriesService.repository(repositoryName);
assertThat(originalRepository, instanceOf(FsRepository.class));

// update repository
Copy link
Member

Choose a reason for hiding this comment

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

I think you can remove this comment

}

public void testUpdateRepository() throws Exception {
waitNoPendingTasksOnAll();
Copy link
Member

Choose a reason for hiding this comment

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

Thinking about it twice, I don't think that this is necessary. I think you can remove it, run the test multiple times andsee if it fails or not.

@vladimirdolzhenko
Copy link
Contributor Author

thanks @tlrx for your comments

@vladimirdolzhenko vladimirdolzhenko merged commit 7313a98 into elastic:master Jun 22, 2018
@vladimirdolzhenko vladimirdolzhenko deleted the fix_repo_update_diff_type branch June 22, 2018 15:44
dnhatn added a commit that referenced this pull request Jun 23, 2018
* master:
  Add get field mappings to High Level REST API Client (#31423)
  [DOCS] Updates Watcher examples for code testing (#31152)
  TEST: Add bwc recovery tests with synced-flush index
  [DOCS] Move sql to docs (#31474)
  [DOCS] Move monitoring to docs folder (#31477)
  Core: Combine doExecute methods in TransportAction (#31517)
  IndexShard should not return null stats (#31528)
  fix repository update with the same settings but different type (#31458)
  Fix Mockito trying to mock IOException that isn't thrown by method (#31433) (#31527)
  Node selector per client rather than per request (#31471)
  Core: Combine messageRecieved methods in TransportRequestHandler (#31519)
  Upgrade to Lucene 7.4.0. (#31529)
  [ML] Add ML filter update API (#31437)
  Allow multiple unicast host providers (#31509)
  Avoid deprecation warning when running the ML datafeed extractor. (#31463)
  REST high-level client: add simulate pipeline API (#31158)
  Get Mapping API to honour allow_no_indices and ignore_unavailable (#31507)
  [PkiRealm] Invalidate cache on role mappings change (#31510)
  [Security] Check auth scheme case insensitively (#31490)
  In NumberFieldType equals and hashCode, make sure that NumberType is taken into account. (#31514)
  [DOCS] Fix REST tests in SQL docs
  [DOCS] Add code snippet testing in more ML APIs (#31339)
  Core: Remove ThreadPool from base TransportAction (#31492)
  [DOCS] Remove fixed file from build.gradle
  Rename createNewTranslog to fileBasedRecovery (#31508)
  Test: Skip assertion on windows
  [DOCS] Creates field and document level security overview (#30937)
  [DOCS] Significantly improve SQL docs
  [DOCS] Move migration APIs to docs (#31473)
  Core: Convert TransportAction.execute uses to client calls (#31487)
  Return transport addresses from UnicastHostsProvider (#31426)
  Ensure local addresses aren't null (#31440)
  Remove unused generic type for client execute method (#31444)
  Introduce http and tcp server channels (#31446)
jasontedor added a commit to hub-cap/elasticsearch that referenced this pull request Jun 25, 2018
* elastic/master: (92 commits)
  Reduce number of raw types warnings (elastic#31523)
  Migrate scripted metric aggregation scripts to ScriptContext design (elastic#30111)
  turn GetFieldMappingsResponse to ToXContentObject (elastic#31544)
  Close xcontent parsers (partial) (elastic#31513)
  Ingest Attachment: Upgrade Tika to 1.18 (elastic#31252)
  TEST: Correct the assertion arguments order (elastic#31540)
  Add get field mappings to High Level REST API Client (elastic#31423)
  [DOCS] Updates Watcher examples for code testing (elastic#31152)
  TEST: Add bwc recovery tests with synced-flush index
  [DOCS] Move sql to docs (elastic#31474)
  [DOCS] Move monitoring to docs folder (elastic#31477)
  Core: Combine doExecute methods in TransportAction (elastic#31517)
  IndexShard should not return null stats (elastic#31528)
  fix repository update with the same settings but different type (elastic#31458)
  Fix Mockito trying to mock IOException that isn't thrown by method (elastic#31433) (elastic#31527)
  Node selector per client rather than per request (elastic#31471)
  Core: Combine messageRecieved methods in TransportRequestHandler (elastic#31519)
  Upgrade to Lucene 7.4.0. (elastic#31529)
  [ML] Add ML filter update API (elastic#31437)
  Allow multiple unicast host providers (elastic#31509)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Distributed Coordination/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs v6.4.0 v7.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants