public void garbageCollect(final long address) { int segmentNum = getSegmentNum(address)-1; final List<File> filesToDelete = Lists.newArrayList(); while (segmentNum >= 0) { final File f = getSegmentPath(dir, segmentNum); segmentNum--; if (f.exists()) { filesToDelete.add(f); } else { break; } } for (int i = filesToDelete.size()-1; i >= 0; i--) { filesToDelete.get(i).delete(); } }
public RecordLogDirectory<E> build() { return new RecordLogDirectory(dir, serializer, maxCachedFiles, codec, blockSize, fileIndexBits, recordIndexBits, padBits, mlockFiles); } }
private void checkpointPosition(final long lastPosition) throws IOException { checkpointer.setCheckpoint(lastPosition); if (gc) recordLogDirectory.garbageCollect(lastPosition); }
final int segmentNum = recordLogDirectory.getSegmentNum(address); try { final Option<RecordFile.Reader<Operation>> option = recordLogDirectory.getFileReader(segmentNum); for (RecordFile.Reader<Operation> reader : option) { try { continue; final int currentSegment = recordLogDirectory.getSegmentNum(currentAddress); if (currentSegment == segmentNum) { index.put(key, position);
/** * @param segment segment number * @return a file pointing at the segment */ public File getSegmentPath(int segment) { return RecordLogDirectory.getSegmentPath(file, segment); }
public int getMaxSegmentNum() throws IOException { return getMaxSegmentNum(dir); }
@Export(name = "current-segment-num", doc = "The current segment that the poller is reading") public int getCurrentSegmentNum() { return recordLogDirectory.getSegmentNum(getLastPosition()); }
@Export(name = "current-segment-timestamp", doc = "Timestamp of the current segment being read") public long getCurrentSegmentTimestamp() throws IOException { return recordLogDirectory.getSegmentTimestamp(getCurrentSegmentNum()); }
public static int getMinSegmentNum(File path) throws IOException { int minSegmentNum = Integer.MAX_VALUE; int minDir = Integer.MAX_VALUE; if (path.exists()) { for (File f : path.listFiles()) { final String name = f.getName(); if (name.matches("\\d+") && f.isDirectory() && f.list().length > 0) { final int dirNum = Integer.parseInt(name); if (dirNum < minDir) minDir = dirNum; } else if (name.matches("\\d+\\.rec")) { final int segmentNum = Integer.parseInt(name.substring(0, name.length()-4)); if (segmentNum < minSegmentNum) minSegmentNum = segmentNum; } } if (minSegmentNum < Integer.MAX_VALUE) return minSegmentNum; if (minDir < Integer.MAX_VALUE) return getMinSegmentNum(new File(path, String.format("%03d", minDir))); } return -1; }
final RecordFile.Reader<T> poller; try { poller = recordLogDirectory.reader(lastPosition); } catch (Exception e) { log.error("error seeking to last valid position", e);
private Put<K, V> lookupAddress(@Nullable final CacheStats cacheStats, final Long position) throws IOException { final long start1 = System.nanoTime(); final Operation op = recordLogDirectory.get(position); if (cacheStats != null) cacheStats.recordLogTime+=System.nanoTime()-start1; if (op.getClass() != Put.class) throw new IOException("class is not Put"); final Put<K,V> put = (Put) op; put.getValue(); return put; }
/** * @param segment segment number * @return a file pointing at the segment */ public File getSegmentPath(int segment) { return RecordLogDirectory.getSegmentPath(file, segment); }
public int getMaxSegmentNum() throws IOException { return getMaxSegmentNum(dir); }
@Export(name = "current-segment-num", doc = "The current segment that the poller is reading") public int getCurrentSegmentNum() { return recordLogDirectory.getSegmentNum(getLastPosition()); }
@Export(name = "max-segment-timestamp", doc = "Timestamp of the max segment that exists in directory") public long getMaxSegmentTimestamp() throws IOException { return recordLogDirectory.getSegmentTimestamp(getMaxSegmentNum()); }
public static int getMinSegmentNum(File path) throws IOException { int minSegmentNum = Integer.MAX_VALUE; int minDir = Integer.MAX_VALUE; if (path.exists()) { for (File f : path.listFiles()) { final String name = f.getName(); if (name.matches("\\d+") && f.isDirectory() && f.list().length > 0) { final int dirNum = Integer.parseInt(name); if (dirNum < minDir) minDir = dirNum; } else if (name.matches("\\d+\\.rec")) { final int segmentNum = Integer.parseInt(name.substring(0, name.length()-4)); if (segmentNum < minSegmentNum) minSegmentNum = segmentNum; } } if (minSegmentNum < Integer.MAX_VALUE) return minSegmentNum; if (minDir < Integer.MAX_VALUE) return getMinSegmentNum(new File(path, String.format("%03d", minDir))); } return -1; }
final RecordFile.Reader<T> poller; try { poller = recordLogDirectory.reader(lastPosition); } catch (Exception e) { log.error("error seeking to last valid position", e);
public void garbageCollect(final long address) { int segmentNum = getSegmentNum(address)-1; final List<File> filesToDelete = Lists.newArrayList(); while (segmentNum >= 0) { final File f = getSegmentPath(dir, segmentNum); segmentNum--; if (f.exists()) { filesToDelete.add(f); } else { break; } } for (int i = filesToDelete.size()-1; i >= 0; i--) { filesToDelete.get(i).delete(); } }
public static File getSegmentPath(File root, int segment) { return getSegmentPath(root, segment, false); }
@Export(name = "max-segment-num", doc = "The max segment number that exists in directory") public int getMaxSegmentNum() throws IOException { return recordLogDirectory.getMaxSegmentNum(); }