/** * ContainsKey implementation for chunk elements */ protected Boolean containsKeyIntern(final FileCacheKey fileCacheKey) throws IOException { for(String file: directory.listAll()) { if(file.equals(fileCacheKey.getFileName())) { return true; } } return false; }
/** * ContainsKey implementation for chunk elements */ protected Boolean containsKeyIntern(final FileCacheKey fileCacheKey) throws IOException { for(String file: directory.listAll()) { if(file.equals(fileCacheKey.getFileName())) { return true; } } return false; }
/** * ContainsKey implementation for chunk elements */ protected Boolean containsKeyIntern(final FileCacheKey fileCacheKey) throws IOException { return Boolean.valueOf(directory.fileExists(fileCacheKey.getFileName())); }
public SingleChunkIndexInput(final IndexInputContext iic) { super(iic.fileKey.getFileName()); ChunkCacheKey key = new ChunkCacheKey(iic.fileKey.getIndexName(), iic.fileKey.getFileName(), 0, iic.fileMetadata.getBufferSize(), iic.affinitySegmentId); byte[] b = (byte[]) iic.chunksCache.get(key); if (b == null) { buffer = Util.EMPTY_BYTE_ARRAY; } else { buffer = b; } bufferPosition = 0; }
public SingleChunkIndexInput(final IndexInputContext iic) { super(iic.fileKey.getFileName()); ChunkCacheKey key = new ChunkCacheKey(iic.fileKey.getIndexName(), iic.fileKey.getFileName(), 0, iic.fileMetadata.getBufferSize()); byte[] b = (byte[]) iic.chunksCache.get(key); if (b == null) { buffer = new byte[0]; } else { buffer = b; } bufferPosition = 0; }
public SingleChunkIndexInput(final IndexInputContext iic) { super(iic.fileKey.getFileName()); ChunkCacheKey key = new ChunkCacheKey(iic.fileKey.getIndexName(), iic.fileKey.getFileName(), 0, iic.fileMetadata.getBufferSize(), iic.affinitySegmentId); byte[] b = (byte[]) iic.chunksCache.get(key); if (b == null) { buffer = new byte[0]; } else { buffer = b; } bufferPosition = 0; }
public InfinispanIndexInput(final IndexInputContext ctx) { super(ctx.fileKey.getFileName()); this.chunksCache = ctx.chunksCache; this.fileKey = ctx.fileKey; this.chunkSize = ctx.fileMetadata.getBufferSize(); this.fileLength = ctx.fileMetadata.getSize(); this.readLocks = ctx.readLocks; this.affinitySegmentId = ctx.affinitySegmentId; this.filename = fileKey.getFileName(); if (trace) { log.tracef("Opened new IndexInput for file:%s in index: %s", filename, fileKey.getIndexName()); } }
public InfinispanIndexInput(final IndexInputContext ctx) { super(ctx.fileKey.getFileName()); this.chunksCache = ctx.chunksCache; this.fileKey = ctx.fileKey; this.chunkSize = ctx.fileMetadata.getBufferSize(); this.fileLength = ctx.fileMetadata.getSize(); this.readLocks = ctx.readLocks; this.filename = fileKey.getFileName(); if (trace) { log.tracef("Opened new IndexInput for file:%s in index: %s", filename, fileKey.getIndexName()); } }
public InfinispanIndexInput(final IndexInputContext ctx) { super(ctx.fileKey.getFileName()); this.chunksCache = ctx.chunksCache; this.fileKey = ctx.fileKey; this.chunkSize = ctx.fileMetadata.getBufferSize(); this.fileLength = ctx.fileMetadata.getSize(); this.readLocks = ctx.readLocks; this.affinitySegmentId = ctx.affinitySegmentId; this.filename = fileKey.getFileName(); if (trace) { log.tracef("Opened new IndexInput for file:%s in index: %s", filename, fileKey.getIndexName()); } }
/** * Load implementation for FileCacheKey: must return the metadata of the * requested file. */ private FileMetadata loadIntern(final FileCacheKey key) throws IOException { final String fileName = key.getFileName(); final long fileLength = directory.fileLength(fileName); // We're forcing the buffer size of a to-be-read segment to the full file size: final int bufferSize = (int) Math.min(fileLength, (long)autoChunkSize); final FileMetadata meta = new FileMetadata(bufferSize); meta.setSize(fileLength); return meta; }
/** * Load implementation for FileCacheKey: must return the metadata of the * requested file. */ private FileMetadata loadIntern(final FileCacheKey key) throws IOException { final String fileName = key.getFileName(); final long fileLength = directory.fileLength(fileName); // We're forcing the buffer size of a to-be-read segment to the full file size: final int bufferSize = (int) Math.min(fileLength, (long)autoChunkSize); final FileMetadata meta = new FileMetadata(bufferSize); meta.setSize(fileLength); return meta; }
private byte[] getChunkById(FileCacheKey fileKey, int chunkNumber, int bufferSize) { if (file.getNumberOfChunks() <= chunkNumber) { return new byte[bufferSize]; } ChunkCacheKey key = new ChunkCacheKey(fileKey.getIndexName(), fileKey.getFileName(), chunkNumber, bufferSize, affinitySegmentId); byte[] readBuffer = (byte[]) chunksCache.get(key); if (readBuffer==null) { return new byte[bufferSize]; } else if (readBuffer.length == bufferSize) { return readBuffer; } else { byte[] newBuffer = new byte[bufferSize]; System.arraycopy(readBuffer, 0, newBuffer, 0, readBuffer.length); return newBuffer; } }
/** * @param bufferToFlush * @param chunkNumber */ private void storeBufferAsChunk(final byte[] bufferToFlush, final int chunkNumber) { ChunkCacheKey key = new ChunkCacheKey(fileKey.getIndexName(), fileKey.getFileName(), chunkNumber, bufferSize, affinitySegmentId); if (trace) log.tracef("Storing segment chunk: %s", key); chunksCacheForStorage.put(key, bufferToFlush); }
/** * @param bufferToFlush * @param chunkNumber */ private void storeBufferAsChunk(final byte[] bufferToFlush, final int chunkNumber) { ChunkCacheKey key = new ChunkCacheKey(fileKey.getIndexName(), fileKey.getFileName(), chunkNumber, bufferSize, affinitySegmentId); if (trace) log.tracef("Storing segment chunk: %s", key); chunksCacheForStorage.put(key, bufferToFlush); }
/** * @param bufferToFlush * @param chunkNumber */ private void storeBufferAsChunk(final byte[] bufferToFlush, final int chunkNumber) { ChunkCacheKey key = new ChunkCacheKey(fileKey.getIndexName(), fileKey.getFileName(), chunkNumber, bufferSize); if (trace) log.tracef("Storing segment chunk: %s", key); chunksCacheForStorage.put(key, bufferToFlush); }
/** * Load implementation for FileCacheKey: must return the metadata of the * requested file. */ private FileMetadata loadIntern(final FileCacheKey key) throws IOException { final String fileName = key.getFileName(); final long fileModified = directory.fileModified(fileName); final long fileLength = directory.fileLength(fileName); // We're forcing the buffer size of a to-be-read segment to the full file size: final int bufferSize = (int) Math.min(fileLength, (long)autoChunkSize); final FileMetadata meta = new FileMetadata(bufferSize); meta.setLastModified(fileModified); meta.setSize(fileLength); return meta; }
public InfinispanIndexOutput(final AdvancedCache<FileCacheKey, FileMetadata> metadataCache, final AdvancedCache<ChunkCacheKey, Object> chunksCache, final FileCacheKey fileKey, final int bufferSize, final FileListOperations fileList,final int affinitySegmentId) { super("InfinispanIndexOutput{metadataCache=" + metadataCache + ", chunksCache=" + chunksCache + ", fileKey=" + fileKey + ", bufferSize=" + bufferSize + '}'); this.metadataCache = metadataCache; this.chunksCache = chunksCache; this.affinitySegmentId = affinitySegmentId; this.chunksCacheForStorage = chunksCache.withFlags(Flag.IGNORE_RETURN_VALUES); this.fileKey = fileKey; this.bufferSize = bufferSize; this.fileOps = fileList; this.buffer = new byte[this.bufferSize]; this.firstChunkBuffer = buffer; this.file = new FileMetadata(bufferSize); if (trace) { log.tracef("Opened new IndexOutput for file:%s in index: %s", fileKey.getFileName(), fileKey.getIndexName()); } }
public InfinispanIndexOutput(final AdvancedCache<FileCacheKey, FileMetadata> metadataCache, final AdvancedCache<ChunkCacheKey, Object> chunksCache, final FileCacheKey fileKey, final int bufferSize, final FileListOperations fileList) { this.metadataCache = metadataCache; this.chunksCache = chunksCache; this.chunksCacheForStorage = chunksCache.withFlags(Flag.IGNORE_RETURN_VALUES); this.fileKey = fileKey; this.bufferSize = bufferSize; this.fileOps = fileList; this.buffer = new byte[this.bufferSize]; this.firstChunkBuffer = buffer; this.file = new FileMetadata(bufferSize); if (trace) { log.tracef("Opened new IndexOutput for file:%s in index: %s", fileKey.getFileName(), fileKey.getIndexName()); } }
public InfinispanIndexOutput(final AdvancedCache<FileCacheKey, FileMetadata> metadataCache, final AdvancedCache<ChunkCacheKey, Object> chunksCache, final FileCacheKey fileKey, final int bufferSize, final FileListOperations fileList,final int affinitySegmentId) { super("InfinispanIndexOutput{metadataCache=" + metadataCache + ", chunksCache=" + chunksCache + ", fileKey=" + fileKey + ", bufferSize=" + bufferSize + '}'); this.metadataCache = metadataCache; this.chunksCache = chunksCache; this.affinitySegmentId = affinitySegmentId; this.chunksCacheForStorage = chunksCache.withFlags(Flag.IGNORE_RETURN_VALUES); this.fileKey = fileKey; this.bufferSize = bufferSize; this.fileOps = fileList; this.buffer = new byte[this.bufferSize]; this.firstChunkBuffer = buffer; this.file = new FileMetadata(bufferSize); if (trace) { log.tracef("Opened new IndexOutput for file:%s in index: %s", fileKey.getFileName(), fileKey.getIndexName()); } }
@Override public void seek(final long pos) throws IOException { final int requestedChunkNumber = getChunkNumberFromPosition(pos, bufferSize); if (pos > file.getSize()) { resizeFileIfNeeded(); if (pos > file.getSize()) // check again, might be fixed by the resize throw new IOException(fileKey.getFileName() + ": seeking past end of file"); } if (requestedChunkNumber != currentChunkNumber) { storeCurrentBuffer(false); if (requestedChunkNumber != 0) { buffer = getChunkById(fileKey, requestedChunkNumber, bufferSize); } else { buffer = firstChunkBuffer; } currentChunkNumber = requestedChunkNumber; } positionInBuffer = getPositionInBuffer(pos, bufferSize); filePosition = pos; }