@@ -899,37 +899,41 @@ public long getId(Value value, boolean create) throws IOException {
899899
900900 public void gcIds (Collection <Long > ids , Collection <Long > nextIds ) throws IOException {
901901 if (!ids .isEmpty ()) {
902- // contains IDs for data types and namespaces which are freed by garbage collecting literals and URIs
903- resizeMap (writeTxn , 2 * ids .size () * (1 + Long .BYTES + 2 + Long .BYTES ));
904-
905- final Collection <Long > finalIds = ids ;
906- final Collection <Long > finalNextIds = nextIds ;
907- writeTransaction ((stack , writeTxn ) -> {
908- MDBVal revIdVal = MDBVal .calloc (stack );
909- MDBVal idVal = MDBVal .calloc (stack );
910- MDBVal dataVal = MDBVal .calloc (stack );
911-
912- ByteBuffer revIdBb = stack .malloc (1 + Long .BYTES + 2 + Long .BYTES );
913- Varint .writeUnsigned (revIdBb , revision .getRevisionId ());
914- int revLength = revIdBb .position ();
915- for (Long id : finalIds ) {
916- revIdBb .position (revLength ).limit (revIdBb .capacity ());
917- revIdVal .mv_data (id2data (revIdBb , id ).flip ());
918- // check if id has internal references and therefore cannot be deleted
919- idVal .mv_data (revIdBb .slice ().position (revLength ));
920- if (mdb_get (writeTxn , refCountsDbi , idVal , dataVal ) == 0 ) {
921- continue ;
902+ // wrap into read txn as resizeMap expects an active surrounding read txn
903+ readTransaction (env , (stack1 , txn1 ) -> {
904+ // contains IDs for data types and namespaces which are freed by garbage collecting literals and URIs
905+ resizeMap (writeTxn , 2 * ids .size () * (1 + Long .BYTES + 2 + Long .BYTES ));
906+
907+ final Collection <Long > finalIds = ids ;
908+ final Collection <Long > finalNextIds = nextIds ;
909+ writeTransaction ((stack , writeTxn ) -> {
910+ MDBVal revIdVal = MDBVal .calloc (stack );
911+ MDBVal idVal = MDBVal .calloc (stack );
912+ MDBVal dataVal = MDBVal .calloc (stack );
913+
914+ ByteBuffer revIdBb = stack .malloc (1 + Long .BYTES + 2 + Long .BYTES );
915+ Varint .writeUnsigned (revIdBb , revision .getRevisionId ());
916+ int revLength = revIdBb .position ();
917+ for (Long id : finalIds ) {
918+ revIdBb .position (revLength ).limit (revIdBb .capacity ());
919+ revIdVal .mv_data (id2data (revIdBb , id ).flip ());
920+ // check if id has internal references and therefore cannot be deleted
921+ idVal .mv_data (revIdBb .slice ().position (revLength ));
922+ if (mdb_get (writeTxn , refCountsDbi , idVal , dataVal ) == 0 ) {
923+ continue ;
924+ }
925+ // mark id as unused
926+ E (mdb_put (writeTxn , unusedDbi , revIdVal , dataVal , 0 ));
922927 }
923- // mark id as unused
924- E (mdb_put (writeTxn , unusedDbi , revIdVal , dataVal , 0 ));
925- }
926928
927- deleteValueToIdMappings (stack , writeTxn , finalIds , finalNextIds );
929+ deleteValueToIdMappings (stack , writeTxn , finalIds , finalNextIds );
928930
929- invalidateRevisionOnCommit = true ;
930- if (nextValueEvictionTime < 0 ) {
931- nextValueEvictionTime = System .currentTimeMillis () + VALUE_EVICTION_INTERVAL ;
932- }
931+ invalidateRevisionOnCommit = true ;
932+ if (nextValueEvictionTime < 0 ) {
933+ nextValueEvictionTime = System .currentTimeMillis () + VALUE_EVICTION_INTERVAL ;
934+ }
935+ return null ;
936+ });
933937 return null ;
934938 });
935939 }
0 commit comments