@@ -4,7 +4,6 @@ use std::fmt;
4
4
use std:: mem:: size_of;
5
5
use std:: path:: Path ;
6
6
use std:: pin:: Pin ;
7
- use std:: str:: FromStr ;
8
7
use std:: sync:: Arc ;
9
8
use std:: task:: Poll ;
10
9
@@ -28,7 +27,7 @@ use crate::io::compat::copy_to_file;
28
27
use crate :: io:: { FileExt , Io , StdIO } ;
29
28
use crate :: segment:: compacted:: CompactedSegmentDataHeader ;
30
29
use crate :: segment:: Frame ;
31
- use crate :: storage:: { Error , RestoreOptions , Result } ;
30
+ use crate :: storage:: { Error , RestoreOptions , Result , SegmentKey } ;
32
31
use crate :: LIBSQL_MAGIC ;
33
32
34
33
pub struct S3Backend < IO > {
@@ -300,95 +299,6 @@ pub struct S3Config {
300
299
cluster_id : String ,
301
300
}
302
301
303
- /// SegmentKey is used to index segment data, where keys a lexicographically ordered.
304
- /// The scheme is `{u64::MAX - start_frame_no}-{u64::MAX - end_frame_no}`. With that naming convention, when looking for
305
- /// the segment containing 'n', we can perform a prefix search with "{u64::MAX - n}". The first
306
- /// element of the range will be the biggest segment that contains n if it exists.
307
- /// Beware that if no segments contain n, either the smallest segment not containing n, if n < argmin
308
- /// {start_frame_no}, or the largest segment if n > argmax {end_frame_no} will be returned.
309
- /// e.g:
310
- /// ```ignore
311
- /// let mut map = BTreeMap::new();
312
- ///
313
- /// let meta = SegmentMeta { start_frame_no: 1, end_frame_no: 100 };
314
- /// map.insert(SegmentKey(&meta).to_string(), meta);
315
- ///
316
- /// let meta = SegmentMeta { start_frame_no: 101, end_frame_no: 500 };
317
- /// map.insert(SegmentKey(&meta).to_string(), meta);
318
- ///
319
- /// let meta = SegmentMeta { start_frame_no: 101, end_frame_no: 1000 };
320
- /// map.insert(SegmentKey(&meta).to_string(), meta);
321
- ///
322
- /// map.range(format!("{:019}", u64::MAX - 50)..).next();
323
- /// map.range(format!("{:019}", u64::MAX - 0)..).next();
324
- /// map.range(format!("{:019}", u64::MAX - 1)..).next();
325
- /// map.range(format!("{:019}", u64::MAX - 100)..).next();
326
- /// map.range(format!("{:019}", u64::MAX - 101)..).next();
327
- /// map.range(format!("{:019}", u64::MAX - 5000)..).next();
328
- /// ```
329
- #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
330
- pub struct SegmentKey {
331
- pub start_frame_no : u64 ,
332
- pub end_frame_no : u64 ,
333
- }
334
-
335
- impl PartialOrd for SegmentKey {
336
- fn partial_cmp ( & self , other : & Self ) -> Option < std:: cmp:: Ordering > {
337
- match self . start_frame_no . partial_cmp ( & other. start_frame_no ) {
338
- Some ( core:: cmp:: Ordering :: Equal ) => { }
339
- ord => return ord,
340
- }
341
- self . end_frame_no . partial_cmp ( & other. end_frame_no )
342
- }
343
- }
344
-
345
- impl Ord for SegmentKey {
346
- fn cmp ( & self , other : & Self ) -> std:: cmp:: Ordering {
347
- self . partial_cmp ( other) . unwrap ( )
348
- }
349
- }
350
-
351
- impl SegmentKey {
352
- pub ( crate ) fn includes ( & self , frame_no : u64 ) -> bool {
353
- ( self . start_frame_no ..=self . end_frame_no ) . contains ( & frame_no)
354
- }
355
- }
356
-
357
- impl From < & SegmentMeta > for SegmentKey {
358
- fn from ( value : & SegmentMeta ) -> Self {
359
- Self {
360
- start_frame_no : value. start_frame_no ,
361
- end_frame_no : value. end_frame_no ,
362
- }
363
- }
364
- }
365
-
366
- impl FromStr for SegmentKey {
367
- type Err = ( ) ;
368
-
369
- fn from_str ( s : & str ) -> std:: result:: Result < Self , Self :: Err > {
370
- let ( rev_start_fno, s) = s. split_at ( 20 ) ;
371
- let start_frame_no = u64:: MAX - rev_start_fno. parse :: < u64 > ( ) . map_err ( |_| ( ) ) ?;
372
- let ( _, rev_end_fno) = s. split_at ( 1 ) ;
373
- let end_frame_no = u64:: MAX - rev_end_fno. parse :: < u64 > ( ) . map_err ( |_| ( ) ) ?;
374
- Ok ( Self {
375
- start_frame_no,
376
- end_frame_no,
377
- } )
378
- }
379
- }
380
-
381
- impl fmt:: Display for SegmentKey {
382
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
383
- write ! (
384
- f,
385
- "{:019}-{:019}" ,
386
- u64 :: MAX - self . start_frame_no,
387
- u64 :: MAX - self . end_frame_no,
388
- )
389
- }
390
- }
391
-
392
302
struct FolderKey < ' a > {
393
303
cluster_id : & ' a str ,
394
304
namespace : & ' a NamespaceName ,
0 commit comments