@Override public FileCacheKey readObject(final ObjectInput input) throws IOException { String indexName = input.readUTF(); String fileName = input.readUTF(); return new FileCacheKey(indexName, fileName); }
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 FileCacheKey(final String indexName, final String fileName, final int affinitySegmentId) { if (fileName == null) throw new IllegalArgumentException("filename must not be null"); this.indexName = indexName; this.fileName = fileName; this.affinitySegmentId = affinitySegmentId; this.hashCode = generatedHashCode(); }
@Test public void testFileCacheKeyCompWithNull() { AssertJUnit.assertFalse("The Instance of FileCacheKey should not be equal to null.", new FileCacheKey("poems and songs, 3000AC-2000DC", "fileName.txt", -1).equals(null)); } }
/** * 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; }
private void setBufferToCurrentChunk() throws IOException { ChunkCacheKey key = new ChunkCacheKey(fileKey.getIndexName(), filename, currentLoadedChunk, chunkSize, affinitySegmentId); buffer = (byte[]) chunksCache.get(key); if (buffer == null) { throw new IOException("Read past EOF: Chunk value could not be found for key " + key); } currentBufferSize = buffer.length; }
private void assertFileAfterDeletion(Cache cache) { FileListCacheValue fileList = (FileListCacheValue) cache.get(new FileListCacheKey(INDEX_NAME, -1)); AssertJUnit.assertNotNull(fileList); AssertJUnit.assertFalse(fileList.contains(filename)); FileMetadata metadata = (FileMetadata) cache.get(new FileCacheKey(INDEX_NAME, filename, -1)); AssertJUnit.assertNotNull(metadata); long totalFileSize = metadata.getSize(); int chunkNumbers = (int)(totalFileSize / CHUNK_SIZE); for(int i = 0; i < chunkNumbers; i++) { AssertJUnit.assertNotNull(cache.get(new ChunkCacheKey(INDEX_NAME, filename, i, CHUNK_SIZE, -1))); } boolean fileNameExistsInCache = false; for(Object key : cache.keySet()) { if(key instanceof FileCacheKey) { FileCacheKey keyObj = (FileCacheKey) key; if(keyObj.getFileName().contains(filename)) { fileNameExistsInCache = true; } } } AssertJUnit.assertTrue(fileNameExistsInCache); }
/** * ContainsKey implementation for chunk elements */ protected Boolean containsKeyIntern(final FileCacheKey fileCacheKey) throws IOException { return Boolean.valueOf(directory.fileExists(fileCacheKey.getFileName())); }
private void setBufferToCurrentChunk() throws IOException { ChunkCacheKey key = new ChunkCacheKey(fileKey.getIndexName(), filename, currentLoadedChunk, chunkSize); buffer = (byte[]) chunksCache.get(key); if (buffer == null) { throw new IOException("Read past EOF: Chunk value could not be found for key " + key); } currentBufferSize = buffer.length; }
public void testLoadEntries() throws Exception { TestHelper.createIndex(rootDir, indexName, elementCount, true); String[] fileNamesFromIndexDir = TestHelper.getFileNamesFromDir(rootDir, indexName); LuceneCacheLoader cacheLoader = (LuceneCacheLoader) TestingUtil.getFirstLoader(cacheManager.getCache()); Set<InternalCacheEntry> loadedEntrySet = PersistenceUtil.toEntrySet(cacheLoader, null, cache.getAdvancedCache().getComponentRegistry().getComponent(InternalEntryFactory.class)); for (String fileName : fileNamesFromIndexDir) { FileCacheKey key = new FileCacheKey(indexName, fileName, segmentId); AssertJUnit.assertNotNull(cacheLoader.load(key)); boolean found = false; for (InternalCacheEntry entry : loadedEntrySet) { FileCacheKey keyFromLoad = null; if (entry.getKey() instanceof FileCacheKey) { keyFromLoad = (FileCacheKey) entry.getKey(); if (keyFromLoad != null && keyFromLoad.equals(key)) { found = true; break; } } } assert found : "No corresponding entry found for " + key; } }
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()); } }
@Override public FileCacheKey readObject(final ObjectInput input) throws IOException { String indexName = input.readUTF(); String fileName = input.readUTF(); int affinitySegmentId = UnsignedNumeric.readUnsignedInt(input); return new FileCacheKey(indexName, fileName, affinitySegmentId); }
/** * 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; }
private void setBufferToCurrentChunk() throws IOException { ChunkCacheKey key = new ChunkCacheKey(fileKey.getIndexName(), filename, currentLoadedChunk, chunkSize, affinitySegmentId); buffer = (byte[]) chunksCache.get(key); if (buffer == null) { throw new IOException("Read past EOF: Chunk value could not be found for key " + key); } currentBufferSize = buffer.length; }
public FileCacheKey(final String indexName, final String fileName) { if (fileName == null) throw new IllegalArgumentException("filename must not be null"); this.indexName = indexName; this.fileName = fileName; this.hashCode = generatedHashCode(); }
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; }
/** * @param fileName * @return the FileMetadata associated with the fileName, or null if the file wasn't found. */ public FileMetadata getFileMetadata(final String fileName) { FileCacheKey key = new FileCacheKey(indexName, fileName, affinitySegmentId); FileMetadata metadata = (FileMetadata) cache.get(key); return metadata; }
/** * 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; }
@Override public void close() { currentBufferSize = 0; bufferPosition = 0; currentLoadedChunk = -1; buffer = null; if (isClone) return; readLocks.deleteOrReleaseReadLock(filename); if (trace) { log.tracef("Closed IndexInput for file:%s in index: %s", filename, fileKey.getIndexName()); } }
public FileCacheKey(final String indexName, final String fileName, final int affinitySegmentId) { if (fileName == null) throw new IllegalArgumentException("filename must not be null"); this.indexName = indexName; this.fileName = fileName; this.affinitySegmentId = affinitySegmentId; this.hashCode = generatedHashCode(); }