7676import org .opensearch .index .shard .IndexingOperationListener ;
7777import org .opensearch .index .shard .SearchOperationListener ;
7878import org .opensearch .index .similarity .SimilarityService ;
79+ import org .opensearch .index .store .DefaultCompositeDirectoryFactory ;
7980import org .opensearch .index .store .FsDirectoryFactory ;
8081import org .opensearch .index .store .remote .directory .RemoteSnapshotDirectoryFactory ;
8182import org .opensearch .index .store .remote .filecache .FileCache ;
@@ -133,6 +134,7 @@ public final class IndexModule {
133134 public static final Setting <Boolean > NODE_STORE_ALLOW_MMAP = Setting .boolSetting ("node.store.allow_mmap" , true , Property .NodeScope );
134135
135136 private static final FsDirectoryFactory DEFAULT_DIRECTORY_FACTORY = new FsDirectoryFactory ();
137+ private static final IndexStorePlugin .CompositeDirectoryFactory DEFAULT_COMPOSITE_DIRECTORY_FACTORY = new DefaultCompositeDirectoryFactory ();
136138
137139 private static final IndexStorePlugin .RecoveryStateFactory DEFAULT_RECOVERY_STATE_FACTORY = RecoveryState ::new ;
138140
@@ -144,6 +146,14 @@ public final class IndexModule {
144146 Property .NodeScope
145147 );
146148
149+ public static final Setting <String > INDEX_COMPOSITE_STORE_TYPE_SETTING = new Setting <>(
150+ "index.composite_store.type" ,
151+ "default" ,
152+ Function .identity (),
153+ Property .IndexScope ,
154+ Property .NodeScope
155+ );
156+
147157 /**
148158 * Index setting which used to determine how the data is cached locally fully or partially.
149159 */
@@ -240,6 +250,7 @@ public final class IndexModule {
240250 private final Set <IndexEventListener > indexEventListeners = new HashSet <>();
241251 private final Map <String , TriFunction <Settings , Version , ScriptService , Similarity >> similarities = new HashMap <>();
242252 private final Map <String , IndexStorePlugin .DirectoryFactory > directoryFactories ;
253+ private final Map <String , IndexStorePlugin .CompositeDirectoryFactory > compositeDirectoryFactories ;
243254 private final SetOnce <BiFunction <IndexSettings , IndicesQueryCache , QueryCache >> forceQueryCacheProvider = new SetOnce <>();
244255 private final List <SearchOperationListener > searchOperationListeners = new ArrayList <>();
245256 private final List <IndexingOperationListener > indexOperationListeners = new ArrayList <>();
@@ -265,6 +276,7 @@ public IndexModule(
265276 final EngineFactory engineFactory ,
266277 final EngineConfigFactory engineConfigFactory ,
267278 final Map <String , IndexStorePlugin .DirectoryFactory > directoryFactories ,
279+ final Map <String , IndexStorePlugin .CompositeDirectoryFactory > compositeDirectoryFactories ,
268280 final BooleanSupplier allowExpensiveQueries ,
269281 final IndexNameExpressionResolver expressionResolver ,
270282 final Map <String , IndexStorePlugin .RecoveryStateFactory > recoveryStateFactories ,
@@ -278,6 +290,7 @@ public IndexModule(
278290 this .searchOperationListeners .add (new SearchSlowLog (indexSettings ));
279291 this .indexOperationListeners .add (new IndexingSlowLog (indexSettings ));
280292 this .directoryFactories = Collections .unmodifiableMap (directoryFactories );
293+ this .compositeDirectoryFactories = Collections .unmodifiableMap (compositeDirectoryFactories );
281294 this .allowExpensiveQueries = allowExpensiveQueries ;
282295 this .expressionResolver = expressionResolver ;
283296 this .recoveryStateFactories = recoveryStateFactories ;
@@ -301,6 +314,7 @@ public IndexModule(
301314 engineFactory ,
302315 engineConfigFactory ,
303316 directoryFactories ,
317+ null ,
304318 allowExpensiveQueries ,
305319 expressionResolver ,
306320 recoveryStateFactories ,
@@ -693,6 +707,7 @@ public IndexService newIndexService(
693707 .get () == null ? (shard ) -> null : indexReaderWrapper .get ();
694708 eventListener .beforeIndexCreated (indexSettings .getIndex (), indexSettings .getSettings ());
695709 final IndexStorePlugin .DirectoryFactory directoryFactory = getDirectoryFactory (indexSettings , directoryFactories );
710+ final IndexStorePlugin .CompositeDirectoryFactory compositeDirectoryFactory = getCompositeDirectoryFactory (indexSettings , compositeDirectoryFactories );
696711 final IndexStorePlugin .RecoveryStateFactory recoveryStateFactory = getRecoveryStateFactory (indexSettings , recoveryStateFactories );
697712 QueryCache queryCache = null ;
698713 IndexAnalyzers indexAnalyzers = null ;
@@ -729,6 +744,7 @@ public IndexService newIndexService(
729744 client ,
730745 queryCache ,
731746 directoryFactory ,
747+ compositeDirectoryFactory ,
732748 remoteDirectoryFactory ,
733749 eventListener ,
734750 readerWrapperFactory ,
@@ -792,6 +808,23 @@ private static IndexStorePlugin.DirectoryFactory getDirectoryFactory(
792808 return factory ;
793809 }
794810
811+ private static IndexStorePlugin .CompositeDirectoryFactory getCompositeDirectoryFactory (
812+ final IndexSettings indexSettings ,
813+ final Map <String , IndexStorePlugin .CompositeDirectoryFactory > indexStoreFactories
814+ ) {
815+ final String compositeStoreType = indexSettings .getValue (INDEX_COMPOSITE_STORE_TYPE_SETTING );
816+ final IndexStorePlugin .CompositeDirectoryFactory factory ;
817+ if (compositeStoreType .isEmpty ()) {
818+ factory = DEFAULT_COMPOSITE_DIRECTORY_FACTORY ;
819+ } else {
820+ factory = indexStoreFactories .get (compositeStoreType );
821+ if (factory == null ) {
822+ throw new IllegalArgumentException ("Unknown composite store type [" + compositeStoreType + "]" );
823+ }
824+ }
825+ return factory ;
826+ }
827+
795828 private static IndexStorePlugin .RecoveryStateFactory getRecoveryStateFactory (
796829 final IndexSettings indexSettings ,
797830 final Map <String , IndexStorePlugin .RecoveryStateFactory > recoveryStateFactories
0 commit comments