public long getMaxWrotePosition() { MappedFile mappedFile = getLastMappedFile(); if (mappedFile != null) { return mappedFile.getFileFromOffset() + mappedFile.getWrotePosition(); } return 0; }
public long getLastOffset() { long lastOffset = -1; int logicFileSize = this.mappedFileSize; MappedFile mappedFile = this.mappedFileQueue.getLastMappedFile(); if (mappedFile != null) { int position = mappedFile.getWrotePosition() - CQ_STORE_UNIT_SIZE; if (position < 0) position = 0; ByteBuffer byteBuffer = mappedFile.sliceByteBuffer(); byteBuffer.position(position); for (int i = 0; i < logicFileSize; i += CQ_STORE_UNIT_SIZE) { long offset = byteBuffer.getLong(); int size = byteBuffer.getInt(); byteBuffer.getLong(); if (offset >= 0 && size > 0) { lastOffset = offset + size; } else { break; } } } return lastOffset; }
public long howMuchFallBehind() { if (this.mappedFiles.isEmpty()) return 0; long committed = this.flushedWhere; if (committed != 0) { MappedFile mappedFile = this.getLastMappedFile(0, false); if (mappedFile != null) { return (mappedFile.getFileFromOffset() + mappedFile.getWrotePosition()) - committed; } } return 0; }
/** * Max address(value is less than 0). * <p/> * <p> * Be careful: it's an address just when invoking this method. * </p> */ public long getMaxAddress() { MappedFile mappedFile = this.mappedFileQueue.getLastMappedFile(); if (mappedFile == null) { return decorate(0); } return decorate(mappedFile.getFileFromOffset() + mappedFile.getWrotePosition()); }
if (mappedFile != null) { if (mappedFile.isFirstCreateInQueue() && cqOffset != 0 && mappedFile.getWrotePosition() == 0) { this.minLogicOffset = expectLogicOffset; this.mappedFileQueue.setFlushedWhere(expectLogicOffset); this.fillPreBlank(mappedFile, expectLogicOffset); log.info("fill pre blank space " + mappedFile.getFileName() + " " + expectLogicOffset + " " + mappedFile.getWrotePosition()); long currentLogicOffset = mappedFile.getWrotePosition() + mappedFile.getFileFromOffset();
public boolean resetOffset(long offset) { MappedFile mappedFileLast = getLastMappedFile(); if (mappedFileLast != null) { long lastOffset = mappedFileLast.getFileFromOffset() + mappedFileLast.getWrotePosition(); long diff = lastOffset - offset; final int maxDiff = this.mappedFileSize * 2; if (diff > maxDiff) return false; } ListIterator<MappedFile> iterator = this.mappedFiles.listIterator(); while (iterator.hasPrevious()) { mappedFileLast = iterator.previous(); if (offset >= mappedFileLast.getFileFromOffset()) { int where = (int) (offset % mappedFileLast.getFileSize()); mappedFileLast.setFlushedPosition(where); mappedFileLast.setWrotePosition(where); mappedFileLast.setCommittedPosition(where); break; } else { iterator.remove(); } } return true; }
public boolean destroy(final long intervalForcibly) { this.shutdown(intervalForcibly); if (this.isCleanupOver()) { try { this.fileChannel.close(); log.info("close file channel " + this.fileName + " OK"); long beginTime = System.currentTimeMillis(); boolean result = this.file.delete(); log.info("delete file[REF:" + this.getRefCount() + "] " + this.fileName + (result ? " OK, " : " Failed, ") + "W:" + this.getWrotePosition() + " M:" + this.getFlushedPosition() + ", " + UtilAll.computeEclipseTimeMilliseconds(beginTime)); } catch (Exception e) { log.warn("close file channel " + this.fileName + " Failed. ", e); } return true; } else { log.warn("destroy mapped file[REF:" + this.getRefCount() + "] " + this.fileName + " Failed. cleanupOver: " + this.cleanupOver); } return false; }
continue; final int wrotePosition = mappedFile.getWrotePosition(); final int blankSize = this.mappedFileSize - wrotePosition - END_BLANK_DATA_LENGTH;
public long getMaxWrotePosition() { MappedFile mappedFile = getLastMappedFile(); if (mappedFile != null) { return mappedFile.getFileFromOffset() + mappedFile.getWrotePosition(); } return 0; }
public long getLastOffset() { long lastOffset = -1; int logicFileSize = this.mappedFileSize; MappedFile mappedFile = this.mappedFileQueue.getLastMappedFile(); if (mappedFile != null) { int position = mappedFile.getWrotePosition() - CQ_STORE_UNIT_SIZE; if (position < 0) position = 0; ByteBuffer byteBuffer = mappedFile.sliceByteBuffer(); byteBuffer.position(position); for (int i = 0; i < logicFileSize; i += CQ_STORE_UNIT_SIZE) { long offset = byteBuffer.getLong(); int size = byteBuffer.getInt(); byteBuffer.getLong(); if (offset >= 0 && size > 0) { lastOffset = offset + size; } else { break; } } } return lastOffset; }
public long howMuchFallBehind() { if (this.mappedFiles.isEmpty()) return 0; long committed = this.flushedWhere; if (committed != 0) { MappedFile mappedFile = this.getLastMappedFile(0, false); if (mappedFile != null) { return (mappedFile.getFileFromOffset() + mappedFile.getWrotePosition()) - committed; } } return 0; }
public boolean destroy(final long intervalForcibly) { this.shutdown(intervalForcibly); if (this.isCleanupOver()) { try { this.fileChannel.close(); log.info("close file channel " + this.fileName + " OK"); long beginTime = System.currentTimeMillis(); boolean result = this.file.delete(); log.info("delete file[REF:" + this.getRefCount() + "] " + this.fileName + (result ? " OK, " : " Failed, ") + "W:" + this.getWrotePosition() + " M:" + this.getFlushedPosition() + ", " + UtilAll.computeEclipseTimeMilliseconds(beginTime)); } catch (Exception e) { log.warn("close file channel " + this.fileName + " Failed. ", e); } return true; } else { log.warn("destroy mapped file[REF:" + this.getRefCount() + "] " + this.fileName + " Failed. cleanupOver: " + this.cleanupOver); } return false; }
if (mappedFile != null) { if (mappedFile.isFirstCreateInQueue() && cqOffset != 0 && mappedFile.getWrotePosition() == 0) { this.minLogicOffset = expectLogicOffset; this.mappedFileQueue.setFlushedWhere(expectLogicOffset); this.fillPreBlank(mappedFile, expectLogicOffset); log.info("fill pre blank space " + mappedFile.getFileName() + " " + expectLogicOffset + " " + mappedFile.getWrotePosition()); long currentLogicOffset = mappedFile.getWrotePosition() + mappedFile.getFileFromOffset();
/** * Max address(value is less than 0). * <p/> * <p> * Be careful: it's an address just when invoking this method. * </p> */ public long getMaxAddress() { MappedFile mappedFile = this.mappedFileQueue.getLastMappedFile(); if (mappedFile == null) { return decorate(0); } return decorate(mappedFile.getFileFromOffset() + mappedFile.getWrotePosition()); }
public boolean resetOffset(long offset) { MappedFile mappedFileLast = getLastMappedFile(); if (mappedFileLast != null) { long lastOffset = mappedFileLast.getFileFromOffset() + mappedFileLast.getWrotePosition(); long diff = lastOffset - offset; final int maxDiff = this.mappedFileSize * 2; if (diff > maxDiff) return false; } ListIterator<MappedFile> iterator = this.mappedFiles.listIterator(); while (iterator.hasPrevious()) { mappedFileLast = iterator.previous(); if (offset >= mappedFileLast.getFileFromOffset()) { int where = (int) (offset % mappedFileLast.getFileSize()); mappedFileLast.setFlushedPosition(where); mappedFileLast.setWrotePosition(where); mappedFileLast.setCommittedPosition(where); break; } else { iterator.remove(); } } return true; }
continue; final int wrotePosition = mappedFile.getWrotePosition(); final int blankSize = this.mappedFileSize - wrotePosition - END_BLANK_DATA_LENGTH;
log.info("topic:{}, queue:{}, queue offset after truncate:{}, origin:{}", topic, queueId, getMaxOffsetInQueue(), queueOffsetOrigin); mappedFile.truncateDirty(mappedFile.getWrotePosition()); return;
public long getMaxWrotePosition() { MappedFile mappedFile = getLastMappedFile(); if (mappedFile != null) { return mappedFile.getFileFromOffset() + mappedFile.getWrotePosition(); } return 0; }
public long howMuchFallBehind() { if (this.mappedFiles.isEmpty()) return 0; long committed = this.flushedWhere; if (committed != 0) { MappedFile mappedFile = this.getLastMappedFile(0, false); if (mappedFile != null) { return (mappedFile.getFileFromOffset() + mappedFile.getWrotePosition()) - committed; } } return 0; }
/** * Max address(value is less than 0). * <p/> * <p> * Be careful: it's an address just when invoking this method. * </p> */ public long getMaxAddress() { MappedFile mappedFile = this.mappedFileQueue.getLastMappedFile(); if (mappedFile == null) { return decorate(0); } return decorate(mappedFile.getFileFromOffset() + mappedFile.getWrotePosition()); }