예제 #1
0
 /**
  * Run an integrity check on the blockfile and all the skiplists in it
  *
  * @return true if the levels were modified.
  */
 public boolean bfck(boolean fix) {
   if (log.shouldLog(Log.INFO)) {
     log.info("magic bytes " + magicBytes);
     log.info("fileLen " + fileLen);
     log.info("freeListStart " + freeListStart);
     log.info("mounted " + mounted);
     log.info("spanSize " + spanSize);
     log.info("Metaindex");
     log.info("Checking meta index in blockfile " + file);
   }
   boolean rv = metaIndex.bslck(fix, true);
   if (rv) {
     if (log.shouldLog(Log.WARN)) log.warn("Repaired meta index in blockfile " + file);
   } else {
     if (log.shouldLog(Log.INFO)) log.info("No errors in meta index in blockfile " + file);
   }
   int items = 0;
   for (SkipIterator iter = metaIndex.iterator(); iter.hasNext(); ) {
     String slname = (String) iter.nextKey();
     Integer page = (Integer) iter.next();
     if (log.shouldLog(Log.INFO)) log.info("List " + slname + " page " + page);
     try {
       // This uses IdentityBytes, so the value class won't be right, but at least
       // it won't fail the out-of-order check
       Serializer keyser =
           slname.equals("%%__REVERSE__%%") ? new IntBytes() : new UTF8StringBytes();
       BSkipList bsl = getIndex(slname, keyser, new IdentityBytes());
       if (bsl == null) {
         log.error("Can't find list? " + slname);
         continue;
       }
       // The check is now done in getIndex(), no need to do here...
       // but we can't get the return value of the check here.
       items++;
     } catch (IOException ioe) {
       log.error("Error with list " + slname, ioe);
     }
   }
   log.info("Checked meta index and " + items + " skiplists");
   if (freeListStart != 0) {
     try {
       if (flb == null) flb = new FreeListBlock(file, freeListStart);
       flb.flbck(true);
     } catch (IOException ioe) {
       log.error("Free list error", ioe);
     }
   } else {
     if (log.shouldLog(Log.INFO)) log.info("No freelist");
   }
   return rv;
 }
예제 #2
0
  /** If the file is writable, this runs an integrity check and repair on first open. */
  public BSkipList getIndex(String name, Serializer key, Serializer val) throws IOException {
    // added I2P
    BSkipList bsl = (BSkipList) openIndices.get(name);
    if (bsl != null) return bsl;

    Integer page = (Integer) metaIndex.get(name);
    if (page == null) {
      return null;
    }
    bsl = new BSkipList(spanSize, this, page.intValue(), key, val, true);
    if (file.canWrite()) {
      log.info("Checking skiplist " + name + " in blockfile " + file);
      if (bsl.bslck(true, false))
        log.logAlways(Log.WARN, "Repaired skiplist " + name + " in blockfile " + file);
      else log.info("No errors in skiplist " + name + " in blockfile " + file);
    }
    openIndices.put(name, bsl);
    return bsl;
  }