com.carrotsearch.hppc.ObjectObjectHashMap Java Examples

The following examples show how to use com.carrotsearch.hppc.ObjectObjectHashMap. 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: SharedPreFlushHook.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Collection<KVPair> transform(Collection<KVPair> buffer) throws Exception{
    if(LOG.isTraceEnabled())
        SpliceLogUtils.trace(LOG,"transform buffer rows=%d",buffer.size());
    Collection<KVPair> newList=new ArrayList<>(buffer.size());
    for(KVPair indexPair : buffer){
        for(Pair<WriteContext, ObjectObjectHashMap<KVPair, KVPair>> pair : sharedMainMutationList){
            KVPair base=pair.getSecond().get(indexPair);
            if(base!=null){
                if(pair.getFirst().canRun(base))
                    newList.add(indexPair);
                break;
            }
        }
    }
    if(LOG.isTraceEnabled())
        SpliceLogUtils.trace(LOG,"transform returns buffer rows=%d",newList.size());
    return newList;
}
 
Example #2
Source File: SharedCallBufferFactory.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
public CallBuffer<KVPair> getWriteBuffer(byte[] conglomBytes,
                                         WriteContext context,
                                         ObjectObjectHashMap<KVPair, KVPair> indexToMainMutationMap,
                                         int maxSize,
                                         boolean useAsyncWriteBuffers,
                                         TxnView txn, byte[] token) throws Exception {

    CallBuffer<KVPair> writeBuffer = sharedCallBufferMap.get(conglomBytes);
    if (writeBuffer == null) {
        writeBuffer = createKvPairCallBuffer(conglomBytes, context, indexToMainMutationMap, maxSize, useAsyncWriteBuffers, txn, token);
    } else {
        ((SharedPreFlushHook) writeBuffer.getPreFlushHook()).registerContext(context, indexToMainMutationMap);
        writeBuffer.getWriteConfiguration().registerContext(context, indexToMainMutationMap);
    }
    return writeBuffer;
}
 
Example #3
Source File: DfsSearchResult.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public static ObjectObjectHashMap<String, CollectionStatistics> readFieldStats(StreamInput in, ObjectObjectHashMap<String, CollectionStatistics> fieldStatistics) throws IOException {
    final int numFieldStatistics = in.readVInt();
    if (fieldStatistics == null) {
        fieldStatistics = HppcMaps.newNoNullKeysMap(numFieldStatistics);
    }
    for (int i = 0; i < numFieldStatistics; i++) {
        final String field = in.readString();
        assert field != null;
        final long maxDoc = in.readVLong();
        final long docCount = subOne(in.readVLong());
        final long sumTotalTermFreq = subOne(in.readVLong());
        final long sumDocFreq = subOne(in.readVLong());
        CollectionStatistics stats = new CollectionStatistics(field, maxDoc, docCount, sumTotalTermFreq, sumDocFreq);
        fieldStatistics.put(field, stats);
    }
    return fieldStatistics;
}
 
Example #4
Source File: ContextAndHeaderHolder.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public synchronized void copyContextFrom(HasContext other) {
    if (other == null) {
        return;
    }

    synchronized (other) {
        ImmutableOpenMap<Object, Object> otherContext = other.getContext();
        if (otherContext == null) {
            return;
        }
        if (context == null) {
            ObjectObjectHashMap<Object, Object> map = new ObjectObjectHashMap<>(other.getContext().size());
            map.putAll(otherContext);
            this.context = map;
        } else {
            context.putAll(otherContext);
        }
    }
}
 
Example #5
Source File: ContextAndHeaderHolder.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public final synchronized <V> V putInContext(Object key, Object value) {
    if (context == null) {
        context = new ObjectObjectHashMap<>(2);
    }
    return (V) context.put(key, value);
}
 
