com.carrotsearch.hppc.cursors.IntObjectCursor Java Examples
The following examples show how to use
com.carrotsearch.hppc.cursors.IntObjectCursor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NodeFetchRequest.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeLong(jobId.getMostSignificantBits()); out.writeLong(jobId.getLeastSignificantBits()); out.writeVInt(fetchPhaseId); if (toFetch == null) { out.writeVInt(0); } else { out.writeVInt(toFetch.size()); for (IntObjectCursor<IntContainer> toFetchCursor : toFetch) { out.writeVInt(toFetchCursor.key); out.writeVInt(toFetchCursor.value.size()); for (IntCursor docCursor : toFetchCursor.value) { out.writeInt(docCursor.value); } } } }
Example #2
Source File: NodeFetchRequest.java From crate with Apache License 2.0 | 6 votes |
@Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeLong(jobId.getMostSignificantBits()); out.writeLong(jobId.getLeastSignificantBits()); out.writeVInt(fetchPhaseId); out.writeBoolean(closeContext); if (toFetch == null) { out.writeVInt(0); } else { out.writeVInt(toFetch.size()); for (IntObjectCursor<? extends IntContainer> toFetchCursor : toFetch) { out.writeVInt(toFetchCursor.key); out.writeVInt(toFetchCursor.value.size()); for (IntCursor docCursor : toFetchCursor.value) { out.writeInt(docCursor.value); } } } }
Example #3
Source File: IndicesShardStoresResponse.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeVInt(storeStatuses.size()); for (ObjectObjectCursor<String, ImmutableOpenIntMap<List<StoreStatus>>> indexShards : storeStatuses) { out.writeString(indexShards.key); out.writeVInt(indexShards.value.size()); for (IntObjectCursor<List<StoreStatus>> shardStatusesEntry : indexShards.value) { out.writeInt(shardStatusesEntry.key); out.writeVInt(shardStatusesEntry.value.size()); for (StoreStatus storeStatus : shardStatusesEntry.value) { storeStatus.writeTo(out); } } } out.writeVInt(failures.size()); for (ShardOperationFailedException failure : failures) { failure.writeTo(out); } }
Example #4
Source File: TransportBroadcastReplicationAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
/** * @return all shard ids the request should run on */ protected List<ShardId> shards(Request request, ClusterState clusterState) { List<ShardId> shardIds = new ArrayList<>(); String[] concreteIndices = indexNameExpressionResolver.concreteIndices(clusterState, request); for (String index : concreteIndices) { IndexMetaData indexMetaData = clusterState.metaData().getIndices().get(index); if (indexMetaData != null) { for (IntObjectCursor<IndexShardRoutingTable> shardRouting : clusterState.getRoutingTable().indicesRouting().get(index).getShards()) { shardIds.add(shardRouting.value.shardId()); } } } return shardIds; }
Example #5
Source File: IndexRoutingTable.java From crate with Apache License 2.0 | 5 votes |
IndexRoutingTable(Index index, ImmutableOpenIntMap<IndexShardRoutingTable> shards) { this.index = index; this.shuffler = new RotationShardShuffler(Randomness.get().nextInt()); this.shards = shards; List<ShardRouting> allActiveShards = new ArrayList<>(); for (IntObjectCursor<IndexShardRoutingTable> cursor : shards) { for (ShardRouting shardRouting : cursor.value) { if (shardRouting.active()) { allActiveShards.add(shardRouting); } } } this.allActiveShards = Collections.unmodifiableList(allActiveShards); }
Example #6
Source File: DefaultWriteConfiguration.java From spliceengine with GNU Affero General Public License v3.0 | 5 votes |
@Override public WriteResponse partialFailure(BulkWriteResult result, BulkWrite request) throws ExecutionException { IntObjectHashMap<WriteResult> failedRows = result.getFailedRows(); for (IntObjectCursor<WriteResult> cursor : failedRows) { if (!cursor.value.canRetry()) return WriteResponse.THROW_ERROR; } return WriteResponse.RETRY; }
Example #7
Source File: UpdatingWriteConfiguration.java From spliceengine with GNU Affero General Public License v3.0 | 5 votes |
@Override @SuppressFBWarnings(value = "SF_SWITCH_NO_DEFAULT",justification = "Intentional") public WriteResponse partialFailure(BulkWriteResult result,BulkWrite request) throws ExecutionException{ for(IntObjectCursor<WriteResult> cursor : result.getFailedRows()){ switch(cursor.value.getCode()){ case NOT_SERVING_REGION: case WRONG_REGION: rebuildable.rebuild(); break; } } return super.partialFailure(result,request); }
Example #8
Source File: CountingWriteConfiguration.java From spliceengine with GNU Affero General Public License v3.0 | 5 votes |
@Override @SuppressFBWarnings(value = "SF_SWITCH_NO_DEFAULT",justification = "Intentional") public WriteResponse partialFailure(BulkWriteResult result,BulkWrite request) throws ExecutionException{ statusReporter.partialFailures.incrementAndGet(); //look for timeouts, not serving regions, wrong regions, and so forth boolean notServingRegion=false; boolean wrongRegion=false; boolean failed=false; boolean writeConflict=false; for(IntObjectCursor<WriteResult> cursor : result.getFailedRows()){ Code code=cursor.value.getCode(); switch(code){ case FAILED: failed=true; break; case WRITE_CONFLICT: writeConflict=true; break; case NOT_SERVING_REGION: notServingRegion=true; break; case WRONG_REGION: wrongRegion=true; break; } } if(notServingRegion) statusReporter.notServingRegionFlushes.incrementAndGet(); if(wrongRegion) statusReporter.wrongRegionFlushes.incrementAndGet(); if(writeConflict) statusReporter.writeConflictBufferFlushes.incrementAndGet(); if(failed) statusReporter.failedBufferFlushes.incrementAndGet(); return super.partialFailure(result,request); }
Example #9
Source File: BulkWriteResult.java From spliceengine with GNU Affero General Public License v3.0 | 5 votes |
@Override public void write(Kryo kryo, Output output, BulkWriteResult object) { kryo.writeObject(output,object.globalStatus); output.writeInt(object.notRunRows.size()); for(IntCursor cursor:object.notRunRows){ output.writeInt(cursor.value); } output.writeInt(object.failedRows.size()); for(IntObjectCursor<WriteResult> c:object.failedRows){ output.writeInt(c.key); kryo.writeObject(output,c.value); } }
Example #10
Source File: BulkWriteAction.java From spliceengine with GNU Affero General Public License v3.0 | 5 votes |
private Exception parseIntoException(BulkWriteResult response){ IntObjectHashMap<WriteResult> failedRows=response.getFailedRows(); Exception first = null; for(IntObjectCursor<WriteResult> cursor : failedRows){ @SuppressWarnings("ThrowableResultOfMethodCallIgnored") Throwable e=pipelineExceptionFactory.processErrorResult(cursor.value); if(e instanceof WriteConflict){ //TODO -sf- find a way to add in StandardExceptions here return (Exception)e; }else if(first==null) first = (Exception)e; } return first; }
Example #11
Source File: BulkWriteAction.java From spliceengine with GNU Affero General Public License v3.0 | 5 votes |
/** * Return an error message describing the types and number of failures in the BatchWrite. * * @param failedRows the rows which failed, and their respective error messages * @return error message describing the failed rows */ private String getFailedRowsMessage(IntObjectHashMap<WriteResult> failedRows){ if(failedRows!=null && !failedRows.isEmpty()){ // Aggregate the error counts by code. HashMap<Code, Integer> errorCodeToCountMap=new HashMap<>(); for(IntObjectCursor<WriteResult> failedRowCursor : failedRows){ WriteResult wr=failedRowCursor.value; Code errorCode=(wr==null?null:wr.getCode()); Integer errorCount=errorCodeToCountMap.get(errorCode); errorCodeToCountMap.put(errorCode,(errorCode==null || errorCount==null?1:errorCount+1)); } // Make a string out of the error map. StringBuilder buf=new StringBuilder(); buf.append("{ "); boolean first=true; for(Map.Entry<Code, Integer> entry : errorCodeToCountMap.entrySet()){ if(!first){ buf.append(", "); }else{ first=false; } buf.append(String.format("%s=%s",entry.getKey(),entry.getValue())); } buf.append(" }"); return buf.toString(); }else{ return "NONE"; } }
Example #12
Source File: PipelineUtils.java From spliceengine with GNU Affero General Public License v3.0 | 5 votes |
public static Collection<KVPair> doPartialRetry(BulkWrite bulkWrite,BulkWriteResult response,long id) throws Exception{ IntHashSet notRunRows=response.getNotRunRows(); IntObjectHashMap<WriteResult> failedRows=response.getFailedRows(); Collection<KVPair> toRetry=new ArrayList<>(failedRows.size()+notRunRows.size()); List<String> errorMsgs= Lists.newArrayListWithCapacity(failedRows.size()); int i=0; Collection<KVPair> allWrites=bulkWrite.getMutations(); for(KVPair kvPair : allWrites){ if(notRunRows.contains(i)) toRetry.add(kvPair); else{ WriteResult writeResult=failedRows.get(i); if(writeResult!=null){ errorMsgs.add(writeResult.getErrorMessage()); if(writeResult.canRetry()) toRetry.add(kvPair); } } i++; } if(LOG.isTraceEnabled()){ int[] errorCounts=new int[11]; for(IntObjectCursor<WriteResult> failedCursor : failedRows){ errorCounts[failedCursor.value.getCode().ordinal()]++; } SpliceLogUtils.trace(LOG,"[%d] %d failures with types: %s",id,failedRows.size(),Arrays.toString(errorCounts)); } return toRetry; }
Example #13
Source File: PermissiveInsertWriteConfiguration.java From spliceengine with GNU Affero General Public License v3.0 | 5 votes |
@Override public WriteResponse partialFailure(BulkWriteResult result, BulkWrite request) throws ExecutionException { if (LOG.isDebugEnabled()) SpliceLogUtils.debug(LOG, "partialFailure result=%s", result); if(operationContext.isFailed()) return WriteResponse.IGNORE; //filter out and report bad records IntObjectHashMap<WriteResult> failedRows = result.getFailedRows(); @SuppressWarnings("MismatchedReadAndWriteOfArray") Object[] fRows = failedRows.values; boolean ignore = result.getNotRunRows().size()<=0 && result.getFailedRows().size()<=0; List<KVPair> kvPairList = request.mutationsList(); for(IntObjectCursor<WriteResult> resultCursor:failedRows) { WriteResult value = resultCursor.value; int rowNum = resultCursor.key; if (!value.canRetry()) { if (operationContext.isFailed()) ignore = true; try { operationContext.recordBadRecord(errorRow(pairDecoder.get().decode(kvPairList.get(rowNum).shallowClone()).toString(), value), null); } catch (Exception e) { ignore = true; } if (operationContext.isFailed()) ignore = true; } } if(ignore) return WriteResponse.IGNORE; else return WriteResponse.RETRY; }
Example #14
Source File: MutableSymbolTable.java From jopenfst with MIT License | 5 votes |
/** * If there are ids to reclaim at the end, then this will do this. Certainly be careful if you are * doing operations where it is expected that the id mappings will be consistent across multiple FSTs * such as in compose where you want the output of A to be equal to the input of B */ public void trimIds() { // typical case shortcut if (idToSymbol.containsKey(nextId - 1)) { return; } int max = -1; for (IntObjectCursor<String> cursor : idToSymbol) { max = Math.max(max, cursor.key); } nextId = max + 1; }
Example #15
Source File: ExpandComponent.java From lucene-solr with Apache License 2.0 | 5 votes |
private Query getGroupQuery(String fname, int size, IntObjectHashMap<BytesRef> ordBytes) { BytesRef[] bytesRefs = new BytesRef[size]; int index = -1; Iterator<IntObjectCursor<BytesRef>>it = ordBytes.iterator(); while (it.hasNext()) { IntObjectCursor<BytesRef> cursor = it.next(); bytesRefs[++index] = cursor.value; } return new TermInSetQuery(fname, bytesRefs); }
Example #16
Source File: IndicesShardStoresResponse.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { if (failures.size() > 0) { builder.startArray(Fields.FAILURES); for (ShardOperationFailedException failure : failures) { builder.startObject(); failure.toXContent(builder, params); builder.endObject(); } builder.endArray(); } builder.startObject(Fields.INDICES); for (ObjectObjectCursor<String, ImmutableOpenIntMap<List<StoreStatus>>> indexShards : storeStatuses) { builder.startObject(indexShards.key); builder.startObject(Fields.SHARDS); for (IntObjectCursor<List<StoreStatus>> shardStatusesEntry : indexShards.value) { builder.startObject(String.valueOf(shardStatusesEntry.key)); builder.startArray(Fields.STORES); for (StoreStatus storeStatus : shardStatusesEntry.value) { builder.startObject(); storeStatus.toXContent(builder, params); builder.endObject(); } builder.endArray(); builder.endObject(); } builder.endObject(); builder.endObject(); } builder.endObject(); return builder; }
Example #17
Source File: TransportBroadcastReplicationAction.java From crate with Apache License 2.0 | 5 votes |
/** * @return all shard ids the request should run on */ protected List<ShardId> shards(Request request, ClusterState clusterState) { List<ShardId> shardIds = new ArrayList<>(); String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, request); for (String index : concreteIndices) { IndexMetaData indexMetaData = clusterState.metaData().getIndices().get(index); if (indexMetaData != null) { for (IntObjectCursor<IndexShardRoutingTable> shardRouting : clusterState.getRoutingTable().indicesRouting().get(index).getShards()) { shardIds.add(shardRouting.value.shardId()); } } } return shardIds; }
Example #18
Source File: NodeFetchResponse.java From crate with Apache License 2.0 | 5 votes |
@Override public void writeTo(StreamOutput out) throws IOException { if (fetched == null) { out.writeVInt(0); } else { out.writeVInt(fetched.size()); for (IntObjectCursor<StreamBucket> cursor : fetched) { out.writeVInt(cursor.key); cursor.value.writeTo(out); } } }
Example #19
Source File: IndexRoutingTable.java From Elasticsearch with Apache License 2.0 | 5 votes |
/** * creates a new {@link IndexRoutingTable} with all shard versions normalized * * @return new {@link IndexRoutingTable} */ public IndexRoutingTable normalizeVersions() { IndexRoutingTable.Builder builder = new Builder(this.index); for (IntObjectCursor<IndexShardRoutingTable> cursor : shards) { builder.addIndexShard(cursor.value.normalizeVersions()); } return builder.build(); }
Example #20
Source File: IndexRoutingTable.java From Elasticsearch with Apache License 2.0 | 5 votes |
IndexRoutingTable(String index, ImmutableOpenIntMap<IndexShardRoutingTable> shards) { this.index = index; this.shuffler = new RotationShardShuffler(ThreadLocalRandom.current().nextInt()); this.shards = shards; List<ShardRouting> allActiveShards = new ArrayList<>(); for (IntObjectCursor<IndexShardRoutingTable> cursor : shards) { for (ShardRouting shardRouting : cursor.value) { shardRouting.freeze(); if (shardRouting.active()) { allActiveShards.add(shardRouting); } } } this.allActiveShards = Collections.unmodifiableList(allActiveShards); }
Example #21
Source File: NodeFetchResponse.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); if (fetched == null) { out.writeVInt(0); } else { out.writeVInt(fetched.size()); for (IntObjectCursor<StreamBucket> cursor : fetched) { out.writeVInt(cursor.key); cursor.value.writeTo(out); } } }
Example #22
Source File: ImmutableOpenIntMap.java From crate with Apache License 2.0 | 4 votes |
@Override public int putAll(Iterable<? extends IntObjectCursor<? extends VType>> iterable) { return map.putAll(iterable); }
Example #23
Source File: JobSetup.java From crate with Apache License 2.0 | 4 votes |
/** * find all phases that don't have any downstreams. * <p> * This is usually only one phase (the handlerPhase, but there might be more in case of bulk operations) * <pre> * * flow: targetToSourceMap: * * 0 1 2 -> [0, 1] * \ / 3 -> [2] * 2 * | * 3 * * leafs = all keys in targetToSource map which have no entry in values (3 in the example above) * </pre> */ private static IntCollection findLeafs(IntObjectMap<? extends IntContainer> targetToSourceMap) { IntArrayList leafs = new IntArrayList(); BitSet sources = new BitSet(); for (IntObjectCursor<? extends IntContainer> sourceIds : targetToSourceMap) { for (IntCursor sourceId : sourceIds.value) { sources.set(sourceId.value); } } for (IntCursor targetPhaseCursor : targetToSourceMap.keys()) { int targetPhase = targetPhaseCursor.value; if (!sources.get(targetPhase)) { leafs.add(targetPhase); } } return leafs; }
Example #24
Source File: FetchTask.java From crate with Apache License 2.0 | 4 votes |
protected void innerClose() { for (IntObjectCursor<Engine.Searcher> cursor : searchers) { cursor.value.close(); } }
Example #25
Source File: InstructionModifier.java From Bats with Apache License 2.0 | 4 votes |
@Override public void visitEnd() { if (logger.isTraceEnabled()) { final StringBuilder sb = new StringBuilder(); sb.append("InstructionModifier "); sb.append(name); sb.append(' '); sb.append(signature); sb.append('\n'); if ((desc != null) && !desc.isEmpty()) { sb.append(" desc: "); sb.append(desc); sb.append('\n'); } int idenId = 0; // used to generate unique ids for the ValueHolderIden's int itemCount = 0; // counts up the number of items found final HashMap<ValueHolderIden, Integer> seenIdens = new HashMap<>(); // iden -> idenId sb.append(" .oldToNew:\n"); for (final IntObjectCursor<ValueHolderIden.ValueHolderSub> ioc : oldToNew) { final ValueHolderIden iden = ioc.value.iden(); if (!seenIdens.containsKey(iden)) { seenIdens.put(iden, ++idenId); sb.append("ValueHolderIden[" + idenId + "]:\n"); iden.dump(sb); } sb.append(" " + ioc.key + " => " + ioc.value + '[' + seenIdens.get(iden) + "]\n"); ++itemCount; } sb.append(" .oldLocalToFirst:\n"); for (final IntIntCursor iic : oldLocalToFirst) { sb.append(" " + iic.key + " => " + iic.value + '\n'); ++itemCount; } if (itemCount > 0) { logger.debug(sb.toString()); } } super.visitEnd(); }
Example #26
Source File: ImmutableOpenIntMap.java From crate with Apache License 2.0 | 4 votes |
@Override public Iterator<IntObjectCursor<VType>> iterator() { return map.iterator(); }
Example #27
Source File: ImmutableOpenIntMap.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public int putAll(Iterable<? extends IntObjectCursor<? extends VType>> iterable) { return map.putAll(iterable); }
Example #28
Source File: ImmutableOpenIntMap.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public Iterator<IntObjectCursor<VType>> iterator() { return map.iterator(); }
Example #29
Source File: FetchContext.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override protected void innerClose(@Nullable Throwable t) { for (IntObjectCursor<Engine.Searcher> cursor : searchers) { cursor.value.close(); } }
Example #30
Source File: ImmutableOpenIntMap.java From crate with Apache License 2.0 | 2 votes |
/** * Returns a cursor over the entries (key-value pairs) in this map. The iterator is * implemented as a cursor and it returns <b>the same cursor instance</b> on every * call to {@link java.util.Iterator#next()}. To read the current key and value use the cursor's * public fields. An example is shown below. * <pre> * for (IntShortCursor c : intShortMap) * { * System.out.println("index=" + c.index * + " key=" + c.key * + " value=" + c.value); * } * </pre> * <p> * The <code>index</code> field inside the cursor gives the internal index inside * the container's implementation. The interpretation of this index depends on * to the container. */ @Override public Iterator<IntObjectCursor<VType>> iterator() { return map.iterator(); }