static void realFileDelete(String indexName, String fileName, AdvancedCache<Object, Integer> locksCache,
AdvancedCache<?, ?> chunksCache, AdvancedCache<?, ?> metadataCache, boolean forceSynchronousDeletes) {
final boolean trace = log.isTraceEnabled();
final FileCacheKey key = new FileCacheKey(indexName, fileName);
if (trace) log.tracef("deleting metadata: %s", key);
final FileMetadata file = (FileMetadata) metadataCache.remove(key);
if (file != null) { //during optimization of index a same file could be deleted twice, so you could see a null here
final int bufferSize = file.getBufferSize();
AdvancedCache<?, ?> chunksCacheNoReturn = chunksCache.withFlags(Flag.IGNORE_RETURN_VALUES);
for (int i = 0; i < file.getNumberOfChunks(); i++) {
ChunkCacheKey chunkKey = new ChunkCacheKey(indexName, fileName, i, bufferSize);
if (trace) log.tracef("deleting chunk: %s", chunkKey);
if (forceSynchronousDeletes) {
chunksCacheNoReturn.remove(chunkKey);
}
else {
chunksCacheNoReturn.removeAsync(chunkKey);
}
}
}
// last operation, as being set as value==0 it prevents others from using it during the
// deletion process:
if (file != null && file.isMultiChunked()) {
FileReadLockKey readLockKey = new FileReadLockKey(indexName, fileName);
if (trace) log.tracef("deleting readlock: %s", readLockKey);
if (forceSynchronousDeletes) {
locksCache.withFlags(Flag.IGNORE_RETURN_VALUES).remove(readLockKey);
} else {