Remove dead code and dead parameters (#18855)

This commit is contained in:
Simon Willnauer 2016-06-14 15:25:44 +02:00 committed by GitHub
parent f5836951f8
commit 4d78f280ed
11 changed files with 35 additions and 54 deletions

View File

@ -304,7 +304,7 @@ public class TransportBulkAction extends HandledTransportAction<BulkRequest, Bul
if (request instanceof IndexRequest) {
IndexRequest indexRequest = (IndexRequest) request;
String concreteIndex = concreteIndices.getConcreteIndex(indexRequest.index()).getName();
ShardId shardId = clusterService.operationRouting().indexShards(clusterState, concreteIndex, indexRequest.type(), indexRequest.id(), indexRequest.routing()).shardId();
ShardId shardId = clusterService.operationRouting().indexShards(clusterState, concreteIndex, indexRequest.id(), indexRequest.routing()).shardId();
List<BulkItemRequest> list = requestsByShard.get(shardId);
if (list == null) {
list = new ArrayList<>();
@ -314,7 +314,7 @@ public class TransportBulkAction extends HandledTransportAction<BulkRequest, Bul
} else if (request instanceof DeleteRequest) {
DeleteRequest deleteRequest = (DeleteRequest) request;
String concreteIndex = concreteIndices.getConcreteIndex(deleteRequest.index()).getName();
ShardId shardId = clusterService.operationRouting().indexShards(clusterState, concreteIndex, deleteRequest.type(), deleteRequest.id(), deleteRequest.routing()).shardId();
ShardId shardId = clusterService.operationRouting().indexShards(clusterState, concreteIndex, deleteRequest.id(), deleteRequest.routing()).shardId();
List<BulkItemRequest> list = requestsByShard.get(shardId);
if (list == null) {
list = new ArrayList<>();
@ -324,7 +324,7 @@ public class TransportBulkAction extends HandledTransportAction<BulkRequest, Bul
} else if (request instanceof UpdateRequest) {
UpdateRequest updateRequest = (UpdateRequest) request;
String concreteIndex = concreteIndices.getConcreteIndex(updateRequest.index()).getName();
ShardId shardId = clusterService.operationRouting().indexShards(clusterState, concreteIndex, updateRequest.type(), updateRequest.id(), updateRequest.routing()).shardId();
ShardId shardId = clusterService.operationRouting().indexShards(clusterState, concreteIndex, updateRequest.id(), updateRequest.routing()).shardId();
List<BulkItemRequest> list = requestsByShard.get(shardId);
if (list == null) {
list = new ArrayList<>();

View File

@ -152,7 +152,7 @@ public class TransportExplainAction extends TransportSingleShardAction<ExplainRe
@Override
protected ShardIterator shards(ClusterState state, InternalRequest request) {
return clusterService.operationRouting().getShards(
clusterService.state(), request.concreteIndex(), request.request().type(), request.request().id(), request.request().routing(), request.request().preference()
clusterService.state(), request.concreteIndex(), request.request().id(), request.request().routing(), request.request().preference()
);
}
}

View File

@ -62,7 +62,7 @@ public class TransportGetAction extends TransportSingleShardAction<GetRequest, G
@Override
protected ShardIterator shards(ClusterState state, InternalRequest request) {
return clusterService.operationRouting()
.getShards(clusterService.state(), request.concreteIndex(), request.request().type(), request.request().id(), request.request().routing(), request.request().preference());
.getShards(clusterService.state(), request.concreteIndex(), request.request().id(), request.request().routing(), request.request().preference());
}
@Override

View File

@ -76,7 +76,7 @@ public class TransportMultiGetAction extends HandledTransportAction<MultiGetRequ
continue;
}
ShardId shardId = clusterService.operationRouting()
.getShards(clusterState, concreteSingleIndex, item.type(), item.id(), item.routing(), null).shardId();
.getShards(clusterState, concreteSingleIndex, item.id(), item.routing(), null).shardId();
MultiGetShardRequest shardRequest = shardRequests.get(shardId);
if (shardRequest == null) {
shardRequest = new MultiGetShardRequest(request, shardId.getIndexName(), shardId.id());

View File

@ -19,7 +19,6 @@
package org.elasticsearch.action.termvectors;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.RoutingMissingException;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.single.shard.TransportSingleShardAction;
@ -56,7 +55,7 @@ public class TransportTermVectorsAction extends TransportSingleShardAction<TermV
@Override
protected ShardIterator shards(ClusterState state, InternalRequest request) {
return clusterService.operationRouting().getShards(state, request.concreteIndex(), request.request().type(), request.request().id(),
return clusterService.operationRouting().getShards(state, request.concreteIndex(), request.request().id(),
request.request().routing(), request.request().preference());
}

View File

@ -153,7 +153,7 @@ public class TransportUpdateAction extends TransportInstanceSingleOperationActio
return clusterState.routingTable().index(request.concreteIndex()).shard(request.getShardId().getId()).primaryShardIt();
}
ShardIterator shardIterator = clusterService.operationRouting()
.indexShards(clusterState, request.concreteIndex(), request.type(), request.id(), request.routing());
.indexShards(clusterState, request.concreteIndex(), request.id(), request.routing());
ShardRouting shard;
while ((shard = shardIterator.nextOrNull()) != null) {
if (shard.primary()) {

View File

@ -52,11 +52,11 @@ public class OperationRouting extends AbstractComponent {
this.awarenessAllocationDecider = awarenessAllocationDecider;
}
public ShardIterator indexShards(ClusterState clusterState, String index, String type, String id, @Nullable String routing) {
public ShardIterator indexShards(ClusterState clusterState, String index, String id, @Nullable String routing) {
return shards(clusterState, index, id, routing).shardsIt();
}
public ShardIterator getShards(ClusterState clusterState, String index, String type, String id, @Nullable String routing, @Nullable String preference) {
public ShardIterator getShards(ClusterState clusterState, String index, String id, @Nullable String routing, @Nullable String preference) {
return preferenceActiveShardIterator(shards(clusterState, index, id, routing), clusterState.nodes().getLocalNodeId(), clusterState.nodes(), preference);
}

View File

@ -35,7 +35,6 @@ public final class Uid {
public static final char DELIMITER = '#';
public static final byte DELIMITER_BYTE = 0x23;
public static final BytesRef DELIMITER_BYTES = new BytesRef(new byte[]{DELIMITER_BYTE});
private final String type;
@ -83,13 +82,6 @@ public final class Uid {
return createUidAsBytes(type, id);
}
public static BytesRef typePrefixAsBytes(BytesRef type) {
BytesRefBuilder bytesRef = new BytesRefBuilder();
bytesRef.append(type);
bytesRef.append(DELIMITER_BYTES);
return bytesRef.toBytesRef();
}
public static Uid createUid(String uid) {
int delimiterIndex = uid.indexOf(DELIMITER); // type is not allowed to have # in it..., ids can
return new Uid(uid.substring(0, delimiterIndex), uid.substring(delimiterIndex + 1));
@ -136,35 +128,4 @@ public final class Uid {
return type + DELIMITER + id;
}
public static boolean hasDelimiter(BytesRef uid) {
final int limit = uid.offset + uid.length;
for (int i = uid.offset; i < limit; i++) {
if (uid.bytes[i] == DELIMITER_BYTE) { // 0x23 is equal to '#'
return true;
}
}
return false;
}
public static BytesRef[] splitUidIntoTypeAndId(BytesRef uid) {
int loc = -1;
final int limit = uid.offset + uid.length;
for (int i = uid.offset; i < limit; i++) {
if (uid.bytes[i] == DELIMITER_BYTE) { // 0x23 is equal to '#'
loc = i;
break;
}
}
if (loc == -1) {
return null;
}
int idStart = loc + 1;
return new BytesRef[] {
new BytesRef(uid.bytes, uid.offset, loc - uid.offset),
new BytesRef(uid.bytes, idStart, limit - idStart)
};
}
}

View File

@ -62,7 +62,7 @@ public class RoutingBackwardCompatibilityTests extends ESTestCase {
MetaData.Builder metaData = MetaData.builder().put(indexMetaData, false);
RoutingTable routingTable = RoutingTable.builder().addAsNew(indexMetaData).build();
ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build();
final int shardId = operationRouting.indexShards(clusterState, index, type, id, routing).shardId().getId();
final int shardId = operationRouting.indexShards(clusterState, index, id, routing).shardId().getId();
assertEquals(currentExpectedShard, shardId);
}
}

View File

@ -26,7 +26,7 @@ import static org.hamcrest.Matchers.equalTo;
public class UidTests extends ESTestCase {
public void testCreateAndSplitId() {
BytesRef createUid = Uid.createUidAsBytes("foo", "bar");
BytesRef[] splitUidIntoTypeAndId = Uid.splitUidIntoTypeAndId(createUid);
BytesRef[] splitUidIntoTypeAndId = splitUidIntoTypeAndId(createUid);
assertThat("foo", equalTo(splitUidIntoTypeAndId[0].utf8ToString()));
assertThat("bar", equalTo(splitUidIntoTypeAndId[1].utf8ToString()));
// split also with an offset
@ -34,8 +34,29 @@ public class UidTests extends ESTestCase {
ref.offset = 9;
ref.length = createUid.length;
System.arraycopy(createUid.bytes, createUid.offset, ref.bytes, ref.offset, ref.length);
splitUidIntoTypeAndId = Uid.splitUidIntoTypeAndId(ref);
splitUidIntoTypeAndId = splitUidIntoTypeAndId(ref);
assertThat("foo", equalTo(splitUidIntoTypeAndId[0].utf8ToString()));
assertThat("bar", equalTo(splitUidIntoTypeAndId[1].utf8ToString()));
}
public static BytesRef[] splitUidIntoTypeAndId(BytesRef uid) {
int loc = -1;
final int limit = uid.offset + uid.length;
for (int i = uid.offset; i < limit; i++) {
if (uid.bytes[i] == Uid.DELIMITER_BYTE) { // 0x23 is equal to '#'
loc = i;
break;
}
}
if (loc == -1) {
return null;
}
int idStart = loc + 1;
return new BytesRef[] {
new BytesRef(uid.bytes, uid.offset, loc - uid.offset),
new BytesRef(uid.bytes, idStart, limit - idStart)
};
}
}

View File

@ -1773,7 +1773,7 @@ public final class InternalTestCluster extends TestCluster {
OperationRouting operationRouting = getInstanceFromNode(OperationRouting.class, node);
while (true) {
String routing = RandomStrings.randomAsciiOfLength(random, 10);
final int targetShard = operationRouting.indexShards(clusterService.state(), index.getName(), type, null, routing).shardId().getId();
final int targetShard = operationRouting.indexShards(clusterService.state(), index.getName(), null, routing).shardId().getId();
if (shard == targetShard) {
return routing;
}