3 #ifndef NO_SYSTEM_INCLUDES
17 #define LOG_CURSOR_HIT -1000
20 * PUBLIC: #ifdef USE_DB4_LOGGING
23 * __vi_marker_recover --
24 * Recovery function for marker.
26 * PUBLIC: int __vi_marker_recover
27 * PUBLIC: __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
30 __vi_marker_recover(dbenv
, dbtp
, lsnp
, op
, info
)
37 __vi_marker_args
*argp
;
40 REC_PRINT(__vi_marker_print
);
41 REC_NOOP_INTRO(__vi_marker_read
);
43 *lsnp
= argp
->prev_lsn
;
50 * __vi_cursor_recover --
51 * Recovery function for cursor.
53 * PUBLIC: int __vi_cursor_recover
54 * PUBLIC: __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
57 __vi_cursor_recover(dbenv
, dbtp
, lsnp
, op
, info
)
64 __vi_cursor_args
*argp
;
68 REC_PRINT(__vi_cursor_print
);
69 REC_NOOP_INTRO(__vi_cursor_read
);
71 sp
= (SCR
*)dbenv
->app_private
;
73 *lsnp
= argp
->prev_lsn
;
74 if (sp
->state
.undo
== UNDO_SETLINE
) {
75 /* Why the check for ep->l_cur ? (copied from log.c)
77 ret
= (argp
->lno
!= sp
->lno
||
78 (argp
->opcode
== LOG_CURSOR_INIT
&& sp
->ep
->l_cur
== 1))
83 (DB_UNDO(op
) ? LOG_CURSOR_INIT
: LOG_CURSOR_END
)
86 sp
->state
.pos
.lno
= argp
->lno
;
87 sp
->state
.pos
.cno
= argp
->cno
;
95 * __vi_mark_recover --
96 * Recovery function for mark.
98 * PUBLIC: int __vi_mark_recover
99 * PUBLIC: __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
102 __vi_mark_recover(dbenv
, dbtp
, lsnp
, op
, info
)
109 __vi_mark_args
*argp
;
114 REC_PRINT(__vi_mark_print
);
115 REC_NOOP_INTRO(__vi_mark_read
);
117 sp
= (SCR
*)dbenv
->app_private
;
118 *lsnp
= argp
->prev_lsn
;
119 m
.lno
= argp
->lmp
.lno
;
120 m
.cno
= argp
->lmp
.cno
;
121 ret
= mark_set(sp
, argp
->lmp
.name
, &m
, 0);
127 * __vi_change_recover --
128 * Recovery function for change.
130 * PUBLIC: int __vi_change_recover
131 * PUBLIC: __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
134 __vi_change_recover(dbenv
, dbtp
, lsnp
, op
, info
)
141 __vi_change_args
*argp
;
145 REC_PRINT(__vi_change_print
);
146 REC_NOOP_INTRO(__vi_change_read
);
150 sp
= (SCR
*)dbenv
->app_private
;
151 if (DB_UNDO(op
) != (argp
->opcode
& 1))
152 switch (argp
->opcode
) {
153 case LOG_LINE_RESET_B
:
154 case LOG_LINE_RESET_F
:
155 ret
= line_insdel(sp
, LINE_RESET
, argp
->lno
);
156 update_cache(sp
, LINE_RESET
, argp
->lno
);
157 ret
= scr_update(sp
, argp
->lno
, LINE_RESET
, 1) || ret
;
159 case LOG_LINE_APPEND_B
:
160 case LOG_LINE_DELETE_F
:
161 ret
= line_insdel(sp
, LINE_DELETE
, argp
->lno
);
162 update_cache(sp
, LINE_DELETE
, argp
->lno
);
163 ret
= scr_update(sp
, argp
->lno
, LINE_DELETE
, 1) || ret
;
165 case LOG_LINE_DELETE_B
:
166 case LOG_LINE_APPEND_F
:
167 ret
= line_insdel(sp
, LINE_INSERT
, argp
->lno
);
168 update_cache(sp
, LINE_INSERT
, argp
->lno
);
169 ret
= scr_update(sp
, argp
->lno
, LINE_INSERT
, 1) || ret
;
173 *lsnp
= argp
->prev_lsn
;
180 * PUBLIC: int __vi_log_truncate __P((EXF *ep));
183 __vi_log_truncate(EXF
*ep
)
188 return __log_vtruncate(ep
->env
, &ep
->lsn_cur
, &ckplsn
);
189 /*return __log_vtruncate(ep->env, &ep->lsn_cur, &ep->lsn_first);*/
194 * PUBLIC: int __vi_log_dispatch __P((DB_ENV *dbenv, DBT *data, DB_LSN *lsn, db_recops ops));
197 __vi_log_dispatch(DB_ENV
*dbenv
, DBT
*data
, DB_LSN
*lsn
, db_recops ops
)
202 memcpy(&rectype
, data
->data
, sizeof(rectype
));
203 snprintf(s
,100,"%d\n", rectype
);
204 return dbenv
->dtab
[rectype
](dbenv
, data
, lsn
, ops
, NULL
);
208 vi_log_get(SCR
*sp
, DB_LOGC
*logc
, DBT
*data
, u_int32_t which
)
217 BINC_GOTO(sp
, sp
->wp
->l_lp
, sp
->wp
->l_len
, nlen
);
218 memset(data
, 0, sizeof(*data
));
219 data
->data
= sp
->wp
->l_lp
;
220 data
->ulen
= sp
->wp
->l_len
;
221 data
->flags
= DB_DBT_USERMEM
;
222 switch ((sp
->db_error
= logc
->get(logc
, &ep
->lsn_cur
, data
, which
))) {
228 msgq(sp
, M_DBERR
, "logc->get");
239 * PUBLIC: int __vi_log_traverse __P((SCR *sp, undo_t undo, MARK *));
242 __vi_log_traverse(SCR
*sp
, undo_t undo
, MARK
*rp
)
254 F_SET(ep
, F_NOLOG
); /* Turn off logging. */
256 sp
->state
.undo
= undo
;
257 ep
->env
->app_private
= sp
;
258 if ((sp
->db_error
= ep
->env
->log_cursor(ep
->env
, &logc
, 0))
260 msgq(sp
, M_DBERR
, "env->log_cursor");
263 if (vi_log_get(sp
, logc
, &data
, DB_SET
))
265 if (undo
== UNDO_FORWARD
) {
266 ops
= DB_TXN_FORWARD_ROLL
;
268 if (vi_log_get(sp
, logc
, &data
, DB_NEXT
))
271 ops
= DB_TXN_BACKWARD_ROLL
;
276 MEMCPY(&lsn
, &ep
->lsn_cur
, 1);
277 ret
= __vi_log_dispatch(ep
->env
, &data
, &lsn
, ops
);
279 if (ret
== LOG_CURSOR_HIT
)
283 if (vi_log_get(sp
, logc
, &data
, which
))
285 if (undo
== UNDO_SETLINE
&&
286 log_compare(&ep
->lsn_cur
, &ep
->lsn_first
) <= 0) {
287 /* Move to previous record without dispatching. */
288 undo
= UNDO_BACKWARD
;
292 if (undo
== UNDO_BACKWARD
)
293 if (vi_log_get(sp
, logc
, &data
, DB_PREV
))
296 logc
->close(logc
, 0);
298 ep
->env
->app_private
= NULL
;
300 MEMMOVE(rp
, &sp
->state
.pos
, 1);
308 vi_db_init_recover(DB_ENV
*dbenv
)
312 if ((ret
= __db_init_recover(dbenv
)) != 0)
314 if ((ret
= __bam_init_recover(dbenv
)) != 0)