/** * Guess in how many chunks we should split this file. Should return the same value consistently * for the same file (segments are immutable) so that a full segment can be rebuilt from the upper * layers without anyone actually specifying the chunks numbers. */ private int figureChunksNumber(String fileName) throws IOException { long fileLength = directory.fileLength(fileName); return figureChunksNumber(fileName, fileLength, autoChunkSize); }
@Override public Boolean visit(final ChunkCacheKey chunkCacheKey) throws IOException { return DirectoryLoaderAdaptor.this.containsKeyIntern(chunkCacheKey); }
/** * @param keysCollector the Set where to add loaded keys to * @param keysToExclude Could be null! * @throws org.infinispan.persistence.spi.PersistenceException */ protected void loadAllKeys(final HashSet<IndexScopedKey> keysCollector, final Set<IndexScopedKey> keysToExclude) { loadSomeKeys(keysCollector, keysToExclude, Integer.MAX_VALUE); }
public void testAutoChunkingOnLargeFiles() throws IOException { Directory mockDirectory = createMockDirectory(); FileCacheKey k = new FileCacheKey(INDEX_NAME, FILE_NAME, segmentId); DirectoryLoaderAdaptor adaptor = new DirectoryLoaderAdaptor(mockDirectory, INDEX_NAME, AUTO_BUFFER, -1); Object loaded = adaptor.load(k); AssertJUnit.assertTrue(loaded instanceof FileMetadata); FileMetadata metadata = (FileMetadata)loaded; AssertJUnit.assertEquals(TEST_SIZE, metadata.getSize()); AssertJUnit.assertEquals(AUTO_BUFFER, metadata.getBufferSize()); }
@Override public boolean contains(final Object key) { if (key instanceof IndexScopedKey) { final IndexScopedKey indexKey = (IndexScopedKey)key; final DirectoryLoaderAdaptor directoryAdaptor = getDirectory(indexKey); return directoryAdaptor.containsKey(indexKey); } else { log.cacheLoaderIgnoringKey(key); return false; } }
/** * Guess in how many chunks we should split this file. Should return the same value consistently * for the same file (segments are immutable) so that a full segment can be rebuilt from the upper * layers without anyone actually specifying the chunks numbers. */ private int figureChunksNumber(String fileName) throws IOException { long fileLength = directory.fileLength(fileName); return figureChunksNumber(fileName, fileLength, autoChunkSize); }
@Test public void testReadExistingIndex() throws IOException { TestHelper.createIndex(rootDir, "index-A", 10 * SCALE, true); TestHelper.createIndex(rootDir, "index-B", 20 * SCALE, false); TestHelper.verifyIndex(rootDir, "index-A", 10 * SCALE, true); verifyDirectory(rootDir, "index-A", 10 * SCALE, true); TestHelper.verifyIndex(rootDir, "index-B", 20 * SCALE, false); verifyDirectory(rootDir, "index-B", 20 * SCALE, false); }
private DirectoryLoaderAdaptor getDirectory(final IndexScopedKey indexKey) { final String indexName = indexKey.getIndexName(); return getDirectory(indexName); }
@BeforeMethod public void setUp() { rootDir = TestHelper.createRootDir(parentDir, getIndexPathName()); }
@Override public IndexInputMock answer(InvocationOnMock invocationOnMock) throws Throwable { return new IndexInputMock(FILE_NAME); } });
/** * Closes the underlying Directory. After it's closed, no other invocations are expected on this Adapter; we don't check explicitly for it * as the Directory instance takes care of it. */ protected void close() { try { directory.close(); } catch (IOException e) { //log but continue execution: we might want to try closing more instance log.errorOnFSDirectoryClose(e); } }
/** * Load implementation for FileListCacheKey; must return a * ConcurrentHashSet containing the names of all files in this Directory. */ private Object loadIntern(final FileListCacheKey key) throws IOException { final String[] listAll = directory.listAll(); final ConcurrentHashSet<String> fileNames = new ConcurrentHashSet<String>(); for (String filename : listAll) { fileNames.add(filename); } return fileNames; }
public void testSmallChunkLoading() throws IOException { Directory mockDirectory = createMockDirectory(); DirectoryLoaderAdaptor adaptor = new DirectoryLoaderAdaptor(mockDirectory, INDEX_NAME, AUTO_BUFFER, -1); Object loaded = adaptor.load(new ChunkCacheKey(INDEX_NAME, FILE_NAME, 0, AUTO_BUFFER, segmentId)); AssertJUnit.assertTrue(loaded instanceof byte[]); AssertJUnit.assertEquals(AUTO_BUFFER, ((byte[])loaded).length); loaded = adaptor.load(new ChunkCacheKey(INDEX_NAME, FILE_NAME, 5, AUTO_BUFFER, segmentId)); AssertJUnit.assertTrue(loaded instanceof byte[]); AssertJUnit.assertEquals(AUTO_BUFFER, ((byte[])loaded).length); final int lastChunk = (int)(TEST_SIZE / AUTO_BUFFER); final long lastChunkSize = TEST_SIZE % AUTO_BUFFER; AssertJUnit.assertEquals(9, lastChunkSize); loaded = adaptor.load(new ChunkCacheKey(INDEX_NAME, FILE_NAME, lastChunk, AUTO_BUFFER, segmentId)); AssertJUnit.assertTrue(loaded instanceof byte[]); AssertJUnit.assertEquals(lastChunkSize, ((byte[])loaded).length); }
@Override public boolean contains(final Object key) { if (key instanceof IndexScopedKey) { final IndexScopedKey indexKey = (IndexScopedKey)key; final DirectoryLoaderAdaptor directoryAdaptor = getDirectory(indexKey); return directoryAdaptor.containsKey(indexKey); } else { log.cacheLoaderIgnoringKey(key); return false; } }
@Override public Boolean visit(final ChunkCacheKey chunkCacheKey) throws IOException { return DirectoryLoaderAdaptor.this.containsKeyIntern(chunkCacheKey); }
@Override public boolean contains(final Object key) { if (key instanceof IndexScopedKey) { final IndexScopedKey indexKey = (IndexScopedKey)key; final DirectoryLoaderAdaptor directoryAdaptor = getDirectory(indexKey); return directoryAdaptor.containsKey(indexKey); } else { log.cacheLoaderIgnoringKey(key); return false; } }
@Override public Boolean visit(final FileCacheKey fileCacheKey) throws IOException { return DirectoryLoaderAdaptor.this.containsKeyIntern(fileCacheKey); }
@Override public Boolean visit(final FileCacheKey fileCacheKey) throws IOException { return DirectoryLoaderAdaptor.this.containsKeyIntern(fileCacheKey); }
@Override public Boolean visit(final ChunkCacheKey chunkCacheKey) throws IOException { return DirectoryLoaderAdaptor.this.containsKeyIntern(chunkCacheKey); }
@Override public Boolean visit(final FileCacheKey fileCacheKey) throws IOException { return DirectoryLoaderAdaptor.this.containsKeyIntern(fileCacheKey); }