Module Name:    src
Committed By:   christos
Date:           Sat Nov 30 14:54:29 UTC 2013

Modified Files:
        src/external/bsd/nvi/dist/common: recover.c vi_db1.c

Log Message:
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


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/external/bsd/nvi/dist/common/recover.c
cvs rdiff -u -r1.4 -r1.5 src/external/bsd/nvi/dist/common/vi_db1.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/bsd/nvi/dist/common/recover.c
diff -u src/external/bsd/nvi/dist/common/recover.c:1.3 src/external/bsd/nvi/dist/common/recover.c:1.4
--- src/external/bsd/nvi/dist/common/recover.c:1.3	Wed Nov 27 16:17:36 2013
+++ src/external/bsd/nvi/dist/common/recover.c	Sat Nov 30 09:54:29 2013
@@ -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");

Index: src/external/bsd/nvi/dist/common/vi_db1.c
diff -u src/external/bsd/nvi/dist/common/vi_db1.c:1.4 src/external/bsd/nvi/dist/common/vi_db1.c:1.5
--- src/external/bsd/nvi/dist/common/vi_db1.c:1.4	Fri Nov 29 16:57:31 2013
+++ src/external/bsd/nvi/dist/common/vi_db1.c	Sat Nov 30 09:54:29 2013
@@ -685,10 +685,19 @@ db_init(SCR *sp, EXF *ep, char *rcv_name
 
 	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
 
 		*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;

Reply via email to