Use UTC as timeszone for index creation date

This commit is contained in:
Simon Willnauer 2015-06-18 11:15:40 +02:00
parent 2a63249441
commit 85dccdb8ab
3 changed files with 7 additions and 3 deletions

View File

@ -48,6 +48,7 @@ import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.search.warmer.IndexWarmersMetaData; import org.elasticsearch.search.warmer.IndexWarmersMetaData;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import java.io.IOException; import java.io.IOException;
import java.text.ParseException; import java.text.ParseException;
@ -940,7 +941,7 @@ public class IndexMetaData implements Diffable<IndexMetaData> {
} }
Long creationDate = settings.getAsLong(SETTING_CREATION_DATE, null); Long creationDate = settings.getAsLong(SETTING_CREATION_DATE, null);
if (creationDate != null) { if (creationDate != null) {
DateTime creationDateTime = new DateTime(creationDate); DateTime creationDateTime = new DateTime(creationDate, DateTimeZone.UTC);
builder.put(SETTING_CREATION_DATE_STRING, creationDateTime.toString()); builder.put(SETTING_CREATION_DATE_STRING, creationDateTime.toString());
} }
return builder.build(); return builder.build();

View File

@ -63,6 +63,8 @@ import org.elasticsearch.index.IndexService;
import org.elasticsearch.indices.*; import org.elasticsearch.indices.*;
import org.elasticsearch.script.ScriptService; import org.elasticsearch.script.ScriptService;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
@ -325,7 +327,7 @@ public class MetaDataCreateIndexService extends AbstractComponent {
} }
if (indexSettingsBuilder.get(SETTING_CREATION_DATE) == null) { if (indexSettingsBuilder.get(SETTING_CREATION_DATE) == null) {
indexSettingsBuilder.put(SETTING_CREATION_DATE, System.currentTimeMillis()); indexSettingsBuilder.put(SETTING_CREATION_DATE, new DateTime(DateTimeZone.UTC).getMillis());
} }
indexSettingsBuilder.put(SETTING_UUID, Strings.randomBase64UUID()); indexSettingsBuilder.put(SETTING_UUID, Strings.randomBase64UUID());

View File

@ -23,6 +23,7 @@ import org.elasticsearch.Version;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.test.ElasticsearchTestCase; import org.elasticsearch.test.ElasticsearchTestCase;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.junit.Test; import org.junit.Test;
import static com.google.common.collect.Sets.newHashSet; import static com.google.common.collect.Sets.newHashSet;
@ -45,6 +46,6 @@ public class HumanReadableIndexSettingsTests extends ElasticsearchTestCase {
assertEquals(versionCreated.toString(), humanSettings.get(IndexMetaData.SETTING_VERSION_CREATED_STRING, null)); assertEquals(versionCreated.toString(), humanSettings.get(IndexMetaData.SETTING_VERSION_CREATED_STRING, null));
assertEquals(versionUpgraded.toString(), humanSettings.get(IndexMetaData.SETTING_VERSION_UPGRADED_STRING, null)); assertEquals(versionUpgraded.toString(), humanSettings.get(IndexMetaData.SETTING_VERSION_UPGRADED_STRING, null));
assertEquals(new DateTime(created).toString(), humanSettings.get(IndexMetaData.SETTING_CREATION_DATE_STRING, null)); assertEquals(new DateTime(created, DateTimeZone.UTC).toString(), humanSettings.get(IndexMetaData.SETTING_CREATION_DATE_STRING, null));
} }
} }