Example #6
Source File: HppcObjMapTest.java    From hashmapTest with The Unlicense 5 votes vote down vote up
@Override
public int test() {
    final ObjectObjectMap<Integer, Integer> m_map = new ObjectObjectHashMap<>( m_keys.length / 2 + 1, m_fillFactor );
    int add = 0, remove = 0;
    while ( add < m_keys.length )
    {
        m_map.put( m_keys[ add ], m_keys[ add ] );
        ++add;
        m_map.put( m_keys[ add ], m_keys[ add ] );
        ++add;
        m_map.remove( m_keys2[ remove++ ] );
    }
    return m_map.size();
}
 
Example #7
Source File: HppcObjMapTest.java    From hashmapTest with The Unlicense 5 votes vote down vote up
@Override
public int test() {
    final ObjectObjectMap<Integer, Integer> m_map = new ObjectObjectHashMap<>( m_keys.length, m_fillFactor );
    for ( int i = 0; i < m_keys.length; ++i )
        m_map.put( m_keys[ i ], m_keys[ i ] );
    for ( int i = 0; i < m_keys2.length; ++i )
        m_map.put( m_keys2[ i ], m_keys2[ i ] );
    return m_map.size();
}
 
Example #8
Source File: HppcObjMapTest.java    From hashmapTest with The Unlicense 5 votes vote down vote up
@Override
public void setup(final int[] keys, final float fillFactor, final int oneFailureOutOf ) {
    super.setup( keys, fillFactor, oneFailureOutOf );
    m_map = new ObjectObjectHashMap<>( keys.length, fillFactor );
    for (Integer key : m_keys)
        m_map.put(new Integer( key % oneFailureOutOf == 0 ? key + 1 : key ), key);
}
 
Example #9
Source File: SharedCallBufferFactory.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
private CallBuffer<KVPair> createKvPairCallBuffer(byte[] conglomBytes,
                                                  WriteContext context,
                                                  ObjectObjectHashMap<KVPair, KVPair> indexToMainMutationMap,
                                                  int maxSize,
                                                  boolean useAsyncWriteBuffers,
                                                  TxnView txn, byte[] token) throws IOException{
    SharedPreFlushHook hook = new SharedPreFlushHook();
    WriteConfiguration writeConfiguration=writerPool.defaultWriteConfiguration();
    WriteConfiguration wc = new SharedWriteConfiguration(writeConfiguration.getMaximumRetries(),
            writeConfiguration.getPause(),
            writeConfiguration.getExceptionFactory());
    if (context.skipConflictDetection() || context.skipWAL()) {
        wc = new UnsafeWriteConfiguration(wc, context.skipConflictDetection(), context.skipWAL());
    }
    if (context.rollforward()) {
        wc = new RollforwardWriteConfiguration(wc);
    }
    hook.registerContext(context, indexToMainMutationMap);
    wc.registerContext(context, indexToMainMutationMap);
    CallBuffer<KVPair> writeBuffer;
    if (useAsyncWriteBuffers) {
        writeBuffer = writerPool.writeBuffer(partitionFactory.getTable(conglomBytes), txn,token, hook, wc, false);
    } else {
        writeBuffer = writerPool.synchronousWriteBuffer(partitionFactory.getTable(conglomBytes), txn, token, hook, wc, maxSize, false);
    }
    sharedCallBufferMap.put(conglomBytes, writeBuffer);
    return writeBuffer;
}
 
Example #10
Source File: BOSSVS.java    From SFA with GNU General Public License v3.0 5 votes vote down vote up
protected void initMatrix(
    final ObjectObjectHashMap<Double, IntFloatHashMap> matrix,
    final Set<Double> uniqueLabels,
    final BagOfPattern[] bag) {
  for (Double label : uniqueLabels) {
    IntFloatHashMap stat = matrix.get(label);
    if (stat == null) {
      matrix.put(label, new IntFloatHashMap(bag[0].bag.size() * bag.length));
    } else {
      stat.clear();
    }
  }
}
 
