12
12
import org .opensearch .common .blobstore .BlobPath ;
13
13
import org .opensearch .core .index .shard .ShardId ;
14
14
import org .opensearch .index .IndexSettings ;
15
+ import org .opensearch .index .remote .RemoteStorePathType ;
15
16
import org .opensearch .index .shard .ShardPath ;
16
17
import org .opensearch .index .store .lockmanager .RemoteStoreLockManager ;
17
18
import org .opensearch .index .store .lockmanager .RemoteStoreLockManagerFactory ;
23
24
import org .opensearch .threadpool .ThreadPool ;
24
25
25
26
import java .io .IOException ;
27
+ import java .util .Objects ;
26
28
import java .util .function .Supplier ;
27
29
28
30
/**
32
34
*/
33
35
public class RemoteSegmentStoreDirectoryFactory implements IndexStorePlugin .DirectoryFactory {
34
36
private static final String SEGMENTS = "segments" ;
37
+ private final static String DATA_DIR = "data" ;
38
+ private final static String METADATA_DIR = "metadata" ;
35
39
36
40
private final Supplier <RepositoriesService > repositoriesService ;
37
41
@@ -46,29 +50,38 @@ public RemoteSegmentStoreDirectoryFactory(Supplier<RepositoriesService> reposito
46
50
public Directory newDirectory (IndexSettings indexSettings , ShardPath path ) throws IOException {
47
51
String repositoryName = indexSettings .getRemoteStoreRepository ();
48
52
String indexUUID = indexSettings .getIndex ().getUUID ();
49
- return newDirectory (repositoryName , indexUUID , path .getShardId ());
53
+ return newDirectory (repositoryName , indexUUID , path .getShardId (), indexSettings . getRemoteStorePathType () );
50
54
}
51
55
52
- public Directory newDirectory (String repositoryName , String indexUUID , ShardId shardId ) throws IOException {
56
+ public Directory newDirectory (String repositoryName , String indexUUID , ShardId shardId , RemoteStorePathType pathType )
57
+ throws IOException {
58
+ assert Objects .nonNull (pathType );
53
59
try (Repository repository = repositoriesService .get ().repository (repositoryName )) {
60
+
54
61
assert repository instanceof BlobStoreRepository : "repository should be instance of BlobStoreRepository" ;
55
62
BlobStoreRepository blobStoreRepository = ((BlobStoreRepository ) repository );
56
- BlobPath commonBlobPath = blobStoreRepository .basePath ();
57
- commonBlobPath = commonBlobPath . add ( indexUUID ). add ( String .valueOf (shardId .id ())). add ( SEGMENTS );
63
+ BlobPath repositoryBasePath = blobStoreRepository .basePath ();
64
+ String shardIdStr = String .valueOf (shardId .id ());
58
65
66
+ // Derive the path for data directory of SEGMENTS
67
+ BlobPath dataBlobPath = pathType .generatePath (repositoryBasePath , indexUUID , shardIdStr , SEGMENTS , DATA_DIR );
59
68
RemoteDirectory dataDirectory = new RemoteDirectory (
60
- blobStoreRepository .blobStore ().blobContainer (commonBlobPath . add ( "data" ) ),
69
+ blobStoreRepository .blobStore ().blobContainer (dataBlobPath ),
61
70
blobStoreRepository ::maybeRateLimitRemoteUploadTransfers ,
62
71
blobStoreRepository ::maybeRateLimitRemoteDownloadTransfers
63
72
);
64
- RemoteDirectory metadataDirectory = new RemoteDirectory (
65
- blobStoreRepository .blobStore ().blobContainer (commonBlobPath .add ("metadata" ))
66
- );
73
+
74
+ // Derive the path for metadata directory of SEGMENTS
75
+ BlobPath mdBlobPath = pathType .generatePath (repositoryBasePath , indexUUID , shardIdStr , SEGMENTS , METADATA_DIR );
76
+ RemoteDirectory metadataDirectory = new RemoteDirectory (blobStoreRepository .blobStore ().blobContainer (mdBlobPath ));
77
+
78
+ // The path for lock is derived within the RemoteStoreLockManagerFactory
67
79
RemoteStoreLockManager mdLockManager = RemoteStoreLockManagerFactory .newLockManager (
68
80
repositoriesService .get (),
69
81
repositoryName ,
70
82
indexUUID ,
71
- String .valueOf (shardId .id ())
83
+ shardIdStr ,
84
+ pathType
72
85
);
73
86
74
87
return new RemoteSegmentStoreDirectory (dataDirectory , metadataDirectory , mdLockManager , threadPool , shardId );
0 commit comments