summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorJason Tedor <jason@tedor.me>2017-06-26 14:46:06 -0400
committerGitHub <noreply@github.com>2017-06-26 14:46:06 -0400
commite9e7007a51e95eb73c258ce58d85382c11be27a3 (patch)
treebb6ce2ee36fc1061dfbf7398eee2655a4ab24939 /core/src
parent56d3a5e6d80318d7d687c1f722007e2f88242d79 (diff)
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
Diffstat (limited to 'core/src')
-rw-r--r--core/src/main/java/org/elasticsearch/common/collect/LongTuple.java66
-rw-r--r--core/src/main/java/org/elasticsearch/index/seqno/GlobalCheckpointTracker.java44
2 files changed, 32 insertions, 78 deletions
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 fab8850d16..0000000000
--- 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<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 + "]";
- }
-
-}
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 aeafbc1110..a669065d32 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<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
.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<String> 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();
}
}