/** * @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; }
@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); }
/** * @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; }
IndexOutput createOutput(final String name) { final FileCacheKey key = new FileCacheKey(indexName, name); // creating new file, metadata is added on flush() or close() of IndexOutPut return new InfinispanIndexOutput(metadataCache, chunksCache, key, chunkSize, fileOps); }
@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); }
TransactionalSharedLuceneLock(Cache<?, ?> cache, String indexName, String lockName, TransactionManager tm) { this.noCacheStoreCache = (Cache<FileCacheKey, FileCacheKey>) cache.getAdvancedCache().withFlags(Flag.SKIP_CACHE_STORE, Flag.SKIP_CACHE_LOAD, Flag.SKIP_INDEXING); this.lockName = lockName; this.indexName = indexName; this.tm = tm; this.keyOfLock = new FileCacheKey(indexName, lockName); }
TransactionalSharedLuceneLock(Cache<?, ?> cache, String indexName, String lockName, TransactionManager tm) { this.noCacheStoreCache = (Cache<FileCacheKey, FileCacheKey>) cache.getAdvancedCache().withFlags(Flag.SKIP_CACHE_STORE, Flag.SKIP_CACHE_LOAD, Flag.SKIP_INDEXING); this.lockName = lockName; this.indexName = indexName; this.tm = tm; this.keyOfLock = new FileCacheKey(indexName, lockName, -1); }
@Test public void testFileCacheKeyExternalizer() throws IOException { FileCacheKey key = new FileCacheKey("myIndex", "fileA.idx", 7); verifyExternalizerForType(key, FileCacheKey.Externalizer.class); }
/** * Used by Lucene v3.x only */ void touchFile(final String fileName) { final FileMetadata file = fileOps.getFileMetadata(fileName); if (file != null) { final FileCacheKey key = new FileCacheKey(indexName, fileName); file.touch(); metadataCache.put(key, file); } }
public Address getLockOwner(String indexName, int affinityId, String lockName) { FileCacheKey fileCacheKey = new FileCacheKey(indexName, lockName, affinityId); Cache<?, Address> lockCache = cacheManager.getCache(lockingCacheName); Address address = lockCache.get(fileCacheKey); log.debugf("Lock owner for %s: %s", fileCacheKey, address); return address; } }
BaseLuceneLock(Cache<?, ?> cache, String indexName, String lockName, int affinitySegmentId) { this.noCacheStoreCache = (Cache<Object, Object>) cache.getAdvancedCache().withFlags(Flag.SKIP_CACHE_STORE, Flag.SKIP_CACHE_LOAD); this.lockName = lockName; this.indexName = indexName; this.keyOfLock = new FileCacheKey(indexName, lockName, affinitySegmentId); Address address = noCacheStoreCache.getCacheManager().getAddress(); this.valueOfLock = address == null ? LocalModeAddress.INSTANCE : address; }
@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)); } }
@Test public void loadFileCacheKey() { AssertJUnit.assertEquals(new FileCacheKey("poems and songs, 3000AC-2000DC", "filename.extension", -1), mapper.getKeyMapping("M|filename.extension|poems and songs, 3000AC-2000DC|-1")); }
/** * Force release of the lock in this directory. Make sure to understand the * consequences */ @Override public void forceUnlock(String lockName) { Cache<Object, Integer> lockCache = getDistLockCache().getAdvancedCache().withFlags(Flag.SKIP_CACHE_STORE, Flag.SKIP_CACHE_LOAD); FileCacheKey fileCacheKey = new FileCacheKey(indexName, lockName, affinitySegmentId); Object previousValue = lockCache.remove(fileCacheKey); if (previousValue!=null && trace) { log.tracef("Lock forcibly removed for index: %s", indexName); } }
/** * Force release of the lock in this directory. Make sure to understand the * consequences */ @Override public void forceUnlock(String lockName) { Cache<Object, Integer> lockCache = getDistLockCache().getAdvancedCache().withFlags(Flag.SKIP_CACHE_STORE, Flag.SKIP_CACHE_LOAD); FileCacheKey fileCacheKey = new FileCacheKey(indexName, lockName, affinitySegmentId); Object previousValue = lockCache.remove(fileCacheKey); if (previousValue!=null && trace) { log.tracef("Lock forcibly removed for index: %s", indexName); } }
public DirectoryImplementor(Cache<?, ?> metadataCache, Cache<?, ?> chunksCache, Cache<?, ?> distLocksCache, String indexName, int chunkSize, SegmentReadLocker readLocker, boolean fileListUpdatedAsync, int affinitySegmentId) { this.affinitySegmentId = affinitySegmentId; if (chunkSize <= 0) throw new IllegalArgumentException("chunkSize must be a positive integer"); this.metadataCache = (AdvancedCache<FileCacheKey, FileMetadata>) metadataCache.getAdvancedCache().withFlags(Flag.SKIP_INDEXING); this.chunksCache = (AdvancedCache<ChunkCacheKey, Object>) chunksCache.getAdvancedCache().withFlags(Flag.SKIP_INDEXING); this.distLocksCache = (AdvancedCache<Object, Integer>) distLocksCache.getAdvancedCache().withFlags(Flag.SKIP_INDEXING); this.indexName = indexName; this.chunkSize = chunkSize; this.fileOps = new FileListOperations(this.metadataCache, indexName, fileListUpdatedAsync, this.affinitySegmentId); this.segmentsGenFileKey = new FileCacheKey(indexName, IndexFileNames.SEGMENTS, this.affinitySegmentId); this.readLocks = readLocker; }
@Test(expectedExceptions = PersistenceException.class) public void testLoadKeyWithNonExistentFile() throws Exception { LuceneCacheLoader cacheLoader = (LuceneCacheLoader) TestingUtil.getFirstLoader(cacheManager.getCache()); FileCacheKey key = new FileCacheKey(indexName, "testKey", segmentId); AssertJUnit.assertNull(cacheLoader.load(key)); }
@Test public void testFileListCacheKeyComparison() { AssertJUnit.assertFalse("The instance of FileListCacheKey should not be equal to null.", new FileListCacheKey("index-A", -1).equals(null)); AssertJUnit.assertFalse("The instance of FileListCacheKey should not be equal to FileCacheKey instance.", new FileListCacheKey("index-A", -1).equals(new FileCacheKey("index-A", "test.txt", -1))); }
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()); }
public void testLoadKey() throws Exception { TestHelper.createIndex(rootDir, indexName, elementCount, true); String[] fileNamesFromIndexDir = TestHelper.getFileNamesFromDir(rootDir, indexName); LuceneCacheLoader cacheLoader = (LuceneCacheLoader) TestingUtil.getFirstLoader(cacheManager.getCache()); for(String fileName : fileNamesFromIndexDir) { FileCacheKey key = new FileCacheKey(indexName, fileName, segmentId); AssertJUnit.assertNotNull(cacheLoader.load(key)); //Testing non-existent keys with non-acceptable type AssertJUnit.assertNull(cacheLoader.load(fileName)); } }