Пример #1
0
 public IndexOutput createOutput(String name, IOContext context, boolean raw)
     throws IOException {
   Directory directory;
   if (isChecksum(name)) {
     directory = distributor.primary();
   } else {
     directory = distributor.any();
   }
   IndexOutput out = directory.createOutput(name, context);
   synchronized (mutex) {
     StoreFileMetaData metaData = new StoreFileMetaData(name, -1, null, directory);
     filesMetadata = MapBuilder.newMapBuilder(filesMetadata).put(name, metaData).immutableMap();
     files = filesMetadata.keySet().toArray(new String[filesMetadata.size()]);
     boolean computeChecksum = !raw;
     if (computeChecksum) {
       // don't compute checksum for segment based files
       if ("segments.gen".equals(name) || name.startsWith("segments")) {
         computeChecksum = false;
       }
     }
     if (computeChecksum) {
       out = new BufferedChecksumIndexOutput(out, new Adler32());
     }
     return new StoreIndexOutput(metaData, out, name);
   }
 }
Пример #2
0
 /**
  * Creates a new Directory from the given distributor. The default implementation returns a new
  * {@link org.elasticsearch.index.store.DistributorDirectory} if there is more than one data path
  * in the distributor.
  */
 public Directory newFromDistributor(final Distributor distributor) throws IOException {
   if (distributor.all().length == 1) {
     // use filter dir for consistent toString methods
     return new FilterDirectory(distributor.primary()) {
       @Override
       public String toString() {
         return distributor.toString();
       }
     };
   }
   return new DistributorDirectory(distributor);
 }
Пример #3
0
 StoreDirectory(Distributor distributor) throws IOException {
   this.distributor = distributor;
   synchronized (mutex) {
     MapBuilder<String, StoreFileMetaData> builder = MapBuilder.newMapBuilder();
     Map<String, String> checksums =
         readChecksums(distributor.all(), new HashMap<String, String>());
     for (Directory delegate : distributor.all()) {
       for (String file : delegate.listAll()) {
         String checksum = checksums.get(file);
         builder.put(
             file, new StoreFileMetaData(file, delegate.fileLength(file), checksum, delegate));
       }
     }
     filesMetadata = builder.immutableMap();
     files = filesMetadata.keySet().toArray(new String[filesMetadata.size()]);
   }
 }
Пример #4
0
 @Override
 public void close() throws IOException {
   for (Directory delegate : distributor.all()) {
     delegate.close();
   }
   synchronized (mutex) {
     filesMetadata = ImmutableMap.of();
     files = Strings.EMPTY_ARRAY;
   }
 }
Пример #5
0
 synchronized void closeInternal() throws IOException {
   if (isOpen) {
     isOpen = false;
     for (Directory delegate : distributor.all()) {
       delegate.close();
     }
     synchronized (mutex) {
       filesMetadata = ImmutableOpenMap.of();
       files = Strings.EMPTY_ARRAY;
     }
   }
 }
Пример #6
0
    public IndexOutput createOutput(String name, IOContext context, boolean raw)
        throws IOException {
      ensureOpen();
      Directory directory;
      // we want to write the segments gen file to the same directory *all* the time
      // to make sure we don't create multiple copies of it
      if (isChecksum(name) || IndexFileNames.SEGMENTS_GEN.equals(name)) {
        directory = distributor.primary();
      } else {
        directory = distributor.any();
      }
      IndexOutput out = directory.createOutput(name, context);
      boolean success = false;
      try {
        synchronized (mutex) {
          StoreFileMetaData metaData = new StoreFileMetaData(name, -1, null, directory);
          filesMetadata = ImmutableOpenMap.builder(filesMetadata).fPut(name, metaData).build();
          files = filesMetadata.keys().toArray(String.class);
          boolean computeChecksum = !raw;
          if (computeChecksum) {
            // don't compute checksum for segment based files
            if (IndexFileNames.SEGMENTS_GEN.equals(name)
                || name.startsWith(IndexFileNames.SEGMENTS)) {
              computeChecksum = false;
            }
          }
          if (computeChecksum) {
            out = new BufferedChecksumIndexOutput(out, new Adler32());
          }

          final StoreIndexOutput storeIndexOutput = new StoreIndexOutput(metaData, out, name);
          success = true;
          return storeIndexOutput;
        }
      } finally {
        if (!success) {
          IOUtils.closeWhileHandlingException(out);
        }
      }
    }
Пример #7
0
 @Override
 public String getLockID() {
   return distributor.primary().getLockID();
 }
Пример #8
0
 @Override
 public LockFactory getLockFactory() {
   return distributor.primary().getLockFactory();
 }
Пример #9
0
 @Override
 public void setLockFactory(LockFactory lockFactory) throws IOException {
   distributor.primary().setLockFactory(lockFactory);
 }
Пример #10
0
 @Override
 public void clearLock(String name) throws IOException {
   distributor.primary().clearLock(name);
 }
Пример #11
0
 @Override
 public Lock makeLock(String name) {
   return distributor.primary().makeLock(name);
 }
Пример #12
0
 public Directory[] delegates() {
   return distributor.all();
 }
Пример #13
0
 @Override
 public String toString() {
   return "store(" + distributor.toString() + ")";
 }