public MappedFile getLastMappedFile(final long startOffset) { return getLastMappedFile(startOffset, true); }
public long getMaxWrotePosition() { MappedFile mappedFile = getLastMappedFile(); if (mappedFile != null) { return mappedFile.getFileFromOffset() + mappedFile.getWrotePosition(); } return 0; }
public long getMaxOffset() { MappedFile mappedFile = getLastMappedFile(); if (mappedFile != null) { return mappedFile.getFileFromOffset() + mappedFile.getReadPosition(); } 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 void deleteLastMappedFile() { MappedFile lastMappedFile = getLastMappedFile(); if (lastMappedFile != null) { lastMappedFile.destroy(1000); this.mappedFiles.remove(lastMappedFile); log.info("on recover, destroy a logic mapped file " + lastMappedFile.getFileName()); } }
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 appendData(long startOffset, byte[] data) { putMessageLock.lock(); try { MappedFile mappedFile = this.mappedFileQueue.getLastMappedFile(startOffset); if (null == mappedFile) { log.error("appendData getLastMappedFile error " + startOffset); return false; } return mappedFile.appendMessage(data); } finally { putMessageLock.unlock(); } }
/** * 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; }
MappedFile mappedFile = this.mappedFileQueue.getLastMappedFile(expectLogicOffset); if (mappedFile != null) {
MappedFile mappedFile = this.mappedFileQueue.getLastMappedFile(); mappedFile = this.mappedFileQueue.getLastMappedFile(0);
public MappedFile getLastMappedFile(final long startOffset, boolean needCreate) { long createOffset = -1; MappedFile mappedFileLast = getLastMappedFile();
long maxExtAddr = 1; while (true) { MappedFile mappedFile = this.mappedFileQueue.getLastMappedFile(); if (mappedFile != null) { ByteBuffer byteBuffer = mappedFile.sliceByteBuffer();
try { MappedFile firstMappedFile = this.getFirstMappedFile(); MappedFile lastMappedFile = this.getLastMappedFile(); if (firstMappedFile != null && lastMappedFile != null) { if (offset < firstMappedFile.getFileFromOffset() || offset >= lastMappedFile.getFileFromOffset() + this.mappedFileSize) {
MappedFile mappedFile = this.mappedFileQueue.getLastMappedFile(); mappedFile = this.mappedFileQueue.getLastMappedFile(0); // Mark: NewFile may be cause noise unlockMappedFile = mappedFile; mappedFile = this.mappedFileQueue.getLastMappedFile(0); if (null == mappedFile) {
MappedFile mappedFile = this.mappedFileQueue.getLastMappedFile(); mappedFile = this.mappedFileQueue.getLastMappedFile(0); // Mark: NewFile may be cause noise unlockMappedFile = mappedFile; mappedFile = this.mappedFileQueue.getLastMappedFile(0); if (null == mappedFile) {
public void deleteLastMappedFile() { MappedFile lastMappedFile = getLastMappedFile(); if (lastMappedFile != null) { lastMappedFile.destroy(1000); this.mappedFiles.remove(lastMappedFile); log.info("on recover, destroy a logic mapped file " + lastMappedFile.getFileName()); } }
public long getMaxWrotePosition() { MappedFile mappedFile = getLastMappedFile(); if (mappedFile != null) { return mappedFile.getFileFromOffset() + mappedFile.getWrotePosition(); } return 0; }
public long getMaxOffset() { MappedFile mappedFile = getLastMappedFile(); if (mappedFile != null) { return mappedFile.getFileFromOffset() + mappedFile.getReadPosition(); } 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; }