52
52
import org .apache .ignite .internal .GridKernalContext ;
53
53
import org .apache .ignite .internal .client .util .GridConcurrentHashSet ;
54
54
import org .apache .ignite .internal .managers .encryption .EncryptionCacheKeyProvider ;
55
- import org .apache .ignite .internal .pagemem .PageIdAllocator ;
56
55
import org .apache .ignite .internal .pagemem .PageIdUtils ;
57
56
import org .apache .ignite .internal .pagemem .store .IgnitePageStoreManager ;
58
57
import org .apache .ignite .internal .pagemem .store .PageStore ;
82
81
import org .jetbrains .annotations .NotNull ;
83
82
import org .jetbrains .annotations .Nullable ;
84
83
85
- import static java .lang .String .format ;
86
84
import static java .nio .file .Files .delete ;
87
85
import static java .nio .file .Files .newDirectoryStream ;
88
86
import static java .util .Objects .requireNonNull ;
92
90
import static org .apache .ignite .internal .processors .cache .persistence .filename .NodeFileTree .CACHE_DIR_WITH_META_FILTER ;
93
91
import static org .apache .ignite .internal .processors .cache .persistence .filename .NodeFileTree .FILE_SUFFIX ;
94
92
import static org .apache .ignite .internal .processors .cache .persistence .filename .NodeFileTree .INDEX_FILE_NAME ;
95
- import static org .apache .ignite .internal .processors .cache .persistence .filename .NodeFileTree .PART_FILE_PREFIX ;
96
- import static org .apache .ignite .internal .processors .cache .persistence .filename .NodeFileTree .PART_FILE_TEMPLATE ;
97
93
import static org .apache .ignite .internal .processors .cache .persistence .filename .NodeFileTree .TMP_SUFFIX ;
94
+ import static org .apache .ignite .internal .processors .cache .persistence .filename .NodeFileTree .partitionFileName ;
95
+ import static org .apache .ignite .internal .processors .cache .persistence .metastorage .MetaStorage .METASTORAGE_DIR_NAME ;
98
96
99
97
/**
100
98
* File page store manager.
@@ -420,7 +418,7 @@ private List<CacheConfiguration> findCacheGroupsWithDisabledWal() {
420
418
PageMetrics pageMetrics = dataRegion .metrics ().cacheGrpPageMetrics (grpId );
421
419
422
420
CacheStoreHolder holder = initDir (
423
- new File ( ft . nodeStorage (), MetaStorage . METASTORAGE_DIR_NAME ) ,
421
+ METASTORAGE_DIR_NAME ,
424
422
grpId ,
425
423
MetaStorage .METASTORAGE_CACHE_NAME ,
426
424
MetaStorage .METASTORAGE_PARTITIONS .size (),
@@ -510,14 +508,12 @@ private List<CacheConfiguration> findCacheGroupsWithDisabledWal() {
510
508
private CacheStoreHolder initForCache (CacheGroupDescriptor grpDesc , CacheConfiguration ccfg ) throws IgniteCheckedException {
511
509
assert !grpDesc .sharedGroup () || ccfg .getGroupName () != null : ccfg .getName ();
512
510
513
- File cacheWorkDir = ft .cacheStorage (ccfg );
514
-
515
511
String dataRegionName = grpDesc .config ().getDataRegionName ();
516
512
DataRegion dataRegion = cctx .database ().dataRegion (dataRegionName );
517
513
PageMetrics pageMetrics = dataRegion .metrics ().cacheGrpPageMetrics (grpDesc .groupId ());
518
514
519
515
return initDir (
520
- cacheWorkDir ,
516
+ ft . cacheDirName ( ccfg ) ,
521
517
grpDesc .groupId (),
522
518
ccfg .getName (),
523
519
grpDesc .config ().getAffinity ().partitions (),
@@ -590,7 +586,7 @@ public EncryptedFileIOFactory encryptedFileIoFactory(FileIOFactory plainFileIOFa
590
586
}
591
587
592
588
/**
593
- * @param cacheWorkDir Work directory .
589
+ * @param cacheDir Cache dir name .
594
590
* @param grpId Group ID.
595
591
* @param cacheName Cache name.
596
592
* @param partitions Number of partitions.
@@ -599,14 +595,17 @@ public EncryptedFileIOFactory encryptedFileIoFactory(FileIOFactory plainFileIOFa
599
595
* @return Cache store holder.
600
596
* @throws IgniteCheckedException If failed.
601
597
*/
602
- private CacheStoreHolder initDir (File cacheWorkDir ,
598
+ private CacheStoreHolder initDir (
599
+ String cacheDir ,
603
600
int grpId ,
604
601
String cacheName ,
605
602
int partitions ,
606
603
PageMetrics pageMetrics ,
607
604
boolean encrypted ,
608
605
Collection <String > grpCaches ) throws IgniteCheckedException {
609
606
try {
607
+ File cacheWorkDir = ft .cacheStorage (cacheDir );
608
+
610
609
boolean dirExisted = checkAndInitCacheWorkDir (cacheWorkDir , log );
611
610
612
611
if (dirExisted ) {
@@ -656,7 +655,7 @@ private CacheStoreHolder initDir(File cacheWorkDir,
656
655
PageStore partStore =
657
656
pageStoreFactory .createPageStore (
658
657
PageStore .TYPE_DATA ,
659
- () -> getPartitionFilePath ( cacheWorkDir , p ),
658
+ () -> NodeFileTree . partitionFile ( ft . nodeStorage (), cacheDir , p ). toPath ( ),
660
659
pageMetrics .totalPages ()::add );
661
660
662
661
partStores [partId ] = partStore ;
@@ -677,27 +676,7 @@ private CacheStoreHolder initDir(File cacheWorkDir,
677
676
* @param partId Partition id.
678
677
*/
679
678
@ NotNull private Path getPartitionFilePath (File cacheWorkDir , int partId ) {
680
- return new File (cacheWorkDir , getPartitionFileName (partId )).toPath ();
681
- }
682
-
683
- /**
684
- * @param workDir Cache work directory.
685
- * @param cacheDirName Cache directory name.
686
- * @param partId Partition id.
687
- * @return Partition file.
688
- */
689
- @ NotNull public static File getPartitionFile (File workDir , String cacheDirName , int partId ) {
690
- return new File (NodeFileTree .cacheStorage (workDir , cacheDirName ), getPartitionFileName (partId ));
691
- }
692
-
693
- /**
694
- * @param partId Partition id.
695
- * @return File name.
696
- */
697
- public static String getPartitionFileName (int partId ) {
698
- assert partId <= MAX_PARTITION_ID || partId == INDEX_PARTITION ;
699
-
700
- return partId == INDEX_PARTITION ? INDEX_FILE_NAME : format (PART_FILE_TEMPLATE , partId );
679
+ return new File (cacheWorkDir , partitionFileName (partId )).toPath ();
701
680
}
702
681
703
682
/**
@@ -822,20 +801,6 @@ public static File cacheDirectory(File dir, int grpId) {
822
801
.orElse (null );
823
802
}
824
803
825
- /**
826
- * @param partFileName Partition file name.
827
- * @return Partition id.
828
- */
829
- public static int partId (String partFileName ) {
830
- if (partFileName .equals (INDEX_FILE_NAME ))
831
- return PageIdAllocator .INDEX_PARTITION ;
832
-
833
- if (partFileName .startsWith (PART_FILE_PREFIX ))
834
- return Integer .parseInt (partFileName .substring (PART_FILE_PREFIX .length (), partFileName .indexOf ('.' )));
835
-
836
- throw new IllegalStateException ("Illegal partition file name: " + partFileName );
837
- }
838
-
839
804
/**
840
805
* @param cacheDir Cache directory to check.
841
806
* @return List of cache partitions in given directory.
@@ -896,7 +861,7 @@ public static File[] cacheDataFiles(File root) {
896
861
*/
897
862
public String cacheDirName (int grpId ) throws IgniteCheckedException {
898
863
if (grpId == MetaStorage .METASTORAGE_CACHE_ID )
899
- return MetaStorage . METASTORAGE_DIR_NAME ;
864
+ return METASTORAGE_DIR_NAME ;
900
865
901
866
CacheGroupContext gctx = cctx .cache ().cacheGroup (grpId );
902
867
0 commit comments