Remove LongTuple

This commit removes an abstraction that was introduced when introducing
the primary context. As this abstraction is used in exactly one place,
we simply make that abstraction local to its usage so that we do not
accumulate yet another general abstraction with exactly one usage.

Relates #25402
This commit is contained in:
Jason Tedor 2017-06-26 14:46:06 -04:00 committed by GitHub
parent 56d3a5e6d8
commit e9e7007a51
2 changed files with 32 additions and 78 deletions

View File

@ -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<T> {
public static <T> LongTuple<T> 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 + "]";
}
}

View File

@ -23,7 +23,6 @@ import com.carrotsearch.hppc.ObjectLongHashMap;
import com.carrotsearch.hppc.ObjectLongMap; import com.carrotsearch.hppc.ObjectLongMap;
import com.carrotsearch.hppc.cursors.ObjectLongCursor; import com.carrotsearch.hppc.cursors.ObjectLongCursor;
import org.elasticsearch.common.SuppressForbidden; import org.elasticsearch.common.SuppressForbidden;
import org.elasticsearch.common.collect.LongTuple;
import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.shard.AbstractIndexShardComponent; import org.elasticsearch.index.shard.AbstractIndexShardComponent;
import org.elasticsearch.index.shard.PrimaryContext; 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 * that we have to sort the incoming local checkpoints from smallest to largest lest we violate that the global checkpoint does not
* regress. * regress.
*/ */
final List<LongTuple<String>> 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<AllocationIdLocalCheckpointPair> inSync =
StreamSupport StreamSupport
.stream(primaryContext.inSyncLocalCheckpoints().spliterator(), false) .stream(primaryContext.inSyncLocalCheckpoints().spliterator(), false)
.map(e -> LongTuple.tuple(e.key, e.value)) .map(e -> new AllocationIdLocalCheckpointPair(e.key, e.value))
.collect(Collectors.toList()); .collect(Collectors.toList());
inSync.sort(Comparator.comparingLong(AllocationIdLocalCheckpointPair::localCheckpoint));
inSync.sort(Comparator.comparingLong(LongTuple::v2)); for (final AllocationIdLocalCheckpointPair cursor : inSync) {
assert cursor.localCheckpoint() >= globalCheckpoint
for (final LongTuple<String> cursor : inSync) { : "local checkpoint [" + cursor.localCheckpoint() + "] "
assert cursor.v2() >= globalCheckpoint + "for allocation ID [" + cursor.allocationId() + "] "
: "local checkpoint [" + cursor.v2() + "] "
+ "for allocation ID [" + cursor.v1() + "] "
+ "violates being at least the global checkpoint [" + globalCheckpoint + "]"; + "violates being at least the global checkpoint [" + globalCheckpoint + "]";
updateLocalCheckpoint(cursor.v1(), cursor.v2()); updateLocalCheckpoint(cursor.allocationId(), cursor.localCheckpoint());
if (trackingLocalCheckpoints.containsKey(cursor.v1())) { if (trackingLocalCheckpoints.containsKey(cursor.allocationId())) {
moveAllocationIdFromTrackingToInSync(cursor.v1(), "relocation"); moveAllocationIdFromTrackingToInSync(cursor.allocationId(), "relocation");
updateGlobalCheckpointOnPrimary(); updateGlobalCheckpointOnPrimary();
} }
} }