mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-04 17:34:14 +08:00
mdbx: drop obsolete commented-out mdbx_node_add().
Change-Id: I092469e251991921b19abb72afab19dcfb70f862
This commit is contained in:
parent
40edf7e323
commit
bcbf040f5d
125
src/mdbx.c
125
src/mdbx.c
@ -8931,131 +8931,6 @@ static int __must_check_result mdbx_node_add_leaf(MDBX_cursor *mc,
|
||||
return MDBX_SUCCESS;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* Add a node to the page pointed to by the cursor.
|
||||
* Set MDBX_TXN_ERROR on failure.
|
||||
*
|
||||
* [in] mc The cursor for this operation.
|
||||
* [in] indx The index on the page where the new node should be added.
|
||||
* [in] key The key for the new node.
|
||||
* [in] data The data for the new node, if any.
|
||||
* [in] pgno The page number, if adding a branch node.
|
||||
* [in] flags Flags for the node.
|
||||
*
|
||||
* Returns 0 on success, non-zero on failure. Possible errors are:
|
||||
*
|
||||
* MDBX_ENOMEM - failed to allocate overflow pages for the node.
|
||||
* MDBX_PAGE_FULL - there is insufficient room in the page. This error
|
||||
* should never happen since all callers already calculate
|
||||
* the page's free space before calling this function. */
|
||||
static int mdbx_node_add(MDBX_cursor *mc, unsigned indx, const MDBX_val *key,
|
||||
MDBX_val *data, pgno_t pgno, unsigned flags) {
|
||||
unsigned i;
|
||||
size_t node_size = NODESIZE;
|
||||
intptr_t room;
|
||||
MDBX_node *node;
|
||||
MDBX_page *mp = mc->mc_pg[mc->mc_top];
|
||||
MDBX_page *ofp = NULL; /* overflow page */
|
||||
void *ndata;
|
||||
|
||||
mdbx_cassert(mc, mp->mp_upper >= mp->mp_lower);
|
||||
|
||||
DKBUF;
|
||||
mdbx_debug("add to %s %spage %" PRIaPGNO " index %i, data size %" PRIuPTR
|
||||
" key size %" PRIuPTR " [%s]",
|
||||
IS_LEAF(mp) ? "leaf" : "branch", IS_SUBP(mp) ? "sub-" : "",
|
||||
mp->mp_pgno, indx, data ? data->iov_len : 0,
|
||||
key ? key->iov_len : 0, DKEY(key));
|
||||
|
||||
room = (intptr_t)SIZELEFT(mp) - (intptr_t)sizeof(indx_t);
|
||||
if (key != NULL)
|
||||
node_size += key->iov_len;
|
||||
if (IS_LEAF(mp)) {
|
||||
mdbx_cassert(mc, key && data);
|
||||
if (unlikely(F_ISSET(flags, F_BIGDATA))) {
|
||||
/* Data already on overflow page. */
|
||||
node_size += sizeof(pgno_t);
|
||||
} else if (unlikely(node_size + data->iov_len >
|
||||
mc->mc_txn->mt_env->me_nodemax)) {
|
||||
pgno_t ovpages = OVPAGES(mc->mc_txn->mt_env, data->iov_len);
|
||||
int rc;
|
||||
/* Put data on overflow page. */
|
||||
mdbx_debug("data size is %" PRIuPTR ", node would be %" PRIuPTR
|
||||
", put data on overflow page",
|
||||
data->iov_len, node_size + data->iov_len);
|
||||
node_size = EVEN(node_size + sizeof(pgno_t));
|
||||
if ((intptr_t)node_size > room)
|
||||
goto full;
|
||||
if ((rc = mdbx_page_new(mc, P_OVERFLOW, ovpages, &ofp)))
|
||||
return rc;
|
||||
mdbx_debug("allocated overflow page %" PRIaPGNO, ofp->mp_pgno);
|
||||
flags |= F_BIGDATA;
|
||||
goto update;
|
||||
} else {
|
||||
node_size += data->iov_len;
|
||||
}
|
||||
}
|
||||
node_size = EVEN(node_size);
|
||||
if (unlikely((intptr_t)node_size > room))
|
||||
goto full;
|
||||
|
||||
update:
|
||||
/* Move higher pointers up one slot. */
|
||||
for (i = NUMKEYS(mp); i > indx; i--)
|
||||
mp->mp_ptrs[i] = mp->mp_ptrs[i - 1];
|
||||
|
||||
/* Adjust free space offsets. */
|
||||
size_t ofs = mp->mp_upper - node_size;
|
||||
mdbx_cassert(mc, ofs >= mp->mp_lower + sizeof(indx_t));
|
||||
mdbx_cassert(mc, ofs <= UINT16_MAX);
|
||||
mp->mp_ptrs[indx] = (uint16_t)ofs;
|
||||
mp->mp_upper = (uint16_t)ofs;
|
||||
mp->mp_lower += sizeof(indx_t);
|
||||
|
||||
/* Write the node data. */
|
||||
node = NODEPTR(mp, indx);
|
||||
node->mn_ksize = (key == NULL) ? 0 : (uint16_t)key->iov_len;
|
||||
node->mn_flags = (uint16_t)flags;
|
||||
if (IS_LEAF(mp))
|
||||
SETDSZ(node, data->iov_len);
|
||||
else
|
||||
SETPGNO(node, pgno);
|
||||
|
||||
if (key)
|
||||
memcpy(NODEKEY(node), key->iov_base, key->iov_len);
|
||||
|
||||
if (IS_LEAF(mp)) {
|
||||
ndata = NODEDATA(node);
|
||||
if (likely(ofp == NULL)) {
|
||||
if (unlikely(F_ISSET(flags, F_BIGDATA)))
|
||||
memcpy(ndata, data->iov_base, sizeof(pgno_t));
|
||||
else if (F_ISSET(flags, MDBX_RESERVE))
|
||||
data->iov_base = ndata;
|
||||
else if (likely(ndata != data->iov_base))
|
||||
memcpy(ndata, data->iov_base, data->iov_len);
|
||||
} else {
|
||||
memcpy(ndata, &ofp->mp_pgno, sizeof(pgno_t));
|
||||
ndata = PAGEDATA(ofp);
|
||||
if (F_ISSET(flags, MDBX_RESERVE))
|
||||
data->iov_base = ndata;
|
||||
else if (likely(ndata != data->iov_base))
|
||||
memcpy(ndata, data->iov_base, data->iov_len);
|
||||
}
|
||||
}
|
||||
|
||||
return MDBX_SUCCESS;
|
||||
|
||||
full:
|
||||
mdbx_debug("not enough room in page %" PRIaPGNO ", got %u ptrs", mp->mp_pgno,
|
||||
NUMKEYS(mp));
|
||||
mdbx_debug("upper-lower = %u - %u = %" PRIiPTR, mp->mp_upper, mp->mp_lower,
|
||||
room);
|
||||
mdbx_debug("node size = %" PRIuPTR, node_size);
|
||||
mc->mc_txn->mt_flags |= MDBX_TXN_ERROR;
|
||||
return MDBX_PAGE_FULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Delete the specified node from a page.
|
||||
* [in] mc Cursor pointing to the node to delete.
|
||||
* [in] ksize The size of a node. Only used if the page is
|
||||
|
Loading…
x
Reference in New Issue
Block a user