Permalink
Browse files

misc concurrency fixes

  • Loading branch information...
1 parent a994c5d commit f6c01d214a39b4cc67de4d8364662756bda8a08f @kraison committed Mar 1, 2011
Showing with 85 additions and 12 deletions.
  1. +74 −3 test-scenarios.lisp
  2. +5 −5 transaction.lisp
  3. +0 −4 triples.lisp
  4. +2 −0 vg-test.lisp
  5. +2 −0 vivace-graph-v2-package.lisp
  6. +2 −0 vivace-graph-v2-test.lisp
View
@@ -1,14 +1,16 @@
(in-package #:vivace-graph-v2-test)
(defparameter *basic-concurrency-1* nil)
+(defparameter *basic-concurrency-2* nil)
+(defparameter *triple-2* nil)
(defun basic-concurrency-1 (&optional (store *store*))
(let ((*store* store))
(let ((thr1 (make-thread
#'(lambda ()
(with-graph-transaction (*store* :timeout 10)
(let ((triple (add-triple "This" "is-a" "test" :graph "VGT")))
- (format t "~%basic-concurrency-1: ~A: ~A~%"
+ (format t "~%basic-concurrency-1 thr1: ~A: ~A~%"
(triple-id triple) triple)
(setq *basic-concurrency-1* triple)
(sleep 3))))))
@@ -18,9 +20,9 @@
(let ((triple (add-triple
"This" "is-a" "test" :graph "VGT")))
(if (triple? triple)
- (format t "basic-concurrency-1 lookup: ~A: ~A~%"
+ (format t "basic-concurrency-1 thr2: ~A: ~A~%"
(triple-id triple) triple)
- (format t "basic-concurrency-1 lookup: ~A~%" triple))
+ (format t "basic-concurrency-1 thr2: ~A~%" triple))
(if (triple-equal triple *basic-concurrency-1*)
(setq *basic-concurrency-1* triple)
(setq *basic-concurrency-1* nil)))))))
@@ -29,3 +31,72 @@
(format t "basic-concurrency-1: ~A~%" *basic-concurrency-1*)
*basic-concurrency-1*)))
+(defun basic-concurrency-2 (&optional (store *store*))
+ (let* ((*store* store)
+ (read-fn #'(lambda ()
+ (let ((*read-uncommitted* t))
+ (sleep (random 2.0))
+ (let ((triple (lookup-triple "This" "is-a" "test-2" "VGT")))
+ (if (triple? triple)
+ (format t "basic-concurrency-2 read-thr: ~A: ~A~%"
+ (triple-id triple) triple)
+ (format t "basic-concurrency-2 read-thr: ~A~%" triple))
+ (push (list (current-thread) triple)
+ *basic-concurrency-2*))))))
+ (let ((thr1 (make-thread
+ #'(lambda ()
+ (with-graph-transaction (*store* :timeout 10)
+ (let ((triple (add-triple "This" "is-a" "test-2" :graph "VGT")))
+ (format t "~%basic-concurrency-2 thr1: ~A: ~A~%"
+ (triple-id triple) triple)
+ (setq *triple-2* triple)
+ (sleep 3))))))
+ (thr2 (make-thread
+ #'(lambda ()
+ (sleep 1)
+ (let ((triple (add-triple
+ "This" "is-a" "test-2" :graph "VGT")))
+ (if (triple? triple)
+ (format t "basic-concurrency-2 thr2: ~A: ~A~%"
+ (triple-id triple) triple)
+ (format t "basic-concurrency-2 thr2: ~A~%" triple))
+ (push (list (current-thread) triple) *basic-concurrency-2*)))))
+ (thr3 (make-thread read-fn))
+ (thr4 (make-thread read-fn))
+ (thr5 (make-thread read-fn)))
+ (join-thread thr1)
+ (join-thread thr2)
+ (join-thread thr3)
+ (join-thread thr4)
+ (join-thread thr5)
+ (every #'(lambda (triple)
+ (triple-equal (second triple) *triple-2*))
+ *basic-concurrency-2*))))
+
+(defun delete-undelete-test ()
+ (let ((triple (add-triple "This" "is-a" "delete-undelete-test")))
+ (let ((triple2 (lookup-triple "This" "is-a" "delete-undelete-test" "VGT")))
+ (unless (triple-equal triple triple2)
+ (error "~A not triple-equal to ~A" triple triple2))
+ (delete-triple triple)
+ (if (triple-deleted? triple)
+ (format t "~%Deleted ~A: ~A~%" triple (triple-deleted? triple))
+ (error "~A not deleted." triple))
+ (let ((triple3 (lookup-triple "This" "is-a" "delete-undelete-test" "VGT")))
+ (unless (null triple3)
+ (error "lookup-triple was not null: ~A!" triple3))
+ (format t "lookup-triple: ~A~%" triple3))
+ (let ((triple3 (lookup-triple "This" "is-a" "delete-undelete-test" "VGT"
+ :retrieve-deleted? t)))
+ (unless (triple? triple3)
+ (error "lookup-triple :retrieve-deleted? t was null: ~A!" triple3))
+ (format t "lookup-triple :retrieve-deleted? t: ~A~%" triple3))
+ (add-triple "This" "is-a" "delete-undelete-test" :graph "VGT")
+ (let ((triple3 (lookup-triple "This" "is-a" "delete-undelete-test" "VGT")))
+ (when (triple? triple3)
+ (format t "undeleted ~A~%" triple3))
+ (triple? triple3)))))
+
+
+
+
View
@@ -39,9 +39,9 @@
(location (if (pathnamep (location store))
(namestring (location store))
(location store))))
+ (format t "Looking for transactions to restore...~%")
(dolist (file (directory (make-pathname :directory location
:name :wild :type :wild)))
- (format t "Looking for transactions: ~A~%" file)
(when (and (pathname-match-p file "tx-*")
(or (null timestamp)
(and (numberp timestamp) (> (file-write-date file) timestamp))))
@@ -184,10 +184,10 @@
(logger :info "Processing message ~A" msg)
(when (transaction? msg)
(record-tx msg store)))
- (logger :info "Snapshotting the store.")
- (snapshot store)
- (logger :info "Marking the store clean.")
- (set-clean store)
+ ;;(logger :info "Snapshotting the store.")
+ ;;(snapshot store)
+ ;;(logger :info "Marking the store clean.")
+ ;;(set-clean store)
(logger :info "Logger thread quitting.")
(return t))
(:snapshot
View
@@ -252,16 +252,12 @@
(multiple-value-bind (subject predicate object graph)
(intern-spog subject predicate object graph)
(with-graph-transaction (*store*)
- (logger :info "~A enqueuing lock ~A/~A/~A/~A~%" *current-transaction*
- subject predicate object graph)
(let ((lock (lock-pattern subject predicate object graph :kind :write)))
(enqueue-lock (list subject predicate object graph) lock :write)
- (logger :info "~A enqueued lock ~A~%" *current-transaction* lock)
(or
(let ((triple (lookup-triple subject predicate object graph
:retrieve-deleted? t
:already-locked? t)))
- (logger :info "~A lookup-triple got ~A~%" *current-transaction* triple)
(when (triple? triple)
(when cf
(set-triple-cf triple cf))
View
@@ -6,3 +6,5 @@
(asdf:oos 'asdf:load-op 'VIVACE-GRAPH-V2-TEST)
(in-package #:VIVACE-GRAPH-V2-TEST)
(run-all-tests)
+(when (and *test-db-dir* (probe-file *test-db-dir*))
+ (format t "WARNING: ~A was not deleted!~%" *test-db-dir*))
@@ -65,6 +65,8 @@
#:unindex-predicate
#:map-text-search
#:delete-triple
+ #:undelete-triple
+ #:triple-deleted?
#:erase-triple
#:dump-triples
#:load-triples
@@ -36,6 +36,8 @@
(fiveam:is (test-select *store*))
;; Concurrency tests
(fiveam:is (triple? (basic-concurrency-1 *store*)))
+ (fiveam:is (basic-concurrency-2 *store*))
+ (fiveam:is (delete-undelete-test))
(fiveam:is-false (close-triple-store))
(fiveam:is (null *store*))
(fiveam:is-false (progn

0 comments on commit f6c01d2

Please sign in to comment.