You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@teaclave.apache.org by ms...@apache.org on 2021/12/11 03:13:58 UTC
[incubator-teaclave] branch master updated: [Fix] Improve log writer and tolerate log reader (#587)
This is an automated email from the ASF dual-hosted git repository.
mssun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-teaclave.git
The following commit(s) were added to refs/heads/master by this push:
new 49eb93f [Fix] Improve log writer and tolerate log reader (#587)
49eb93f is described below
commit 49eb93fd8f2a7b14fd1c759174baf2ae0cb71405
Author: Zhaofeng Chen <zf...@apache.org>
AuthorDate: Fri Dec 10 19:13:49 2021 -0800
[Fix] Improve log writer and tolerate log reader (#587)
---
common/rusty_leveldb_sgx/src/log.rs | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/common/rusty_leveldb_sgx/src/log.rs b/common/rusty_leveldb_sgx/src/log.rs
index da3c849..e834760 100644
--- a/common/rusty_leveldb_sgx/src/log.rs
+++ b/common/rusty_leveldb_sgx/src/log.rs
@@ -102,12 +102,14 @@ impl<W: Write> LogWriter<W> {
let chksum = mask_crc(self.digest.sum32());
- let mut s = 0;
- s += self.dst.write(&chksum.encode_fixed_vec())?;
- s += self.dst.write_fixedint(len as u16)?;
- s += self.dst.write(&[t as u8])?;
- s += self.dst.write(&data[0..len])?;
-
+ let mut s1 = 0;
+ let mut v = Vec::<u8>::with_capacity(len + HEADER_SIZE);
+ s1 += v.write(&chksum.encode_fixed_vec())?;
+ s1 += v.write_fixedint(len as u16)?;
+ s1 += v.write(&[t as u8])?;
+ s1 += v.write(&data[0..len])?;
+ let s = self.dst.write(v.as_slice())?;
+ assert!(s == s1);
self.current_block_offset += s;
Ok(s)
}
@@ -150,7 +152,9 @@ impl<R: Read> LogReader<R> {
dst.clear();
loop {
- if self.blocksize - self.blk_off < HEADER_SIZE {
+ if self.blocksize < self.blk_off {
+ self.blk_off = 0;
+ } else if self.blocksize - self.blk_off < HEADER_SIZE {
// skip to next block
self.src
.read(&mut self.head_scratch[0..self.blocksize - self.blk_off])?;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@teaclave.apache.org
For additional commands, e-mail: commits-help@teaclave.apache.org