ImmutableOpenIntMapDiff(ImmutableOpenIntMap<T> before, ImmutableOpenIntMap<T> after, KeySerializer<Integer> keySerializer, ValueSerializer<Integer, T> valueSerializer) { super(keySerializer, valueSerializer); assert after != null && before != null; for (IntCursor key : before.keys()) { if (!after.containsKey(key.value)) { deletes.add(key.value); } } for (IntObjectCursor<T> partIter : after) { T beforePart = before.get(partIter.key); if (beforePart == null) { upserts.put(partIter.key, partIter.value); } else if (partIter.value.equals(beforePart) == false) { if (valueSerializer.supportsDiffableValues()) { diffs.put(partIter.key, valueSerializer.diff(partIter.value, beforePart)); } else { upserts.put(partIter.key, partIter.value); } } } }
/** * Builds a new instance of the */ public ImmutableOpenIntMap<VType> build() { IntObjectHashMap<VType> map = this.map; this.map = null; // nullify the map, so any operation post build will fail! (hackish, but safest) return new ImmutableOpenIntMap<>(map); }
@Override public ImmutableOpenIntMap<T> apply(ImmutableOpenIntMap<T> map) { ImmutableOpenIntMap.Builder<T> builder = ImmutableOpenIntMap.builder(); builder.putAll(map); for (Integer part : deletes) { builder.remove(part); } for (Map.Entry<Integer, Diff<T>> diff : diffs.entrySet()) { builder.put(diff.getKey(), diff.getValue().apply(builder.get(diff.getKey()))); } for (Map.Entry<Integer, T> upsert : upserts.entrySet()) { builder.put(upsert.getKey(), upsert.getValue()); } return builder.build(); } }
/** * Returns <code>true</code> if all primary shards are in * {@link ShardRoutingState#UNASSIGNED} state. Otherwise <code>false</code>. */ public boolean allPrimaryShardsUnassigned() { return primaryShardsUnassigned() == shards.size(); }
public Set<String> inSyncAllocationIds(int shardId) { assert shardId >= 0 && shardId < numberOfShards; return inSyncAllocationIds.get(shardId); }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; IndexRoutingTable that = (IndexRoutingTable) o; if (!index.equals(that.index)) return false; if (!shards.equals(that.shards)) return false; return true; }
@Override public int hashCode() { int result = index.hashCode(); result = 31 * result + shards.hashCode(); return result; }
@Override public Iterator<IndexShardRoutingTable> iterator() { return shards.valuesIt(); }
/** * Returns <code>true</code> if all shards are primary and active. Otherwise <code>false</code>. */ public boolean allPrimaryShardsActive() { return primaryShardsActive() == shards().size(); }
public IndexShardRoutingTable shard(int shardId) { return shards.get(shardId); }
return false; if (!inSyncAllocationIds.equals(that.inSyncAllocationIds)) { return false;
@Override public int hashCode() { int result = index.hashCode(); result = 31 * result + Long.hashCode(version); result = 31 * result + state.hashCode(); result = 31 * result + aliases.hashCode(); result = 31 * result + settings.hashCode(); result = 31 * result + mappings.hashCode(); result = 31 * result + customData.hashCode(); result = 31 * result + Long.hashCode(routingFactor); result = 31 * result + Long.hashCode(routingNumShards); result = 31 * result + Arrays.hashCode(primaryTerms); result = 31 * result + inSyncAllocationIds.hashCode(); result = 31 * result + rolloverInfos.hashCode(); return result; }
@Override public Iterator<IndexShardRoutingTable> iterator() { return shards.valuesIt(); }
@Override public void writeTo(StreamOutput out) throws IOException { index.writeTo(out); out.writeVInt(shards.size()); for (IndexShardRoutingTable indexShard : this) { IndexShardRoutingTable.Builder.writeToThin(indexShard, out); } }
ImmutableOpenIntMapDiff(ImmutableOpenIntMap<T> before, ImmutableOpenIntMap<T> after, KeySerializer<Integer> keySerializer, ValueSerializer<Integer, T> valueSerializer) { super(keySerializer, valueSerializer); assert after != null && before != null; for (IntCursor key : before.keys()) { if (!after.containsKey(key.value)) { deletes.add(key.value); } } for (IntObjectCursor<T> partIter : after) { T beforePart = before.get(partIter.key); if (beforePart == null) { upserts.put(partIter.key, partIter.value); } else if (partIter.value.equals(beforePart) == false) { if (valueSerializer.supportsDiffableValues()) { diffs.put(partIter.key, valueSerializer.diff(partIter.value, beforePart)); } else { upserts.put(partIter.key, partIter.value); } } } }
public Set<String> inSyncAllocationIds(int shardId) { assert shardId >= 0 && shardId < numberOfShards; return inSyncAllocationIds.get(shardId); }
public Builder(String index) { this.index = index; this.mappings = ImmutableOpenMap.builder(); this.aliases = ImmutableOpenMap.builder(); this.customMetaData = ImmutableOpenMap.builder(); this.inSyncAllocationIds = ImmutableOpenIntMap.builder(); this.rolloverInfos = ImmutableOpenMap.builder(); }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; IndexRoutingTable that = (IndexRoutingTable) o; if (!index.equals(that.index)) return false; if (!shards.equals(that.shards)) return false; return true; }
@Override public int hashCode() { int result = index.hashCode(); result = 31 * result + shards.hashCode(); return result; }
/** * Builds a new instance of the */ public ImmutableOpenIntMap<VType> build() { IntObjectHashMap<VType> map = this.map; this.map = null; // nullify the map, so any operation post build will fail! (hackish, but safest) return new ImmutableOpenIntMap<>(map); }