5 #ifndef NO_SYSTEM_INCLUDES
19 #define LOG_CURSOR_HIT -1000
22 * PUBLIC: #ifdef USE_DB4_LOGGING
25 * __vi_marker_recover --
26 * Recovery function for marker.
28 * PUBLIC: int __vi_marker_recover
29 * PUBLIC: __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
32 __vi_marker_recover(dbenv
, dbtp
, lsnp
, op
, info
)
39 __vi_marker_args
*argp
;
42 REC_PRINT(__vi_marker_print
);
43 REC_NOOP_INTRO(__vi_marker_read
);
45 *lsnp
= argp
->prev_lsn
;
52 * __vi_cursor_recover --
53 * Recovery function for cursor.
55 * PUBLIC: int __vi_cursor_recover
56 * PUBLIC: __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
59 __vi_cursor_recover(dbenv
, dbtp
, lsnp
, op
, info
)
66 __vi_cursor_args
*argp
;
70 REC_PRINT(__vi_cursor_print
);
71 REC_NOOP_INTRO(__vi_cursor_read
);
73 sp
= (SCR
*)dbenv
->app_private
;
75 *lsnp
= argp
->prev_lsn
;
76 if (sp
->state
.undo
== UNDO_SETLINE
) {
77 /* Why the check for ep->l_cur ? (copied from log.c)
79 ret
= (argp
->lno
!= sp
->lno
||
80 (argp
->opcode
== LOG_CURSOR_INIT
&& sp
->ep
->l_cur
== 1))
85 (DB_UNDO(op
) ? LOG_CURSOR_INIT
: LOG_CURSOR_END
)
88 sp
->state
.pos
.lno
= argp
->lno
;
89 sp
->state
.pos
.cno
= argp
->cno
;
97 * __vi_mark_recover --
98 * Recovery function for mark.
100 * PUBLIC: int __vi_mark_recover
101 * PUBLIC: __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
104 __vi_mark_recover(dbenv
, dbtp
, lsnp
, op
, info
)
111 __vi_mark_args
*argp
;
116 REC_PRINT(__vi_mark_print
);
117 REC_NOOP_INTRO(__vi_mark_read
);
119 sp
= (SCR
*)dbenv
->app_private
;
120 *lsnp
= argp
->prev_lsn
;
121 m
.lno
= argp
->lmp
.lno
;
122 m
.cno
= argp
->lmp
.cno
;
123 ret
= mark_set(sp
, argp
->lmp
.name
, &m
, 0);
129 * __vi_change_recover --
130 * Recovery function for change.
132 * PUBLIC: int __vi_change_recover
133 * PUBLIC: __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
136 __vi_change_recover(dbenv
, dbtp
, lsnp
, op
, info
)
143 __vi_change_args
*argp
;
147 REC_PRINT(__vi_change_print
);
148 REC_NOOP_INTRO(__vi_change_read
);
152 sp
= (SCR
*)dbenv
->app_private
;
153 if (DB_UNDO(op
) != (argp
->opcode
& 1))
154 switch (argp
->opcode
) {
155 case LOG_LINE_RESET_B
:
156 case LOG_LINE_RESET_F
:
157 ret
= line_insdel(sp
, LINE_RESET
, argp
->lno
);
158 update_cache(sp
, LINE_RESET
, argp
->lno
);
159 ret
= scr_update(sp
, argp
->lno
, LINE_RESET
, 1) || ret
;
161 case LOG_LINE_APPEND_B
:
162 case LOG_LINE_DELETE_F
:
163 ret
= line_insdel(sp
, LINE_DELETE
, argp
->lno
);
164 update_cache(sp
, LINE_DELETE
, argp
->lno
);
165 ret
= scr_update(sp
, argp
->lno
, LINE_DELETE
, 1) || ret
;
167 case LOG_LINE_DELETE_B
:
168 case LOG_LINE_APPEND_F
:
169 ret
= line_insdel(sp
, LINE_INSERT
, argp
->lno
);
170 update_cache(sp
, LINE_INSERT
, argp
->lno
);
171 ret
= scr_update(sp
, argp
->lno
, LINE_INSERT
, 1) || ret
;
175 *lsnp
= argp
->prev_lsn
;
182 * PUBLIC: int __vi_log_truncate __P((EXF *ep));
185 __vi_log_truncate(EXF
*ep
)
190 return __log_vtruncate(ep
->env
, &ep
->lsn_cur
, &ckplsn
);
191 /*return __log_vtruncate(ep->env, &ep->lsn_cur, &ep->lsn_first);*/
196 * PUBLIC: int __vi_log_dispatch __P((DB_ENV *dbenv, DBT *data, DB_LSN *lsn, db_recops ops));
199 __vi_log_dispatch(DB_ENV
*dbenv
, DBT
*data
, DB_LSN
*lsn
, db_recops ops
)
204 memcpy(&rectype
, data
->data
, sizeof(rectype
));
205 snprintf(s
,100,"%d\n", rectype
);
206 return dbenv
->dtab
[rectype
](dbenv
, data
, lsn
, ops
, NULL
);
210 vi_log_get(SCR
*sp
, DB_LOGC
*logc
, DBT
*data
, u_int32_t which
)
219 BINC_GOTO(sp
, sp
->wp
->l_lp
, sp
->wp
->l_len
, nlen
);
220 memset(data
, 0, sizeof(*data
));
221 data
->data
= sp
->wp
->l_lp
;
222 data
->ulen
= sp
->wp
->l_len
;
223 data
->flags
= DB_DBT_USERMEM
;
224 switch ((sp
->db_error
= logc
->get(logc
, &ep
->lsn_cur
, data
, which
))) {
230 msgq(sp
, M_DBERR
, "logc->get");
241 * PUBLIC: int __vi_log_traverse __P((SCR *sp, undo_t undo, MARK *));
244 __vi_log_traverse(SCR
*sp
, undo_t undo
, MARK
*rp
)
256 F_SET(ep
, F_NOLOG
); /* Turn off logging. */
258 sp
->state
.undo
= undo
;
259 ep
->env
->app_private
= sp
;
260 if ((sp
->db_error
= ep
->env
->log_cursor(ep
->env
, &logc
, 0))
262 msgq(sp
, M_DBERR
, "env->log_cursor");
265 if (vi_log_get(sp
, logc
, &data
, DB_SET
))
267 if (undo
== UNDO_FORWARD
) {
268 ops
= DB_TXN_FORWARD_ROLL
;
270 if (vi_log_get(sp
, logc
, &data
, DB_NEXT
))
273 ops
= DB_TXN_BACKWARD_ROLL
;
278 MEMCPY(&lsn
, &ep
->lsn_cur
, 1);
279 ret
= __vi_log_dispatch(ep
->env
, &data
, &lsn
, ops
);
281 if (ret
== LOG_CURSOR_HIT
)
285 if (vi_log_get(sp
, logc
, &data
, which
))
287 if (undo
== UNDO_SETLINE
&&
288 log_compare(&ep
->lsn_cur
, &ep
->lsn_first
) <= 0) {
289 /* Move to previous record without dispatching. */
290 undo
= UNDO_BACKWARD
;
294 if (undo
== UNDO_BACKWARD
)
295 if (vi_log_get(sp
, logc
, &data
, DB_PREV
))
298 logc
->close(logc
, 0);
300 ep
->env
->app_private
= NULL
;
302 MEMMOVE(rp
, &sp
->state
.pos
, 1);
310 vi_db_init_recover(DB_ENV
*dbenv
)
314 if ((ret
= __db_init_recover(dbenv
)) != 0)
316 if ((ret
= __bam_init_recover(dbenv
)) != 0)