-
Notifications
You must be signed in to change notification settings - Fork 29
/
txn-log.lisp
51 lines (48 loc) · 2.18 KB
/
txn-log.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
(in-package :graph-db)
(defmethod snapshot ((graph graph) &key include-deleted-p
(check-data-integrity-p t))
(let ((count nil))
(with-recursive-lock-held ((txn-lock graph))
(let ((problems (when check-data-integrity-p
(check-data-integrity graph
:include-deleted-p
include-deleted-p))))
(if problems
(progn
(log:error "data integrity errors on ~A" graph)
(dolist (problem problems)
(log:error "data integrity: ~A" problem))
(return-from snapshot
(values :data-integrity-issues
problems)))
(progn
(multiple-value-bind (sec msec) #+sbcl(sb-ext:get-time-of-day) #-sbcl(gettimeofday)
(let ((snap-file (format nil "~A/txn-log/snap-~D.~6,'0D"
(location graph) sec msec)))
(setq count (backup graph
snap-file
:include-deleted-p include-deleted-p))))
count))))))
(defun find-newest-snapshot (dir)
(let ((file (first (sort
(remove-if-not (lambda (file)
(cl-ppcre:scan "^snap-"
(file-namestring file)))
(cl-fad:list-directory dir))
'> :key 'file-write-date))))
(when file
(values file (file-write-date file)))))
(defmethod replay ((graph graph) txn-dir package-name &key (check-integrity-p t))
(let ((snapshot (find-newest-snapshot txn-dir)))
(when snapshot
(recreate-graph graph snapshot :package-name package-name))
(log:debug "Generating graph views.")
(map nil
(lambda (pair)
(destructuring-bind (class-name . view-name) pair
(regenerate-view graph class-name view-name)))
(all-views graph))
(log:debug "Checking data integrity.")
(if check-integrity-p
(check-data-integrity graph)
graph)))