@@ -64,7 +64,6 @@ pub struct Index<O: Op> {
6464
6565impl < O : Op > Index < O > {
6666 pub fn create ( path : PathBuf , options : IndexOptions ) -> Result < Arc < Self > , CreateError > {
67- let flexible = IndexFlexibleOptions :: default ( ) ;
6867 if let Err ( err) = options. validate ( ) {
6968 return Err ( CreateError :: InvalidIndexOptions {
7069 reason : err. to_string ( ) ,
@@ -82,7 +81,7 @@ impl<O: Op> Index<O> {
8281 IndexStartup {
8382 sealeds : HashSet :: new ( ) ,
8483 growings : HashSet :: new ( ) ,
85- flexible,
84+ flexible : IndexFlexibleOptions :: default ( ) ,
8685 } ,
8786 ) ;
8887 let delete = Delete :: create ( path. join ( "delete" ) ) ;
@@ -99,6 +98,7 @@ impl<O: Op> Index<O> {
9998 } ) ,
10099 view : ArcSwap :: new ( Arc :: new ( IndexView {
101100 options : options. clone ( ) ,
101+ flexible : IndexFlexibleOptions :: default ( ) ,
102102 sealed : HashMap :: new ( ) ,
103103 growing : HashMap :: new ( ) ,
104104 delete : delete. clone ( ) ,
@@ -119,6 +119,7 @@ impl<O: Op> Index<O> {
119119 . unwrap ( ) ;
120120 let tracker = Arc :: new ( IndexTracker { path : path. clone ( ) } ) ;
121121 let startup = FileAtomic :: < IndexStartup > :: open ( path. join ( "startup" ) ) ;
122+ let flexible = startup. get ( ) . flexible . clone ( ) ;
122123 clean (
123124 path. join ( "segments" ) ,
124125 startup
@@ -173,6 +174,7 @@ impl<O: Op> Index<O> {
173174 } ) ,
174175 view : ArcSwap :: new ( Arc :: new ( IndexView {
175176 options : options. clone ( ) ,
177+ flexible,
176178 delete : delete. clone ( ) ,
177179 sealed,
178180 growing,
@@ -191,25 +193,20 @@ impl<O: Op> Index<O> {
191193 pub fn view ( & self ) -> Arc < IndexView < O > > {
192194 self . view . load_full ( )
193195 }
194- pub fn setting ( self : & Arc < Self > , key : String , value : String ) -> Result < ( ) , SettingError > {
196+ pub fn alter ( self : & Arc < Self > , key : String , value : String ) -> Result < ( ) , AlterError > {
195197 let mut protect = self . protect . lock ( ) ;
196198 match key. as_str ( ) {
197199 "optimizing.threads" => {
198200 let parsed = i32:: from_str ( value. as_str ( ) )
199- . map_err ( |_e| SettingError :: BadValue { key, value } ) ?;
201+ . map_err ( |_e| AlterError :: BadValue { key, value } ) ?;
200202 let optimizing_threads = match parsed {
201- - 1 => IndexFlexibleOptions :: default_optimizing_threads ( ) ,
203+ 0 => IndexFlexibleOptions :: default_optimizing_threads ( ) ,
202204 threads_limit => threads_limit as u16 ,
203205 } ;
204206 protect. flexible_set ( IndexFlexibleOptions { optimizing_threads } ) ;
205- let mut background = self . background_indexing . lock ( ) ;
206- if let Some ( ( sender, join_handle) ) = background. take ( ) {
207- drop ( sender) ;
208- let _ = join_handle. join ( ) ;
209- * background = Some ( OptimizerIndexing :: new ( self . clone ( ) ) . spawn ( ) ) ;
210- }
207+ protect. maintain ( self . options . clone ( ) , self . delete . clone ( ) , & self . view ) ;
211208 }
212- _ => return Err ( SettingError :: BadKey { key } ) ,
209+ _ => return Err ( AlterError :: BadKey { key } ) ,
213210 } ;
214211 Ok ( ( ) )
215212 }
@@ -320,6 +317,7 @@ impl Drop for IndexTracker {
320317
321318pub struct IndexView < O : Op > {
322319 pub options : IndexOptions ,
320+ pub flexible : IndexFlexibleOptions ,
323321 pub delete : Arc < Delete > ,
324322 pub sealed : HashMap < Uuid , Arc < SealedSegment < O > > > ,
325323 pub growing : HashMap < Uuid , Arc < GrowingSegment < O > > > ,
@@ -545,14 +543,17 @@ struct IndexProtect<O: Op> {
545543}
546544
547545impl < O : Op > IndexProtect < O > {
546+ /// Export IndexProtect to IndexView
548547 fn maintain (
549548 & mut self ,
550549 options : IndexOptions ,
551550 delete : Arc < Delete > ,
552551 swap : & ArcSwap < IndexView < O > > ,
553552 ) {
553+ let old_startup = self . startup . get ( ) ;
554554 let view = Arc :: new ( IndexView {
555555 options,
556+ flexible : old_startup. flexible . clone ( ) ,
556557 delete,
557558 sealed : self . sealed . clone ( ) ,
558559 growing : self . growing . clone ( ) ,
@@ -564,7 +565,7 @@ impl<O: Op> IndexProtect<O> {
564565 self . startup . set ( IndexStartup {
565566 sealeds : startup_sealeds,
566567 growings : startup_growings,
567- flexible : self . flexible_get ( ) ,
568+ flexible : old_startup . flexible . clone ( ) ,
568569 } ) ;
569570 swap. swap ( view) ;
570571 }
@@ -576,8 +577,4 @@ impl<O: Op> IndexProtect<O> {
576577 flexible,
577578 } ) ;
578579 }
579- fn flexible_get ( & self ) -> IndexFlexibleOptions {
580- let src = self . startup . get ( ) ;
581- src. flexible . clone ( )
582- }
583580}
0 commit comments