Example #11
Source File: ContextAndHeaderHolder.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public final synchronized void putAllInContext(ObjectObjectAssociativeContainer<Object, Object> map) {
    if (map == null) {
        return;
    }
    if (context == null) {
        context = new ObjectObjectHashMap<>(map);
    } else {
        context.putAll(map);
    }
}
 
Example #12
Source File: HppcMaps.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * Wraps the given map and prevent adding of <code>null</code> keys.
 * 
 * @param expectedElements
 *          The expected number of elements guaranteed not to cause buffer
 *          expansion (inclusive).
 */
public static <K, V> ObjectObjectHashMap<K, V> ensureNoNullKeys(int expectedElements) {
    return new ObjectObjectHashMap<K, V>(expectedElements) {
        @Override
        public V put(K key, V value) {
            if (key == null) {
                throw new IllegalArgumentException("Map key must not be null");
            }
            return super.put(key, value);
        }
    };
}
 
Example #13
Source File: PipelineWriteContext.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public CallBuffer<KVPair> getSharedWriteBuffer(byte[] conglomBytes,
                                               ObjectObjectHashMap<KVPair, KVPair> indexToMainMutationMap,
                                               int maxSize, boolean useAsyncWriteBuffers, TxnView txn, byte[] token) throws Exception {
    assert indexSharedCallBuffer != null;
    return indexSharedCallBuffer.getWriteBuffer(conglomBytes, this, indexToMainMutationMap, maxSize, useAsyncWriteBuffers, txn, token);
}
 
Example #14
Source File: ParseContext.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
/** Add fields so that they can later be fetched using {@link #getByKey(Object)}. */
public void addWithKey(Object key, IndexableField field) {
    if (keyedFields == null) {
        keyedFields = new ObjectObjectHashMap<>();
    } else if (keyedFields.containsKey(key)) {
        throw new IllegalStateException("Only one field can be stored per key");
    }
    keyedFields.put(key, field);
    add(field);
}
 
Example #15
Source File: ParseContext.java    From crate with Apache License 2.0 5 votes vote down vote up
/** Add fields so that they can later be fetched using {@link #getByKey(Object)}. */
public void addWithKey(Object key, IndexableField field) {
    if (keyedFields == null) {
        keyedFields = new ObjectObjectHashMap<>();
    } else if (keyedFields.containsKey(key)) {
        throw new IllegalStateException("Only one field can be stored per key");
    }
    keyedFields.put(key, field);
    add(field);
}
 
Example #16
Source File: DfsSearchResult.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public static void writeFieldStats(StreamOutput out, ObjectObjectHashMap<String, CollectionStatistics> fieldStatistics) throws IOException {
    out.writeVInt(fieldStatistics.size());

    for (ObjectObjectCursor<String, CollectionStatistics> c : fieldStatistics) {
        out.writeString(c.key);
        CollectionStatistics statistics = c.value;
        assert statistics.maxDoc() >= 0;
        out.writeVLong(statistics.maxDoc());
        out.writeVLong(addOne(statistics.docCount()));
        out.writeVLong(addOne(statistics.sumTotalTermFreq()));
        out.writeVLong(addOne(statistics.sumDocFreq()));
    }
}
 
