|
46 | 46 | unmarshal-fn)) |
47 | 47 |
|
48 | 48 | (defn- read-snapshot [s3-cli s3-sdk-cli bucket snapshot-path] |
49 | | - (if (snapshot-exists? s3-cli bucket snapshot-path) |
50 | | - (let [v2-path (snapshot-v2-path snapshot-path) |
51 | | - snap1 (read-object s3-sdk-cli bucket snapshot-path unmarshal)] |
52 | | - (try |
53 | | - (if (snapshot-exists? s3-cli bucket v2-path) |
54 | | - (let [snap2 (read-object s3-sdk-cli bucket v2-path unmarshal-from-in)] |
55 | | - (println "Snapshot v1" (if (= snap1 snap2) "IS" "IS NOT") "equal to v2")) |
56 | | - (println v2-path "object not found in bucket.")) |
57 | | - (catch Exception e |
58 | | - (.printStackTrace e))) |
59 | | - snap1) |
60 | | - {:partkey 0})) |
61 | | - |
62 | | -(defn- save-snapshot! [s3-cli s3-sdk-cli bucket snapshot-path snapshot] |
63 | | - (util/aws-invoke s3-cli {:op :PutObject |
64 | | - :request {:Bucket bucket |
65 | | - :Key snapshot-path |
66 | | - :Body (marshal snapshot)}}) |
| 49 | + (let [v2-path (snapshot-v2-path snapshot-path)] |
| 50 | + (if (snapshot-exists? s3-cli bucket v2-path) |
| 51 | + (read-object s3-sdk-cli bucket v2-path unmarshal-from-in) |
| 52 | + {:partkey 0}))) |
| 53 | + |
| 54 | +(defn- save-snapshot! [s3-sdk-cli bucket snapshot-path snapshot] |
67 | 55 | (try |
68 | 56 | (let [v2-path (snapshot-v2-path snapshot-path) |
69 | 57 | temp-file (java.io.File/createTempFile "snapshot" "")] ; We use an intermediary file to easily determine the length of the stream. Otherwise, to determine its length, Amazon's SDK would buffer the entire stream in RAM, defeating our purpose. |
|
160 | 148 | (println "Saving snapshot to bucket...") |
161 | 149 | ; Since s3 update is atomic, if saving snapshot fails next prevayler will pick the previous state |
162 | 150 | ; and restore events from the previous partkey |
163 | | - (save-snapshot! s3-client s3-sdk-cli s3-bucket snapshot-path {:state @state-atom |
| 151 | + (save-snapshot! s3-sdk-cli s3-bucket snapshot-path {:state @state-atom |
164 | 152 | :partkey (inc @snapshot-index-atom)}) |
165 | 153 | (println "Snapshot done.") |
166 | 154 | (swap! snapshot-index-atom inc) |
|
0 commit comments