Example #1
0
 /**
  * deleting a container affects the containers in RAM and all the BLOB files the deleted
  * containers are merged and returned as result of the method
  *
  * @throws IOException
  */
 @Override
 public ReferenceContainer<ReferenceType> remove(final byte[] termHash) throws IOException {
   removeDelayed();
   ReferenceContainer<ReferenceType> c1 = null;
   try {
     c1 = this.array.get(termHash);
   } catch (final SpaceExceededException e2) {
     ConcurrentLog.logException(e2);
   }
   if (c1 != null) {
     this.array.delete(termHash);
   }
   final ReferenceContainer<ReferenceType> c0 = this.ram.remove(termHash);
   if (c1 == null) return c0;
   if (c0 == null) return c1;
   try {
     return c1.merge(c0);
   } catch (final SpaceExceededException e) {
     // try to free some ram
     try {
       return c1.merge(c0);
     } catch (final SpaceExceededException e1) {
       // go silently over the problem
       return (c1.size() > c0.size()) ? c1 : c0;
     }
   }
 }
Example #2
0
  /**
   * count number of references for a given term this method may cause strong IO load if called too
   * frequently.
   */
  @Override
  public int count(final byte[] termHash) {
    final Integer cachedCount = this.countCache.get(termHash);
    if (cachedCount != null) return cachedCount.intValue();

    int countFile = 0;
    // read fresh values from file
    try {
      countFile = this.array.count(termHash);
    } catch (final Throwable e) {
      ConcurrentLog.logException(e);
    }
    assert countFile >= 0;

    // count from container in ram
    final ReferenceContainer<ReferenceType> countRam = this.ram.get(termHash, null);
    assert countRam == null || countRam.size() >= 0;
    int c = countRam == null ? countFile : countFile + countRam.size();
    // exclude entries from delayed remove
    synchronized (this.removeDelayedURLs) {
      final HandleSet s = this.removeDelayedURLs.get(termHash);
      if (s != null) c -= s.size();
      if (c < 0) c = 0;
    }
    // put count result into cache
    if (MemoryControl.shortStatus()) this.countCache.clear();
    this.countCache.insert(termHash, c);
    return c;
  }
Example #3
0
 /**
  * all containers in the BLOBs and the RAM are merged and returned. Please be aware that the
  * returned values may be top-level cloned ReferenceContainers or direct links to containers If
  * the containers are modified after they are returned, they MAY alter the stored index.
  *
  * @throws IOException
  * @return a container with merged ReferenceContainer from RAM and the file array or null if there
  *     is no data to be returned
  */
 @Override
 public ReferenceContainer<ReferenceType> get(final byte[] termHash, final HandleSet urlselection)
     throws IOException {
   final ReferenceContainer<ReferenceType> c0 = this.ram.get(termHash, null);
   ReferenceContainer<ReferenceType> c1 = null;
   try {
     c1 = this.array.get(termHash);
   } catch (final SpaceExceededException e2) {
     ConcurrentLog.logException(e2);
   }
   ReferenceContainer<ReferenceType> result = null;
   if (c0 != null && c1 != null) {
     try {
       result = c1.merge(c0);
     } catch (final SpaceExceededException e) {
       // try to free some ram
       try {
         result = c1.merge(c0);
       } catch (final SpaceExceededException e1) {
         // go silently over the problem
         result = (c1.size() > c0.size()) ? c1 : c0;
       }
     }
   } else if (c0 != null) {
     result = c0;
   } else if (c1 != null) {
     result = c1;
   }
   if (result == null) return null;
   // remove the failed urls
   synchronized (this.removeDelayedURLs) {
     final HandleSet s = this.removeDelayedURLs.get(termHash);
     if (s != null) result.removeEntries(s);
   }
   return result;
 }