Package org.infinispan.lucene

Examples of org.infinispan.lucene.FileMetadata


   static void realFileDelete(FileReadLockKey readLockKey, AdvancedCache cache) {
      final String indexName = readLockKey.getIndexName();
      final String filename = readLockKey.getFileName();
      FileCacheKey key = new FileCacheKey(indexName, filename);
      boolean batch = cache.startBatch();
      FileMetadata file = (FileMetadata) cache.withFlags(Flag.SKIP_LOCKING).remove(key);
      if (file != null) { //during optimization of index a same file could be deleted twice, so you could see a null here
         for (int i = 0; i < file.getNumberOfChunks(); i++) {
            ChunkCacheKey chunkKey = new ChunkCacheKey(indexName, filename, i);
            cache.withFlags(Flag.SKIP_REMOTE_LOOKUP).removeAsync(chunkKey);
         }
         cache.withFlags(Flag.SKIP_REMOTE_LOOKUP).removeAsync(key);
      }
View Full Code Here


      final boolean trace = log.isTraceEnabled();
      final String indexName = readLockKey.getIndexName();
      final String filename = readLockKey.getFileName();
      FileCacheKey key = new FileCacheKey(indexName, filename);
      if (trace) log.trace("deleting metadata: " + key);
      FileMetadata file = (FileMetadata) metadataCache.withFlags(Flag.SKIP_LOCKING).remove(key);
      if (file != null) { //during optimization of index a same file could be deleted twice, so you could see a null here
         for (int i = 0; i < file.getNumberOfChunks(); i++) {
            ChunkCacheKey chunkKey = new ChunkCacheKey(indexName, filename, i);
            if (trace) log.trace("deleting chunk: " + chunkKey);
            chunksCache.withFlags(Flag.SKIP_REMOTE_LOOKUP, Flag.SKIP_CACHE_LOAD, Flag.SKIP_LOCKING).removeAsync(chunkKey);
         }
      }
View Full Code Here

      this.fileKey = fileKey;
      this.bufferSize = bufferSize;
      this.fileOps = fileList;
      this.buffer = new byte[this.bufferSize];
      this.firstChunkBuffer = buffer;
      this.file = new FileMetadata(bufferSize);
      if (trace) {
         log.tracef("Opened new IndexOutput for file:%s in index: %s", fileKey.getFileName(), fileKey.getIndexName());
      }
   }
View Full Code Here

       }
    }

    void renameFile(final String from, final String to) {
       final FileCacheKey fromKey = new FileCacheKey(indexName, from);
       final FileMetadata metadata = metadataCache.get(fromKey);
       final int bufferSize = metadata.getBufferSize();
       // preparation: copy all chunks to new keys
       int i = -1;
       Object ob;
       do {
          final ChunkCacheKey fromChunkKey = new ChunkCacheKey(indexName, from, ++i, bufferSize);
View Full Code Here

          log.tracef("Renamed file from: %s to: %s in index %s", from, to, indexName);
       }
    }

    long fileLength(final String name) {
       final FileMetadata fileMetadata = fileOps.getFileMetadata(name);
       if (fileMetadata == null) {
          return 0L; //as in FSDirectory (RAMDirectory throws an exception instead)
       }
       else {
          return fileMetadata.getSize();
       }
    }
View Full Code Here

       }
    }

    IndexInputContext openInput(final String name) throws IOException {
       final FileCacheKey fileKey = new FileCacheKey(indexName, name);
       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);
       }
       else {
          boolean locked = readLocks.acquireReadLock(name);
View Full Code Here

    * @see org.apache.lucene.store.Directory#deleteFile(String)
    */
   @Override
   public void deleteOrReleaseReadLock(String filename) {
      final FileCacheKey fileCacheKey = new FileCacheKey(indexName, filename);
      final FileMetadata fileMetadata = metadataCache.get(fileCacheKey);
      final boolean isMultiChunked = fileMetadata.isMultiChunked();
      if (isMultiChunked) {
         int newValue = 0;
         FileReadLockKey readLockKey = new FileReadLockKey(indexName, filename);
         boolean done = false;
         Object lockValue = locksCache.get(readLockKey);
View Full Code Here

   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 {
View Full Code Here

   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;
   }
View Full Code Here

    * @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);
      FileMetadata metadata = (FileMetadata) cache.get(key);
      return metadata;
   }
View Full Code Here

TOP

Related Classes of org.infinispan.lucene.FileMetadata

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.