Locking based on fcntl instead of flock.
authorAdam Dickmeiss <adam@indexdata.dk>
Mon, 11 Dec 1995 11:43:29 +0000 (11:43 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Mon, 11 Dec 1995 11:43:29 +0000 (11:43 +0000)
Setting commitEnable removed. Command line option -n can be used to
prevent commit if commit setting is defined in the configuration file.

index/index.h
index/lockidx.c
index/locksrv.c
index/lockutil.c
index/main.c

index a6ad7d9..0c0435c 100644 (file)
@@ -4,7 +4,12 @@
  * 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.
@@ -219,3 +224,7 @@ int zebraIndexWait (int commitPhase);
 #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);
index 75bec86..c04bd89 100644 (file)
@@ -4,7 +4,12 @@
  * 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.
@@ -16,7 +21,6 @@
 #include <stdio.h>
 #include <assert.h>
 #include <unistd.h>
-#include <sys/file.h>
 #include <fcntl.h>
 #include <string.h>
 #include <errno.h>
@@ -47,7 +51,7 @@ int zebraIndexWait (int commitPhase)
         }
     }
     else
-        flock (server_lock_cmt, LOCK_UN);
+        zebraUnlock (server_lock_cmt);
     if (server_lock_org == -1)
     {
         sprintf (path, "%s%s", FNAME_ORG_LOCK, pathPrefix);
@@ -59,12 +63,12 @@ int zebraIndexWait (int commitPhase)
         }
     }
     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)
         {
@@ -75,13 +79,13 @@ int zebraIndexWait (int commitPhase)
             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;
 }
 
@@ -135,12 +139,12 @@ void zebraIndexLock (int commitNow)
         {
             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
@@ -210,6 +214,6 @@ void zebraIndexLock (int commitNow)
         else
             break;
     }
-    flock (lock_fd, LOCK_EX);
+    zebraLock (lock_fd, 1);
 }
 
index 535af27..0e391fa 100644 (file)
@@ -4,7 +4,12 @@
  * 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.
@@ -16,7 +21,6 @@
 #include <stdio.h>
 #include <assert.h>
 #include <unistd.h>
-#include <sys/file.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <string.h>
@@ -57,12 +61,12 @@ int zebraServerLock (int commitPhase)
     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;
 }
@@ -74,12 +78,12 @@ void zebraServerUnlock (int commitPhase)
     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);
     }
 }
 
index acd6541..79dd0dc 100644 (file)
@@ -4,17 +4,22 @@
  * 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"
@@ -31,3 +36,27 @@ void zebraLockPrefix (char *pathPrefix)
     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);
+}
index f40cd03..a3fb510 100644 (file)
@@ -4,7 +4,12 @@
  * 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.
@@ -123,6 +128,7 @@ int main (int argc, char **argv)
     char *arg;
     char *configName = NULL;
     int nsections;
+    int disableCommit = 0;
 
     struct recordGroup rGroupDef;
     
@@ -148,10 +154,11 @@ int main (int argc, char **argv)
        " -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)
         {
@@ -177,10 +184,16 @@ int main (int argc, char **argv)
                 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");
@@ -205,8 +218,8 @@ int main (int argc, char **argv)
                 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");
@@ -224,14 +237,17 @@ int main (int argc, char **argv)
                 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));
@@ -277,6 +293,8 @@ int main (int argc, char **argv)
             configName = arg;
         else if (ret == 't')
             rGroupDef.recordType = arg;
+        else if (ret == 'n')
+            disableCommit = 1;
         else
         {
             logf (LOG_FATAL, "Unknown option '-%s'", arg);