Remove MathUtils. #17454
It has a single method: mod, which can be replaced with Math.floorMod since we always coll it with a positive divisor.
This commit is contained in:
parent
baa2d51e59
commit
8afc0f1748
|
@ -27,7 +27,6 @@ import org.elasticsearch.common.Nullable;
|
|||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.math.MathUtils;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.IndexNotFoundException;
|
||||
import org.elasticsearch.index.shard.ShardId;
|
||||
|
@ -226,7 +225,7 @@ public class OperationRouting extends AbstractComponent {
|
|||
} else {
|
||||
hash = Murmur3HashFunction.hash(routing);
|
||||
}
|
||||
return MathUtils.mod(hash, indexMetaData.getNumberOfShards());
|
||||
return Math.floorMod(hash, indexMetaData.getNumberOfShards());
|
||||
}
|
||||
|
||||
private void ensureNodeIdExists(DiscoveryNodes nodes, String nodeId) {
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.common.math;
|
||||
|
||||
public enum MathUtils {
|
||||
;
|
||||
|
||||
/**
|
||||
* Return the (positive) remainder of the division of <code>v</code> by <code>mod</code>.
|
||||
*/
|
||||
public static int mod(int v, int m) {
|
||||
int r = v % m;
|
||||
if (r < 0) {
|
||||
r += m;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
}
|
|
@ -49,7 +49,6 @@ import org.elasticsearch.common.lucene.LoggerInfoStream;
|
|||
import org.elasticsearch.common.lucene.Lucene;
|
||||
import org.elasticsearch.common.lucene.index.ElasticsearchDirectoryReader;
|
||||
import org.elasticsearch.common.lucene.uid.Versions;
|
||||
import org.elasticsearch.common.math.MathUtils;
|
||||
import org.elasticsearch.common.unit.ByteSizeValue;
|
||||
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
|
||||
import org.elasticsearch.common.util.concurrent.ReleasableLock;
|
||||
|
@ -913,7 +912,7 @@ public class InternalEngine extends Engine {
|
|||
|
||||
private Object dirtyLock(BytesRef uid) {
|
||||
int hash = Murmur3HashFunction.hash(uid.bytes, uid.offset, uid.length);
|
||||
return dirtyLocks[MathUtils.mod(hash, dirtyLocks.length)];
|
||||
return dirtyLocks[Math.floorMod(hash, dirtyLocks.length)];
|
||||
}
|
||||
|
||||
private Object dirtyLock(Term uid) {
|
||||
|
|
|
@ -35,7 +35,6 @@ import org.elasticsearch.common.io.stream.ReleasableBytesStreamOutput;
|
|||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.lease.Releasable;
|
||||
import org.elasticsearch.common.lease.Releasables;
|
||||
import org.elasticsearch.common.math.MathUtils;
|
||||
import org.elasticsearch.common.metrics.CounterMetric;
|
||||
import org.elasticsearch.common.netty.NettyUtils;
|
||||
import org.elasticsearch.common.netty.OpenChannelsHandler;
|
||||
|
@ -1311,15 +1310,15 @@ public class NettyTransport extends AbstractLifecycleComponent<Transport> implem
|
|||
|
||||
public Channel channel(TransportRequestOptions.Type type) {
|
||||
if (type == TransportRequestOptions.Type.REG) {
|
||||
return reg[MathUtils.mod(regCounter.incrementAndGet(), reg.length)];
|
||||
return reg[Math.floorMod(regCounter.incrementAndGet(), reg.length)];
|
||||
} else if (type == TransportRequestOptions.Type.STATE) {
|
||||
return state[MathUtils.mod(stateCounter.incrementAndGet(), state.length)];
|
||||
return state[Math.floorMod(stateCounter.incrementAndGet(), state.length)];
|
||||
} else if (type == TransportRequestOptions.Type.PING) {
|
||||
return ping[MathUtils.mod(pingCounter.incrementAndGet(), ping.length)];
|
||||
return ping[Math.floorMod(pingCounter.incrementAndGet(), ping.length)];
|
||||
} else if (type == TransportRequestOptions.Type.BULK) {
|
||||
return bulk[MathUtils.mod(bulkCounter.incrementAndGet(), bulk.length)];
|
||||
return bulk[Math.floorMod(bulkCounter.incrementAndGet(), bulk.length)];
|
||||
} else if (type == TransportRequestOptions.Type.RECOVERY) {
|
||||
return recovery[MathUtils.mod(recoveryCounter.incrementAndGet(), recovery.length)];
|
||||
return recovery[Math.floorMod(recoveryCounter.incrementAndGet(), recovery.length)];
|
||||
} else {
|
||||
throw new IllegalArgumentException("no type channel for [" + type + "]");
|
||||
}
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.common.math;
|
||||
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
public class MathUtilsTests extends ESTestCase {
|
||||
public void testMod() {
|
||||
final int iters = scaledRandomIntBetween(1000, 10000);
|
||||
for (int i = 0; i < iters; ++i) {
|
||||
final int v = rarely() ? Integer.MIN_VALUE : rarely() ? Integer.MAX_VALUE : randomInt();
|
||||
final int m = rarely() ? Integer.MAX_VALUE : randomIntBetween(1, Integer.MAX_VALUE);
|
||||
final int mod = MathUtils.mod(v, m);
|
||||
assertTrue(mod >= 0);
|
||||
assertTrue(mod < m);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -45,7 +45,6 @@ import org.elasticsearch.common.Nullable;
|
|||
import org.elasticsearch.common.Priority;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.collect.Tuple;
|
||||
import org.elasticsearch.common.math.MathUtils;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.discovery.zen.ZenDiscovery;
|
||||
|
@ -468,7 +467,7 @@ public class DiscoveryWithServiceDisruptionsIT extends ESIntegTestCase {
|
|||
logger.info("[{}] Acquired semaphore and it has {} permits left", name, semaphore.availablePermits());
|
||||
try {
|
||||
id = Integer.toString(idGenerator.incrementAndGet());
|
||||
int shard = MathUtils.mod(Murmur3HashFunction.hash(id), numPrimaries);
|
||||
int shard = Math.floorMod(Murmur3HashFunction.hash(id), numPrimaries);
|
||||
logger.trace("[{}] indexing id [{}] through node [{}] targeting shard [{}]", name, id, node, shard);
|
||||
IndexResponse response = client.prepareIndex("test", "type", id).setSource("{}").setTimeout("1s").get();
|
||||
assertThat(response.getVersion(), equalTo(1L));
|
||||
|
|
|
@ -24,20 +24,17 @@ import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
|
|||
import org.elasticsearch.action.admin.indices.stats.ShardStats;
|
||||
import org.elasticsearch.action.get.GetResponse;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.cluster.routing.Murmur3HashFunction;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||
import org.elasticsearch.common.Priority;
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.math.MathUtils;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.index.IndexSettings;
|
||||
import org.elasticsearch.index.shard.DocsStats;
|
||||
import org.elasticsearch.index.shard.ShardId;
|
||||
import org.elasticsearch.index.translog.Translog;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.sort.SortOrder;
|
||||
import org.elasticsearch.test.BackgroundIndexer;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
|
|
Loading…
Reference in New Issue