improve exception and remove complex test, such indexes will not be loaded into a closed state.
we will not load them at all.
This commit is contained in:
parent
6e5c301739
commit
ef7258413f
|
@ -80,12 +80,23 @@ public class CompressorFactory {
|
||||||
|
|
||||||
XContentType contentType = XContentFactory.xContentType(bytes);
|
XContentType contentType = XContentFactory.xContentType(bytes);
|
||||||
if (contentType == null) {
|
if (contentType == null) {
|
||||||
|
if (isAncient(bytes)) {
|
||||||
|
throw new IllegalStateException("unsupported compression: index was created before v2.0.0.beta1 and wasn't upgraded?");
|
||||||
|
}
|
||||||
throw new NotXContentException("Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes");
|
throw new NotXContentException("Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes");
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** true if the bytes were compressed with LZF: only used before elasticsearch 2.0 */
|
||||||
|
private static boolean isAncient(BytesReference bytes) {
|
||||||
|
return bytes.length() >= 3 &&
|
||||||
|
bytes.get(0) == 'Z' &&
|
||||||
|
bytes.get(1) == 'V' &&
|
||||||
|
(bytes.get(2) == 0 || bytes.get(2) == 1);
|
||||||
|
}
|
||||||
|
|
||||||
public static Compressor compressor(ChannelBuffer buffer) {
|
public static Compressor compressor(ChannelBuffer buffer) {
|
||||||
for (Compressor compressor : compressors) {
|
for (Compressor compressor : compressors) {
|
||||||
if (compressor.isCompressed(buffer)) {
|
if (compressor.isCompressed(buffer)) {
|
||||||
|
|
|
@ -280,46 +280,6 @@ public class OldIndexBackwardsCompatibilityIT extends ESIntegTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testHandlingOfUnsupportedDanglingIndexes() throws Exception {
|
|
||||||
setupCluster();
|
|
||||||
Collections.shuffle(unsupportedIndexes, getRandom());
|
|
||||||
for (String index : unsupportedIndexes) {
|
|
||||||
assertUnsupportedIndexHandling(index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Waits for the index to show up in the cluster state in closed state
|
|
||||||
*/
|
|
||||||
void ensureClosed(final String index) throws InterruptedException {
|
|
||||||
assertTrue(awaitBusy(() -> {
|
|
||||||
ClusterState state = client().admin().cluster().prepareState().get().getState();
|
|
||||||
return state.metaData().hasIndex(index) && state.metaData().index(index).getState() == IndexMetaData.State.CLOSE;
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks that the given index cannot be opened due to incompatible version
|
|
||||||
*/
|
|
||||||
void assertUnsupportedIndexHandling(String index) throws Exception {
|
|
||||||
long startTime = System.currentTimeMillis();
|
|
||||||
logger.info("--> Testing old index " + index);
|
|
||||||
String indexName = loadIndex(index);
|
|
||||||
// force reloading dangling indices with a cluster state republish
|
|
||||||
client().admin().cluster().prepareReroute().get();
|
|
||||||
ensureClosed(indexName);
|
|
||||||
try {
|
|
||||||
client().admin().indices().prepareOpen(indexName).get();
|
|
||||||
fail("Shouldn't be able to open an old index");
|
|
||||||
} catch (IllegalStateException ex) {
|
|
||||||
assertThat(ex.getMessage(), containsString("was created before v2.0.0.beta1 and wasn't upgraded"));
|
|
||||||
}
|
|
||||||
unloadIndex(indexName);
|
|
||||||
logger.info("--> Done testing " + index + ", took " + ((System.currentTimeMillis() - startTime) / 1000.0) + " seconds");
|
|
||||||
}
|
|
||||||
|
|
||||||
void assertOldIndexWorks(String index) throws Exception {
|
void assertOldIndexWorks(String index) throws Exception {
|
||||||
Version version = extractVersion(index);
|
Version version = extractVersion(index);
|
||||||
String indexName = loadIndex(index);
|
String indexName = loadIndex(index);
|
||||||
|
|
Loading…
Reference in New Issue