|
17 | 17 | import static org.mockito.Mockito.when; |
18 | 18 | import static org.testng.Assert.assertEquals; |
19 | 19 | import static org.testng.Assert.assertFalse; |
| 20 | +import static org.testng.Assert.assertNotNull; |
| 21 | +import static org.testng.Assert.assertNull; |
20 | 22 | import static org.testng.Assert.assertTrue; |
21 | 23 |
|
22 | 24 | import com.linkedin.davinci.config.VeniceServerConfig; |
|
40 | 42 | import com.linkedin.venice.meta.VersionStatus; |
41 | 43 | import com.linkedin.venice.store.rocksdb.RocksDBUtils; |
42 | 44 | import com.linkedin.venice.utils.PropertyBuilder; |
| 45 | +import com.linkedin.venice.utils.TestUtils; |
43 | 46 | import com.linkedin.venice.utils.Utils; |
44 | 47 | import com.linkedin.venice.utils.VeniceProperties; |
45 | 48 | import java.io.File; |
46 | 49 | import java.nio.ByteBuffer; |
47 | 50 | import java.util.Random; |
48 | 51 | import java.util.concurrent.CompletableFuture; |
| 52 | +import java.util.concurrent.TimeUnit; |
49 | 53 | import org.apache.commons.io.FileUtils; |
50 | 54 | import org.apache.helix.NotificationContext; |
51 | 55 | import org.apache.helix.model.Message; |
@@ -84,7 +88,11 @@ public void setUp() { |
84 | 88 | partitionPushStatusAccessorFuture = CompletableFuture.completedFuture(mock(HelixPartitionStatusAccessor.class)); |
85 | 89 | stateTransitionStats = mock(ParticipantStateTransitionStats.class); |
86 | 90 | heartbeatMonitoringService = mock(HeartbeatMonitoringService.class); |
87 | | - leaderFollowerPartitionStateModel = new LeaderFollowerPartitionStateModel( |
| 91 | + leaderFollowerPartitionStateModel = buildModel(notifier); |
| 92 | + } |
| 93 | + |
| 94 | + private LeaderFollowerPartitionStateModel buildModel(LeaderFollowerIngestionProgressNotifier notifier) { |
| 95 | + return new LeaderFollowerPartitionStateModel( |
88 | 96 | ingestionBackend, |
89 | 97 | storeAndServerConfigs, |
90 | 98 | partition, |
@@ -359,6 +367,48 @@ public void testNonCurrentVersionSkipsGracefulDrop() { |
359 | 367 | assertEquals(resetTimestamp, -1L, "Timestamp should be reset to -1 after transition"); |
360 | 368 | } |
361 | 369 |
|
| 370 | + /** |
| 371 | + * OFFLINE->STANDBY needs to complete when the current version is demoted to a backup version. |
| 372 | + */ |
| 373 | + @Test |
| 374 | + public void testOnStandbyCompletionUponDemotionToBackupVersion() throws Exception { |
| 375 | + Store store = mock(Store.class); |
| 376 | + when(store.getCurrentVersion()).thenReturn(storeVersion); // Version starts as current so the latch is created |
| 377 | + when(store.getBootstrapToOnlineTimeoutInHours()).thenReturn(24); // large timeout for latch await |
| 378 | + doReturn(store).when(metadataRepo).getStoreOrThrow(anyString()); |
| 379 | + LeaderFollowerIngestionProgressNotifier notifier = new LeaderFollowerIngestionProgressNotifier(); |
| 380 | + LeaderFollowerPartitionStateModel model = buildModel(notifier); |
| 381 | + |
| 382 | + // Start the OFFLINE -> STANDBY transition in a background thread which should be blocked in |
| 383 | + // waitConsumptionCompleted, because this is the current version, |
| 384 | + Message message = mock(Message.class); |
| 385 | + when(message.getResourceName()).thenReturn(resourceName); |
| 386 | + NotificationContext context = mock(NotificationContext.class); |
| 387 | + CompletableFuture<Void> transitionFuture = |
| 388 | + CompletableFuture.runAsync(() -> model.onBecomeStandbyFromOffline(message, context)); |
| 389 | + |
| 390 | + // Wait until the latch is created, confirming the transition is blocking. |
| 391 | + TestUtils.waitForNonDeterministicAssertion( |
| 392 | + 5, |
| 393 | + TimeUnit.SECONDS, |
| 394 | + () -> assertNotNull( |
| 395 | + notifier.getIngestionCompleteFlag(resourceName, partition), |
| 396 | + "Latch must be created for a current-version OFFLINE->STANDBY transition")); |
| 397 | + assertFalse(transitionFuture.isDone(), "Transition must be blocked waiting for the latch"); |
| 398 | + |
| 399 | + // Simulate CURRENT -> BACKUP version role flip: a newer version has been promoted. |
| 400 | + when(store.getCurrentVersion()).thenReturn(storeVersion + 1); |
| 401 | + |
| 402 | + // Simulate StoreIngestionTask.stopTrackingCurrentVersionIngestion() being called |
| 403 | + notifier.stopped(resourceName, partition, null); |
| 404 | + TestUtils.waitForNonDeterministicCompletion(5, TimeUnit.SECONDS, transitionFuture::isDone); |
| 405 | + // Ensure the transition completed successfully (will throw if it completed exceptionally) |
| 406 | + transitionFuture.join(); |
| 407 | + assertNull( |
| 408 | + notifier.getIngestionCompleteFlag(resourceName, partition), |
| 409 | + "Latch should be released/removed after current version is demoted"); |
| 410 | + } |
| 411 | + |
362 | 412 | /** |
363 | 413 | * Integration test that verifies RocksDB deletion rate limiting is honored during |
364 | 414 | * OFFLINE->DROPPED state transition (backup version deletion). |
|
0 commit comments