/** * Evaluates if the file is potentially being stored as fragmented into multiple chunks; * when it's a single chunk we don't need to apply readlocks. * @param filename * @return true if it is definitely fragmented, or if it's possibly fragmented. */ private boolean isMultiChunked(final String filename) { final FileCacheKey fileCacheKey = new FileCacheKey(indexName, filename, affinitySegmentId); final FileMetadata fileMetadata = metadataCache.get(fileCacheKey); if (fileMetadata==null) { //This might happen under high load when the metadata is being written //using putAsync; in such case we return true as it's the safest option. //Skipping the readlocks is just a performance optimisation, and this //condition is extremely rare. return true; } else { return fileMetadata.isMultiChunked(); } }
/** * Evaluates if the file is potentially being stored as fragmented into multiple chunks; * when it's a single chunk we don't need to apply readlocks. * @param filename * @return true if it is definitely fragmented, or if it's possibly fragmented. */ private boolean isMultiChunked(final String filename) { final FileCacheKey fileCacheKey = new FileCacheKey(indexName, filename, affinitySegmentId); final FileMetadata fileMetadata = metadataCache.get(fileCacheKey); if (fileMetadata==null) { //This might happen under high load when the metadata is being written //using putAsync; in such case we return true as it's the safest option. //Skipping the readlocks is just a performance optimisation, and this //condition is extremely rare. return true; } else { return fileMetadata.isMultiChunked(); } }
IndexInputContext openInput(final String name) throws IOException { final FileCacheKey fileKey = new FileCacheKey(indexName, name, affinitySegmentId); FileMetadata fileMetadata; try { fileMetadata = metadataCache.get(fileKey); } catch (PersistenceException pe) { //When loading through the LuceneCacheLoader, a valid FileNotFoundException would be wrapped by a PersistenceException: //just ignore it so that we re-throw the needed FileNotFoundException fileMetadata = null; } if (fileMetadata == null) { throw new FileNotFoundException("Error loading metadata for index file: " + fileKey); } else if (!fileMetadata.isMultiChunked()) { //files smaller than chunkSize don't need a readLock return new IndexInputContext(chunksCache, fileKey, fileMetadata, null, affinitySegmentId); } else { boolean locked = readLocks.acquireReadLock(name); if (!locked) { // safest reaction is to tell this file doesn't exist anymore. throw new FileNotFoundException("Error loading metadata for index file: " + fileKey); } return new IndexInputContext(chunksCache, fileKey, fileMetadata, readLocks, affinitySegmentId); } }
IndexInputContext openInput(final String name) throws IOException { final FileCacheKey fileKey = new FileCacheKey(indexName, name, affinitySegmentId); FileMetadata fileMetadata; try { fileMetadata = metadataCache.get(fileKey); } catch (PersistenceException pe) { //When loading through the LuceneCacheLoader, a valid FileNotFoundException would be wrapped by a PersistenceException: //just ignore it so that we re-throw the needed FileNotFoundException fileMetadata = null; } if (fileMetadata == null) { throw new FileNotFoundException("Error loading metadata for index file: " + fileKey); } else if (!fileMetadata.isMultiChunked()) { //files smaller than chunkSize don't need a readLock return new IndexInputContext(chunksCache, fileKey, fileMetadata, null, affinitySegmentId); } else { boolean locked = readLocks.acquireReadLock(name); if (!locked) { // safest reaction is to tell this file doesn't exist anymore. throw new FileNotFoundException("Error loading metadata for index file: " + fileKey); } return new IndexInputContext(chunksCache, fileKey, fileMetadata, readLocks, affinitySegmentId); } }
if (file != null && file.isMultiChunked()) { FileReadLockKey readLockKey = new FileReadLockKey(indexName, fileName, affinitySegmentId); if (trace) log.tracef("deleting readlock: %s", readLockKey);
if (file != null && file.isMultiChunked()) { FileReadLockKey readLockKey = new FileReadLockKey(indexName, fileName, affinitySegmentId); if (trace) log.tracef("deleting readlock: %s", readLockKey);