[rucksack-cvs] CVS rucksack
alemmens
alemmens at common-lisp.net
Thu Aug 3 18:37:51 UTC 2006
Update of /project/rucksack/cvsroot/rucksack
In directory clnet:/tmp/cvs-serv2990
Modified Files:
cache.lisp transactions.lisp
Log Message:
Ensure unique transaction IDs (from Edi Weitz).
--- /project/rucksack/cvsroot/rucksack/cache.lisp 2006/08/03 10:59:52 1.6
+++ /project/rucksack/cvsroot/rucksack/cache.lisp 2006/08/03 18:37:50 1.7
@@ -1,4 +1,4 @@
-;; $Id: cache.lisp,v 1.6 2006/08/03 10:59:52 alemmens Exp $
+;; $Id: cache.lisp,v 1.7 2006/08/03 18:37:50 alemmens Exp $
(in-package :rucksack)
@@ -62,6 +62,11 @@
cache."))
+(defgeneric make-transaction-id (cache)
+ (:documentation "Returns a new transaction ID. The result is an
+integer greater than all previous IDs."))
+
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; The cache
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -87,9 +92,10 @@
:documentation "A queue of the ids of all non-dirty objects
that are currently in the cache memory. Whenever an object is
retrieved (i.e. read), it's added to the queue.")
- (highest-transaction-id :initarg :highest-transaction-id
- :initform 0
- :accessor highest-transaction-id)
+ (last-timestamp :initform (get-universal-time)
+ :accessor last-timestamp)
+ (transaction-id-helper :initform -1
+ :accessor transaction-id-helper)
(transactions :initform (make-hash-table)
:reader transactions
:documentation "A mapping from transaction ids to
@@ -115,6 +121,18 @@
(pathname (heap-stream (heap cache)))
(cache-count cache))))
+
+(defmethod make-transaction-id ((cache standard-cache))
+ ;; This would allow for up to 100 transactions per millisecond
+ ;; The result is a bignum but it at least fits in 8 octets and
+ ;; can thus be serialized with SERIALIZE-BYTE-64.
+ (let ((timestamp (get-universal-time)))
+ (when (> timestamp (last-timestamp cache))
+ (setf (last-timestamp cache) timestamp
+ (transaction-id-helper cache) -1))
+ (+ (* timestamp 100000)
+ (mod (incf (transaction-id-helper cache)) 1000000))))
+
;;
;; Open/close/initialize
;;
--- /project/rucksack/cvsroot/rucksack/transactions.lisp 2006/08/03 11:52:46 1.5
+++ /project/rucksack/cvsroot/rucksack/transactions.lisp 2006/08/03 18:37:50 1.6
@@ -1,4 +1,4 @@
-;; $Id: transactions.lisp,v 1.5 2006/08/03 11:52:46 alemmens Exp $
+;; $Id: transactions.lisp,v 1.6 2006/08/03 18:37:50 alemmens Exp $
(in-package :rucksack)
@@ -133,7 +133,7 @@
(rucksack standard-rucksack)
&key &allow-other-keys)
;; Create new transaction.
- (let* ((id (incf (highest-transaction-id cache)))
+ (let* ((id (make-transaction-id cache))
(transaction (make-instance 'standard-transaction :id id)))
;; Add to open transactions.
(open-transaction cache transaction)
More information about the rucksack-cvs
mailing list