pub fn new(
        config: Config,
        partition: String,
        id: u64,
        store: S,
        start_ts: u64,
    ) -> Result<SegmentWriter<S>, Error> {
        let path = Path::new(&config.dir)
            .join("partition")
            .join(partition.to_string());
        create_dir_all(&path)?;
        // create segment file.
        let mut file = File::create(path.join(format!("{}.segment", id)))?;

        // write the layout.
        let mut buf = Vec::new();
        buf.push(IoSlice::new(&MAGIC_TEXT.as_bytes()));
        buf.push(IoSlice::new(&[MAGIC_NUMBER; 1]));
        let _ = file.write_vectored(&buf[..])?;
        let file_index = (&MAGIC_TEXT.as_bytes().len() + 1) as u64;
        let info = file.metadata().unwrap();
        assert_eq!(info.len(), 14);
        Ok(SegmentWriter {
            config: config,
            segment_file: file,
            partition: partition,
            batch: Vec::new(),
            file_offset: file_index,
            store: store,
            id: id,
            start_ts: start_ts,
            end_ts: start_ts,
            index_posting_list: HashMap::default(),
            json_key_posting_list: HashMap::default(),
            index_size: 0,
            entry_offsets: Vec::new(),
            flushed_offset: file_index,
        })
    }
/// new create a segment file and returns SegmentWriter.
new create a segment file and returns SegmentWriter.
new create a segment file and returns SegmentWriter .
pub fn new(
        config: Config,
        partition: String,
        id: u64,
        store: S,
        start_ts: u64,
    ) -> Result<SegmentWriter<S>, Error> {
        let path = Path::new(&config.dir)
            .join("partition")
            .join(partition.to_string());
        create_dir_all(&path)?;
        // create segment file.
        let mut file = File::create(path.join(format!("{}.segment", id)))?;
        // write the layout.
        let mut buf = Vec::new();
        buf.push(IoSlice::new(&MAGIC_TEXT.as_bytes()));
        buf.push(IoSlice::new(&[MAGIC_NUMBER; 1]));
        let _ = file.write_vectored(&buf[..])?;
        let file_index = (&MAGIC_TEXT.as_bytes().len() + 1) as u64;
        let info = file.metadata().unwrap();
        assert_eq!(info.len(), 14);
        Ok(SegmentWriter {
            config: config,
            segment_file: file,
            partition: partition,
            batch: Vec::new(),
            file_offset: file_index,
            store: store,
            id: id,
            start_ts: start_ts,
            end_ts: start_ts,
            index_posting_list: HashMap::default(),
            json_key_posting_list: HashMap::default(),
            index_size: 0,
            entry_offsets: Vec::new(),
            flushed_offset: file_index,
        })
    }
pub fn new ( config : Config , partition : String , id : u64 , store : S , start_ts : u64 , ) -> Result < SegmentWriter < S > , Error > { let path = Path :: new ( & config . dir ) . join ( " " ) . join ( partition . to_string ( ) ) ; create_dir_all ( & path ) ? ; // create segment file. let mut file = File :: create ( path . join ( format ! ( " " id ) ) ) ? ; // write the layout. let mut buf = Vec :: new ( ) ; buf . push ( IoSlice :: new ( & MAGIC_TEXT . as_bytes ( ) ) ) ; buf . push ( IoSlice :: new ( & [ MAGIC_NUMBER ; 1 ] ) ) ; let _ = file . write_vectored ( & buf [ .. ] ) ? ; let file_index = ( & MAGIC_TEXT . as_bytes ( ) . len ( ) + 1 ) as u64 ; let info = file . metadata ( ) . unwrap ( ) ; assert_eq ! ( info len ( ) 14 ) ; Ok ( SegmentWriter { config : config , segment_file : file , partition : partition , batch : Vec :: new ( ) , file_offset : file_index , store : store , id : id , start_ts : start_ts , end_ts : start_ts , index_posting_list : HashMap :: default ( ) , json_key_posting_list : HashMap :: default ( ) , index_size : 0 , entry_offsets : Vec :: new ( ) , flushed_offset : file_index , } ) }
new create a segment file and returns SegmentWriter.
new create a segment file and returns SegmentWriter .
config
Config
partition
String
id
u64
store
S
start_ts
u64