Example #17
Source File: NonPersistentTopic.java    From pulsar with Apache License 2.0 4 votes vote down vote up
public NonPersistentTopicStats getStats(boolean getPreciseBacklog) {

        NonPersistentTopicStats stats = new NonPersistentTopicStats();

        ObjectObjectHashMap<String, PublisherStats> remotePublishersStats = new ObjectObjectHashMap<String, PublisherStats>();

        producers.values().forEach(producer -> {
            NonPersistentPublisherStats publisherStats = (NonPersistentPublisherStats) producer.getStats();
            stats.msgRateIn += publisherStats.msgRateIn;
            stats.msgThroughputIn += publisherStats.msgThroughputIn;

            if (producer.isRemote()) {
                remotePublishersStats.put(producer.getRemoteCluster(), publisherStats);
            } else {
                stats.getPublishers().add(publisherStats);
            }
        });

        stats.averageMsgSize = stats.msgRateIn == 0.0 ? 0.0 : (stats.msgThroughputIn / stats.msgRateIn);
        stats.msgInCounter = getMsgInCounter();
        stats.bytesInCounter = getBytesInCounter();

        subscriptions.forEach((name, subscription) -> {
            NonPersistentSubscriptionStats subStats = subscription.getStats();

            stats.msgRateOut += subStats.msgRateOut;
            stats.msgThroughputOut += subStats.msgThroughputOut;
            stats.bytesOutCounter += subStats.bytesOutCounter;
            stats.msgOutCounter += subStats.msgOutCounter;
            stats.getSubscriptions().put(name, subStats);
        });

        replicators.forEach((cluster, replicator) -> {
            NonPersistentReplicatorStats replicatorStats = replicator.getStats();

            // Add incoming msg rates
            PublisherStats pubStats = remotePublishersStats.get(replicator.getRemoteCluster());
            if (pubStats != null) {
                replicatorStats.msgRateIn = pubStats.msgRateIn;
                replicatorStats.msgThroughputIn = pubStats.msgThroughputIn;
                replicatorStats.inboundConnection = pubStats.getAddress();
                replicatorStats.inboundConnectedSince = pubStats.getConnectedSince();
            }

            stats.msgRateOut += replicatorStats.msgRateOut;
            stats.msgThroughputOut += replicatorStats.msgThroughputOut;

            stats.getReplication().put(replicator.getRemoteCluster(), replicatorStats);
        });

        return stats;
    }
 
Example #18
Source File: ForwardingWriteConfiguration.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void registerContext(WriteContext context,
                            ObjectObjectHashMap<KVPair, KVPair> indexToMainMutationMap) {
    delegate.registerContext(context, indexToMainMutationMap);
}
 
Example #19
Source File: SharedWriteConfiguration.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void registerContext(WriteContext context, ObjectObjectHashMap<KVPair, KVPair> indexToMainMutationMap) {
    sharedMainMutationList.add(Pair.newPair(context,indexToMainMutationMap));
    completedCount.incrementAndGet();
}
 
Example #20
Source File: WriteContext.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Retrieve the sharedWriteBuffer for the index upsert handler
 */
CallBuffer<KVPair> getSharedWriteBuffer(byte[] conglomBytes,
                                        ObjectObjectHashMap<KVPair, KVPair> indexToMainMutationMap,
                                        int maxSize,
                                        boolean useAsyncWriteBuffers,
                                        TxnView txn, byte[] token) throws Exception;
 
Example #21
Source File: WriteNode.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public CallBuffer<KVPair> getSharedWriteBuffer(byte[] conglomBytes,
                                               ObjectObjectHashMap<KVPair, KVPair> indexToMainMutationMap,
                                               int maxSize, boolean useAsyncWriteBuffers, TxnView txn, byte[] token) throws Exception {
    return pipelineWriteContext.getSharedWriteBuffer(conglomBytes, indexToMainMutationMap, maxSize, useAsyncWriteBuffers, txn, token);
}
 
Example #22
Source File: BaseWriteConfiguration.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void registerContext(WriteContext context, ObjectObjectHashMap<KVPair, KVPair> indexToMainMutationMap) {
    SpliceLogUtils.warn(LOG, "registering Context with a base class");
}
 
Example #23
Source File: SharedPreFlushHook.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
public void registerContext(WriteContext context,ObjectObjectHashMap<KVPair, KVPair> indexToMainMutationMap){
    sharedMainMutationList.add(Pair.newPair(context,indexToMainMutationMap));
}
 
Example #24
Source File: ImmutableOpenMap.java    From crate with Apache License 2.0 4 votes vote down vote up
private ImmutableOpenMap(ObjectObjectHashMap<KType, VType> map) {
    this.map = map;
}
 
