@@ -561,7 +561,7 @@ protected void filterUsedIds(Collection<Long> ids) throws IOException {
561561 keyBuf .clear ();
562562 Varint .writeUnsigned (keyBuf , id );
563563 keyData .mv_data (keyBuf .flip ());
564- if (mdb_get (txn , contextsDbi , keyData , valueData ) == 0 ) {
564+ if (E ( mdb_get (txn , contextsDbi , keyData , valueData )) == MDB_SUCCESS ) {
565565 it .remove ();
566566 }
567567 }
@@ -587,15 +587,15 @@ protected void filterUsedIds(Collection<Long> ids) throws IOException {
587587
588588 if (fullScan ) {
589589 long [] quad = new long [4 ];
590- int rc = mdb_cursor_get (cursor , keyData , valueData , MDB_FIRST );
591- while (rc == 0 && !ids .isEmpty ()) {
590+ int rc = E ( mdb_cursor_get (cursor , keyData , valueData , MDB_FIRST ) );
591+ while (rc == MDB_SUCCESS && !ids .isEmpty ()) {
592592 index .keyToQuad (keyData .mv_data (), quad );
593593 ids .remove (quad [0 ]);
594594 ids .remove (quad [1 ]);
595595 ids .remove (quad [2 ]);
596596 ids .remove (quad [3 ]);
597597
598- rc = mdb_cursor_get (cursor , keyData , valueData , MDB_NEXT );
598+ rc = E ( mdb_cursor_get (cursor , keyData , valueData , MDB_NEXT ) );
599599 }
600600 } else {
601601 for (Iterator <Long > it = ids .iterator (); it .hasNext ();) {
@@ -625,15 +625,15 @@ protected void filterUsedIds(Collection<Long> ids) throws IOException {
625625
626626 // set cursor to min key
627627 keyData .mv_data (keyBuf );
628- int rc = mdb_cursor_get (cursor , keyData , valueData , MDB_SET_RANGE );
628+ int rc = E ( mdb_cursor_get (cursor , keyData , valueData , MDB_SET_RANGE ) );
629629 boolean exists = false ;
630630 while (!exists && rc == 0 ) {
631631 if (mdb_cmp (txn , dbi , keyData , maxKey ) > 0 ) {
632632 // id was not found
633633 break ;
634634 } else if (!matcher .matches (keyData .mv_data ())) {
635635 // value doesn't match search key/mask, fetch next value
636- rc = mdb_cursor_get (cursor , keyData , valueData , MDB_NEXT );
636+ rc = E ( mdb_cursor_get (cursor , keyData , valueData , MDB_NEXT ) );
637637 } else {
638638 exists = true ;
639639 }
@@ -708,7 +708,7 @@ protected double cardinality(long subj, long pred, long obj, long context) throw
708708
709709 // set cursor to min key
710710 keyData .mv_data (keyBuf );
711- int rc = mdb_cursor_get (cursor , keyData , valueData , MDB_SET_RANGE );
711+ int rc = E ( mdb_cursor_get (cursor , keyData , valueData , MDB_SET_RANGE ) );
712712 if (rc != 0 || mdb_cmp (txn , dbi , keyData , maxKey ) >= 0 ) {
713713 break ;
714714 } else {
@@ -717,13 +717,13 @@ protected double cardinality(long subj, long pred, long obj, long context) throw
717717
718718 // set cursor to max key
719719 keyData .mv_data (maxKeyBuf );
720- rc = mdb_cursor_get (cursor , keyData , valueData , MDB_SET_RANGE );
720+ rc = E ( mdb_cursor_get (cursor , keyData , valueData , MDB_SET_RANGE ) );
721721 if (rc != 0 ) {
722722 // directly go to last value
723- rc = mdb_cursor_get (cursor , keyData , valueData , MDB_LAST );
723+ rc = E ( mdb_cursor_get (cursor , keyData , valueData , MDB_LAST ) );
724724 } else {
725725 // go to previous value of selected key
726- rc = mdb_cursor_get (cursor , keyData , valueData , MDB_PREV );
726+ rc = E ( mdb_cursor_get (cursor , keyData , valueData , MDB_PREV ) );
727727 }
728728 if (rc == 0 ) {
729729 Varint .readListUnsigned (keyData .mv_data (), s .maxValues );
@@ -747,8 +747,8 @@ protected double cardinality(long subj, long pred, long obj, long context) throw
747747 keyData .mv_data (keyBuf );
748748
749749 int currentSamplesCount = 0 ;
750- rc = mdb_cursor_get (cursor , keyData , valueData , MDB_SET_RANGE );
751- while (rc == 0 && currentSamplesCount < s .MAX_SAMPLES_PER_BUCKET ) {
750+ rc = E ( mdb_cursor_get (cursor , keyData , valueData , MDB_SET_RANGE ) );
751+ while (rc == MDB_SUCCESS && currentSamplesCount < s .MAX_SAMPLES_PER_BUCKET ) {
752752 if (mdb_cmp (txn , dbi , keyData , maxKey ) >= 0 ) {
753753 endOfRange = true ;
754754 break ;
@@ -776,7 +776,7 @@ protected double cardinality(long subj, long pred, long obj, long context) throw
776776 }
777777 }
778778 }
779- rc = mdb_cursor_get (cursor , keyData , valueData , MDB_NEXT );
779+ rc = E ( mdb_cursor_get (cursor , keyData , valueData , MDB_NEXT ) );
780780 if (rc != 0 ) {
781781 // no more elements are available
782782 endOfRange = true ;
@@ -862,6 +862,7 @@ public boolean storeTriple(long subj, long pred, long obj, long context, boolean
862862 logger .debug ("resize of map size {} required while adding - initialize record cache" , mapSize );
863863 }
864864 }
865+
865866 if (recordCache != null ) {
866867 long quad [] = new long [] { subj , pred , obj , context };
867868 if (explicit ) {
@@ -872,7 +873,7 @@ public boolean storeTriple(long subj, long pred, long obj, long context, boolean
872873 return recordCache .storeRecord (quad , explicit );
873874 }
874875
875- int rc = mdb_put (writeTxn , mainIndex .getDB (explicit ), keyVal , dataVal , MDB_NOOVERWRITE );
876+ int rc = E ( mdb_put (writeTxn , mainIndex .getDB (explicit ), keyVal , dataVal , MDB_NOOVERWRITE ) );
876877 if (rc != MDB_SUCCESS && rc != MDB_KEYEXIST ) {
877878 throw new IOException (mdb_strerror (rc ));
878879 }
@@ -884,6 +885,7 @@ public boolean storeTriple(long subj, long pred, long obj, long context, boolean
884885
885886 if (stAdded ) {
886887 for (int i = 1 ; i < indexes .size (); i ++) {
888+
887889 TripleIndex index = indexes .get (i );
888890 keyBuf .clear ();
889891 index .toKey (keyBuf , subj , pred , obj , context );
@@ -918,7 +920,7 @@ private void incrementContext(MemoryStack stack, long context) throws IOExceptio
918920 idVal .mv_data (bb );
919921 MDBVal dataVal = MDBVal .calloc (stack );
920922 long newCount = 1 ;
921- if (mdb_get (writeTxn , contextsDbi , idVal , dataVal ) == 0 ) {
923+ if (E ( mdb_get (writeTxn , contextsDbi , idVal , dataVal )) == MDB_SUCCESS ) {
922924 // update count
923925 newCount = Varint .readUnsigned (dataVal .mv_data ()) + 1 ;
924926 }
@@ -942,7 +944,7 @@ private boolean decrementContext(MemoryStack stack, long context) throws IOExcep
942944 bb .flip ();
943945 idVal .mv_data (bb );
944946 MDBVal dataVal = MDBVal .calloc (stack );
945- if (mdb_get (writeTxn , contextsDbi , idVal , dataVal ) == 0 ) {
947+ if (E ( mdb_get (writeTxn , contextsDbi , idVal , dataVal )) == MDB_SUCCESS ) {
946948 // update count
947949 long newCount = Varint .readUnsigned (dataVal .mv_data ()) - 1 ;
948950 if (newCount <= 0 ) {
@@ -953,7 +955,7 @@ private boolean decrementContext(MemoryStack stack, long context) throws IOExcep
953955 ByteBuffer countBb = stack .malloc (Varint .calcLengthUnsigned (newCount ));
954956 Varint .writeUnsigned (countBb , newCount );
955957 dataVal .mv_data (countBb .flip ());
956- mdb_put (writeTxn , contextsDbi , idVal , dataVal , 0 );
958+ E ( mdb_put (writeTxn , contextsDbi , idVal , dataVal , 0 ) );
957959 }
958960 }
959961 return false ;
@@ -980,7 +982,7 @@ public void removeTriplesByContext(long subj, long pred, long obj, long context,
980982 }
981983
982984 public void removeTriples (RecordIterator it , boolean explicit , Consumer <long []> handler ) throws IOException {
983- try (MemoryStack stack = MemoryStack .stackPush ()) {
985+ try (it ; MemoryStack stack = MemoryStack .stackPush ()) {
984986 MDBVal keyValue = MDBVal .callocStack (stack );
985987 ByteBuffer keyBuf = stack .malloc (MAX_KEY_LENGTH );
986988
@@ -1013,8 +1015,6 @@ public void removeTriples(RecordIterator it, boolean explicit, Consumer<long[]>
10131015 decrementContext (stack , quad [CONTEXT_IDX ]);
10141016 handler .accept (quad );
10151017 }
1016- } finally {
1017- it .close ();
10181018 }
10191019 }
10201020
0 commit comments