[elephant-cvs] CVS update: elephant/src/controller.lisp

blee at common-lisp.net blee at common-lisp.net
Sat Aug 28 06:39:57 UTC 2004


Update of /project/elephant/cvsroot/elephant/src
In directory common-lisp.net:/tmp/cvs-serv22079/src

Modified Files:
	controller.lisp 
Log Message:
poor man's counters, performance tweaking

Date: Sat Aug 28 08:39:56 2004
Author: blee

Index: elephant/src/controller.lisp
diff -u elephant/src/controller.lisp:1.3 elephant/src/controller.lisp:1.4
--- elephant/src/controller.lisp:1.3	Fri Aug 27 19:31:59 2004
+++ elephant/src/controller.lisp	Sat Aug 28 08:39:56 2004
@@ -80,6 +80,33 @@
 	;; Should get cached since make-instance calls cache-instance
 	(make-instance class-name :from-oid oid))))
 
+
+;; OID stuff
+;; This stuff is all a hack until sequences appear in Sleepycat 4.3
+(defvar %oid-entry (uffi:allocate-foreign-object :char 12))
+(defvar %oid-lock (uffi:allocate-foreign-object :char 16))
+
+(eval-when (:load-toplevel)
+  (loop for c across "%ELEPHANTOID"
+	for i from 0 to 11
+	do (setf (uffi:deref-array %oid-entry '(:array :char) i)
+		 (char-code c)))
+  (loop for c across "%ELEPHANTOIDLOCK"
+	for i from 0 to 15
+	do (setf (uffi:deref-array %oid-lock '(:array :char) i) 
+		 (char-code c)))
+  )
+
+(defvar %oid-entry-length 12)
+(defvar %oid-lock-length 16)
+
+(defmethod next-oid ((sc store-controller))
+  (sleepycat::next-counter (controller-environment sc)
+			   (controller-db sc)
+			   %oid-entry %oid-entry-length
+			   %oid-lock %oid-lock-length))
+
+;; Open/close     
 (defmethod open-controller ((sc store-controller) &key (recover nil)
 			    (recover-fatal nil) (thread t))
   "Opens the underlying environment and all the necessary
@@ -96,6 +123,13 @@
 	       :auto-commit t :type DB-BTREE :create t :thread thread)
       (let ((root (make-instance 'btree :from-oid -1)))
 	(setf (slot-value sc 'root) root)
+	(let ((*auto-commit* t))
+	  (unless (db-get-key-buffered db %oid-entry %oid-entry-length)
+	    (buffer-write-int 0 *out-buf*)
+	    (db-put-buffered db %oid-entry %oid-entry-length 
+			     (buffer-stream-buffer *out-buf*) 4
+			     :auto-commit t)
+	    (finish-buffer *out-buf*)))
 	sc))))
 
 (defmethod close-controller ((sc store-controller))
@@ -120,47 +154,3 @@
 	 , at body)
      (close-controller ,sc)))
 
-(defmacro with-transaction ((&key transaction 
-				  (environment (controller-environment
-						*store-controller*))
-				  (globally t)
-				  (parent *current-transaction*)
-				  dirty-read txn-nosync
-				  txn-nowait txn-sync)
-			    &body body)
-  `(sleepycat:with-transaction (:transaction ,transaction
-				:environment ,environment
-				:globally ,globally
-				:parent ,parent
-				:dirty-read ,dirty-read
-				:txn-nosync ,txn-nosync
-				:txn-nowait ,txn-nowait
-				:txn-sync ,txn-sync)
-    , at body))
-
-(defmacro with-transaction-retry ((&key transaction environment 
-					(globally t) 
-					(parent *current-transaction*)
-					(retries 100)
-					dirty-read txn-nosync 
-					txn-nowait txn-sync)
-				  &body body)
-  `(sleepycat:with-transaction-retry (:transaction ,transaction
-				      :environment ,environment
-				      :globally ,globally
-				      :parent ,parent
-				      :retries ,retries
-				      :dirty-read ,dirty-read
-				      :txn-nosync ,txn-nosync
-				      :txn-nowait ,txn-nowait
-				      :txn-sync ,txn-sync)
-    , at body))
-
-
-;; This stuff is all a hack until sequences appear in Sleepycat 4.3
-(defconstant max-oid most-positive-fixnum)
-
-(defmethod next-oid ((sc store-controller))
-  (random max-oid))
-
-     
\ No newline at end of file





More information about the Elephant-cvs mailing list