Skip to content

Commit 6ce9bf8

Browse files
baumsternJoon-Mo Yang
authored andcommitted
Compress snapshot files
1 parent c006836 commit 6ce9bf8

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sync/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ parking_lot = "0.5"
1818
patricia-trie = { path = "../util/patricia_trie" }
1919
rand = "0.5.3"
2020
rlp = { path = "../util/rlp" }
21+
snap = "0.2"
2122
time = "0.1"
2223
triehash = { path = "../util/triehash" }
2324

sync/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ extern crate patricia_trie as trie;
3030
extern crate rand;
3131
#[cfg_attr(test, macro_use)]
3232
extern crate rlp;
33+
extern crate snap;
3334
extern crate time;
3435
extern crate triehash;
3536

sync/src/snapshot/service.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use ctypes::H256;
2525

2626
use kvdb::KeyValueDB;
2727
use rlp::{decode as rlp_decode, RlpStream};
28+
use snap;
2829
use trie::{Node, OwnedNode};
2930

3031
use super::error::Error;
@@ -90,7 +91,8 @@ fn write_snapshot(db: Arc<KeyValueDB>, path: PathBuf, root: &H256) -> Result<(),
9091
}
9192

9293
{
93-
let mut file = File::create(path.join("head"))?;
94+
let file = File::create(path.join("head"))?;
95+
let mut snappy = snap::Writer::new(file);
9496

9597
let mut stream = RlpStream::new();
9698
stream.begin_unbounded_list();
@@ -101,12 +103,14 @@ fn write_snapshot(db: Arc<KeyValueDB>, path: PathBuf, root: &H256) -> Result<(),
101103
}
102104
stream.complete_unbounded_list();
103105

104-
file.write(&stream.drain())?;
106+
snappy.write(&stream.drain())?;
105107
}
106108

107109
for (grandchild, _) in &grandchildren {
108110
let nodes = enumerate_subtree(&db, grandchild)?;
109-
let mut file = File::create(path.join(format!("{:x}", grandchild)))?;
111+
let file = File::create(path.join(format!("{:x}", grandchild)))?;
112+
let mut snappy = snap::Writer::new(file);
113+
110114
let mut stream = RlpStream::new();
111115
stream.begin_unbounded_list();
112116
for (key, value) in nodes {
@@ -115,7 +119,8 @@ fn write_snapshot(db: Arc<KeyValueDB>, path: PathBuf, root: &H256) -> Result<(),
115119
stream.append(&value);
116120
}
117121
stream.complete_unbounded_list();
118-
file.write(&stream.drain())?;
122+
123+
snappy.write(&stream.drain())?;
119124
}
120125

121126
Ok(())

0 commit comments

Comments
 (0)