Asterisk - The Open Source Telephony Project GIT-master-f3e88d3
Functions
rec_delete.c File Reference
#include <sys/types.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include "../include/db.h"
#include "recno.h"
Include dependency graph for rec_delete.c:

Go to the source code of this file.

Functions

static int rec_rdelete __P ((BTREE *, recno_t))
 
int __rec_delete (DB *dbp, const DBT *key, u_int flags) const
 
int __rec_dleaf (BTREE *t, PAGE *h, u_int32_t idx)
 
static int rec_rdelete (BTREE *t, recno_t nrec)
 

Function Documentation

◆ __P()

static int rec_rdelete __P ( (BTREE *, recno_t )
static

◆ __rec_delete()

int __rec_delete ( DB dbp,
const DBT key,
u_int  flags 
) const

Definition at line 64 of file rec_delete.c.

68{
69 BTREE *t;
70 recno_t nrec;
71 int status;
72
73 t = dbp->internal;
74
75 /* Toss any page pinned across calls. */
76 if (t->bt_pinned != NULL) {
77 mpool_put(t->bt_mp, t->bt_pinned, 0);
78 t->bt_pinned = NULL;
79 }
80
81 switch(flags) {
82 case 0:
83 if ((nrec = *(recno_t *)key->data) == 0)
84 goto einval;
85 if (nrec > t->bt_nrecs)
86 return (RET_SPECIAL);
87 --nrec;
88 status = rec_rdelete(t, nrec);
89 break;
90 case R_CURSOR:
91 if (!F_ISSET(&t->bt_cursor, CURS_INIT))
92 goto einval;
93 if (t->bt_nrecs == 0)
94 return (RET_SPECIAL);
96 if (status == RET_SUCCESS)
97 --t->bt_cursor.rcursor;
98 break;
99 default:
100einval: errno = EINVAL;
101 return (RET_ERROR);
102 }
103
104 if (status == RET_SUCCESS)
106 return (status);
107}
jack_status_t status
Definition: app_jack.c:146
#define F_ISSET(p, f)
Definition: btree.h:42
#define B_MODIFIED
Definition: btree.h:370
#define R_MODIFIED
Definition: btree.h:382
#define CURS_INIT
Definition: btree.h:291
#define F_SET(p, f)
Definition: btree.h:40
#define R_CURSOR
Definition: db.h:91
#define RET_SUCCESS
Definition: db.h:52
u_int32_t recno_t
Definition: db.h:82
#define RET_ERROR
Definition: db.h:51
#define RET_SPECIAL
Definition: db.h:53
static DB * dbp
Definition: hsearch.c:49
int errno
int mpool_put(MPOOL *mp, void *page, u_int flags)
Definition: mpool.c:251
static int rec_rdelete(BTREE *t, recno_t nrec)
Definition: rec_delete.c:120
#define NULL
Definition: resample.c:96
void * data
Definition: db.h:86
void * internal
Definition: db.h:137
Definition: btree.h:312
CURSOR bt_cursor
Definition: btree.h:320
MPOOL * bt_mp
Definition: btree.h:313
PAGE * bt_pinned
Definition: btree.h:318
recno_t bt_nrecs
Definition: btree.h:360
recno_t rcursor
Definition: btree.h:286

References B_MODIFIED, _btree::bt_cursor, _btree::bt_mp, _btree::bt_nrecs, _btree::bt_pinned, CURS_INIT, DBT::data, dbp, errno, F_ISSET, F_SET, __db::internal, mpool_put(), NULL, R_CURSOR, R_MODIFIED, _cursor::rcursor, rec_rdelete(), RET_ERROR, RET_SPECIAL, RET_SUCCESS, and status.

Referenced by __rec_open().

◆ __rec_dleaf()

int __rec_dleaf ( BTREE t,
PAGE h,
u_int32_t  idx 
)

Definition at line 154 of file rec_delete.c.

158{
159 RLEAF *rl;
160 indx_t *ip, cnt, offset;
161 u_int32_t nbytes;
162 char *from;
163 void *to;
164
165 /*
166 * Delete a record from a recno leaf page. Internal records are never
167 * deleted from internal pages, regardless of the records that caused
168 * them to be added being deleted. Pages made empty by deletion are
169 * not reclaimed. They are, however, made available for reuse.
170 *
171 * Pack the remaining entries at the end of the page, shift the indices
172 * down, overwriting the deleted record and its index. If the record
173 * uses overflow pages, make them available for reuse.
174 */
175 to = rl = GETRLEAF(h, idx);
176 if (rl->flags & P_BIGDATA && __ovfl_delete(t, rl->bytes) == RET_ERROR)
177 return (RET_ERROR);
178 nbytes = NRLEAF(rl);
179
180 /*
181 * Compress the key/data pairs. Compress and adjust the [BR]LEAF
182 * offsets. Reset the headers.
183 */
184 from = (char *)h + h->upper;
185 memmove(from + nbytes, from, (char *)to - from);
186 h->upper += nbytes;
187
188 offset = h->linp[idx];
189 for (cnt = &h->linp[idx] - (ip = &h->linp[0]); cnt--; ++ip)
190 if (ip[0] < offset)
191 ip[0] += nbytes;
192 for (cnt = &h->linp[NEXTINDEX(h)] - ip; --cnt; ++ip)
193 ip[0] = ip[1] < offset ? ip[1] + nbytes : ip[1];
194 h->lower -= sizeof(indx_t);
195 --t->bt_nrecs;
196 return (RET_SUCCESS);
197}
int __ovfl_delete(BTREE *t, void *p)
Definition: bt_overflow.c:193
#define NRLEAF(p)
Definition: btree.h:224
#define NEXTINDEX(p)
Definition: btree.h:98
#define P_BIGDATA
Definition: btree.h:131
#define GETRLEAF(pg, indx)
Definition: btree.h:220
u_int16_t indx_t
Definition: db.h:80
unsigned int u_int32_t
indx_t lower
Definition: btree.h:89
indx_t upper
Definition: btree.h:90
indx_t linp[1]
Definition: btree.h:91
Definition: btree.h:213
u_char flags
Definition: btree.h:215
char bytes[1]
Definition: btree.h:216

References __ovfl_delete(), _btree::bt_nrecs, _rleaf::bytes, _rleaf::flags, GETRLEAF, _page::linp, _page::lower, NEXTINDEX, NRLEAF, P_BIGDATA, RET_ERROR, RET_SUCCESS, and _page::upper.

Referenced by __rec_iput(), and rec_rdelete().

◆ rec_rdelete()

static int rec_rdelete ( BTREE t,
recno_t  nrec 
)
static

Definition at line 120 of file rec_delete.c.

123{
124 EPG *e;
125 PAGE *h;
126 int status;
127
128 /* Find the record; __rec_search pins the page. */
129 if ((e = __rec_search(t, nrec, SDELETE)) == NULL)
130 return (RET_ERROR);
131
132 /* Delete the record. */
133 h = e->page;
134 status = __rec_dleaf(t, h, e->index);
135 if (status != RET_SUCCESS) {
136 mpool_put(t->bt_mp, h, 0);
137 return (status);
138 }
140 return (RET_SUCCESS);
141}
#define MPOOL_DIRTY
Definition: mpool.h:61
int __rec_dleaf(BTREE *t, PAGE *h, u_int32_t idx)
Definition: rec_delete.c:154
EPG * __rec_search(BTREE *t, recno_t recno, enum SRCHOP op)
Definition: rec_search.c:64
@ SDELETE
Definition: recno.h:36
Definition: btree.h:254
indx_t index
Definition: btree.h:256
PAGE * page
Definition: btree.h:255
Definition: btree.h:75

References __rec_dleaf(), __rec_search(), _btree::bt_mp, _epg::index, MPOOL_DIRTY, mpool_put(), NULL, _epg::page, RET_ERROR, RET_SUCCESS, SDELETE, and status.

Referenced by __rec_delete().