From 7e3b091d6944a2ef10f1c6e983181be53b565e34 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 12 Dec 1995 16:00:54 +0000 Subject: [PATCH] System call sync(2) used after update/commit. Locking (based on fcntl) uses F_EXLCK and F_SHLCK instead of F_WRLCK and F_RDLCK. --- index/extract.c | 9 ++++++--- index/lockidx.c | 17 ++++++++++++++--- index/lockutil.c | 17 +++++++++++++++-- index/main.c | 16 +++++++++------- 4 files changed, 44 insertions(+), 15 deletions(-) diff --git a/index/extract.c b/index/extract.c index 5c1f738..b320cbc 100644 --- a/index/extract.c +++ b/index/extract.c @@ -4,7 +4,12 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: extract.c,v $ - * Revision 1.43 1995-12-11 09:12:46 adam + * Revision 1.44 1995-12-12 16:00:54 adam + * System call sync(2) used after update/commit. + * Locking (based on fcntl) uses F_EXLCK and F_SHLCK instead of F_WRLCK + * and F_RDLCK. + * + * Revision 1.43 1995/12/11 09:12:46 adam * The rec_get function returns NULL if record doesn't exist - will * happen in the server if the result set records have been deleted since * the creation of the set (i.e. the search). @@ -184,7 +189,6 @@ void key_open (int mem) { if (mem < 50000) mem = 50000; - logf (LOG_LOG, "key_open %d", mem); key_buf = xmalloc (mem); ptr_top = mem/sizeof(char*); ptr_i = 0; @@ -311,7 +315,6 @@ void key_flush (void) int key_close (void) { key_flush (); - logf (LOG_LOG, "buf free"); xfree (key_buf); rec_close (&records); dict_close (matchDict); diff --git a/index/lockidx.c b/index/lockidx.c index c04bd89..eb833b2 100644 --- a/index/lockidx.c +++ b/index/lockidx.c @@ -4,7 +4,12 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: lockidx.c,v $ - * Revision 1.3 1995-12-11 11:43:29 adam + * Revision 1.4 1995-12-12 16:00:57 adam + * System call sync(2) used after update/commit. + * Locking (based on fcntl) uses F_EXLCK and F_SHLCK instead of F_WRLCK + * and F_RDLCK. + * + * Revision 1.3 1995/12/11 11:43:29 adam * Locking based on fcntl instead of flock. * Setting commitEnable removed. Command line option -n can be used to * prevent commit if commit setting is defined in the configuration file. @@ -134,11 +139,17 @@ void zebraIndexLock (int commitNow) sprintf (path, "%s%s", pathPrefix, FNAME_MAIN_LOCK); while (1) { - lock_fd = open (path, O_CREAT|O_RDWR|O_EXCL|O_SYNC, 0666); + lock_fd = open (path, O_CREAT|O_RDWR|O_EXCL, 0666); if (lock_fd == -1) { lock_fd = open (path, O_RDONLY); - assert (lock_fd != -1); + if (lock_fd == -1) + { + if (errno == ENOENT) + continue; + logf (LOG_FATAL|LOG_ERRNO, "open %s", path); + exit (1); + } if (zebraLockNB (lock_fd, 1) == -1) { if (errno == EWOULDBLOCK) diff --git a/index/lockutil.c b/index/lockutil.c index 79dd0dc..d626d70 100644 --- a/index/lockutil.c +++ b/index/lockutil.c @@ -4,7 +4,12 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: lockutil.c,v $ - * Revision 1.2 1995-12-11 11:43:29 adam + * Revision 1.3 1995-12-12 16:00:57 adam + * System call sync(2) used after update/commit. + * Locking (based on fcntl) uses F_EXLCK and F_SHLCK instead of F_WRLCK + * and F_RDLCK. + * + * Revision 1.2 1995/12/11 11:43:29 adam * Locking based on fcntl instead of flock. * Setting commitEnable removed. Command line option -n can be used to * prevent commit if commit setting is defined in the configuration file. @@ -48,12 +53,20 @@ static int intLock (int fd, int type, int cmd) int zebraLock (int fd, int wr) { +#if 1 + return intLock (fd, wr ? F_EXLCK : F_SHLCK, F_SETLKW); +#else return intLock (fd, wr ? F_WRLCK : F_RDLCK, F_SETLKW); +#endif } int zebraLockNB (int fd, int wr) { - return intLock (fd, wr ? F_WRLCK : F_RDLCK, F_SETLK); +#if 1 + return intLock (fd, wr ? F_EXLCK : F_SHLCK, F_SETLKW); +#else + return intLock (fd, wr ? F_WRLCK : F_RDLCK, F_SETLKW); +#endif } int zebraUnlock (int fd) diff --git a/index/main.c b/index/main.c index a3fb510..553e280 100644 --- a/index/main.c +++ b/index/main.c @@ -4,7 +4,12 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: main.c,v $ - * Revision 1.29 1995-12-11 11:43:30 adam + * Revision 1.30 1995-12-12 16:00:59 adam + * System call sync(2) used after update/commit. + * Locking (based on fcntl) uses F_EXLCK and F_SHLCK instead of F_WRLCK + * and F_RDLCK. + * + * Revision 1.29 1995/12/11 11:43:30 adam * Locking based on fcntl instead of flock. * Setting commitEnable removed. Command line option -n can be used to * prevent commit if commit setting is defined in the configuration file. @@ -148,6 +153,7 @@ int main (int argc, char **argv) " update Update index with files below .\n" " If is empty filenames are read from stdin.\n" " delete Delete index with files below .\n" + " commit Commit changes\n" "Options:\n" " -t Index files as (grs or text).\n" " -c Read configuration file .\n" @@ -201,6 +207,7 @@ int main (int argc, char **argv) zebraIndexWait (1); logf (LOG_LOG, "Commit execute"); bf_commitExec (); + sync (); zebraIndexLockMsg ("d"); zebraIndexWait (0); logf (LOG_LOG, "Commit clean"); @@ -212,12 +219,6 @@ int main (int argc, char **argv) else if (!strcmp (arg, "stat") || !strcmp (arg, "status")) { zebraIndexLock (0); - bf_cache (0); - rec_prstat (); - } - else if (!strcmp (arg, "cstat") || !strcmp (arg, "cstatus")) - { - zebraIndexLock (1); rval = res_get (common_resource, "commit"); if (rval && *rval) { @@ -270,6 +271,7 @@ int main (int argc, char **argv) logf (LOG_LOG, "Merging with index"); key_input (FNAME_WORD_DICT, FNAME_WORD_ISAM, nsections, 60); + sync (); } } } -- 1.7.10.4