Example #1
0
 /**
  * Returns the time when the index segment with the given <code>indexName</code> was in use for
  * the last time. The returned time does not accurately say until when an index segment was in
  * use, but it does guarantee that the index segment in question was not in use anymore at the
  * returned time.
  *
  * <p>There are two special cases of return values:
  *
  * <ul>
  *   <li>{@link Long#MAX_VALUE}: indicates that the index segment is still in active use.
  *   <li>{@link Long#MIN_VALUE}: indicates that there is no index segment with the given name.
  * </ul>
  *
  * @param indexName name of an index segment.
  * @return the time when the index segment with the given name was in use the last time.
  */
 long getLastUseOf(String indexName) {
   Long previous = null;
   for (Map.Entry<Long, IndexInfos> entry : indexInfosMap.entrySet()) {
     IndexInfos infos = entry.getValue();
     if (infos.contains(indexName)) {
       if (previous == null) {
         // still in use
         return Long.MAX_VALUE;
       } else {
         return previous;
       }
     }
     previous = infos.getLastModified();
   }
   return Long.MIN_VALUE;
 }
Example #2
0
 /**
  * Adds an index infos to the history. This method will not modify nor keep a reference to the
  * passed <code>infos</code>.
  *
  * @param infos the index infos to add.
  */
 void addIndexInfos(IndexInfos infos) {
   // must clone infos because it is modifiable
   indexInfosMap.put(infos.getGeneration(), infos.clone());
 }
Example #3
0
 /** Removes index infos older than {@link #maxAge} from this history. */
 void pruneOutdated() {
   long threshold = System.currentTimeMillis() - maxAge;
   log.debug("Pruning index infos older than: " + threshold + "(" + indexDir + ")");
   Iterator<IndexInfos> it = indexInfosMap.values().iterator();
   // never prune the current generation
   if (it.hasNext()) {
     IndexInfos infos = it.next();
     log.debug("Skipping first index infos. generation=" + infos.getGeneration());
   }
   while (it.hasNext()) {
     IndexInfos infos = (IndexInfos) it.next();
     if (infos.getLastModified() < threshold) {
       // check associated redo log
       try {
         String logName = getRedoLogName(infos.getGeneration());
         if (indexDir.fileExists(logName)) {
           long lastModified = indexDir.fileModified(logName);
           if (lastModified > threshold) {
             log.debug(
                 "Keeping redo log with generation={}, timestamp={}",
                 infos.getGeneration(),
                 lastModified);
             continue;
           }
           // try do delete it
           try {
             indexDir.deleteFile(logName);
             log.debug(
                 "Deleted redo log with generation={}, timestamp={}",
                 infos.getGeneration(),
                 lastModified);
           } catch (IOException e) {
             log.warn("Unable to delete: " + indexDir + "/" + logName);
             continue;
           }
         }
         // delete index infos
         try {
           indexDir.deleteFile(infos.getFileName());
           log.debug("Deleted index infos with generation={}", infos.getGeneration());
           it.remove();
         } catch (IOException e) {
           log.warn("Unable to delete: " + indexDir + "/" + infos.getFileName());
         }
       } catch (IOException e) {
         log.warn("Failed to check if {} is outdated: {}", infos.getFileName(), e);
       }
     }
   }
 }