@@ -23,7 +23,6 @@ use std::{
23
23
24
24
use log:: warn;
25
25
use rocketmq_common:: UtilAll :: offset_to_file_name;
26
- use tokio:: sync:: Mutex ;
27
26
use tracing:: info;
28
27
29
28
use crate :: {
@@ -37,7 +36,8 @@ pub struct MappedFileQueue {
37
36
38
37
pub ( crate ) mapped_file_size : u64 ,
39
38
//pub(crate) mapped_files: Arc<Mutex<Vec<LocalMappedFile>>>,
40
- pub ( crate ) mapped_files : Vec < Arc < Mutex < LocalMappedFile > > > ,
39
+ //pub(crate) mapped_files: Vec<Arc<Mutex<LocalMappedFile>>>,
40
+ pub ( crate ) mapped_files : Vec < Arc < LocalMappedFile > > ,
41
41
// pub(crate) mapped_files: Vec<LocalMappedFile>,
42
42
pub ( crate ) allocate_mapped_file_service : Option < AllocateMappedFileService > ,
43
43
@@ -130,7 +130,7 @@ impl MappedFileQueue {
130
130
LocalMappedFile :: new ( file. to_string_lossy ( ) . to_string ( ) , self . mapped_file_size ) ;
131
131
// Set wrote, flushed, committed positions for mapped_file
132
132
133
- self . mapped_files . push ( Arc :: new ( Mutex :: new ( mapped_file) ) ) ;
133
+ self . mapped_files . push ( Arc :: new ( mapped_file) ) ;
134
134
// self.mapped_files
135
135
// .push(mapped_file);
136
136
info ! ( "load {} OK" , file. display( ) ) ;
@@ -153,7 +153,7 @@ impl MappedFileQueue {
153
153
// self.mapped_files.last()
154
154
// }
155
155
156
- pub fn get_last_mapped_file ( & self ) -> Option < Arc < Mutex < LocalMappedFile > > > {
156
+ pub fn get_last_mapped_file ( & self ) -> Option < Arc < LocalMappedFile > > {
157
157
if self . mapped_files . is_empty ( ) {
158
158
return None ;
159
159
}
@@ -164,7 +164,7 @@ impl MappedFileQueue {
164
164
& mut self ,
165
165
start_offset : u64 ,
166
166
need_create : bool ,
167
- ) -> Option < Arc < Mutex < LocalMappedFile > > > {
167
+ ) -> Option < Arc < LocalMappedFile > > {
168
168
let mut create_offset = -1i64 ;
169
169
let file_size = self . mapped_file_size as i64 ;
170
170
let mapped_file_last = self . get_last_mapped_file ( ) ;
@@ -173,8 +173,8 @@ impl MappedFileQueue {
173
173
create_offset = start_offset as i64 - ( start_offset as i64 % file_size) ;
174
174
}
175
175
Some ( ref value) => {
176
- if value. lock ( ) . await . is_full ( ) {
177
- create_offset = value. lock ( ) . await . get_file_from_offset ( ) as i64 + file_size
176
+ if value. is_full ( ) {
177
+ create_offset = value. get_file_from_offset ( ) as i64 + file_size
178
178
}
179
179
}
180
180
}
@@ -184,10 +184,7 @@ impl MappedFileQueue {
184
184
mapped_file_last
185
185
}
186
186
187
- pub fn try_create_mapped_file (
188
- & mut self ,
189
- create_offset : u64 ,
190
- ) -> Option < Arc < Mutex < LocalMappedFile > > > {
187
+ pub fn try_create_mapped_file ( & mut self , create_offset : u64 ) -> Option < Arc < LocalMappedFile > > {
191
188
let next_file_path =
192
189
PathBuf :: from ( self . store_path . clone ( ) ) . join ( offset_to_file_name ( create_offset) ) ;
193
190
let next_next_file_path = PathBuf :: from ( self . store_path . clone ( ) )
@@ -199,7 +196,7 @@ impl MappedFileQueue {
199
196
& mut self ,
200
197
next_file_path : PathBuf ,
201
198
_next_next_file_path : PathBuf ,
202
- ) -> Option < Arc < Mutex < LocalMappedFile > > > {
199
+ ) -> Option < Arc < LocalMappedFile > > {
203
200
let mut mapped_file = match self . allocate_mapped_file_service {
204
201
None => LocalMappedFile :: new (
205
202
next_file_path. to_string_lossy ( ) . to_string ( ) ,
@@ -213,12 +210,12 @@ impl MappedFileQueue {
213
210
if self . mapped_files . is_empty ( ) {
214
211
mapped_file. set_first_create_in_queue ( true ) ;
215
212
}
216
- let inner = Arc :: new ( Mutex :: new ( mapped_file) ) ;
213
+ let inner = Arc :: new ( mapped_file) ;
217
214
self . mapped_files . push ( inner. clone ( ) ) ;
218
215
Some ( inner)
219
216
}
220
217
221
- pub fn get_mapped_files ( & self ) -> Vec < Arc < Mutex < LocalMappedFile > > > {
218
+ pub fn get_mapped_files ( & self ) -> Vec < Arc < LocalMappedFile > > {
222
219
self . mapped_files . to_vec ( )
223
220
}
224
221
@@ -231,6 +228,34 @@ impl MappedFileQueue {
231
228
}
232
229
233
230
pub fn truncate_dirty_files ( & mut self , offset : i64 ) { }
231
+
232
+ pub fn get_max_offset ( & self ) -> i64 {
233
+ /*let handle = Handle::current();
234
+ let mapped_file = self.get_last_mapped_file();
235
+ std::thread::spawn(move || {
236
+ handle.block_on(async move {
237
+ match mapped_file {
238
+ None => 0,
239
+ Some(value) => {
240
+ let file = value.lock().await;
241
+ file.get_file_from_offset() as i64 + file.get_read_position() as i64
242
+ }
243
+ }
244
+ })
245
+ })
246
+ .join()
247
+ .unwrap()*/
248
+ match self . get_last_mapped_file ( ) {
249
+ None => 0 ,
250
+ Some ( file) => file. get_file_from_offset ( ) as i64 + file. get_read_position ( ) as i64 ,
251
+ }
252
+ }
253
+
254
+ pub fn delete_last_mapped_file ( & self ) {
255
+ unimplemented ! ( )
256
+ }
257
+
258
+ pub ( crate ) fn delete_expired_file ( & self , files : Vec < Option < Arc < LocalMappedFile > > > ) { }
234
259
}
235
260
236
261
#[ cfg( test) ]
0 commit comments