@ -1438,8 +1438,8 @@ mdb_page_alloc(MDB_cursor *mc, int num, MDB_page **mp)
if ( ! mop ) {
if ( ! mop ) {
if ( ! ( env - > me_pghead = mop = mdb_midl_alloc ( i ) ) )
if ( ! ( env - > me_pghead = mop = mdb_midl_alloc ( i ) ) )
return ENOMEM ;
return ENOMEM ;
} else if ( mop_len + i > mop [ - 1 ] ) {
} else {
if ( ( rc = mdb_midl_grow ( & env - > me_pghead , i ) ) ! = 0 )
if ( ( rc = mdb_midl_need ( & env - > me_pghead , i ) ) ! = 0 )
return rc ;
return rc ;
mop = env - > me_pghead ;
mop = env - > me_pghead ;
}
}
@ -1538,12 +1538,13 @@ mdb_page_touch(MDB_cursor *mc)
int rc ;
int rc ;
if ( ! F_ISSET ( mp - > mp_flags , P_DIRTY ) ) {
if ( ! F_ISSET ( mp - > mp_flags , P_DIRTY ) ) {
if ( ( rc = mdb_page_alloc ( mc , 1 , & np ) ) )
if ( ( rc = mdb_midl_need ( & txn - > mt_free_pgs , 1 ) ) | |
( rc = mdb_page_alloc ( mc , 1 , & np ) ) )
return rc ;
return rc ;
pgno = np - > mp_pgno ;
pgno = np - > mp_pgno ;
DPRINTF ( " touched db %u page %zu -> %zu " , mc - > mc_dbi , mp - > mp_pgno , pgno ) ;
DPRINTF ( " touched db %u page %zu -> %zu " , mc - > mc_dbi , mp - > mp_pgno , pgno ) ;
assert ( mp - > mp_pgno ! = pgno ) ;
assert ( mp - > mp_pgno ! = pgno ) ;
mdb_midl_append ( & txn - > mt_free_pgs , mp - > mp_pgno ) ;
mdb_midl_x append ( txn - > mt_free_pgs , mp - > mp_pgno ) ;
/* Update the parent page, if any, to point to the new page */
/* Update the parent page, if any, to point to the new page */
if ( mc - > mc_top ) {
if ( mc - > mc_top ) {
MDB_page * parent = mc - > mc_pg [ mc - > mc_top - 1 ] ;
MDB_page * parent = mc - > mc_pg [ mc - > mc_top - 1 ] ;
@ -4207,16 +4208,11 @@ mdb_ovpage_free(MDB_cursor *mc, MDB_page *mp)
*/
*/
if ( ( mp - > mp_flags & P_DIRTY ) & & ! txn - > mt_parent & & txn - > mt_env - > me_pghead ) {
if ( ( mp - > mp_flags & P_DIRTY ) & & ! txn - > mt_parent & & txn - > mt_env - > me_pghead ) {
unsigned j , x ;
unsigned j , x ;
pgno_t * mop = txn - > mt_env - > me_pghead ;
pgno_t * mop ;
MDB_ID2 * dl , ix , iy ;
MDB_ID2 * dl , ix , iy ;
/* Prepare to insert pg */
rc = mdb_midl_need ( & txn - > mt_env - > me_pghead , ovpages ) ;
j = mop [ 0 ] + ovpages ;
if ( rc )
if ( j > mop [ - 1 ] ) {
return rc ;
rc = mdb_midl_grow ( & mop , ovpages ) ;
if ( rc )
return rc ;
txn - > mt_env - > me_pghead = mop ;
}
/* Remove from dirty list */
/* Remove from dirty list */
dl = txn - > mt_u . dirty_list ;
dl = txn - > mt_u . dirty_list ;
x = dl [ 0 ] . mid - - ;
x = dl [ 0 ] . mid - - ;
@ -4231,16 +4227,17 @@ mdb_ovpage_free(MDB_cursor *mc, MDB_page *mp)
}
}
}
}
/* Insert in me_pghead */
/* Insert in me_pghead */
mop = txn - > mt_env - > me_pghead ;
j = mop [ 0 ] + ovpages ;
for ( i = mop [ 0 ] ; i & & mop [ i ] < pg ; i - - )
for ( i = mop [ 0 ] ; i & & mop [ i ] < pg ; i - - )
mop [ j - - ] = mop [ i ] ;
mop [ j - - ] = mop [ i ] ;
while ( j > i )
while ( j > i )
mop [ j - - ] = pg + + ;
mop [ j - - ] = pg + + ;
mop [ 0 ] + = ovpages ;
mop [ 0 ] + = ovpages ;
} else {
} else {
for ( i = 0 ; i < ovpages ; i + + ) {
rc = mdb_midl_append_range ( & txn - > mt_free_pgs , pg , ovpages ) ;
mdb_midl_append ( & txn - > mt_free_pgs , pg ) ;
if ( rc )
pg + + ;
return rc ;
}
}
}
mc - > mc_db - > md_overflow_pages - = ovpages ;
mc - > mc_db - > md_overflow_pages - = ovpages ;
return 0 ;
return 0 ;
@ -5229,7 +5226,8 @@ current:
memcpy ( METADATA ( omp ) , data - > mv_data , data - > mv_size ) ;
memcpy ( METADATA ( omp ) , data - > mv_data , data - > mv_size ) ;
goto done ;
goto done ;
} else {
} else {
mdb_ovpage_free ( mc , omp ) ;
if ( ( rc2 = mdb_ovpage_free ( mc , omp ) ) ! = MDB_SUCCESS )
return rc2 ;
}
}
} else if ( NODEDSZ ( leaf ) = = data - > mv_size ) {
} else if ( NODEDSZ ( leaf ) = = data - > mv_size ) {
/* same size, just replace it. Note that we could
/* same size, just replace it. Note that we could
@ -6308,7 +6306,10 @@ mdb_page_merge(MDB_cursor *csrc, MDB_cursor *cdst)
return rc ;
return rc ;
}
}
mdb_midl_append ( & csrc - > mc_txn - > mt_free_pgs , csrc - > mc_pg [ csrc - > mc_top ] - > mp_pgno ) ;
rc = mdb_midl_append ( & csrc - > mc_txn - > mt_free_pgs ,
csrc - > mc_pg [ csrc - > mc_top ] - > mp_pgno ) ;
if ( rc )
return rc ;
if ( IS_LEAF ( csrc - > mc_pg [ csrc - > mc_top ] ) )
if ( IS_LEAF ( csrc - > mc_pg [ csrc - > mc_top ] ) )
csrc - > mc_db - > md_leaf_pages - - ;
csrc - > mc_db - > md_leaf_pages - - ;
else
else
@ -6409,7 +6410,9 @@ mdb_rebalance(MDB_cursor *mc)
mc - > mc_db - > md_root = P_INVALID ;
mc - > mc_db - > md_root = P_INVALID ;
mc - > mc_db - > md_depth = 0 ;
mc - > mc_db - > md_depth = 0 ;
mc - > mc_db - > md_leaf_pages = 0 ;
mc - > mc_db - > md_leaf_pages = 0 ;
mdb_midl_append ( & mc - > mc_txn - > mt_free_pgs , mp - > mp_pgno ) ;
rc = mdb_midl_append ( & mc - > mc_txn - > mt_free_pgs , mp - > mp_pgno ) ;
if ( rc )
return rc ;
/* Adjust cursors pointing to mp */
/* Adjust cursors pointing to mp */
mc - > mc_snum = 0 ;
mc - > mc_snum = 0 ;
mc - > mc_top = 0 ;
mc - > mc_top = 0 ;
@ -6434,7 +6437,9 @@ mdb_rebalance(MDB_cursor *mc)
}
}
} else if ( IS_BRANCH ( mp ) & & NUMKEYS ( mp ) = = 1 ) {
} else if ( IS_BRANCH ( mp ) & & NUMKEYS ( mp ) = = 1 ) {
DPUTS ( " collapsing root page! " ) ;
DPUTS ( " collapsing root page! " ) ;
mdb_midl_append ( & mc - > mc_txn - > mt_free_pgs , mp - > mp_pgno ) ;
rc = mdb_midl_append ( & mc - > mc_txn - > mt_free_pgs , mp - > mp_pgno ) ;
if ( rc )
return rc ;
mc - > mc_db - > md_root = NODEPGNO ( NODEPTR ( mp , 0 ) ) ;
mc - > mc_db - > md_root = NODEPGNO ( NODEPTR ( mp , 0 ) ) ;
rc = mdb_page_get ( mc - > mc_txn , mc - > mc_db - > md_root , & mc - > mc_pg [ 0 ] , NULL ) ;
rc = mdb_page_get ( mc - > mc_txn , mc - > mc_db - > md_root , & mc - > mc_pg [ 0 ] , NULL ) ;
if ( rc )
if ( rc )
@ -6539,10 +6544,9 @@ mdb_cursor_del0(MDB_cursor *mc, MDB_node *leaf)
pgno_t pg ;
pgno_t pg ;
memcpy ( & pg , NODEDATA ( leaf ) , sizeof ( pg ) ) ;
memcpy ( & pg , NODEDATA ( leaf ) , sizeof ( pg ) ) ;
if ( ( rc = mdb_page_get ( mc - > mc_txn , pg , & omp , NULL ) ) ! = 0 )
if ( ( rc = mdb_page_get ( mc - > mc_txn , pg , & omp , NULL ) ) | |
( rc = mdb_ovpage_free ( mc , omp ) ) )
return rc ;
return rc ;
assert ( IS_OVERFLOW ( omp ) ) ;
mdb_ovpage_free ( mc , omp ) ;
}
}
mdb_node_del ( mc - > mc_pg [ mc - > mc_top ] , mc - > mc_ki [ mc - > mc_top ] , mc - > mc_db - > md_pad ) ;
mdb_node_del ( mc - > mc_pg [ mc - > mc_top ] , mc - > mc_ki [ mc - > mc_top ] , mc - > mc_db - > md_pad ) ;
mc - > mc_db - > md_entries - - ;
mc - > mc_db - > md_entries - - ;
@ -7312,7 +7316,6 @@ mdb_drop0(MDB_cursor *mc, int subs)
for ( i = 0 ; i < n ; i + + ) {
for ( i = 0 ; i < n ; i + + ) {
ni = NODEPTR ( mp , i ) ;
ni = NODEPTR ( mp , i ) ;
if ( ni - > mn_flags & F_BIGDATA ) {
if ( ni - > mn_flags & F_BIGDATA ) {
int j , ovpages ;
MDB_page * omp ;
MDB_page * omp ;
pgno_t pg ;
pgno_t pg ;
memcpy ( & pg , NODEDATA ( ni ) , sizeof ( pg ) ) ;
memcpy ( & pg , NODEDATA ( ni ) , sizeof ( pg ) ) ;
@ -7320,11 +7323,10 @@ mdb_drop0(MDB_cursor *mc, int subs)
if ( rc ! = 0 )
if ( rc ! = 0 )
return rc ;
return rc ;
assert ( IS_OVERFLOW ( omp ) ) ;
assert ( IS_OVERFLOW ( omp ) ) ;
ovpages = omp - > mp_pages ;
rc = mdb_midl_append_range ( & txn - > mt_free_pgs ,
for ( j = 0 ; j < ovpages ; j + + ) {
pg , omp - > mp_pages ) ;
mdb_midl_append ( & txn - > mt_free_pgs , pg ) ;
if ( rc )
pg + + ;
return rc ;
}
} else if ( subs & & ( ni - > mn_flags & F_SUBDATA ) ) {
} else if ( subs & & ( ni - > mn_flags & F_SUBDATA ) ) {
mdb_xcursor_init1 ( mc , ni ) ;
mdb_xcursor_init1 ( mc , ni ) ;
rc = mdb_drop0 ( & mc - > mc_xcursor - > mx_cursor , 0 ) ;
rc = mdb_drop0 ( & mc - > mc_xcursor - > mx_cursor , 0 ) ;
@ -7333,12 +7335,14 @@ mdb_drop0(MDB_cursor *mc, int subs)
}
}
}
}
} else {
} else {
if ( ( rc = mdb_midl_need ( & txn - > mt_free_pgs , n ) ) ! = 0 )
return rc ;
for ( i = 0 ; i < n ; i + + ) {
for ( i = 0 ; i < n ; i + + ) {
pgno_t pg ;
pgno_t pg ;
ni = NODEPTR ( mp , i ) ;
ni = NODEPTR ( mp , i ) ;
pg = NODEPGNO ( ni ) ;
pg = NODEPGNO ( ni ) ;
/* free it */
/* free it */
mdb_midl_append ( & txn - > mt_free_pgs , pg ) ;
mdb_midl_x append ( txn - > mt_free_pgs , pg ) ;
}
}
}
}
if ( ! mc - > mc_top )
if ( ! mc - > mc_top )
@ -7358,9 +7362,11 @@ mdb_drop0(MDB_cursor *mc, int subs)
}
}
}
}
/* free it */
/* free it */
mdb_midl_append ( & txn - > mt_free_pgs , mc - > mc_db - > md_root ) ;
rc = mdb_midl_append ( & txn - > mt_free_pgs , mc - > mc_db - > md_root ) ;
} else if ( rc = = MDB_NOTFOUND ) {
rc = MDB_SUCCESS ;
}
}
return 0 ;
return rc ;
}
}
int mdb_drop ( MDB_txn * txn , MDB_dbi dbi , int del )
int mdb_drop ( MDB_txn * txn , MDB_dbi dbi , int del )