|
|
@ -745,7 +745,7 @@ typedef struct MDB_page { |
|
|
|
/** The number of overflow pages needed to store the given size. */ |
|
|
|
/** The number of overflow pages needed to store the given size. */ |
|
|
|
#define OVPAGES(size, psize) ((PAGEHDRSZ-1 + (size)) / (psize) + 1) |
|
|
|
#define OVPAGES(size, psize) ((PAGEHDRSZ-1 + (size)) / (psize) + 1) |
|
|
|
|
|
|
|
|
|
|
|
/** Link in #MDB_txn.%mt_loose_pages list */ |
|
|
|
/** Link in #MDB_txn.%mt_loose_pgs list */ |
|
|
|
#define NEXT_LOOSE_PAGE(p) (*(MDB_page **)((p) + 2)) |
|
|
|
#define NEXT_LOOSE_PAGE(p) (*(MDB_page **)((p) + 2)) |
|
|
|
|
|
|
|
|
|
|
|
/** Header for a single key/data pair within a page.
|
|
|
|
/** Header for a single key/data pair within a page.
|
|
|
@ -950,6 +950,8 @@ struct MDB_txn { |
|
|
|
* in this transaction, linked through #NEXT_LOOSE_PAGE(page). |
|
|
|
* in this transaction, linked through #NEXT_LOOSE_PAGE(page). |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
MDB_page *mt_loose_pgs; |
|
|
|
MDB_page *mt_loose_pgs; |
|
|
|
|
|
|
|
/* #Number of loose pages (#mt_loose_pgs) */ |
|
|
|
|
|
|
|
int mt_loose_count; |
|
|
|
/** The sorted list of dirty pages we temporarily wrote to disk
|
|
|
|
/** The sorted list of dirty pages we temporarily wrote to disk
|
|
|
|
* because the dirty list was full. page numbers in here are |
|
|
|
* because the dirty list was full. page numbers in here are |
|
|
|
* shifted left by 1, deleted slots have the LSB set. |
|
|
|
* shifted left by 1, deleted slots have the LSB set. |
|
|
@ -1661,6 +1663,7 @@ mdb_page_loose(MDB_cursor *mc, MDB_page *mp) |
|
|
|
mp->mp_pgno)); |
|
|
|
mp->mp_pgno)); |
|
|
|
NEXT_LOOSE_PAGE(mp) = mc->mc_txn->mt_loose_pgs; |
|
|
|
NEXT_LOOSE_PAGE(mp) = mc->mc_txn->mt_loose_pgs; |
|
|
|
mc->mc_txn->mt_loose_pgs = mp; |
|
|
|
mc->mc_txn->mt_loose_pgs = mp; |
|
|
|
|
|
|
|
mc->mc_txn->mt_loose_count++; |
|
|
|
mp->mp_flags |= P_LOOSE; |
|
|
|
mp->mp_flags |= P_LOOSE; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
int rc = mdb_midl_append(&mc->mc_txn->mt_free_pgs, pgno); |
|
|
|
int rc = mdb_midl_append(&mc->mc_txn->mt_free_pgs, pgno); |
|
|
@ -1950,6 +1953,7 @@ mdb_page_alloc(MDB_cursor *mc, int num, MDB_page **mp) |
|
|
|
if (num == 1 && txn->mt_loose_pgs) { |
|
|
|
if (num == 1 && txn->mt_loose_pgs) { |
|
|
|
np = txn->mt_loose_pgs; |
|
|
|
np = txn->mt_loose_pgs; |
|
|
|
txn->mt_loose_pgs = NEXT_LOOSE_PAGE(np); |
|
|
|
txn->mt_loose_pgs = NEXT_LOOSE_PAGE(np); |
|
|
|
|
|
|
|
txn->mt_loose_count--; |
|
|
|
DPRINTF(("db %d use loose page %"Z"u", DDBI(mc), |
|
|
|
DPRINTF(("db %d use loose page %"Z"u", DDBI(mc), |
|
|
|
np->mp_pgno)); |
|
|
|
np->mp_pgno)); |
|
|
|
*mp = np; |
|
|
|
*mp = np; |
|
|
@ -2823,30 +2827,17 @@ mdb_freelist_save(MDB_txn *txn) |
|
|
|
return rc; |
|
|
|
return rc; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Dispose of loose pages. Usually they will have all
|
|
|
|
if (!env->me_pghead) { |
|
|
|
* been used up by the time we get here. |
|
|
|
/* Put loose page numbers in mt_free_pgs, since
|
|
|
|
|
|
|
|
* we may be unable to return them to me_pghead. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
if (txn->mt_loose_pgs) { |
|
|
|
|
|
|
|
MDB_page *mp = txn->mt_loose_pgs; |
|
|
|
MDB_page *mp = txn->mt_loose_pgs; |
|
|
|
/* Just return them to freeDB */ |
|
|
|
if ((rc = mdb_midl_need(&txn->mt_free_pgs, txn->mt_loose_count)) != 0) |
|
|
|
if (env->me_pghead) { |
|
|
|
return rc; |
|
|
|
int i, j; |
|
|
|
for (; mp; mp = NEXT_LOOSE_PAGE(mp)) |
|
|
|
mop = env->me_pghead; |
|
|
|
mdb_midl_xappend(txn->mt_free_pgs, mp->mp_pgno); |
|
|
|
for (; mp; mp = NEXT_LOOSE_PAGE(mp)) { |
|
|
|
|
|
|
|
pgno_t pg = mp->mp_pgno; |
|
|
|
|
|
|
|
j = mop[0] + 1; |
|
|
|
|
|
|
|
for (i = mop[0]; i && mop[i] < pg; i--) |
|
|
|
|
|
|
|
mop[j--] = mop[i]; |
|
|
|
|
|
|
|
mop[j] = pg; |
|
|
|
|
|
|
|
mop[0] += 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
/* Oh well, they were wasted. Put on freelist */ |
|
|
|
|
|
|
|
for (; mp; mp = NEXT_LOOSE_PAGE(mp)) { |
|
|
|
|
|
|
|
mdb_midl_append(&txn->mt_free_pgs, mp->mp_pgno); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
txn->mt_loose_pgs = NULL; |
|
|
|
txn->mt_loose_pgs = NULL; |
|
|
|
|
|
|
|
txn->mt_loose_count = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* MDB_RESERVE cancels meminit in ovpage malloc (when no WRITEMAP) */ |
|
|
|
/* MDB_RESERVE cancels meminit in ovpage malloc (when no WRITEMAP) */ |
|
|
@ -2910,7 +2901,7 @@ mdb_freelist_save(MDB_txn *txn) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
mop = env->me_pghead; |
|
|
|
mop = env->me_pghead; |
|
|
|
mop_len = mop ? mop[0] : 0; |
|
|
|
mop_len = (mop ? mop[0] : 0) + txn->mt_loose_count; |
|
|
|
|
|
|
|
|
|
|
|
/* Reserve records for me_pghead[]. Split it if multi-page,
|
|
|
|
/* Reserve records for me_pghead[]. Split it if multi-page,
|
|
|
|
* to avoid searching freeDB for a page range. Use keys in |
|
|
|
* to avoid searching freeDB for a page range. Use keys in |
|
|
@ -2950,6 +2941,28 @@ mdb_freelist_save(MDB_txn *txn) |
|
|
|
total_room += head_room; |
|
|
|
total_room += head_room; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Return loose page numbers to me_pghead, though usually none are
|
|
|
|
|
|
|
|
* left at this point. The pages themselves remain in dirty_list. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
if (txn->mt_loose_pgs) { |
|
|
|
|
|
|
|
MDB_page *mp = txn->mt_loose_pgs; |
|
|
|
|
|
|
|
unsigned count = txn->mt_loose_count; |
|
|
|
|
|
|
|
MDB_IDL loose; |
|
|
|
|
|
|
|
/* Room for loose pages + temp IDL with same */ |
|
|
|
|
|
|
|
if ((rc = mdb_midl_need(&env->me_pghead, 2*count+1)) != 0) |
|
|
|
|
|
|
|
return rc; |
|
|
|
|
|
|
|
mop = env->me_pghead; |
|
|
|
|
|
|
|
loose = mop + MDB_IDL_ALLOCLEN(mop) - count; |
|
|
|
|
|
|
|
for (count = 0; mp; mp = NEXT_LOOSE_PAGE(mp)) |
|
|
|
|
|
|
|
loose[ ++count ] = mp->mp_pgno; |
|
|
|
|
|
|
|
loose[0] = count; |
|
|
|
|
|
|
|
mdb_midl_sort(loose); |
|
|
|
|
|
|
|
mdb_midl_xmerge(mop, loose); |
|
|
|
|
|
|
|
txn->mt_loose_pgs = NULL; |
|
|
|
|
|
|
|
txn->mt_loose_count = 0; |
|
|
|
|
|
|
|
mop_len = mop[0]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Fill in the reserved me_pghead records */ |
|
|
|
/* Fill in the reserved me_pghead records */ |
|
|
|
rc = MDB_SUCCESS; |
|
|
|
rc = MDB_SUCCESS; |
|
|
|
if (mop_len) { |
|
|
|
if (mop_len) { |
|
|
@ -3264,6 +3277,7 @@ mdb_txn_commit(MDB_txn *txn) |
|
|
|
for (lp = &parent->mt_loose_pgs; *lp; lp = &NEXT_LOOSE_PAGE(lp)) |
|
|
|
for (lp = &parent->mt_loose_pgs; *lp; lp = &NEXT_LOOSE_PAGE(lp)) |
|
|
|
; |
|
|
|
; |
|
|
|
*lp = txn->mt_loose_pgs; |
|
|
|
*lp = txn->mt_loose_pgs; |
|
|
|
|
|
|
|
parent->mt_loose_count += txn->mt_loose_count; |
|
|
|
|
|
|
|
|
|
|
|
parent->mt_child = NULL; |
|
|
|
parent->mt_child = NULL; |
|
|
|
mdb_midl_free(((MDB_ntxn *)txn)->mnt_pgstate.mf_pghead); |
|
|
|
mdb_midl_free(((MDB_ntxn *)txn)->mnt_pgstate.mf_pghead); |
|
|
@ -3326,6 +3340,10 @@ mdb_txn_commit(MDB_txn *txn) |
|
|
|
(rc = mdb_env_write_meta(txn))) |
|
|
|
(rc = mdb_env_write_meta(txn))) |
|
|
|
goto fail; |
|
|
|
goto fail; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Free P_LOOSE pages left behind in dirty_list */ |
|
|
|
|
|
|
|
if (!(env->me_flags & MDB_WRITEMAP)) |
|
|
|
|
|
|
|
mdb_dlist_free(txn); |
|
|
|
|
|
|
|
|
|
|
|
done: |
|
|
|
done: |
|
|
|
env->me_pglast = 0; |
|
|
|
env->me_pglast = 0; |
|
|
|
env->me_txn = NULL; |
|
|
|
env->me_txn = NULL; |
|
|
|