Skip to content

Commit

Permalink
Updates for changes in hppc classes
Browse files Browse the repository at this point in the history
There are 3 changes in hppc that impact OpenSearch:

- ObjectIntScatterMap has been removed. I could have replaced it with
ObjectIntHashMap, but a plain java.util.HashMap seems to solve the
problem well so I used that instead.

- `indexRemove(int index)` is a new method in two interfaces that we
extend in a delegate pattern, so I have had to add that method as a
pass-through in two places.

- The seeded version of `BitMixer.mix(int, int)` [has been removed][1].
The implementation that was removed simply xor'd the value to the seed
before calling the single-int variant of the method. I have changed the
OpenSearch code to do the xor directly, so this should be equivalent to
the previous implementation.

[1]: carrotsearch/hppc#10

Signed-off-by: Andrew Ross <[email protected]>
  • Loading branch information
andrross committed May 10, 2022
1 parent 0d765c4 commit c15a379
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,11 @@ public void indexInsert(int index, int key, VType value) {
map.indexInsert(index, key, value);
}

@Override
public VType indexRemove(int index) {
return map.indexRemove(index);
}

@Override
public void release() {
map.release();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,11 @@ public void indexInsert(int index, KType key, VType value) {
map.indexInsert(index, key, value);
}

@Override
public VType indexRemove(int index) {
return map.indexRemove(index);
}

@Override
public void release() {
map.release();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public RandomScoreFunction(int seed, int salt, IndexFieldData<?> uidFieldData) {
public RandomScoreFunction(int seed, int salt, IndexFieldData<?> uidFieldData, @Nullable String functionName) {
super(CombineFunction.MULTIPLY);
this.originalSeed = seed;
this.saltedSeed = BitMixer.mix(seed, salt);
this.saltedSeed = BitMixer.mix(seed ^ salt);
this.fieldData = uidFieldData;
this.functionName = functionName;
}
Expand All @@ -97,7 +97,7 @@ public LeafScoreFunction getLeafScoreFunction(LeafReaderContext ctx) {
public double score(int docId, float subQueryScore) throws IOException {
int hash;
if (values == null) {
hash = BitMixer.mix(ctx.docBase + docId, saltedSeed);
hash = BitMixer.mix((ctx.docBase + docId) ^ saltedSeed);
} else if (values.advanceExact(docId)) {
hash = StringHelper.murmurhash3_x86_32(values.nextValue(), saltedSeed);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

package org.opensearch.rest.action.cat;

import com.carrotsearch.hppc.ObjectIntScatterMap;
import org.opensearch.action.admin.cluster.node.stats.NodeStats;
import org.opensearch.action.admin.cluster.node.stats.NodesStatsRequest;
import org.opensearch.action.admin.cluster.node.stats.NodesStatsResponse;
Expand All @@ -51,7 +50,9 @@
import org.opensearch.rest.action.RestActionListener;
import org.opensearch.rest.action.RestResponseListener;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableList;
Expand Down Expand Up @@ -129,7 +130,7 @@ protected Table getTableWithHeader(final RestRequest request) {
}

private Table buildTable(RestRequest request, final ClusterStateResponse state, final NodesStatsResponse stats) {
final ObjectIntScatterMap<String> allocs = new ObjectIntScatterMap<>();
final Map<String, Integer> allocs = new HashMap<>();

for (ShardRouting shard : state.getState().routingTable().allShards()) {
String nodeId = "UNASSIGNED";
Expand All @@ -138,7 +139,7 @@ private Table buildTable(RestRequest request, final ClusterStateResponse state,
nodeId = shard.currentNodeId();
}

allocs.addTo(nodeId, 1);
allocs.merge(nodeId, 1, Integer::sum);
}

Table table = getTableWithHeader(request);
Expand Down

0 comments on commit c15a379

Please sign in to comment.