|
@@ -61,6 +61,8 @@ import java.util.Set;
|
|
|
import java.util.stream.StreamSupport;
|
|
|
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
+import static org.hamcrest.Matchers.hasSize;
|
|
|
+import static org.hamcrest.Matchers.instanceOf;
|
|
|
import static org.hamcrest.Matchers.is;
|
|
|
import static org.hamcrest.Matchers.not;
|
|
|
import static org.hamcrest.Matchers.notNullValue;
|
|
@@ -80,7 +82,7 @@ public class MetaDataStateFormatTests extends ESTestCase {
|
|
|
|
|
|
@Override
|
|
|
public MetaData fromXContent(XContentParser parser) throws IOException {
|
|
|
- return MetaData.Builder.fromXContent(parser);
|
|
|
+ return MetaData.Builder.fromXContent(parser, false);
|
|
|
}
|
|
|
};
|
|
|
Path tmp = createTempDir();
|
|
@@ -233,7 +235,23 @@ public class MetaDataStateFormatTests extends ESTestCase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void testLoadState() throws IOException {
|
|
|
+ public void testLoadStateWithoutMissingCustoms() throws IOException {
|
|
|
+ runLoadStateTest(false, false);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testLoadStateWithoutMissingCustomsButPreserved() throws IOException {
|
|
|
+ runLoadStateTest(false, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testLoadStateWithMissingCustomsButPreserved() throws IOException {
|
|
|
+ runLoadStateTest(true, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testLoadStateWithMissingCustomsAndNotPreserved() throws IOException {
|
|
|
+ runLoadStateTest(true, false);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void runLoadStateTest(boolean hasMissingCustoms, boolean preserveUnknownCustoms) throws IOException {
|
|
|
final Path[] dirs = new Path[randomIntBetween(1, 5)];
|
|
|
int numStates = randomIntBetween(1, 5);
|
|
|
List<MetaData> meta = new ArrayList<>();
|
|
@@ -241,7 +259,7 @@ public class MetaDataStateFormatTests extends ESTestCase {
|
|
|
meta.add(randomMeta());
|
|
|
}
|
|
|
Set<Path> corruptedFiles = new HashSet<>();
|
|
|
- MetaDataStateFormat<MetaData> format = metaDataFormat();
|
|
|
+ MetaDataStateFormat<MetaData> format = metaDataFormat(preserveUnknownCustoms);
|
|
|
for (int i = 0; i < dirs.length; i++) {
|
|
|
dirs[i] = createTempDir();
|
|
|
Files.createDirectories(dirs[i].resolve(MetaDataStateFormat.STATE_DIR_NAME));
|
|
@@ -258,11 +276,12 @@ public class MetaDataStateFormatTests extends ESTestCase {
|
|
|
}
|
|
|
List<Path> dirList = Arrays.asList(dirs);
|
|
|
Collections.shuffle(dirList, random());
|
|
|
- MetaData loadedMetaData = format.loadLatestState(logger, xContentRegistry(), dirList.toArray(new Path[0]));
|
|
|
+ MetaData loadedMetaData = format.loadLatestState(logger, hasMissingCustoms ?
|
|
|
+ NamedXContentRegistry.EMPTY : xContentRegistry(), dirList.toArray(new Path[0]));
|
|
|
MetaData latestMetaData = meta.get(numStates-1);
|
|
|
assertThat(loadedMetaData.clusterUUID(), not(equalTo("_na_")));
|
|
|
assertThat(loadedMetaData.clusterUUID(), equalTo(latestMetaData.clusterUUID()));
|
|
|
- ImmutableOpenMap<String,IndexMetaData> indices = loadedMetaData.indices();
|
|
|
+ ImmutableOpenMap<String, IndexMetaData> indices = loadedMetaData.indices();
|
|
|
assertThat(indices.size(), equalTo(latestMetaData.indices().size()));
|
|
|
for (IndexMetaData original : latestMetaData) {
|
|
|
IndexMetaData deserialized = indices.get(original.getIndex().getName());
|
|
@@ -275,7 +294,23 @@ public class MetaDataStateFormatTests extends ESTestCase {
|
|
|
}
|
|
|
|
|
|
// make sure the index tombstones are the same too
|
|
|
- assertThat(loadedMetaData.indexGraveyard(), equalTo(latestMetaData.indexGraveyard()));
|
|
|
+ if (hasMissingCustoms) {
|
|
|
+ if (preserveUnknownCustoms) {
|
|
|
+ assertNotNull(loadedMetaData.custom(IndexGraveyard.TYPE));
|
|
|
+ assertThat(loadedMetaData.custom(IndexGraveyard.TYPE), instanceOf(MetaData.UnknownGatewayOnlyCustom.class));
|
|
|
+
|
|
|
+ // check that we reserialize unknown metadata correctly again
|
|
|
+ final Path tempdir = createTempDir();
|
|
|
+ metaDataFormat(randomBoolean()).write(loadedMetaData, tempdir);
|
|
|
+ final MetaData reloadedMetaData = metaDataFormat(randomBoolean()).loadLatestState(logger, xContentRegistry(), tempdir);
|
|
|
+ assertThat(reloadedMetaData.indexGraveyard(), equalTo(latestMetaData.indexGraveyard()));
|
|
|
+ } else {
|
|
|
+ assertNotNull(loadedMetaData.indexGraveyard());
|
|
|
+ assertThat(loadedMetaData.indexGraveyard().getTombstones(), hasSize(0));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ assertThat(loadedMetaData.indexGraveyard(), equalTo(latestMetaData.indexGraveyard()));
|
|
|
+ }
|
|
|
|
|
|
// now corrupt all the latest ones and make sure we fail to load the state
|
|
|
for (int i = 0; i < dirs.length; i++) {
|
|
@@ -419,7 +454,7 @@ public class MetaDataStateFormatTests extends ESTestCase {
|
|
|
writeAndReadStateSuccessfully(format, paths);
|
|
|
}
|
|
|
|
|
|
- private static MetaDataStateFormat<MetaData> metaDataFormat() {
|
|
|
+ private static MetaDataStateFormat<MetaData> metaDataFormat(boolean preserveUnknownCustoms) {
|
|
|
return new MetaDataStateFormat<MetaData>(MetaData.GLOBAL_STATE_FILE_PREFIX) {
|
|
|
@Override
|
|
|
public void toXContent(XContentBuilder builder, MetaData state) throws IOException {
|
|
@@ -428,7 +463,7 @@ public class MetaDataStateFormatTests extends ESTestCase {
|
|
|
|
|
|
@Override
|
|
|
public MetaData fromXContent(XContentParser parser) throws IOException {
|
|
|
- return MetaData.Builder.fromXContent(parser);
|
|
|
+ return MetaData.Builder.fromXContent(parser, preserveUnknownCustoms);
|
|
|
}
|
|
|
};
|
|
|
}
|