changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > ventivac / changeset: do a "sync" when a client disconnect.

changeset 89: 301697094735
parent 88: 9cd17b4554ae
child 90: ac5d87081700
author: Mechiel Lukkien <mechiel@ueber.net>
date: Fri, 20 Jul 2007 14:23:15 +0200
files: appl/cmd/ventisrv.b
description: do a "sync" when a client disconnect.

this is especially necessary when using compression, since blocksg et buffered in memory. previously, without an explicit sync by a client (which they should do), data would never be synced. this is a bit safer.
     1.1--- a/appl/cmd/ventisrv.b	Fri Jul 20 14:03:57 2007 +0200
     1.2+++ b/appl/cmd/ventisrv.b	Fri Jul 20 14:23:15 2007 +0200
     1.3@@ -1,5 +1,4 @@
     1.4 # ideas
     1.5-# - sync when client disconnects?  sync periodically?
     1.6 # - tool for diagnosing problems in index file and data file
     1.7 
     1.8 # - speedup syncing index file from data file at startup?
     1.9@@ -843,7 +842,8 @@
    1.10 			}
    1.11 		Sync =>
    1.12 			if(lasterr != nil) {
    1.13-				syncdonec<- = (ref Vmsg.Rerror(0, st.tid, lasterr), st.c);
    1.14+				if(st.c != nil)
    1.15+					syncdonec<- = (ref Vmsg.Rerror(0, st.tid, lasterr), st.c);
    1.16 				continue;
    1.17 			}
    1.18 			rmsg: ref Vmsg;
    1.19@@ -853,7 +853,8 @@
    1.20 					err = "compress/write: "+err;
    1.21 					seterror(err);
    1.22 					rmsg = ref Vmsg.Rerror(0, st.tid, err);
    1.23-					syncdonec<- = (rmsg, st.c);
    1.24+					if(st.c != nil)
    1.25+						syncdonec<- = (rmsg, st.c);
    1.26 					continue;
    1.27 				}
    1.28 			}
    1.29@@ -863,7 +864,8 @@
    1.30 				rmsg = ref Vmsg.Rerror(0, st.tid, sprint("syncing: %r"));
    1.31 				seterror(sprint("syncing: %r"));
    1.32 			}
    1.33-			syncdonec<- = (rmsg, st.c);
    1.34+			if(st.c != nil)
    1.35+				syncdonec<- = (rmsg, st.c);
    1.36 			if(debug) say("writer: sync is done");
    1.37 		}
    1.38 	}
    1.39@@ -898,6 +900,14 @@
    1.40 	if(debug) say("main: rmsg from reader handled");
    1.41 }
    1.42 
    1.43+takewrites()
    1.44+{
    1.45+	while(nreaderwrites > 0) {
    1.46+		(iswrite, rm, rc) := <-lookupdonec;
    1.47+		lookupdone(iswrite, rm, rc);
    1.48+	}
    1.49+}
    1.50+
    1.51 ticker(c: chan of int)
    1.52 {
    1.53 	for(;;) {
    1.54@@ -974,6 +984,10 @@
    1.55 	(ok, c) := <-wrotec =>
    1.56 		if(debug) say("main: client wrote vmsg");
    1.57 		if(ok == 0) {
    1.58+			if(writeerror == nil && !c.readonly) {
    1.59+				takewrites();
    1.60+				storec<- = ref Store.Sync(nil, 0);
    1.61+			}
    1.62 			killc(c);
    1.63 			if(debug) say("main: client killed after write error");
    1.64 		} else
    1.65@@ -982,6 +996,10 @@
    1.66 	(vmsg, c) := <-reqc =>
    1.67 		if(debug) say("main: client read message: "+vmsg.text());
    1.68 		if(vmsg == nil) {
    1.69+			if(writeerror == nil && !c.readonly) {
    1.70+				takewrites();
    1.71+				storec<- = ref Store.Sync(nil, 0);
    1.72+			}
    1.73 			killc(c);
    1.74 			if(debug) say("main: client killed after read error");
    1.75 			continue;
    1.76@@ -1060,10 +1078,7 @@
    1.77 			if(nowritemsg != nil) {
    1.78 				c.respc<- = ref Vmsg.Rerror(0, tmsg.tid, nowritemsg);
    1.79 			} else {
    1.80-				while(nreaderwrites > 0) {
    1.81-					(iswrite, rm, rc) := <-lookupdonec;
    1.82-					lookupdone(iswrite, rm, rc);
    1.83-				}
    1.84+				takewrites();
    1.85 				storec<- = ref Store.Sync(c, tmsg.tid);
    1.86 			}
    1.87