@@ -93,19 +93,49 @@ fn test_load_payload_index() {
9393}
9494
9595#[ test]
96- fn drop_index_if_incompatible_keeps_index_on_on_disk_only_change ( ) {
96+ fn drop_index_if_incompatible_keeps_non_appendable_index_on_on_disk_only_change ( ) {
97+ use std:: collections:: HashMap ;
98+ use std:: sync:: Arc ;
99+
100+ use atomic_refcell:: AtomicRefCell ;
101+
102+ use super :: StructPayloadIndex ;
97103 use crate :: data_types:: index:: IntegerIndexParams ;
98- use crate :: fixtures:: payload_context_fixture:: create_struct_payload_index;
104+ use crate :: fixtures:: payload_context_fixture:: {
105+ create_id_tracker_fixture, create_payload_storage_fixture,
106+ } ;
99107 use crate :: fixtures:: payload_fixtures:: INT_KEY ;
100108 use crate :: index:: PayloadIndex ;
101109 use crate :: types:: PayloadSchemaParams ;
102110
103111 let dir = Builder :: new ( ) . prefix ( "payload_dir" ) . tempdir ( ) . unwrap ( ) ;
104- let mut index = create_struct_payload_index ( dir. path ( ) , 100 , 42 ) ;
112+ let payload_storage = Arc :: new ( AtomicRefCell :: new (
113+ create_payload_storage_fixture ( 100 , 42 ) . into ( ) ,
114+ ) ) ;
115+ let id_tracker = Arc :: new ( AtomicRefCell :: new ( create_id_tracker_fixture ( 100 ) ) ) ;
116+
117+ // Non-appendable: `on_disk` is meaningful, so an on_disk-only change is
118+ // reused (reloaded in `build_index`), not dropped.
119+ let mut index = StructPayloadIndex :: open (
120+ payload_storage,
121+ id_tracker,
122+ HashMap :: new ( ) ,
123+ dir. path ( ) ,
124+ false ,
125+ true ,
126+ )
127+ . unwrap ( ) ;
128+
105129 let field = JsonPath :: from_str ( INT_KEY ) . unwrap ( ) ;
130+ index
131+ . set_indexed (
132+ & field,
133+ PayloadSchemaType :: Integer ,
134+ & HardwareCounterCell :: new ( ) ,
135+ )
136+ . unwrap ( ) ;
106137
107- // The fixture indexed INT_KEY as `FieldType(Integer)` (on_disk = false).
108- // Flip only `on_disk` to true; every other param stays at its default.
138+ // Same integer index, but with on_disk flipped to true.
109139 let on_disk_schema =
110140 PayloadFieldSchema :: FieldParams ( PayloadSchemaParams :: Integer ( IntegerIndexParams {
111141 on_disk : Some ( true ) ,
@@ -118,14 +148,49 @@ fn drop_index_if_incompatible_keeps_index_on_on_disk_only_change() {
118148
119149 assert ! (
120150 !dropped,
121- "an on_disk-only change must be treated as compatible , not dropped" ,
151+ "a non-appendable on_disk-only change must be reused , not dropped" ,
122152 ) ;
123153 assert ! (
124154 index. field_indexes. contains_key( & field) ,
125155 "the index must remain present after an on_disk-only change" ,
126156 ) ;
127157}
128158
159+ #[ test]
160+ fn drop_index_if_incompatible_drops_appendable_index_on_on_disk_only_change ( ) {
161+ use crate :: data_types:: index:: IntegerIndexParams ;
162+ use crate :: fixtures:: payload_context_fixture:: create_struct_payload_index;
163+ use crate :: fixtures:: payload_fixtures:: INT_KEY ;
164+ use crate :: index:: PayloadIndex ;
165+ use crate :: types:: PayloadSchemaParams ;
166+
167+ let dir = Builder :: new ( ) . prefix ( "payload_dir" ) . tempdir ( ) . unwrap ( ) ;
168+ // Appendable Gridstore: `on_disk` has no storage-layer effect, so an
169+ // on_disk-only change falls back to the drop-and-rebuild path (optimizing
170+ // the appendable case is handled separately).
171+ let mut index = create_struct_payload_index ( dir. path ( ) , 100 , 42 ) ;
172+ let field = JsonPath :: from_str ( INT_KEY ) . unwrap ( ) ;
173+
174+ let on_disk_schema =
175+ PayloadFieldSchema :: FieldParams ( PayloadSchemaParams :: Integer ( IntegerIndexParams {
176+ on_disk : Some ( true ) ,
177+ ..Default :: default ( )
178+ } ) ) ;
179+
180+ let dropped = index
181+ . drop_index_if_incompatible ( & field, & on_disk_schema)
182+ . unwrap ( ) ;
183+
184+ assert ! (
185+ dropped,
186+ "an appendable on_disk-only change drops (rebuild path) on this branch" ,
187+ ) ;
188+ assert ! (
189+ !index. field_indexes. contains_key( & field) ,
190+ "the appendable index is removed by the drop" ,
191+ ) ;
192+ }
193+
129194#[ test]
130195fn build_index_reloads_in_new_mode_on_on_disk_change ( ) {
131196 use std:: collections:: HashMap ;
0 commit comments