-
Notifications
You must be signed in to change notification settings - Fork 29
/
backup.lisp
80 lines (74 loc) · 2.96 KB
/
backup.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
(in-package :graph-db)
(defgeneric backup (object location &key include-deleted-p))
(defmethod backup :around ((node node) location &key include-deleted-p)
(when (or include-deleted-p (not (deleted-p node)))
(call-next-method)))
(defmethod backup ((v vertex) (stream stream) &key include-deleted-p)
(declare (ignore include-deleted-p))
(let ((plist
(list :v
(type-of v)
(when (slot-boundp v 'data)
(data v))
:id (id v)
:revision (revision v)
:deleted-p (deleted-p v))))
(let ((*print-pretty* nil))
(format stream "~S~%" plist))))
(defmethod backup ((e edge) (stream stream) &key include-deleted-p)
(declare (ignore include-deleted-p))
(let ((plist
(list :e
(type-of e)
(from e)
(to e)
(weight e)
(when (slot-boundp e 'data)
(data e))
:id (id e)
:revision (revision e)
:deleted-p (deleted-p e))))
(let ((*print-pretty* nil))
(format stream "~S~%" plist))))
(defmethod backup ((graph graph) location &key include-deleted-p)
(ensure-directories-exist location)
(let ((count 0))
(with-open-file (out location :direction :output)
(map-vertices (lambda (v)
(maybe-init-node-data v :graph graph)
(incf count)
(backup v out))
graph :include-deleted-p include-deleted-p)
(map-edges (lambda (e)
(maybe-init-node-data e :graph graph)
(incf count)
(backup e out))
graph :include-deleted-p include-deleted-p)
(values count location))))
(defmethod check-data-integrity ((graph graph) &key include-deleted-p)
(let ((*cache-enabled* nil))
(let ((problems nil) (count 0))
(map-vertices (lambda (v)
(incf count)
(when (= 0 (mod count 1000))
(format t ".")
(force-output))
(handler-case
(maybe-init-node-data v :graph graph)
(error (c)
(log:error "data integrity ~A: ~A" (string-id v) c)
(push (cons (string-id v) c) problems))))
graph :include-deleted-p include-deleted-p)
(map-edges (lambda (e)
(incf count)
(when (= 0 (mod count 1000))
(format t ".")
(force-output))
(handler-case
(maybe-init-node-data e :graph graph)
(error (c)
(log:error "data integrity ~A: ~A" (string-id e) c)
(push (cons (string-id e) c) problems))))
graph :include-deleted-p include-deleted-p)
(terpri)
problems)))