@@ -425,7 +425,6 @@ public void mutate(BackendMutation mutation) {
425425 Lock readLock = this .storeLock .readLock ();
426426 readLock .lock ();
427427 try {
428- this .checkOpened ();
429428 if (LOG .isDebugEnabled ()) {
430429 LOG .debug ("Store {} mutation: {}" , this .store , mutation );
431430 }
@@ -490,7 +489,6 @@ public Iterator<BackendEntry> query(Query query) {
490489 readLock .lock ();
491490
492491 try {
493- this .checkOpened ();
494492 HugeType tableType = RocksDBTable .tableType (query );
495493 RocksDBTable table ;
496494 RocksDBSessions .Session session ;
@@ -525,7 +523,6 @@ public Number queryNumber(Query query) {
525523 Lock readLock = this .storeLock .readLock ();
526524 readLock .lock ();
527525 try {
528- this .checkOpened ();
529526 HugeType tableType = RocksDBTable .tableType (query );
530527 RocksDBTable table = this .table (tableType );
531528 return table .queryNumber (this .session (tableType ), query );
@@ -648,8 +645,6 @@ public void beginTx() {
648645 Lock readLock = this .storeLock .readLock ();
649646 readLock .lock ();
650647 try {
651- this .checkOpened ();
652-
653648 for (RocksDBSessions .Session session : this .session ()) {
654649 assert !session .hasChanges ();
655650 }
@@ -663,7 +658,6 @@ public void commitTx() {
663658 Lock readLock = this .storeLock .readLock ();
664659 readLock .lock ();
665660 try {
666- this .checkOpened ();
667661 // Unable to guarantee atomicity when committing multi sessions
668662 for (RocksDBSessions .Session session : this .session ()) {
669663 Object count = session .commit ();
@@ -681,8 +675,6 @@ public void rollbackTx() {
681675 Lock readLock = this .storeLock .readLock ();
682676 readLock .lock ();
683677 try {
684- this .checkOpened ();
685-
686678 for (RocksDBSessions .Session session : this .session ()) {
687679 session .rollback ();
688680 }
@@ -691,19 +683,6 @@ public void rollbackTx() {
691683 }
692684 }
693685
694- @ Override
695- protected RocksDBSessions .Session session (HugeType tableType ) {
696- this .checkOpened ();
697-
698- // Optimized disk
699- String disk = this .tableDiskMapping .get (tableType );
700- if (disk != null ) {
701- return this .db (disk ).session ();
702- }
703-
704- return this .sessions .session ();
705- }
706-
707686 @ Override
708687 public Map <String , String > createSnapshot (String snapshotPrefix ) {
709688 Lock readLock = this .storeLock .readLock ();
@@ -785,22 +764,6 @@ private void useSessions() {
785764 }
786765 }
787766
788- private List <RocksDBSessions .Session > session () {
789- this .checkOpened ();
790-
791- if (this .tableDiskMapping .isEmpty ()) {
792- return Collections .singletonList (this .sessions .session ());
793- }
794-
795- // Collect session of each table with optimized disk
796- List <RocksDBSessions .Session > list = new ArrayList <>(this .tableDiskMapping .size () + 1 );
797- list .add (this .sessions .session ());
798- for (String disk : this .tableDiskMapping .values ()) {
799- list .add (db (disk ).session ());
800- }
801- return list ;
802- }
803-
804767 private void closeSessions () {
805768 Iterator <Map .Entry <String , RocksDBSessions >> iter = this .dbs .entrySet ().iterator ();
806769 while (iter .hasNext ()) {
@@ -813,12 +776,56 @@ private void closeSessions() {
813776 }
814777 }
815778
816- private Collection <RocksDBSessions > sessions () {
779+ private final Collection <RocksDBSessions > sessions () {
817780 return this .dbs .values ();
818781 }
819782
820- private void parseTableDiskMapping (Map <String , String > disks , String dataPath ) {
783+ private final List <RocksDBSessions .Session > session () {
784+ this .checkDbOpened ();
785+
786+ // Collect session of standard disk
787+ RocksDBSessions .Session session = this .sessions .session ();
788+ if (!session .opened ()) {
789+ this .checkOpened ();
790+ }
791+
792+ if (this .tableDiskMapping .isEmpty ()) {
793+ return ImmutableList .of (session );
794+ }
821795
796+ // Collect session of each table with optimized disk
797+ List <RocksDBSessions .Session > list = new ArrayList <>(this .tableDiskMapping .size () + 1 );
798+ list .add (session );
799+ for (String disk : this .tableDiskMapping .values ()) {
800+ RocksDBSessions .Session optimizedSession = this .db (disk ).session ();
801+ assert optimizedSession .opened ();
802+ list .add (optimizedSession );
803+ }
804+ return list ;
805+ }
806+
807+ @ Override
808+ protected RocksDBSessions .Session session (HugeType tableType ) {
809+ this .checkDbOpened ();
810+
811+ RocksDBSessions .Session session ;
812+ String disk = this .tableDiskMapping .get (tableType );
813+ if (disk != null ) {
814+ // Optimized disk
815+ session = this .db (disk ).session ();
816+ } else {
817+ // Standard disk
818+ session = this .sessions .session ();
819+ }
820+
821+ if (!session .opened ()) {
822+ this .checkOpened ();
823+ }
824+ return session ;
825+ }
826+
827+ private void parseTableDiskMapping (Map <String , String > disks , String dataPath ) {
828+ // reset and parse
822829 this .tableDiskMapping .clear ();
823830 for (Map .Entry <String , String > disk : disks .entrySet ()) {
824831 // The format of `disk` like: `graph/vertex: /path/to/disk1`
@@ -869,7 +876,7 @@ private void checkDbOpened() {
869876 }
870877
871878 protected RocksDBSessions db (HugeType tableType ) {
872- this .checkOpened ();
879+ this .checkDbOpened ();
873880
874881 // Optimized disk
875882 String disk = this .tableDiskMapping .get (tableType );
0 commit comments