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()]); } }
@Override public void close() throws IOException { for (Directory delegate : distributor.all()) { delegate.close(); } synchronized (mutex) { filesMetadata = ImmutableMap.of(); files = Strings.EMPTY_ARRAY; } }
/** * 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); }
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; } } }
public Directory[] delegates() { return distributor.all(); }