1212// See the License for the specific language governing permissions and
1313// limitations under the License.
1414
15+ use std:: fmt;
1516use std:: fs;
1617use std:: io;
1718use std:: io:: BufReader ;
@@ -28,7 +29,7 @@ use crate::raft_types::SnapshotMeta;
2829use crate :: sys_data:: SysData ;
2930
3031/// A readonly leveled map that owns the data.
31- #[ derive( Debug , Clone ) ]
32+ #[ derive( Clone ) ]
3233pub struct DB {
3334 pub storage_path : String ,
3435 pub rel_path : String ,
@@ -37,6 +38,17 @@ pub struct DB {
3738 pub rotbl : Arc < Rotbl > ,
3839}
3940
41+ impl fmt:: Debug for DB {
42+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
43+ f. debug_struct ( "DB" )
44+ . field ( "storage_path" , & self . storage_path )
45+ . field ( "rel_path" , & self . rel_path )
46+ . field ( "meta" , & self . meta )
47+ . field ( "sys_data" , & self . sys_data )
48+ . finish ( )
49+ }
50+ }
51+
4052impl AsRef < SysData > for DB {
4153 fn as_ref ( & self ) -> & SysData {
4254 & self . sys_data
@@ -163,3 +175,37 @@ pub struct DBStat {
163175 /// Total number of read block from disk.
164176 pub read_block_from_disk : u64 ,
165177}
178+
179+ #[ cfg( test) ]
180+ mod tests {
181+
182+ use rotbl:: storage:: impls:: fs:: FsStorage ;
183+ use rotbl:: v001:: Config ;
184+ use rotbl:: v001:: RotblMeta ;
185+
186+ use super :: * ;
187+
188+ /// Debug should not output db cache data.
189+ #[ test]
190+ fn test_db_debug ( ) {
191+ let tmp_dir = tempfile:: tempdir ( ) . unwrap ( ) ;
192+ let storage = FsStorage :: new ( tmp_dir. path ( ) . to_path_buf ( ) ) ;
193+ let config = Config :: default ( ) ;
194+ let path = "test_rotbl" ;
195+ let rotbl =
196+ Rotbl :: create_table ( storage, config, path, RotblMeta :: new ( 1 , "foo" ) , [ ] ) . unwrap ( ) ;
197+
198+ let db = DB {
199+ storage_path : "a" . to_string ( ) ,
200+ rel_path : "b" . to_string ( ) ,
201+ meta : Default :: default ( ) ,
202+ sys_data : Default :: default ( ) ,
203+ rotbl : Arc :: new ( rotbl) ,
204+ } ;
205+
206+ assert_eq ! (
207+ format!( "{:?}" , db) ,
208+ r#"DB { storage_path: "a", rel_path: "b", meta: SnapshotMeta { last_log_id: None, last_membership: StoredMembership { log_id: None, membership: Membership { configs: [], nodes: {} } }, snapshot_id: "" }, sys_data: SysData { last_applied: None, last_membership: StoredMembership { log_id: None, membership: Membership { configs: [], nodes: {} } }, nodes: {}, sequence: 0, key_counts: {}, sm_features: {} } }"#
209+ ) ;
210+ }
211+ }
0 commit comments