Пример #1
0
 void putIfAbsent(Query query, DocIdSet set) {
   assert query instanceof BoostQuery == false;
   assert query instanceof ConstantScoreQuery == false;
   if (cache.putIfAbsent(query, set) == null) {
     // the set was actually put
     onDocIdSetCache(HASHTABLE_RAM_BYTES_PER_ENTRY + set.ramBytesUsed());
   }
 }
Пример #2
0
 void remove(Query query) {
   assert query instanceof BoostQuery == false;
   assert query instanceof ConstantScoreQuery == false;
   DocIdSet removed = cache.remove(query);
   if (removed != null) {
     onDocIdSetEviction(HASHTABLE_RAM_BYTES_PER_ENTRY + removed.ramBytesUsed());
   }
 }
Пример #3
0
 private RoaringDocIdSet(DocIdSet[] docIdSets, int cardinality) {
   this.docIdSets = docIdSets;
   long ramBytesUsed = BASE_RAM_BYTES_USED + RamUsageEstimator.shallowSizeOf(docIdSets);
   for (DocIdSet set : this.docIdSets) {
     if (set != null) {
       ramBytesUsed += set.ramBytesUsed();
     }
   }
   this.ramBytesUsed = ramBytesUsed;
   this.cardinality = cardinality;
 }
Пример #4
0
  // pkg-private for testing
  synchronized void assertConsistent() {
    if (requiresEviction()) {
      throw new AssertionError(
          "requires evictions: size="
              + mostRecentlyUsedQueries.size()
              + ", maxSize="
              + maxSize
              + ", ramBytesUsed="
              + ramBytesUsed()
              + ", maxRamBytesUsed="
              + maxRamBytesUsed);
    }
    for (LeafCache leafCache : cache.values()) {
      Set<Query> keys = Collections.newSetFromMap(new IdentityHashMap<>());
      keys.addAll(leafCache.cache.keySet());
      keys.removeAll(mostRecentlyUsedQueries);
      if (!keys.isEmpty()) {
        throw new AssertionError(
            "One leaf cache contains more keys than the top-level cache: " + keys);
      }
    }
    long recomputedRamBytesUsed =
        HASHTABLE_RAM_BYTES_PER_ENTRY * cache.size()
            + LINKED_HASHTABLE_RAM_BYTES_PER_ENTRY * uniqueQueries.size();
    for (Query query : mostRecentlyUsedQueries) {
      recomputedRamBytesUsed += ramBytesUsed(query);
    }
    for (LeafCache leafCache : cache.values()) {
      recomputedRamBytesUsed += HASHTABLE_RAM_BYTES_PER_ENTRY * leafCache.cache.size();
      for (DocIdSet set : leafCache.cache.values()) {
        recomputedRamBytesUsed += set.ramBytesUsed();
      }
    }
    if (recomputedRamBytesUsed != ramBytesUsed) {
      throw new AssertionError(
          "ramBytesUsed mismatch : " + ramBytesUsed + " != " + recomputedRamBytesUsed);
    }

    long recomputedCacheSize = 0;
    for (LeafCache leafCache : cache.values()) {
      recomputedCacheSize += leafCache.cache.size();
    }
    if (recomputedCacheSize != getCacheSize()) {
      throw new AssertionError(
          "cacheSize mismatch : " + getCacheSize() + " != " + recomputedCacheSize);
    }
  }