1/* 2 * PREF_FUNC_recover -- 3 * Recovery function for FUNC. 4 * 5 * PUBLIC: int PREF_FUNC_recover 6 * PUBLIC: __P((dbenv *, DBT *, DB_LSN *, db_recops)); 7 */ 8int 9PREF_FUNC_recover(dbenv, dbtp, lsnp, op) 10 dbenv *dbenv; 11 DBT *dbtp; 12 DB_LSN *lsnp; 13 db_recops op; 14{ 15 PREF_DUP_args *argp; 16 int cmp_n, cmp_p, modified, ret; 17 18#ifdef DEBUG_RECOVER 19 (void)PREF_DUP_print(dbenv, dbtp, lsnp, op); 20#endif 21 argp = NULL; 22 if ((ret = PREF_DUP_read(dbenv, dbtp->data, &argp)) != 0) 23 goto out; 24 25 modified = 0; 26 cmp_n = 0; 27 cmp_p = 0; 28 29 /* 30 * The function now needs to calculate cmp_n and cmp_p based 31 * on whatever is in argp (usually an LSN representing the state 32 * of an object BEFORE the operation described in this record was 33 * applied) and whatever other information the function needs, 34 * e.g., the LSN of the object as it exists now. 35 * 36 * cmp_p should be set to 0 if the current state of the object 37 * is believed to be same as the state of the object BEFORE the 38 * described operation was applied. For example, if you had an 39 * LSN in the log record (argp->prevlsn) and a current LSN of the 40 * object (curlsn), you might want to do: 41 * 42 * cmp_p = log_compare(curlsn, argp->prevlsn); 43 * 44 * Similarly, cmp_n should be set to 0 if the current state 45 * of the object reflects the object AFTER this operation has 46 * been applied. Thus, if you can figure out an object's current 47 * LSN, yo might set cmp_n as: 48 * 49 * cmp_n = log_compare(lsnp, curlsn); 50 */ 51 if (cmp_p == 0 && DB_REDO(op)) { 52 /* Need to redo update described. */ 53 modified = 1; 54 } else if (cmp_n == 0 && !DB_REDO(op)) { 55 /* Need to undo update described. */ 56 modified = 1; 57 } 58 59 /* Allow for following LSN pointers through a transaction. */ 60 *lsnp = argp->prev_lsn; 61 ret = 0; 62 63out: if (argp != NULL) 64 free(argp); 65 66 return (ret); 67} 68 69