You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@teaclave.apache.org by zf...@apache.org on 2021/12/02 21:56:31 UTC

[incubator-teaclave] branch master updated: [Fix] leveldb lru bug, using disk db for unit test. (#583)

This is an automated email from the ASF dual-hosted git repository.

zfc 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 4c32f62  [Fix] leveldb lru bug, using disk db for unit test. (#583)
4c32f62 is described below

commit 4c32f6215547047979032911277f96a4898ae187
Author: Zhaofeng Chen <zf...@apache.org>
AuthorDate: Thu Dec 2 13:56:23 2021 -0800

    [Fix] leveldb lru bug, using disk db for unit test. (#583)
---
 common/rusty_leveldb_sgx/src/cache.rs   | 45 ++++++++++++++++++++++++++++++++-
 services/storage/enclave/src/service.rs |  8 ++++--
 2 files changed, 50 insertions(+), 3 deletions(-)

diff --git a/common/rusty_leveldb_sgx/src/cache.rs b/common/rusty_leveldb_sgx/src/cache.rs
index 88e23bd..2c5b27e 100644
--- a/common/rusty_leveldb_sgx/src/cache.rs
+++ b/common/rusty_leveldb_sgx/src/cache.rs
@@ -18,6 +18,49 @@ struct LRUList<T> {
     count: usize,
 }
 
+use std::fmt;
+impl<T> fmt::Display for LRUNode<T> {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        if self.next.is_some() {
+            let node = self.next.as_ref().unwrap();
+            writeln!(
+                f,
+                "(self: {:?}, next: {:?}, pre: {:?}, data:{})",
+                self as *const _,
+                (*node).as_ref() as *const _,
+                self.prev,
+                self.data.is_some()
+            )
+        } else {
+            writeln!(
+                f,
+                "(self: {:?}, next: {}, pre: {:?}, data:{})",
+                self as *const _,
+                "None",
+                self.prev,
+                self.data.is_some()
+            )
+        }
+    }
+}
+
+impl<T> fmt::Display for LRUList<T> {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        let _ = write!(
+            f,
+            "\n {:?}, count: {}, head: {}",
+            self as *const _, self.count, self.head
+        )?;
+        let mut opt_node = &self.head.next;
+        while opt_node.is_some() {
+            let node = opt_node.as_ref().unwrap();
+            let _ = write!(f, "\t {}", node)?;
+            opt_node = &node.next
+        }
+        writeln!(f,)
+    }
+}
+
 /// This is likely unstable; more investigation is needed into correct behavior!
 impl<T> LRUList<T> {
     fn new() -> LRUList<T> {
@@ -93,7 +136,7 @@ impl<T> LRUList<T> {
         unsafe {
             // If has next
             if let Some(ref mut nextp) = (*node_handle).next {
-                swap(&mut (**nextp).prev, &mut (*node_handle).prev);
+                (**nextp).prev = (*node_handle).prev;
             }
             // If has prev
             if let Some(ref mut prevp) = (*node_handle).prev {
diff --git a/services/storage/enclave/src/service.rs b/services/storage/enclave/src/service.rs
index 94030d5..5a10341 100644
--- a/services/storage/enclave/src/service.rs
+++ b/services/storage/enclave/src/service.rs
@@ -233,8 +233,12 @@ pub mod tests {
 
     fn get_mock_service() -> TeaclaveStorageService {
         let (_sender, receiver) = channel();
-        let opt = rusty_leveldb::in_memory();
-        let mut database = DB::open("mock_db", opt).unwrap();
+        let key = [
+            0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a,
+            0x09, 0x08,
+        ];
+        let opt = rusty_leveldb::Options::new_disk_db_with(key);
+        let mut database = DB::open("mock_db_unit_test", opt).unwrap();
         database.put(b"test_get_key", b"test_get_value").unwrap();
         database
             .put(b"test_delete_key", b"test_delete_value")

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@teaclave.apache.org
For additional commands, e-mail: commits-help@teaclave.apache.org