X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Flockidx.c;h=7adf2eb93a0aa2d3af605e60985028fdce4fbe73;hb=69da23537c6bb71ab948e079708bf8ea090de73f;hp=9cc80c2c795d2a4342755cdfc3da53de8939ab77;hpb=c5ef994b26d692fbfecc3ac97f69e4bf7bd0fcea;p=idzebra-moved-to-github.git diff --git a/index/lockidx.c b/index/lockidx.c index 9cc80c2..7adf2eb 100644 --- a/index/lockidx.c +++ b/index/lockidx.c @@ -1,10 +1,28 @@ /* - * Copyright (C) 1994-1995, Index Data I/S + * Copyright (C) 1994-1999, Index Data * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: lockidx.c,v $ - * Revision 1.12 1997-09-25 14:54:43 adam + * 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 + * The test option (-s) only uses read-lock (and not write lock). + * + * Revision 1.13 1997/09/29 09:08:36 adam + * Revised locking system to be thread safe for the server. + * + * Revision 1.12 1997/09/25 14:54:43 adam * WIN32 files lock support. * * Revision 1.11 1997/09/17 12:19:15 adam @@ -52,7 +70,7 @@ */ #include #include -#ifdef WINDOWS +#ifdef WIN32 #include #else #include @@ -69,17 +87,16 @@ static ZebraLockHandle server_lock_org = NULL; int zebraIndexWait (int commitPhase) { - char pathPrefix[1024]; - char path[1024]; ZebraLockHandle h; - - zebraLockPrefix (common_resource, pathPrefix); if (server_lock_cmt) zebra_unlock (server_lock_cmt); else { - sprintf (path, "%s%s", pathPrefix, FNAME_COMMIT_LOCK); + char path[1024]; + + zebra_lock_prefix (common_resource, path); + strcat (path, FNAME_COMMIT_LOCK); server_lock_cmt = zebra_lock_create (path, 1); if (!server_lock_cmt) { @@ -91,7 +108,10 @@ int zebraIndexWait (int commitPhase) zebra_unlock (server_lock_org); else { - sprintf (path, "%s%s", pathPrefix, FNAME_ORG_LOCK); + char path[1024]; + + zebra_lock_prefix (common_resource, path); + strcat (path, FNAME_ORG_LOCK); server_lock_org = zebra_lock_create (path, 1); if (!server_lock_org) { @@ -105,7 +125,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"); @@ -130,7 +150,6 @@ int zebraIndexWait (int commitPhase) void zebraIndexLockMsg (const char *str) { char path[1024]; - char pathPrefix[1024]; int l, r, fd; assert (server_lock_main); @@ -143,8 +162,8 @@ void zebraIndexLockMsg (const char *str) logf (LOG_FATAL|LOG_ERRNO, "write lock file"); exit (1); } - zebraLockPrefix (common_resource, pathPrefix); - sprintf (path, "%s%s", pathPrefix, FNAME_TOUCH_TIME); + zebra_lock_prefix (common_resource, path); + strcat (path, FNAME_TOUCH_TIME); fd = creat (path, 0666); close (fd); } @@ -152,24 +171,26 @@ void zebraIndexLockMsg (const char *str) void zebraIndexUnlock (void) { char path[1024]; - char pathPrefix[1024]; - - zebraLockPrefix (common_resource, pathPrefix); - sprintf (path, "%s%s", pathPrefix, FNAME_MAIN_LOCK); - unlink (path); + + zebra_lock_destroy (server_lock_main); + server_lock_main = 0; + zebra_lock_prefix (common_resource, path); + strcat (path, FNAME_MAIN_LOCK); + if (unlink (path) && errno != ENOENT) + logf (LOG_WARN|LOG_ERRNO, "unlink %s failed", path); } -void zebraIndexLock (BFiles bfs, int commitNow, const char *rval) +int zebraIndexLock (BFiles bfs, int commitNow, const char *rval) { char path[1024]; - char pathPrefix[1024]; char buf[256]; int r; if (server_lock_main) - return ; - zebraLockPrefix (common_resource, pathPrefix); - sprintf (path, "%s%s", pathPrefix, FNAME_MAIN_LOCK); + return 0; + + zebra_lock_prefix (common_resource, path); + strcat (path, FNAME_MAIN_LOCK); while (1) { server_lock_main = zebra_lock_create (path, 2); @@ -178,14 +199,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); @@ -244,7 +263,12 @@ void zebraIndexLock (BFiles bfs, int commitNow, const char *rval) } else if (*buf == 'w') { - logf (LOG_WARN, "your index may be inconsistent"); + logf (LOG_WARN, + "The lock file indicates that your index is"); + logf (LOG_WARN, "inconsistent. Perhaps the indexer"); + logf (LOG_WARN, "terminated abnormally in the previous"); + logf (LOG_WARN, "run. You can try to proceed by"); + logf (LOG_WARN, "deleting the file %s", path); exit (1); } else if (*buf == 'c') @@ -271,5 +295,6 @@ void zebraIndexLock (BFiles bfs, int commitNow, const char *rval) break; } zebra_lock (server_lock_main); + return 0; }