Skip to content

Commit

Permalink
Made changes to revertSubGraph. Bugs though. Some relations are not c…
Browse files Browse the repository at this point in the history
…reated. Curiously the number of relations not created is constant for the same test set.
  • Loading branch information
xenomorph1096 committed Aug 5, 2017
1 parent c5b2da5 commit 0ec8112
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 45 deletions.
2 changes: 2 additions & 0 deletions src/gnowdb/neo4j/gqb.clj
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@
:characteristicString]
:or {:characteristicString ""
:editPropertyList []}}]
(if (not (coll? editPropertyList))
(println editPropertyList))
{:pre [(string? varName)
(coll? editPropertyList)
(every? string? editPropertyList)]}
Expand Down
14 changes: 10 additions & 4 deletions src/gnowdb/neo4j/grcs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
:rcs-bkp-dir (details :rcs-bkp-dir)
}
)
(def ^{:private true} neo4j-schema-filepath (str (details :rcs-directory) "/" neo4j-schema-filename))
(def ^{:private true} neo4j-schema-filepath (str (details :rcs-directory) "/" neo4j-schema-filename))
)

(defn isRevision?
Expand Down Expand Up @@ -174,9 +174,15 @@
:dir dir]
result (apply shell/sh args-r)
]
(if (= (:exit result) 0)
(:out result)
(throw (Exception. (:err result))))))
(if (= (result :exit) 0)
(result :out)
(if (.contains (result :err) "No revision on branch 1 has a date before")
(with-out-str (clojure.pprint/pprint {:node {:labels []
:properties {}}
:inRelations #{}
:deleted? true
:rcsExists? false}))
(throw (Exception. (result :err)))))))

(defn co-p
[& {:keys [:GDB_UUID
Expand Down
85 changes: 44 additions & 41 deletions src/gnowdb/neo4j/grcs_revert.clj
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,17 @@
:inRelations #{}
:deleted? true}
fr)]
(if (= latestRevision oldRevision)
(if (or (= latestRevision oldRevision)
(and (latestRevision :deleted?)
(oldRevision :deleted?)))
nil
(if (oldRevision :deleted?)
(if (and (oldRevision :deleted?)
(not (latestRevision :deleted?)))
(gneo/deleteDetachNodes :labels ((latestRevision :node) :labels)
:parameters ((latestRevision :node) :properties)
:execute? execute?)
(if (latestRevision :deleted?)
(if (and (latestRevision :deleted?)
(not (oldRevision :deleted?)))
(let [nodeCreateQuery (gneo/createNewNode :uuid? false
:labels ((oldRevision :node) :labels)
:parameters ((oldRevision :node) :properties)
Expand Down Expand Up @@ -208,44 +212,43 @@
(every? string? UUIDList)
(or getNBH?
getLatest?)]}
(let [missingNodes (into #{} (filter (fn
[UUID]
(let [fr (if getNBH?
((gdriver/getNBH :UUIDList [UUID]) UUID)
(read-string (grcs/getLatest :GDB_UUID UUID)))
or (read-string (grcs/co-p :GDB_UUID UUID
:date date))]
(and (if (nil? fr)
true
fr)
(not (or :deleted?)))))
UUIDList))
revertNodes (clojure.set/difference (into #{} UUIDList)
missingNodes)
constraintQueries (if revertSchema?
(revertSchema :date date
:getLatest? getLatest?
:getSchema? getNBH?
:execute? false)
{})
rvLR (if getLatest?
nil
(gdriver/getNBH :UUIDList revertNodes))
revertQueries (concat (gneo/reduceQueryColl (pmap #(revertNode :UUID %
:date date
:getLatest? getLatest?
:getNBH? getNBH?
:exeute? false)
missingNodes))
(gneo/reduceQueryColl (pmap #(revertNode :UUID %
:date date
:getLatest? getLatest?
:getNBH? getNBH?
:execute? false)
revertNodes)))
transactions (filter identity [(constraintQueries :remConstraints)
revertQueries
(constraintQueries :addConstraints)])]
(let [UUIDMap (apply merge (pmap #(-> {% 1}) UUIDList))
uuidlset (into #{} UUIDList)
UUIDPriorityMap (reduce (fn [umap
uuid]
(let [nbh (read-string (grcs/co-p :GDB_UUID uuid
:date date))
dependentUUIDs (filter #(contains? uuidlset %)
(map #(% "fromUUID")
(nbh :inRelations)))]
(reduce #(update %1
%2
(fn [a b]
(if (nil? a)
b
(+ a b)))
1)
umap
dependentUUIDs)))
UUIDMap
UUIDList)
sortedUUIDList (sort #(> (UUIDPriorityMap %1)
(UUIDPriorityMap %2)) UUIDList)
dataQueries (gneo/reduceQueryColl (pmap #(revertNode :UUID %
:date date
:getLatest? getLatest?
:getNBH? getNBH?
:execute? false) sortedUUIDList))
schemaQueries (if revertSchema?
(revertSchema :getLatest? getLatest?
:getSchema? getNBH?
:date date
:execute? false)
{:remConstraints []
:addConstraints []})
transactions [(schemaQueries :remConstraints)
dataQueries
(schemaQueries :addConstraints)]]
(if execute?
(apply gdriver/runTransactions transactions)
transactions)))

0 comments on commit 0ec8112

Please sign in to comment.