diff --git a/core/src/main/java/org/elasticsearch/common/collect/LongTuple.java b/core/src/main/java/org/elasticsearch/common/collect/LongTuple.java deleted file mode 100644 index fab8850d162..00000000000 --- a/core/src/main/java/org/elasticsearch/common/collect/LongTuple.java +++ /dev/null @@ -1,66 +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.collect; - -public class LongTuple { - - public static LongTuple tuple(final T v1, final long v2) { - return new LongTuple<>(v1, v2); - } - - private final T v1; - private final long v2; - - private LongTuple(final T v1, final long v2) { - this.v1 = v1; - this.v2 = v2; - } - - public T v1() { - return v1; - } - - public long v2() { - return v2; - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - LongTuple tuple = (LongTuple) o; - - return (v1 == null ? tuple.v1 == null : v1.equals(tuple.v1)) && (v2 == tuple.v2); - } - - @Override - public int hashCode() { - int result = v1 != null ? v1.hashCode() : 0; - result = 31 * result + Long.hashCode(v2); - return result; - } - - @Override - public String toString() { - return "Tuple [v1=" + v1 + ", v2=" + v2 + "]"; - } - -} diff --git a/core/src/main/java/org/elasticsearch/index/seqno/GlobalCheckpointTracker.java b/core/src/main/java/org/elasticsearch/index/seqno/GlobalCheckpointTracker.java index aeafbc11108..a669065d32b 100644 --- a/core/src/main/java/org/elasticsearch/index/seqno/GlobalCheckpointTracker.java +++ b/core/src/main/java/org/elasticsearch/index/seqno/GlobalCheckpointTracker.java @@ -23,7 +23,6 @@ import com.carrotsearch.hppc.ObjectLongHashMap; import com.carrotsearch.hppc.ObjectLongMap; import com.carrotsearch.hppc.cursors.ObjectLongCursor; import org.elasticsearch.common.SuppressForbidden; -import org.elasticsearch.common.collect.LongTuple; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.shard.AbstractIndexShardComponent; import org.elasticsearch.index.shard.PrimaryContext; @@ -377,22 +376,43 @@ public class GlobalCheckpointTracker extends AbstractIndexShardComponent { * that we have to sort the incoming local checkpoints from smallest to largest lest we violate that the global checkpoint does not * regress. */ - final List> inSync = + + class AllocationIdLocalCheckpointPair { + + private final String allocationId; + + public String allocationId() { + return allocationId; + } + + private final long localCheckpoint; + + public long localCheckpoint() { + return localCheckpoint; + } + + private AllocationIdLocalCheckpointPair(final String allocationId, final long localCheckpoint) { + this.allocationId = allocationId; + this.localCheckpoint = localCheckpoint; + } + + } + + final List inSync = StreamSupport .stream(primaryContext.inSyncLocalCheckpoints().spliterator(), false) - .map(e -> LongTuple.tuple(e.key, e.value)) + .map(e -> new AllocationIdLocalCheckpointPair(e.key, e.value)) .collect(Collectors.toList()); + inSync.sort(Comparator.comparingLong(AllocationIdLocalCheckpointPair::localCheckpoint)); - inSync.sort(Comparator.comparingLong(LongTuple::v2)); - - for (final LongTuple cursor : inSync) { - assert cursor.v2() >= globalCheckpoint - : "local checkpoint [" + cursor.v2() + "] " - + "for allocation ID [" + cursor.v1() + "] " + for (final AllocationIdLocalCheckpointPair cursor : inSync) { + assert cursor.localCheckpoint() >= globalCheckpoint + : "local checkpoint [" + cursor.localCheckpoint() + "] " + + "for allocation ID [" + cursor.allocationId() + "] " + "violates being at least the global checkpoint [" + globalCheckpoint + "]"; - updateLocalCheckpoint(cursor.v1(), cursor.v2()); - if (trackingLocalCheckpoints.containsKey(cursor.v1())) { - moveAllocationIdFromTrackingToInSync(cursor.v1(), "relocation"); + updateLocalCheckpoint(cursor.allocationId(), cursor.localCheckpoint()); + if (trackingLocalCheckpoints.containsKey(cursor.allocationId())) { + moveAllocationIdFromTrackingToInSync(cursor.allocationId(), "relocation"); updateGlobalCheckpointOnPrimary(); } }