From 0481af84d950138597ad9c075b9ff7063fe60f9e Mon Sep 17 00:00:00 2001 From: christos Date: Sat, 30 Nov 2013 14:54:29 +0000 Subject: [PATCH] Fix recovery mode, there were multiple issues: 1. the btree filename was not set so that we always used a transient in-memory db for the data 2. we did not call sync after creation with R_RECNOSYNC so that the header of the btree was never written 3. we did not call the right flavor of sync before copying the tree to the preserved files --- external/bsd/nvi/dist/common/recover.c | 12 ++++++++++-- external/bsd/nvi/dist/common/vi_db1.c | 23 +++++++++++++++++++---- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/external/bsd/nvi/dist/common/recover.c b/external/bsd/nvi/dist/common/recover.c index 779fe743981b..0776ef83f7c0 100644 --- a/external/bsd/nvi/dist/common/recover.c +++ b/external/bsd/nvi/dist/common/recover.c @@ -1,4 +1,4 @@ -/* $NetBSD: recover.c,v 1.3 2013/11/27 21:17:36 christos Exp $ */ +/* $NetBSD: recover.c,v 1.4 2013/11/30 14:54:29 christos Exp $ */ /*- * Copyright (c) 1993, 1994 * The Regents of the University of California. All rights reserved. @@ -260,7 +260,15 @@ rcv_sync(SCR *sp, u_int flags) /* Sync the file if it's been modified. */ if (F_ISSET(ep, F_MODIFIED)) { - if (ep->db->sync(ep->db, 0)) { + /* + * If we are using a db1 version of the database, + * we want to sync the underlying btree not the + * recno tree which is transient anyway. + */ +#ifndef R_RECNOSYNC +#define R_RECNOSYNC 0 +#endif + if (ep->db->sync(ep->db, R_RECNOSYNC)) { F_CLR(ep, F_RCV_ON | F_RCV_NORM); msgq_str(sp, M_SYSERR, ep->rcv_path, "060|File backup failed: %s"); diff --git a/external/bsd/nvi/dist/common/vi_db1.c b/external/bsd/nvi/dist/common/vi_db1.c index f892ad6b47bc..471ee957fcdd 100644 --- a/external/bsd/nvi/dist/common/vi_db1.c +++ b/external/bsd/nvi/dist/common/vi_db1.c @@ -685,10 +685,19 @@ db_init(SCR *sp, EXF *ep, char *rcv_name, char *oname, size_t psize, int *open_e memset(&oinfo, 0, sizeof(RECNOINFO)); oinfo.bval = '\n'; /* Always set. */ - oinfo.psize = psize; - oinfo.flags = R_SNAPSHOT; - if (rcv_name) - oinfo.bfname = ep->rcv_path; + /* + * If we are not recovering, set the pagesize and arrange to + * first get a snapshot of the file. + */ + if (rcv_name == NULL) { + oinfo.psize = psize; + oinfo.flags = R_SNAPSHOT; + } + /* + * Always set the btree name, otherwise we are going to be using + * an in-memory database for the btree. + */ + oinfo.bfname = ep->rcv_path; #define _DB_OPEN_MODE S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH @@ -709,6 +718,12 @@ db_init(SCR *sp, EXF *ep, char *rcv_name, char *oname, size_t psize, int *open_e *open_err = 1; return 1; + } else { + /* + * We always sync the underlying btree so that the header + * is written first + */ + ep->db->sync(ep->db, R_RECNOSYNC); } return 0;