* Sebastian Hammer, Adam Dickmeiss
*
* $Log: index.h,v $
- * Revision 1.33 1995-12-08 16:22:53 adam
+ * Revision 1.34 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.
+ *
+ * Revision 1.33 1995/12/08 16:22:53 adam
* Work on update while servers are running. Three lock files introduced.
* The servers reload their registers when necessary, but they don't
* reestablish result sets yet.
#define FNAME_COMMIT_LOCK "zebracmt.LCK"
#define FNAME_ORG_LOCK "zebraorg.LCK"
#define FNAME_TOUCH_TIME "zebraidx.time"
+
+int zebraLock (int fd, int wr);
+int zebraLockNB (int fd, int wr);
+int zebraUnlock (int fd);
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: lockidx.c,v $
- * Revision 1.2 1995-12-08 16:22:54 adam
+ * 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.
+ *
+ * Revision 1.2 1995/12/08 16:22:54 adam
* Work on update while servers are running. Three lock files introduced.
* The servers reload their registers when necessary, but they don't
* reestablish result sets yet.
#include <stdio.h>
#include <assert.h>
#include <unistd.h>
-#include <sys/file.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
}
}
else
- flock (server_lock_cmt, LOCK_UN);
+ zebraUnlock (server_lock_cmt);
if (server_lock_org == -1)
{
sprintf (path, "%s%s", FNAME_ORG_LOCK, pathPrefix);
}
}
else
- flock (server_lock_org, LOCK_UN);
+ zebraUnlock (server_lock_org);
if (commitPhase)
fd = server_lock_cmt;
else
fd = server_lock_org;
- if (flock (fd, LOCK_EX|LOCK_NB) == -1)
+ if (zebraLockNB (fd, 1) == -1)
{
if (errno != EWOULDBLOCK)
{
logf (LOG_LOG, "Waiting for lock cmt");
else
logf (LOG_LOG, "Waiting for lock org");
- if (flock (fd, LOCK_EX) == -1)
+ if (zebraLock (fd, 1) == -1)
{
logf (LOG_FATAL|LOG_ERRNO, "flock");
exit (1);
}
}
- flock (fd, LOCK_UN);
+ zebraUnlock (fd);
return 0;
}
{
lock_fd = open (path, O_RDONLY);
assert (lock_fd != -1);
- if (flock (lock_fd, LOCK_EX|LOCK_NB) == -1)
+ if (zebraLockNB (lock_fd, 1) == -1)
{
if (errno == EWOULDBLOCK)
{
logf (LOG_LOG, "Waiting for other index process");
- flock (lock_fd, LOCK_EX);
+ zebraLock (lock_fd, 1);
continue;
}
else
else
break;
}
- flock (lock_fd, LOCK_EX);
+ zebraLock (lock_fd, 1);
}
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: locksrv.c,v $
- * Revision 1.2 1995-12-08 16:22:55 adam
+ * 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.
+ *
+ * Revision 1.2 1995/12/08 16:22:55 adam
* Work on update while servers are running. Three lock files introduced.
* The servers reload their registers when necessary, but they don't
* reestablish result sets yet.
#include <stdio.h>
#include <assert.h>
#include <unistd.h>
-#include <sys/file.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
if (commitPhase)
{
logf (LOG_LOG, "Server locks org");
- flock (server_lock_org, LOCK_SH);
+ zebraLock (server_lock_org, 0);
}
else
{
logf (LOG_LOG, "Server locks cmt");
- flock (server_lock_cmt, LOCK_SH);
+ zebraLock (server_lock_cmt, 0);
}
return 0;
}
if (commitPhase)
{
logf (LOG_LOG, "Server unlocks org");
- flock (server_lock_org, LOCK_UN);
+ zebraUnlock (server_lock_org);
}
else
{
logf (LOG_LOG, "Server unlocks cmt");
- flock (server_lock_cmt, LOCK_UN);
+ zebraUnlock (server_lock_cmt);
}
}
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: lockutil.c,v $
- * Revision 1.1 1995-12-07 17:38:47 adam
+ * 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.
+ *
+ * Revision 1.1 1995/12/07 17:38:47 adam
* Work locking mechanisms for concurrent updates/commit.
*
*/
#include <stdio.h>
#include <assert.h>
-#include <unistd.h>
-#include <sys/file.h>
-#include <fcntl.h>
#include <string.h>
#include <errno.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <unistd.h>
#include <alexutil.h>
#include "index.h"
if (*pathPrefix && pathPrefix[strlen(pathPrefix)-1] != '/')
strcat (pathPrefix, "/");
}
+
+static int intLock (int fd, int type, int cmd)
+{
+ struct flock area;
+ area.l_type = type;
+ area.l_whence = SEEK_SET;
+ area.l_len = area.l_start = 0L;
+ return fcntl (fd, cmd, &area);
+}
+
+int zebraLock (int fd, int wr)
+{
+ return intLock (fd, wr ? F_WRLCK : F_RDLCK, F_SETLKW);
+}
+
+int zebraLockNB (int fd, int wr)
+{
+ return intLock (fd, wr ? F_WRLCK : F_RDLCK, F_SETLK);
+}
+
+int zebraUnlock (int fd)
+{
+ return intLock (fd, F_UNLCK, F_SETLKW);
+}
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: main.c,v $
- * Revision 1.28 1995-12-08 16:22:56 adam
+ * 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.
+ *
+ * Revision 1.28 1995/12/08 16:22:56 adam
* Work on update while servers are running. Three lock files introduced.
* The servers reload their registers when necessary, but they don't
* reestablish result sets yet.
char *arg;
char *configName = NULL;
int nsections;
+ int disableCommit = 0;
struct recordGroup rGroupDef;
" -g <group> Index files according to group settings.\n"
" -d <database> Records belong to Z39.50 database <database>.\n"
" -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
+ " -n Don't use commit system\n"
" -v <level> Set logging to <level>.\n");
exit (1);
}
- while ((ret = options ("t:c:g:d:m:v:", argv, argc, &arg)) != -2)
+ while ((ret = options ("t:c:g:d:m:v:n", argv, argc, &arg)) != -2)
{
if (ret == 0)
{
else if (!strcmp (arg, "commit"))
{
zebraIndexLock (1);
- rval = res_get (common_resource, "commitEnable");
- if (rval && atoi (rval))
+ rval = res_get (common_resource, "commit");
+ if (rval && *rval)
bf_cache (1);
-
+ else
+ {
+ logf (LOG_FATAL, "Cannot perform commit");
+ logf (LOG_FATAL, "No commit area defined "
+ "in the configuration file");
+ exit (1);
+ }
if (bf_commitExists ())
{
logf (LOG_LOG, "Commit start");
else if (!strcmp (arg, "cstat") || !strcmp (arg, "cstatus"))
{
zebraIndexLock (1);
- rval = res_get (common_resource, "commitEnable");
- if (rval && atoi(rval))
+ rval = res_get (common_resource, "commit");
+ if (rval && *rval)
{
bf_cache (1);
zebraIndexLockMsg ("r");
struct recordGroup rGroup;
zebraIndexLock (0);
- rval = res_get (common_resource, "commitEnable");
- if (rval && atoi(rval))
+ rval = res_get (common_resource, "commit");
+ if (rval && *rval && !disableCommit)
{
bf_cache (1);
zebraIndexLockMsg ("r");
}
else
+ {
+ bf_cache (0);
zebraIndexLockMsg ("w");
+ }
zebraIndexWait (0);
memcpy (&rGroup, &rGroupDef, sizeof(rGroup));
configName = arg;
else if (ret == 't')
rGroupDef.recordType = arg;
+ else if (ret == 'n')
+ disableCommit = 1;
else
{
logf (LOG_FATAL, "Unknown option '-%s'", arg);