Пример #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
    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);
        }
      }
    }
Пример #4
0
 @Override
 public String getLockID() {
   return distributor.primary().getLockID();
 }
Пример #5
0
 @Override
 public LockFactory getLockFactory() {
   return distributor.primary().getLockFactory();
 }
Пример #6
0
 @Override
 public void setLockFactory(LockFactory lockFactory) throws IOException {
   distributor.primary().setLockFactory(lockFactory);
 }
Пример #7
0
 @Override
 public void clearLock(String name) throws IOException {
   distributor.primary().clearLock(name);
 }
Пример #8
0
 @Override
 public Lock makeLock(String name) {
   return distributor.primary().makeLock(name);
 }