Index: dbmod.scm ================================================================== --- dbmod.scm +++ dbmod.scm @@ -242,11 +242,18 @@ ;; NOTE: ;; These operate directly on the disk file, NOT on the inmemory db ;; The lockname is the filename (can have many to one, run-id to fname ;;====================================================================== -(define (with-lock-db dbfile proc) +;; only use for main.db - need to re-write some of this :( +;; +(define (db:get-main-lock dbfile) + (db:with-lock-db dbfile + (lambda (dbh dbfile) + (db:get-iam-server-lock dbh dbfile)))) + +(define (db:with-lock-db dbfile proc) (let* ((dbh (db:open-run-db dbfile db:initialize-db)) (res (proc dbh dbfile))) (sqlite3:finalize! dbh) res)) @@ -262,11 +269,11 @@ (db:take-lock dbh dbfname)))))) ;; (exn sqlite3) (define (db:get-locker dbh dbfname) (condition-case - (sqlite3:first-row dbh "SELECT owner_pid,owner_host,event_time FROM locks WHERE lockname=%;" dbfname) + (sqlite3:first-row dbh "SELECT owner_pid,owner_host,event_time FROM locks WHERE lockname=?;" dbfname) (exn (sqlite3) #f))) ;; should never fail because it is run in a transaction with a test for the lock ;; (define (db:take-lock dbh dbfname) Index: http-transportmod.scm ================================================================== --- http-transportmod.scm +++ http-transportmod.scm @@ -450,18 +450,10 @@ ;;====================================================================== ;; NEW SERVER METHOD ;;====================================================================== -;; only use for main.db - need to re-write some of this :( -;; -(define (get-lock-db dbfile) - (let* ((dbh (db:open-run-db dbfile db:initialize-db)) - (res (db:get-iam-server-lock dbh dbfile))) - (sqlite3:finalize! dbh) - res)) - (define *srvpktspec* `((server (host . h) (port . p) (servkey . k) (pid . i) @@ -632,11 +624,11 @@ (best-srv (get-best-candidate viables db-file)) (best-srv-key (if best-srv (alist-ref 'servkey best-srv) #f))) (debug:print 0 *default-log-port* "best-srv-key: "best-srv-key", server-key: "server-key) ;; am I the best-srv, compare server-keys to know (if (equal? best-srv-key server-key) - (if (get-lock-db db-file) ;; (db:get-iam-server-lock *dbstruct-db* *toppath* run-id) + (if (db:get-main-lock db-file) (begin (debug:print 0 *default-log-port* "I'm the server!") (servdat-dbfile-set! sdat db-file)) (begin (debug:print 0 *default-log-port* "I'm not the server, exiting.") Index: rmtmod.scm ================================================================== --- rmtmod.scm +++ rmtmod.scm @@ -1779,13 +1779,13 @@ (delete-file* pkt-file) (if (and dbfile (string-match ".*/main.db$" dbfile)) (begin (debug:print-info 0 *default-log-port* "Releasing lock for "dbfile) - (with-lock-db (servdat-dbfile *server-info*) - (lambda (dbh dbfile) - (db:release-lock dbh))))))) + (db:with-lock-db (servdat-dbfile *server-info*) + (lambda (dbh dbfile) + (db:release-lock dbh))))))) (if (bdat-task-db *bdat*) ;; TODO: Check that this is correct for task db (let ((db (cdr (bdat-task-db *bdat*)))) (if (sqlite3:database? db) (begin (sqlite3:interrupt! db)