@@ -10,15 +10,6 @@ pub enum OperationLogs {
1010 OnDisk ( FileOpLogs ) ,
1111}
1212
13- macro_rules! delegate_wal_method {
14- ( $self: ident. $method: ident( $( $arg: ident) ,* ) ) => {
15- match $self {
16- Self :: Memory ( wal) => wal. $method( $( $arg) ,* ) ,
17- Self :: OnDisk ( wal) => wal. $method( $( $arg) ,* ) ,
18- }
19- } ;
20- }
21-
2213impl OperationLogs {
2314 pub fn new_inmemory ( ) -> Self {
2415 Self :: Memory ( Default :: default ( ) )
@@ -28,13 +19,23 @@ impl OperationLogs {
2819 }
2920 /// Append one or more `WriteOperation`s to the log.
3021 pub ( crate ) fn write_many ( & mut self , ops : Vec < WriteOperation > ) -> anyhow:: Result < ( ) > {
31- delegate_wal_method ! ( self . write_many( ops) )
22+ match self {
23+ OperationLogs :: Memory ( memory_op_logs) => memory_op_logs. write_many ( ops) ,
24+ OperationLogs :: OnDisk ( file_op_logs) => file_op_logs. write_many ( ops) ,
25+ }
3226 }
3327
3428 /// Retrieve logs that fall between the current 'commit' index and target 'log' index.
3529 /// This is NOT async as it is expected to be infallible and an in-memory operation.
3630 pub ( crate ) fn range ( & self , start_exclusive : u64 , end_inclusive : u64 ) -> Vec < WriteOperation > {
37- delegate_wal_method ! ( self . range( start_exclusive, end_inclusive) )
31+ match self {
32+ OperationLogs :: Memory ( memory_op_logs) => {
33+ memory_op_logs. range ( start_exclusive, end_inclusive)
34+ } ,
35+ OperationLogs :: OnDisk ( file_op_logs) => {
36+ file_op_logs. range ( start_exclusive, end_inclusive)
37+ } ,
38+ }
3839 }
3940
4041 /// Replays all logged operations from the beginning of the WAL, calling the provided callback `f` for each operation.
@@ -43,21 +44,33 @@ impl OperationLogs {
4344 where
4445 F : FnMut ( WriteOperation ) + Send ,
4546 {
46- delegate_wal_method ! ( self . replay( f) )
47+ match self {
48+ OperationLogs :: Memory ( memory_op_logs) => memory_op_logs. replay ( f) ,
49+ OperationLogs :: OnDisk ( file_op_logs) => file_op_logs. replay ( f) ,
50+ }
4751 }
4852
4953 /// Retrieves the log at a given index.
5054 pub ( crate ) fn read_at ( & mut self , at : u64 ) -> Option < WriteOperation > {
51- delegate_wal_method ! ( self . read_at( at) )
55+ match self {
56+ OperationLogs :: Memory ( memory_op_logs) => memory_op_logs. read_at ( at) ,
57+ OperationLogs :: OnDisk ( file_op_logs) => file_op_logs. read_at ( at) ,
58+ }
5259 }
5360
5461 /// Returns true if there are no logs. Otherwise, returns false.
5562 pub ( crate ) fn is_empty ( & self ) -> bool {
56- delegate_wal_method ! ( self . is_empty( ) )
63+ match self {
64+ OperationLogs :: Memory ( memory_op_logs) => memory_op_logs. is_empty ( ) ,
65+ OperationLogs :: OnDisk ( file_op_logs) => file_op_logs. is_empty ( ) ,
66+ }
5767 }
5868
5969 /// Truncate logs that are positioned after `log_index`.
6070 pub ( crate ) fn truncate_after ( & mut self , log_index : u64 ) {
61- delegate_wal_method ! ( self . truncate_after( log_index) )
71+ match self {
72+ OperationLogs :: Memory ( memory_op_logs) => memory_op_logs. truncate_after ( log_index) ,
73+ OperationLogs :: OnDisk ( file_op_logs) => file_op_logs. truncate_after ( log_index) ,
74+ }
6275 }
6376}
0 commit comments