Exemplo n.º 1
0
 /**
  * Returns the file name to use for the read-only version of the provided log file.
  *
  * <p>The file name is based on the lowest and highest key in the log file.
  *
  * @return the name to use for the read-only version of the log file
  * @throws ChangelogException If an error occurs.
  */
 private String generateReadOnlyFileName(final LogFile<K, V> logFile) throws ChangelogException {
   final K lowestKey = logFile.getOldestRecord().getKey();
   final K highestKey = logFile.getNewestRecord().getKey();
   return recordParser.encodeKeyToString(lowestKey)
       + LOG_FILE_NAME_SEPARATOR
       + recordParser.encodeKeyToString(highestKey)
       + LOG_FILE_SUFFIX;
 }
Exemplo n.º 2
0
 /**
  * Find the highest key that corresponds to a record that is the oldest (or first) of a read-only
  * log file and where value mapped from the record is lower or equals to provided limit value.
  *
  * <p>Example<br>
  * Given a log with 3 log files, with Record<Int, String> and Mapper<String, Long> mapping a
  * string to its long value
  *
  * <ul>
  *   <li>1_10.log where oldest record is (key=1, value="50")
  *   <li>11_20.log where oldest record is (key=11, value="150")
  *   <li>head.log where oldest record is (key=25, value="250")
  * </ul>
  *
  * Then
  *
  * <ul>
  *   <li>findBoundaryKeyFromRecord(mapper, 20) => null
  *   <li>findBoundaryKeyFromRecord(mapper, 50) => 1
  *   <li>findBoundaryKeyFromRecord(mapper, 100) => 1
  *   <li>findBoundaryKeyFromRecord(mapper, 150) => 11
  *   <li>findBoundaryKeyFromRecord(mapper, 200) => 11
  *   <li>findBoundaryKeyFromRecord(mapper, 250) => 25
  *   <li>findBoundaryKeyFromRecord(mapper, 300) => 25
  * </ul>
  *
  * @param <V2> Type of the value extracted from the record
  * @param mapper The mapper to extract a value from a record. It is expected that extracted values
  *     are ordered according to an order consistent with this log ordering, i.e. for two records,
  *     if key(R1) > key(R2) then extractedValue(R1) > extractedValue(R2).
  * @param limitValue The limit value to search for
  * @return the key or {@code null} if no key corresponds
  * @throws ChangelogException If a problem occurs
  */
 <V2 extends Comparable<V2>> K findBoundaryKeyFromRecord(
     Record.Mapper<V, V2> mapper, V2 limitValue) throws ChangelogException {
   sharedLock.lock();
   try {
     K key = null;
     for (LogFile<K, V> logFile : logFiles.values()) {
       final Record<K, V> record = logFile.getOldestRecord();
       final V2 oldestValue = mapper.map(record.getValue());
       if (oldestValue.compareTo(limitValue) > 0) {
         return key;
       }
       key = record.getKey();
     }
     return key;
   } finally {
     sharedLock.unlock();
   }
 }