@@ -171,23 +171,25 @@ def standalonescrub(self, table, *indexes, acceptable_errors=None):
171171 self .launch_standalone_scrub (KEYSPACE , '{}.{}' .format (table , index ))
172172 return self .get_sstables (table , indexes )
173173
174- def increment_generation_by (self , sstable , generation_increment ):
174+ def get_latest_generation (self , sstables ):
175175 """
176- Set the generation number for an sstable file name
176+ Get the latest generation ID of the provided sstables
177177 """
178- return re .sub ('(\d(?!\d))\-' , lambda x : str (int (x .group (1 )) + generation_increment ) + '-' , sstable )
178+ latest_gen = None
179+ for table_or_index , table_sstables in list (sstables .items ()):
180+ gen = max (parse .search ('{}-{generation}-{}.{}' , s ).named ['generation' ] for s in table_sstables )
181+ latest_gen = gen if latest_gen is None else max ([gen , latest_gen ])
182+ return latest_gen
179183
180- def increase_sstable_generations (self , sstables ):
184+ def get_earliest_generation (self , sstables ):
181185 """
182- After finding the number of existing sstables, increase all of the
183- generations by that amount.
186+ Get the earliest generation ID of the provided sstables
184187 """
188+ earliest_gen = None
185189 for table_or_index , table_sstables in list (sstables .items ()):
186- increment_by = len (set (parse .search ('{}-{increment_by}-{suffix}.{file_extention}' , s ).named ['increment_by' ] for s in table_sstables ))
187- sstables [table_or_index ] = [self .increment_generation_by (s , increment_by ) for s in table_sstables ]
188-
189- logger .debug ('sstables after increment {}' .format (str (sstables )))
190-
190+ gen = min (parse .search ('{}-{generation}-{}.{}' , s ).named ['generation' ] for s in table_sstables )
191+ earliest_gen = gen if earliest_gen is None else min ([gen , earliest_gen ])
192+ return earliest_gen
191193
192194@since ('2.2' )
193195class TestScrubIndexes (TestHelper ):
@@ -240,16 +242,15 @@ def test_scrub_static_table(self):
240242 initial_sstables = self .flush ('users' , 'gender_idx' , 'state_idx' , 'birth_year_idx' )
241243 scrubbed_sstables = self .scrub ('users' , 'gender_idx' , 'state_idx' , 'birth_year_idx' )
242244
243- self .increase_sstable_generations (initial_sstables )
244- assert initial_sstables == scrubbed_sstables
245+ assert self .get_latest_generation (initial_sstables ) < self .get_earliest_generation (scrubbed_sstables )
245246
246247 users = self .query_users (session )
247248 assert initial_users == users
248249
249250 # Scrub and check sstables and data again
251+ initial_sstables = scrubbed_sstables
250252 scrubbed_sstables = self .scrub ('users' , 'gender_idx' , 'state_idx' , 'birth_year_idx' )
251- self .increase_sstable_generations (initial_sstables )
252- assert initial_sstables == scrubbed_sstables
253+ assert self .get_latest_generation (initial_sstables ) < self .get_earliest_generation (scrubbed_sstables )
253254
254255 users = self .query_users (session )
255256 assert initial_users == users
@@ -281,8 +282,7 @@ def test_standalone_scrub(self):
281282 cluster .stop ()
282283
283284 scrubbed_sstables = self .standalonescrub ('users' , 'gender_idx' , 'state_idx' , 'birth_year_idx' )
284- self .increase_sstable_generations (initial_sstables )
285- assert initial_sstables == scrubbed_sstables
285+ assert self .get_latest_generation (initial_sstables ) < self .get_earliest_generation (scrubbed_sstables )
286286
287287 cluster .start ()
288288 session = self .patient_cql_connection (node1 )
@@ -315,16 +315,14 @@ def test_scrub_collections_table(self):
315315 initial_sstables = self .flush ('users' , 'user_uuids_idx' )
316316 scrubbed_sstables = self .scrub ('users' , 'user_uuids_idx' )
317317
318- self .increase_sstable_generations (initial_sstables )
319- assert initial_sstables == scrubbed_sstables
318+ assert self .get_latest_generation (initial_sstables ) < self .get_earliest_generation (scrubbed_sstables )
320319
321320 users = list (session .execute (("SELECT * from users where uuids contains {some_uuid}" ).format (some_uuid = _id )))
322321 assert initial_users == users
323322
323+ initial_sstables = scrubbed_sstables
324324 scrubbed_sstables = self .scrub ('users' , 'user_uuids_idx' )
325-
326- self .increase_sstable_generations (initial_sstables )
327- assert initial_sstables == scrubbed_sstables
325+ assert self .get_latest_generation (initial_sstables ) < self .get_earliest_generation (scrubbed_sstables )
328326
329327 users = list (session .execute (("SELECT * from users where uuids contains {some_uuid}" ).format (some_uuid = _id )))
330328
@@ -377,16 +375,15 @@ def test_nodetool_scrub(self):
377375 initial_sstables = self .flush ('users' )
378376 scrubbed_sstables = self .scrub ('users' )
379377
380- self .increase_sstable_generations (initial_sstables )
381- assert initial_sstables == scrubbed_sstables
378+ assert self .get_latest_generation (initial_sstables ) < self .get_earliest_generation (scrubbed_sstables )
382379
383380 users = self .query_users (session )
384381 assert initial_users == users
385382
386383 # Scrub and check sstables and data again
384+ initial_sstables = scrubbed_sstables
387385 scrubbed_sstables = self .scrub ('users' )
388- self .increase_sstable_generations (initial_sstables )
389- assert initial_sstables == scrubbed_sstables
386+ assert self .get_latest_generation (initial_sstables ) < self .get_earliest_generation (scrubbed_sstables )
390387
391388 users = self .query_users (session )
392389 assert initial_users == users
@@ -418,8 +415,7 @@ def test_standalone_scrub(self):
418415 cluster .stop ()
419416
420417 scrubbed_sstables = self .standalonescrub ('users' )
421- self .increase_sstable_generations (initial_sstables )
422- assert initial_sstables == scrubbed_sstables
418+ assert self .get_latest_generation (initial_sstables ) < self .get_earliest_generation (scrubbed_sstables )
423419
424420 cluster .start ()
425421 session = self .patient_cql_connection (node1 )
@@ -447,8 +443,7 @@ def test_standalone_scrub_essential_files_only(self):
447443 self .delete_non_essential_sstable_files ('users' )
448444
449445 scrubbed_sstables = self .standalonescrub (table = 'users' , acceptable_errors = ["WARN.*Could not recreate or deserialize existing bloom filter, continuing with a pass-through bloom filter but this will significantly impact reads performance" ])
450- self .increase_sstable_generations (initial_sstables )
451- assert initial_sstables == scrubbed_sstables
446+ assert self .get_latest_generation (initial_sstables ) < self .get_earliest_generation (scrubbed_sstables )
452447
453448 cluster .start ()
454449 session = self .patient_cql_connection (node1 )
0 commit comments