Example #25
Source File: ImmutableOpenMap.java    From crate with Apache License 2.0 4 votes vote down vote up
public Builder(int size) {
    this.map = new ObjectObjectHashMap<>(size);
}
 
Example #26
Source File: ImmutableOpenMap.java    From crate with Apache License 2.0 4 votes vote down vote up
/**
 * Builds a new instance of the
 */
public ImmutableOpenMap<KType, VType> build() {
    ObjectObjectHashMap<KType, VType> map = this.map;
    this.map = null; // nullify the map, so any operation post build will fail! (hackish, but safest)
    return new ImmutableOpenMap<>(map);
}
 
Example #27
Source File: PersistentTopic.java    From pulsar with Apache License 2.0 4 votes vote down vote up
public TopicStats getStats(boolean getPreciseBacklog) {

        TopicStats stats = new TopicStats();

        ObjectObjectHashMap<String, PublisherStats> remotePublishersStats = new ObjectObjectHashMap<String, PublisherStats>();

        producers.values().forEach(producer -> {
            PublisherStats publisherStats = producer.getStats();
            stats.msgRateIn += publisherStats.msgRateIn;
            stats.msgThroughputIn += publisherStats.msgThroughputIn;

            if (producer.isRemote()) {
                remotePublishersStats.put(producer.getRemoteCluster(), publisherStats);
            } else {
                stats.publishers.add(publisherStats);
            }
        });

        stats.averageMsgSize = stats.msgRateIn == 0.0 ? 0.0 : (stats.msgThroughputIn / stats.msgRateIn);
        stats.msgInCounter = getMsgInCounter();
        stats.bytesInCounter = getBytesInCounter();
        stats.msgChunkPublished = this.msgChunkPublished;

        subscriptions.forEach((name, subscription) -> {
            SubscriptionStats subStats = subscription.getStats(getPreciseBacklog);

            stats.msgRateOut += subStats.msgRateOut;
            stats.msgThroughputOut += subStats.msgThroughputOut;
            stats.bytesOutCounter += subStats.bytesOutCounter;
            stats.msgOutCounter += subStats.msgOutCounter;
            stats.subscriptions.put(name, subStats);
        });

        replicators.forEach((cluster, replicator) -> {
            ReplicatorStats replicatorStats = replicator.getStats();

            // Add incoming msg rates
            PublisherStats pubStats = remotePublishersStats.get(replicator.getRemoteCluster());
            if (pubStats != null) {
                replicatorStats.msgRateIn = pubStats.msgRateIn;
                replicatorStats.msgThroughputIn = pubStats.msgThroughputIn;
                replicatorStats.inboundConnection = pubStats.getAddress();
                replicatorStats.inboundConnectedSince = pubStats.getConnectedSince();
            }

            stats.msgRateOut += replicatorStats.msgRateOut;
            stats.msgThroughputOut += replicatorStats.msgThroughputOut;

            stats.replication.put(replicator.getRemoteCluster(), replicatorStats);
        });

        stats.storageSize = ledger.getTotalSize();
        stats.backlogSize = ledger.getEstimatedBacklogSize();
        stats.deduplicationStatus = messageDeduplication.getStatus().toString();

        return stats;
    }
 
Example #28
Source File: PersistentTopic.java    From pulsar with Apache License 2.0 4 votes vote down vote up
public TopicStatsHelper() {
    remotePublishersStats = new ObjectObjectHashMap<>();
    reset();
}
 
Example #29
Source File: AggregatedDfs.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public AggregatedDfs(ObjectObjectHashMap<Term, TermStatistics> termStatistics, ObjectObjectHashMap<String, CollectionStatistics> fieldStatistics, long maxDoc) {
    this.termStatistics = termStatistics;
    this.fieldStatistics = fieldStatistics;
    this.maxDoc = maxDoc;
}
 
Example #30
Source File: NonPersistentTopic.java    From pulsar with Apache License 2.0 4 votes vote down vote up
public TopicStats() {
    remotePublishersStats = new ObjectObjectHashMap<>();
    reset();
}