X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Flockidx.c;h=4904de47d10e9e610d4194952a1381aa7b1ee69c;hb=5adb31268b057741850de38eafd42baf8dc947ea;hp=730a2bf79f980a804bcdeeaf058b88ac96879214;hpb=e89f9552c15bc7f95c0495457a36ac45914fcb40;p=idzebra-moved-to-github.git diff --git a/index/lockidx.c b/index/lockidx.c index 730a2bf..4904de4 100644 --- a/index/lockidx.c +++ b/index/lockidx.c @@ -1,10 +1,28 @@ /* - * Copyright (C) 1994-1998, Index Data I/S + * Copyright (C) 1994-1999, Index Data * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: lockidx.c,v $ - * Revision 1.15 1998-02-17 10:31:33 adam + * Revision 1.21 2002-02-20 17:30:01 adam + * Work on new API. Locking system re-implemented + * + * Revision 1.20 2000/10/16 20:16:00 adam + * Fixed problem with close of lock file for WIN32. + * + * Revision 1.19 2000/09/05 14:04:05 adam + * Updates for prefix 'yaz_' for YAZ log functions. + * + * Revision 1.18 2000/02/24 11:00:07 adam + * Fixed bug: indexer would run forever when lock dir was non-existant. + * + * Revision 1.17 1999/12/08 15:03:11 adam + * Implemented bf_reset. + * + * Revision 1.16 1999/02/02 14:50:57 adam + * Updated WIN32 code specific sections. Changed header. + * + * Revision 1.15 1998/02/17 10:31:33 adam * Fixed bug in zebraIndexUnlock. On NT, the lock files wasn't removed. * * Revision 1.14 1998/01/12 15:04:08 adam @@ -61,7 +79,7 @@ */ #include #include -#ifdef WINDOWS +#ifdef WIN32 #include #else #include @@ -71,12 +89,13 @@ #include #include "index.h" +#include "zserver.h" static ZebraLockHandle server_lock_main = NULL; static ZebraLockHandle server_lock_cmt = NULL; static ZebraLockHandle server_lock_org = NULL; -int zebraIndexWait (int commitPhase) +int zebraIndexWait (ZebraHandle zh, int commitPhase) { ZebraLockHandle h; @@ -86,7 +105,7 @@ int zebraIndexWait (int commitPhase) { char path[1024]; - zebra_lock_prefix (common_resource, path); + zebra_lock_prefix (zh->service->res, path); strcat (path, FNAME_COMMIT_LOCK); server_lock_cmt = zebra_lock_create (path, 1); if (!server_lock_cmt) @@ -101,7 +120,7 @@ int zebraIndexWait (int commitPhase) { char path[1024]; - zebra_lock_prefix (common_resource, path); + zebra_lock_prefix (zh->service->res, path); strcat (path, FNAME_ORG_LOCK); server_lock_org = zebra_lock_create (path, 1); if (!server_lock_org) @@ -116,7 +135,7 @@ int zebraIndexWait (int commitPhase) h = server_lock_org; if (zebra_lock_nb (h)) { -#ifndef WINDOWS +#ifndef WIN32 if (errno != EWOULDBLOCK) { logf (LOG_FATAL|LOG_ERRNO, "flock"); @@ -138,7 +157,7 @@ int zebraIndexWait (int commitPhase) } -void zebraIndexLockMsg (const char *str) +void zebraIndexLockMsg (ZebraHandle zh, const char *str) { char path[1024]; int l, r, fd; @@ -153,33 +172,41 @@ void zebraIndexLockMsg (const char *str) logf (LOG_FATAL|LOG_ERRNO, "write lock file"); exit (1); } - zebra_lock_prefix (common_resource, path); + zebra_lock_prefix (zh->service->res, path); strcat (path, FNAME_TOUCH_TIME); fd = creat (path, 0666); close (fd); } -void zebraIndexUnlock (void) +void zebraIndexUnlock (ZebraHandle zh) { char path[1024]; - zebra_lock_destroy (server_lock_main); - zebra_lock_prefix (common_resource, path); + zebra_lock_prefix (zh->service->res, path); strcat (path, FNAME_MAIN_LOCK); - if (unlink (path)) - logf (LOG_WARN|LOG_ERRNO, "unlink %s", path); +#ifdef WIN32 + zebra_lock_destroy (server_lock_main); + if (unlink (path) && errno != ENOENT) + logf (LOG_WARN|LOG_ERRNO, "unlink %s failed", path); +#else + if (unlink (path) && errno != ENOENT) + logf (LOG_WARN|LOG_ERRNO, "unlink %s failed", path); + zebra_lock_destroy (server_lock_main); +#endif + server_lock_main = 0; } -void zebraIndexLock (BFiles bfs, int commitNow, const char *rval) +int zebraIndexLock (BFiles bfs, ZebraHandle zh, int commitNow, + const char *rval) { char path[1024]; char buf[256]; int r; if (server_lock_main) - return ; + return 0; - zebra_lock_prefix (common_resource, path); + zebra_lock_prefix (zh->service->res, path); strcat (path, FNAME_MAIN_LOCK); while (1) { @@ -189,14 +216,12 @@ void zebraIndexLock (BFiles bfs, int commitNow, const char *rval) server_lock_main = zebra_lock_create (path, 1); if (!server_lock_main) { - if (errno == ENOENT) - continue; - logf (LOG_FATAL|LOG_ERRNO, "open %s", path); - exit (1); + logf (LOG_FATAL, "couldn't obtain indexer lock"); + exit (1); } if (zebra_lock_nb (server_lock_main) == -1) { -#ifdef WINDOWS +#ifdef WIN32 logf (LOG_LOG, "waiting for other index process"); zebra_lock (server_lock_main); zebra_unlock (server_lock_main); @@ -287,5 +312,6 @@ void zebraIndexLock (BFiles bfs, int commitNow, const char *rval) break; } zebra_lock (server_lock_main); + return 0; }