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

Index "creation_date" not accurate when created with settings from another index #12854

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -375,6 +375,35 @@ public CreateIndexRequest source(BytesReference source) {
return this;
}

/**
* To filter the parameters in settings that are not be used
* by elasticsearch users but only allowed for internal usage.
*/
private Map<String, Object> filterBannedSettings(Map<String, Object> value) {
// banning version.created as it is just an internal settings
// we should remove it from both within index and outside index
// as api allows settings encapsulated within index and outside it.
if (value.get("version") != null) {
filterCreatedParam((Map<String, Object>) value.get("version"));
}
if (value.get("index") != null) {
Map<String, Object> index = (Map<String, Object>)value.get("index");
if (index.get("version") != null) {
filterCreatedParam((Map<String, Object>) index.get("version"));
}
}
return value;
}

/**
* To filter "created" param from the input settings.
*/
private void filterCreatedParam(Map<String, Object> value) {
if (value.get("created") != null) {
value.remove("created");
}
}

/**
* Sets the settings and mappings as a single source.
*/
Expand All @@ -385,7 +414,7 @@ public CreateIndexRequest source(Map<String, ?> source) {
String name = entry.getKey();
if (name.equals("settings")) {
found = true;
settings((Map<String, Object>) entry.getValue());
settings(filterBannedSettings((Map<String, Object>) entry.getValue()));
} else if (name.equals("mappings")) {
found = true;
Map<String, Object> mappings = (Map<String, Object>) entry.getValue();
Expand Down
Expand Up @@ -329,9 +329,10 @@ public ClusterState execute(ClusterState currentState) throws Exception {
indexSettingsBuilder.put(SETTING_VERSION_CREATED, createdVersion);
}

if (indexSettingsBuilder.get(SETTING_CREATION_DATE) == null) {
indexSettingsBuilder.put(SETTING_CREATION_DATE, new DateTime(DateTimeZone.UTC).getMillis());
}
// removing it due to bug : https://github.com/elastic/elasticsearch/issues/12790
// if (indexSettingsBuilder.get(SETTING_CREATION_DATE) == null) {
indexSettingsBuilder.put(SETTING_CREATION_DATE, new DateTime(DateTimeZone.UTC).getMillis());
//}

indexSettingsBuilder.put(SETTING_INDEX_UUID, Strings.randomBase64UUID());

Expand Down
Expand Up @@ -40,22 +40,6 @@
@ClusterScope(scope = Scope.TEST)
public class CreateIndexIT extends ESIntegTestCase {

@Test
public void testCreationDate_Given() {
prepareCreate("test").setSettings(Settings.builder().put(IndexMetaData.SETTING_CREATION_DATE, 4l)).get();
ClusterStateResponse response = client().admin().cluster().prepareState().get();
ClusterState state = response.getState();
assertThat(state, notNullValue());
MetaData metadata = state.getMetaData();
assertThat(metadata, notNullValue());
ImmutableOpenMap<String, IndexMetaData> indices = metadata.getIndices();
assertThat(indices, notNullValue());
assertThat(indices.size(), equalTo(1));
IndexMetaData index = indices.get("test");
assertThat(index, notNullValue());
assertThat(index.creationDate(), equalTo(4l));
}

@Test
public void testCreationDate_Generated() {
long timeBeforeRequest = System.currentTimeMillis();
Expand Down