Skip to content

Conversation

bleskes
Copy link
Contributor

@bleskes bleskes commented Jan 25, 2016

In the early days Elasticsearch used to use the index name as the index identity. Around 1.0.0 we introduced a unique index uuid which is stored in the index setting. Since then we used that uuid in a few places but it is by far not the main identifier when working with indices, partially because it's not always readily available in all places.

This PR start to make a move in the direction of using uuids instead of name by making sure that the uuid is available on the Index class (currently just a wrapper around the name) and as such also available via ShardRouting and ShardId.

Note that this is by no means an attempt to do the right thing with the uuid in all places. In almost all places it falls back to the name based comparison that was done before. It is meant as a first step towards slowly improving the situation.

PS. This came from starting to think about implementing storing indices on disk using folders NAME_UUID pattern (instead of just name as we do today) and thus being able to avoid collision between indices that are named the same (but deleted and recreated). The hope is that this will als remove the need for the in memory shard locks we have now. The problem was that I didn't have easy access to the uuid in all places.

While the tests are not all passing ( 99% of them are). I think this is ready to get initial feedback.

@bleskes bleskes changed the title Make index uuid available on ShardRouting, ShardId Make index uuid available in Index, ShardRouting & ShardId Jan 26, 2016

private Index() {

}

public Index(String name) {
public Index(String name, String uuid) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we please get rid of the interning? I think we should do this in a sep PR before this get's merged

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure - didn't want to make things controversial. I'll make a PR to remove the name.intern()

@s1monw
Copy link
Contributor

s1monw commented Jan 26, 2016

I love this - infact I started the same effort last week but didn't get too far time wise. I am +100 on this. I really think we have to try to get rid of the _na_ as much as possible or at least use assertions to ensure we never get it when we really need a real uuid! please get this in ASAP :)

@bleskes
Copy link
Contributor Author

bleskes commented Jan 26, 2016

@s1monw I rebased on master and addressed your comments. All test pass now. Can you take another look?

}
} else {
minimumCompatibleLuceneVersion = null;
}

return new IndexMetaData(index, version, state, numberOfShards, numberOfReplicas, tmpSettings, mappings.build(),
final String uuid = settings.get(SETTING_INDEX_UUID, INDEX_UUID_NA_VALUE);
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure but shouldn't this one be a generated one if it's not in the settings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At least at the moment the uuid generation is done on MetaDataCreateIndexService#createIndex - here we just create a IndexMetaData object, not knowing if it's new or old. The way I did it mimics what the old code did (by return this from the settings directly). I want to keep the semantic change as small as possible.

@s1monw
Copy link
Contributor

s1monw commented Jan 27, 2016

@bleskes LGTM I left minor comments in the code, can we maybe also add an assertion that the uuid is a real UUID when we create IndexService? that would be awesome. No need for another review!!! thanks so much for doing this

@bleskes bleskes closed this in 2a137b5 Jan 28, 2016
@@ -76,7 +76,7 @@ public boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
ShardId shardId1 = (ShardId) o;
return shardId == shardId1.shardId && index.name().equals(shardId1.index.name());
return shardId == shardId1.shardId && index.getName().equals(shardId1.index.getName());
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 this should be:

        return shardId == shardId1.shardId && index.equals(shardId1.index);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants