Skip to content

Commit

Permalink
Internal: Remove deprecated METADATA cluster block level
Browse files Browse the repository at this point in the history
This commit removes the deprecated ClusterBlockLevel.METADATA, replaced in #9203 with METADATA_READ and METADATA_WRITE.
  • Loading branch information
tlrx committed Apr 28, 2015
1 parent 180403f commit 2ce0ea1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 54 deletions.
Expand Up @@ -131,7 +131,7 @@ public void readFrom(StreamInput in) throws IOException {
final int len = in.readVInt();
ArrayList<ClusterBlockLevel> levels = new ArrayList<>();
for (int i = 0; i < len; i++) {
levels.addAll(ClusterBlockLevel.fromId(in.readVInt()));
levels.add(ClusterBlockLevel.fromId(in.readVInt()));
}
this.levels = EnumSet.copyOf(levels);
retryable = in.readBoolean();
Expand All @@ -145,7 +145,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeString(description);
out.writeVInt(levels.size());
for (ClusterBlockLevel level : levels) {
out.writeVInt(level.toId(out.getVersion()));
out.writeVInt(level.id());
}
out.writeBoolean(retryable);
out.writeBoolean(disableStatePersistence);
Expand Down
Expand Up @@ -20,7 +20,6 @@
package org.elasticsearch.cluster.block;

import org.elasticsearch.ElasticsearchIllegalArgumentException;
import org.elasticsearch.Version;

import java.util.EnumSet;

Expand All @@ -30,16 +29,8 @@
public enum ClusterBlockLevel {
READ(0),
WRITE(1),

/**
* Since 1.6.0, METADATA has been split into two distincts cluster block levels
* @deprecated Use METADATA_READ or METADATA_WRITE instead.
*/
@Deprecated
METADATA(2),

METADATA_READ(3),
METADATA_WRITE(4);
METADATA_READ(2),
METADATA_WRITE(3);

public static final EnumSet<ClusterBlockLevel> ALL = EnumSet.of(READ, WRITE, METADATA_READ, METADATA_WRITE);
public static final EnumSet<ClusterBlockLevel> READ_WRITE = EnumSet.of(READ, WRITE);
Expand All @@ -54,35 +45,15 @@ public int id() {
return this.id;
}

/**
* Returns the ClusterBlockLevel's id according to a given version, this to ensure backward compatibility.
*
* @param version the version
* @return the ClusterBlockLevel's id
*/
public int toId(Version version) {
assert version != null : "Version shouldn't be null";
// Since 1.6.0, METADATA has been split into two distincts cluster block levels
if (version.before(Version.V_1_6_0)) {
if (this == ClusterBlockLevel.METADATA_READ || this == ClusterBlockLevel.METADATA_WRITE) {
return ClusterBlockLevel.METADATA.id();
}
}
return id();
}

static EnumSet<ClusterBlockLevel> fromId(int id) {
static ClusterBlockLevel fromId(int id) {
if (id == 0) {
return EnumSet.of(READ);
return READ;
} else if (id == 1) {
return EnumSet.of(WRITE);
return WRITE;
} else if (id == 2) {
// Since 1.6.0, METADATA has been split into two distincts cluster block levels
return EnumSet.of(METADATA_READ, METADATA_WRITE);
return METADATA_READ;
} else if (id == 3) {
return EnumSet.of(METADATA_READ);
} else if (id == 4) {
return EnumSet.of(METADATA_WRITE);
return METADATA_WRITE;
}
throw new ElasticsearchIllegalArgumentException("No cluster block level matching [" + id + "]");
}
Expand Down
Expand Up @@ -28,7 +28,6 @@

import java.util.EnumSet;

import static org.elasticsearch.cluster.block.ClusterBlockLevel.*;
import static org.elasticsearch.test.VersionUtils.randomVersion;
import static org.hamcrest.CoreMatchers.equalTo;

Expand Down Expand Up @@ -64,21 +63,7 @@ public void testSerialization() throws Exception {
assertThat(result.description(), equalTo(clusterBlock.description()));
assertThat(result.retryable(), equalTo(clusterBlock.retryable()));
assertThat(result.disableStatePersistence(), equalTo(clusterBlock.disableStatePersistence()));

// This enum set is used to count the expected serialized/deserialized number of blocks
EnumSet<ClusterBlockLevel> expected = EnumSet.noneOf(ClusterBlockLevel.class);

for (ClusterBlockLevel level : clusterBlock.levels()) {
if (level == METADATA) {
assertTrue(result.levels().contains(METADATA_READ));
assertTrue(result.levels().contains(METADATA_WRITE));
} else {
assertTrue(result.levels().contains(level));
}

expected.addAll(ClusterBlockLevel.fromId(level.toId(version)));
}
assertThat(result.levels().size(), equalTo(expected.size()));
assertArrayEquals(result.levels().toArray(), clusterBlock.levels().toArray());
}
}
}

0 comments on commit 2ce0ea1

Please sign in to comment.