Browse files

Added some logging to main SPTM operations.

  • Loading branch information...
1 parent ae022bc commit dfb508ab1811c2a7833e9b155dc7da694a0b6bef @avodonosov avodonosov committed Dec 19, 2012
Showing with 48 additions and 31 deletions.
  1. +2 −1 sptm.asd
  2. +5 −1 sptm/replica.lisp
  3. +41 −29 sptm/versioned-data.lisp
View
3 sptm.asd
@@ -11,7 +11,8 @@
#:gzip-stream
#:babel
#:alexandria
- #:test-grid-utils)
+ #:test-grid-utils
+ #:log4cl)
:components
((:module "sptm"
:serial t
View
6 sptm/replica.lisp
@@ -38,10 +38,14 @@
(setf (vdata replica)
(make-instance 'versioned-data
:version (getf plist :version)
- :data (getf plist :data))))
+ :data (getf plist :data)))
+ (log:info "read local snapshot of version ~A from ~A"
+ (version replica)
+ (truename (local-snapshot-file replica))))
replica)
(defmethod save-local-snapshot ((replica replica))
+ (log:info "saving local snapshot to ~A" (local-snapshot-file replica))
(let ((versioned-data (vdata replica)))
(test-grid-utils::write-to-file (list :version (version versioned-data)
:data (data versioned-data))
View
70 sptm/versioned-data.lisp
@@ -8,7 +8,8 @@
((version :type fixnum
:accessor version
:initform 0
- :initarg :version)
+ :initarg :version
+ :documentation "Must be >= 0")
(data :type t
:accessor data
:initform nil
@@ -107,34 +108,45 @@ there is no saved snapshots."))
;;; play transaction log
-(defmethod roll-forward (log versioned-data &optional (transaction-checker (constantly 't)))
- (assert (>= (version versioned-data) 0))
-
- (let ((min-tx-ver (min-transaction-version log :if-absent :absent)))
- (if (eq :absent min-tx-ver)
- ;; The log doesn't have transaction records
- ;; Check if a snaphost is present that is later
- ;; than our version of data.
- (if (> (snapshot-version log :if-absent 0)
- (version versioned-data))
- (get-snapshot log)
- versioned-data)
- (let ((cur-vdata (if (< (version versioned-data)
- (1- min-tx-ver))
- ;; Our versioned-data is so outdated, that transaction
- ;; log doesn't have all the transactions necessary to roll forward.
- ;;
- ;; Then we start from scratch. There must be a snaphsot.
- (get-snapshot log)
- versioned-data)))
- (assert (>= (version cur-vdata) (1- min-tx-ver)))
- (flet ((apply-transaction* (vdata transaction)
- (unless (funcall transaction-checker (func transaction))
- (error "The transaction ~A retrieved from transaction log specifies function ~S forbidden by the transaction checker"
- transaction (func transaction)))
- (apply-transaction vdata transaction)))
- (reduce #'apply-transaction* (list-transactions log (version cur-vdata))
- :initial-value cur-vdata))))))
+(defmethod roll-forward (log versioned-data &optional (transaction-checker (constantly 't)))
+ ;; wrappers around basic transaction log functions
+ (flet ((apply-transaction* (vdata transaction)
+ (unless (funcall transaction-checker (func transaction))
+ (error "The transaction ~A retrieved from transaction log specifies function ~S forbidden by the transaction checker"
+ transaction (func transaction)))
+ (log:info "executing transaction ~A ~S" (version transaction) (func transaction))
+ (apply-transaction vdata transaction))
+ (list-transactions* (log version)
+ (let ((transactions (list-transactions log version)))
+ (log:info "~A new transactions found after version ~A" (length transactions) version)
+ transactions))
+ (get-snapshot* (log)
+ (let ((snapshot (get-snapshot log)))
+ (log:info "retrieved snapshot of version ~A" (version snapshot))
+ snapshot)))
+
+ (assert (>= (version versioned-data) 0))
+
+ (let ((min-tx-ver (min-transaction-version log :if-absent :absent)))
+ (if (eq :absent min-tx-ver)
+ ;; The log doesn't have transaction records
+ ;; Check if a snaphost is present that is later
+ ;; than our version of data.
+ (if (> (snapshot-version log :if-absent 0)
+ (version versioned-data))
+ (get-snapshot* log)
+ versioned-data)
+ (let* ((cur-vdata (if (< (version versioned-data)
+ (1- min-tx-ver))
+ ;; Our versioned-data is so outdated, that transaction
+ ;; log doesn't have all the transactions necessary to roll forward.
+ ;;
+ ;; Then we start from scratch. There must be a snaphsot.
+ (get-snapshot* log)
+ versioned-data))
+ (transactions (list-transactions* log (version cur-vdata))))
+ (assert (>= (version cur-vdata) (1- min-tx-ver)))
+ (reduce #'apply-transaction* transactions :initial-value cur-vdata))))))
;;; perform new transactions

0 comments on commit dfb508a

Please sign in to comment.