introduce an internal metadata uuid
This commit is contained in:
parent
937a4e9d9d
commit
aee388ec46
|
@ -26,6 +26,7 @@ import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.collect.*;
|
import com.google.common.collect.*;
|
||||||
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
||||||
|
import org.elasticsearch.Version;
|
||||||
import org.elasticsearch.action.support.IgnoreIndices;
|
import org.elasticsearch.action.support.IgnoreIndices;
|
||||||
import org.elasticsearch.cluster.block.ClusterBlock;
|
import org.elasticsearch.cluster.block.ClusterBlock;
|
||||||
import org.elasticsearch.cluster.block.ClusterBlockLevel;
|
import org.elasticsearch.cluster.block.ClusterBlockLevel;
|
||||||
|
@ -116,6 +117,7 @@ public class MetaData implements Iterable<IndexMetaData> {
|
||||||
|
|
||||||
public static final String GLOBAL_PERSISTENT_ONLY_PARAM = "global_persistent_only";
|
public static final String GLOBAL_PERSISTENT_ONLY_PARAM = "global_persistent_only";
|
||||||
|
|
||||||
|
private final String uuid;
|
||||||
private final long version;
|
private final long version;
|
||||||
|
|
||||||
private final Settings transientSettings;
|
private final Settings transientSettings;
|
||||||
|
@ -136,7 +138,8 @@ public class MetaData implements Iterable<IndexMetaData> {
|
||||||
private final ImmutableOpenMap<String, String[]> aliasAndIndexToIndexMap;
|
private final ImmutableOpenMap<String, String[]> aliasAndIndexToIndexMap;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
MetaData(long version, Settings transientSettings, Settings persistentSettings, ImmutableOpenMap<String, IndexMetaData> indices, ImmutableOpenMap<String, IndexTemplateMetaData> templates, ImmutableOpenMap<String, Custom> customs) {
|
MetaData(String uuid, long version, Settings transientSettings, Settings persistentSettings, ImmutableOpenMap<String, IndexMetaData> indices, ImmutableOpenMap<String, IndexTemplateMetaData> templates, ImmutableOpenMap<String, Custom> customs) {
|
||||||
|
this.uuid = uuid;
|
||||||
this.version = version;
|
this.version = version;
|
||||||
this.transientSettings = transientSettings;
|
this.transientSettings = transientSettings;
|
||||||
this.persistentSettings = persistentSettings;
|
this.persistentSettings = persistentSettings;
|
||||||
|
@ -229,6 +232,10 @@ public class MetaData implements Iterable<IndexMetaData> {
|
||||||
return this.version;
|
return this.version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String uuid() {
|
||||||
|
return this.uuid;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the merges transient and persistent settings.
|
* Returns the merges transient and persistent settings.
|
||||||
*/
|
*/
|
||||||
|
@ -964,6 +971,7 @@ public class MetaData implements Iterable<IndexMetaData> {
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
|
|
||||||
|
private String uuid;
|
||||||
private long version;
|
private long version;
|
||||||
|
|
||||||
private Settings transientSettings = ImmutableSettings.Builder.EMPTY_SETTINGS;
|
private Settings transientSettings = ImmutableSettings.Builder.EMPTY_SETTINGS;
|
||||||
|
@ -974,12 +982,14 @@ public class MetaData implements Iterable<IndexMetaData> {
|
||||||
private final ImmutableOpenMap.Builder<String, Custom> customs;
|
private final ImmutableOpenMap.Builder<String, Custom> customs;
|
||||||
|
|
||||||
public Builder() {
|
public Builder() {
|
||||||
|
uuid = "_na_";
|
||||||
indices = ImmutableOpenMap.builder();
|
indices = ImmutableOpenMap.builder();
|
||||||
templates = ImmutableOpenMap.builder();
|
templates = ImmutableOpenMap.builder();
|
||||||
customs = ImmutableOpenMap.builder();
|
customs = ImmutableOpenMap.builder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder(MetaData metaData) {
|
public Builder(MetaData metaData) {
|
||||||
|
this.uuid = metaData.uuid;
|
||||||
this.transientSettings = metaData.transientSettings;
|
this.transientSettings = metaData.transientSettings;
|
||||||
this.persistentSettings = metaData.persistentSettings;
|
this.persistentSettings = metaData.persistentSettings;
|
||||||
this.version = metaData.version;
|
this.version = metaData.version;
|
||||||
|
@ -1102,8 +1112,15 @@ public class MetaData implements Iterable<IndexMetaData> {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder generateUuidIfNeeded() {
|
||||||
|
if (uuid.equals("_na_")) {
|
||||||
|
uuid = Strings.randomBase64UUID();
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public MetaData build() {
|
public MetaData build() {
|
||||||
return new MetaData(version, transientSettings, persistentSettings, indices.build(), templates.build(), customs.build());
|
return new MetaData(uuid, version, transientSettings, persistentSettings, indices.build(), templates.build(), customs.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String toXContent(MetaData metaData) throws IOException {
|
public static String toXContent(MetaData metaData) throws IOException {
|
||||||
|
@ -1119,6 +1136,7 @@ public class MetaData implements Iterable<IndexMetaData> {
|
||||||
builder.startObject("meta-data");
|
builder.startObject("meta-data");
|
||||||
|
|
||||||
builder.field("version", metaData.version());
|
builder.field("version", metaData.version());
|
||||||
|
builder.field("uuid", metaData.uuid);
|
||||||
|
|
||||||
if (!metaData.persistentSettings().getAsMap().isEmpty()) {
|
if (!metaData.persistentSettings().getAsMap().isEmpty()) {
|
||||||
builder.startObject("settings");
|
builder.startObject("settings");
|
||||||
|
@ -1210,6 +1228,8 @@ public class MetaData implements Iterable<IndexMetaData> {
|
||||||
} else if (token.isValue()) {
|
} else if (token.isValue()) {
|
||||||
if ("version".equals(currentFieldName)) {
|
if ("version".equals(currentFieldName)) {
|
||||||
builder.version = parser.longValue();
|
builder.version = parser.longValue();
|
||||||
|
} else if ("uuid".equals(currentFieldName)) {
|
||||||
|
builder.uuid = parser.text();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1219,6 +1239,9 @@ public class MetaData implements Iterable<IndexMetaData> {
|
||||||
public static MetaData readFrom(StreamInput in) throws IOException {
|
public static MetaData readFrom(StreamInput in) throws IOException {
|
||||||
Builder builder = new Builder();
|
Builder builder = new Builder();
|
||||||
builder.version = in.readLong();
|
builder.version = in.readLong();
|
||||||
|
if (in.getVersion().after(Version.V_0_90_7)) {
|
||||||
|
builder.uuid = in.readString();
|
||||||
|
}
|
||||||
builder.transientSettings(readSettingsFromStream(in));
|
builder.transientSettings(readSettingsFromStream(in));
|
||||||
builder.persistentSettings(readSettingsFromStream(in));
|
builder.persistentSettings(readSettingsFromStream(in));
|
||||||
int size = in.readVInt();
|
int size = in.readVInt();
|
||||||
|
@ -1240,6 +1263,9 @@ public class MetaData implements Iterable<IndexMetaData> {
|
||||||
|
|
||||||
public static void writeTo(MetaData metaData, StreamOutput out) throws IOException {
|
public static void writeTo(MetaData metaData, StreamOutput out) throws IOException {
|
||||||
out.writeLong(metaData.version);
|
out.writeLong(metaData.version);
|
||||||
|
if (out.getVersion().after(Version.V_0_90_7)) {
|
||||||
|
out.writeString(metaData.uuid);
|
||||||
|
}
|
||||||
writeSettingsToStream(metaData.transientSettings(), out);
|
writeSettingsToStream(metaData.transientSettings(), out);
|
||||||
writeSettingsToStream(metaData.persistentSettings(), out);
|
writeSettingsToStream(metaData.persistentSettings(), out);
|
||||||
out.writeVInt(metaData.indices.size());
|
out.writeVInt(metaData.indices.size());
|
||||||
|
|
|
@ -247,6 +247,8 @@ public class GatewayService extends AbstractLifecycleComponent<GatewayService> i
|
||||||
.removeGlobalBlock(STATE_NOT_RECOVERED_BLOCK);
|
.removeGlobalBlock(STATE_NOT_RECOVERED_BLOCK);
|
||||||
|
|
||||||
MetaData.Builder metaDataBuilder = MetaData.builder(recoveredState.metaData());
|
MetaData.Builder metaDataBuilder = MetaData.builder(recoveredState.metaData());
|
||||||
|
// automatically generate a UID for the metadata if we need to
|
||||||
|
metaDataBuilder.generateUuidIfNeeded();
|
||||||
|
|
||||||
if (recoveredState.metaData().settings().getAsBoolean(MetaData.SETTING_READ_ONLY, false) || currentState.metaData().settings().getAsBoolean(MetaData.SETTING_READ_ONLY, false)) {
|
if (recoveredState.metaData().settings().getAsBoolean(MetaData.SETTING_READ_ONLY, false) || currentState.metaData().settings().getAsBoolean(MetaData.SETTING_READ_ONLY, false)) {
|
||||||
blocks.addGlobalBlock(MetaData.CLUSTER_READ_ONLY_BLOCK);
|
blocks.addGlobalBlock(MetaData.CLUSTER_READ_ONLY_BLOCK);
|
||||||
|
|
|
@ -274,6 +274,9 @@ public class SimpleRecoveryLocalGatewayTests extends ElasticsearchIntegrationTes
|
||||||
assertHitCount(client().prepareCount().setQuery(matchAllQuery()).execute().actionGet(), 2);
|
assertHitCount(client().prepareCount().setQuery(matchAllQuery()).execute().actionGet(), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String metaDataUuid = client().admin().cluster().prepareState().execute().get().getState().getMetaData().uuid();
|
||||||
|
assertThat(metaDataUuid, not(equalTo("_na_")));
|
||||||
|
|
||||||
logger.info("--> closing first node, and indexing more data to the second node");
|
logger.info("--> closing first node, and indexing more data to the second node");
|
||||||
cluster().fullRestart(new RestartCallback() {
|
cluster().fullRestart(new RestartCallback() {
|
||||||
|
|
||||||
|
@ -314,6 +317,8 @@ public class SimpleRecoveryLocalGatewayTests extends ElasticsearchIntegrationTes
|
||||||
assertThat(clusterHealth.isTimedOut(), equalTo(false));
|
assertThat(clusterHealth.isTimedOut(), equalTo(false));
|
||||||
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
|
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
|
||||||
|
|
||||||
|
assertThat(client().admin().cluster().prepareState().execute().get().getState().getMetaData().uuid(), equalTo(metaDataUuid));
|
||||||
|
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
assertHitCount(client().prepareCount().setQuery(matchAllQuery()).execute().actionGet(), 3);
|
assertHitCount(client().prepareCount().setQuery(matchAllQuery()).execute().actionGet(), 3);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue