forked from linkedin/venice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestHybrid.java
More file actions
1754 lines (1611 loc) · 84.1 KB
/
Copy pathTestHybrid.java
File metadata and controls
1754 lines (1611 loc) · 84.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package com.linkedin.venice.endToEnd;
import static com.linkedin.davinci.store.rocksdb.RocksDBServerConfig.ROCKSDB_BLOB_FILES_ENABLED;
import static com.linkedin.davinci.store.rocksdb.RocksDBServerConfig.ROCKSDB_PLAIN_TABLE_FORMAT_ENABLED;
import static com.linkedin.venice.ConfigKeys.DEFAULT_MAX_NUMBER_OF_PARTITIONS;
import static com.linkedin.venice.ConfigKeys.KAFKA_BOOTSTRAP_SERVERS;
import static com.linkedin.venice.ConfigKeys.LOG_COMPACTION_ENABLED;
import static com.linkedin.venice.ConfigKeys.LOG_COMPACTION_INTERVAL_MS;
import static com.linkedin.venice.ConfigKeys.LOG_COMPACTION_SCHEDULING_ENABLED;
import static com.linkedin.venice.ConfigKeys.LOG_COMPACTION_VERSION_STALENESS_THRESHOLD_MS;
import static com.linkedin.venice.ConfigKeys.PERSISTENCE_TYPE;
import static com.linkedin.venice.ConfigKeys.REPUSH_ORCHESTRATOR_CLASS_NAME;
import static com.linkedin.venice.ConfigKeys.SERVER_CONSUMER_POOL_ALLOCATION_STRATEGY;
import static com.linkedin.venice.ConfigKeys.SERVER_CONSUMER_POOL_SIZE_PER_KAFKA_CLUSTER;
import static com.linkedin.venice.ConfigKeys.SERVER_DATABASE_CHECKSUM_VERIFICATION_ENABLED;
import static com.linkedin.venice.ConfigKeys.SERVER_DATABASE_SYNC_BYTES_INTERNAL_FOR_DEFERRED_WRITE_MODE;
import static com.linkedin.venice.ConfigKeys.SERVER_DEDICATED_DRAINER_FOR_SORTED_INPUT_ENABLED;
import static com.linkedin.venice.ConfigKeys.SERVER_PROMOTION_TO_LEADER_REPLICA_DELAY_SECONDS;
import static com.linkedin.venice.ConfigKeys.SERVER_SHARED_CONSUMER_ASSIGNMENT_STRATEGY;
import static com.linkedin.venice.ConfigKeys.SSL_TO_KAFKA_LEGACY;
import static com.linkedin.venice.integration.utils.VeniceClusterWrapper.DEFAULT_KEY_SCHEMA;
import static com.linkedin.venice.integration.utils.VeniceClusterWrapper.DEFAULT_VALUE_SCHEMA;
import static com.linkedin.venice.meta.BufferReplayPolicy.REWIND_FROM_EOP;
import static com.linkedin.venice.meta.BufferReplayPolicy.REWIND_FROM_SOP;
import static com.linkedin.venice.pubsub.PubSubConstants.PUBSUB_OPERATION_TIMEOUT_MS_DEFAULT_VALUE;
import static com.linkedin.venice.router.api.VenicePathParser.TYPE_STORAGE;
import static com.linkedin.venice.utils.IntegrationTestPushUtils.createStoreForJob;
import static com.linkedin.venice.utils.IntegrationTestPushUtils.defaultVPJProps;
import static com.linkedin.venice.utils.IntegrationTestPushUtils.getSamzaProducer;
import static com.linkedin.venice.utils.IntegrationTestPushUtils.getSamzaProducerConfig;
import static com.linkedin.venice.utils.IntegrationTestPushUtils.runVPJ;
import static com.linkedin.venice.utils.IntegrationTestPushUtils.sendCustomSizeStreamingRecord;
import static com.linkedin.venice.utils.IntegrationTestPushUtils.sendStreamingRecord;
import static com.linkedin.venice.utils.TestWriteUtils.STRING_SCHEMA;
import static com.linkedin.venice.utils.TestWriteUtils.getTempDataDirectory;
import static com.linkedin.venice.vpj.VenicePushJobConstants.DEFER_VERSION_SWAP;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.luben.zstd.Zstd;
import com.linkedin.davinci.kafka.consumer.KafkaConsumerService;
import com.linkedin.davinci.kafka.consumer.KafkaConsumerServiceDelegator;
import com.linkedin.venice.client.store.AvroGenericStoreClient;
import com.linkedin.venice.client.store.ClientConfig;
import com.linkedin.venice.client.store.ClientFactory;
import com.linkedin.venice.compression.CompressionStrategy;
import com.linkedin.venice.compression.CompressorFactory;
import com.linkedin.venice.compression.VeniceCompressor;
import com.linkedin.venice.controller.Admin;
import com.linkedin.venice.controller.repush.RepushJobRequest;
import com.linkedin.venice.controller.repush.RepushOrchestrator;
import com.linkedin.venice.controllerapi.ControllerClient;
import com.linkedin.venice.controllerapi.ControllerResponse;
import com.linkedin.venice.controllerapi.RepushJobResponse;
import com.linkedin.venice.controllerapi.StoreResponse;
import com.linkedin.venice.controllerapi.UpdateStoreQueryParams;
import com.linkedin.venice.controllerapi.VersionCreationResponse;
import com.linkedin.venice.exceptions.RecordTooLargeException;
import com.linkedin.venice.exceptions.VeniceException;
import com.linkedin.venice.helix.HelixBaseRoutingRepository;
import com.linkedin.venice.integration.utils.PubSubBrokerWrapper;
import com.linkedin.venice.integration.utils.ServiceFactory;
import com.linkedin.venice.integration.utils.VeniceClusterCreateOptions;
import com.linkedin.venice.integration.utils.VeniceClusterWrapper;
import com.linkedin.venice.integration.utils.VeniceServerWrapper;
import com.linkedin.venice.kafka.protocol.GUID;
import com.linkedin.venice.kafka.protocol.KafkaMessageEnvelope;
import com.linkedin.venice.kafka.protocol.LeaderMetadata;
import com.linkedin.venice.kafka.protocol.ProducerMetadata;
import com.linkedin.venice.kafka.protocol.Put;
import com.linkedin.venice.kafka.protocol.enums.MessageType;
import com.linkedin.venice.message.KafkaKey;
import com.linkedin.venice.meta.BufferReplayPolicy;
import com.linkedin.venice.meta.Instance;
import com.linkedin.venice.meta.InstanceStatus;
import com.linkedin.venice.meta.PersistenceType;
import com.linkedin.venice.meta.QueryAction;
import com.linkedin.venice.meta.Store;
import com.linkedin.venice.meta.StoreInfo;
import com.linkedin.venice.meta.StoreStatus;
import com.linkedin.venice.meta.Version;
import com.linkedin.venice.producer.VeniceProducer;
import com.linkedin.venice.producer.online.OnlineProducerFactory;
import com.linkedin.venice.pubsub.PubSubProducerAdapterFactory;
import com.linkedin.venice.pubsub.api.PubSubSymbolicPosition;
import com.linkedin.venice.pubsub.api.PubSubTopic;
import com.linkedin.venice.pubsub.manager.TopicManager;
import com.linkedin.venice.samza.SamzaExitMode;
import com.linkedin.venice.samza.VeniceSystemFactory;
import com.linkedin.venice.samza.VeniceSystemProducer;
import com.linkedin.venice.serializer.AvroGenericDeserializer;
import com.linkedin.venice.serializer.AvroSerializer;
import com.linkedin.venice.utils.ByteUtils;
import com.linkedin.venice.utils.DataProviderUtils;
import com.linkedin.venice.utils.IntegrationTestPushUtils;
import com.linkedin.venice.utils.Pair;
import com.linkedin.venice.utils.TestMockTime;
import com.linkedin.venice.utils.TestUtils;
import com.linkedin.venice.utils.TestWriteUtils;
import com.linkedin.venice.utils.Time;
import com.linkedin.venice.utils.Utils;
import com.linkedin.venice.utils.VeniceProperties;
import com.linkedin.venice.writer.CompletableFutureCallback;
import com.linkedin.venice.writer.VeniceWriter;
import com.linkedin.venice.writer.VeniceWriterOptions;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.util.AbstractMap;
import java.util.Arrays;
import java.util.Base64;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.apache.avro.Schema;
import org.apache.avro.util.Utf8;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
import org.apache.http.impl.nio.client.HttpAsyncClients;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.samza.config.MapConfig;
import org.apache.samza.system.SystemProducer;
import org.mockito.Mockito;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class TestHybrid {
private static final Logger LOGGER = LogManager.getLogger(TestHybrid.class);
public static final int STREAMING_RECORD_SIZE = 1024;
// Log compaction test constants
private static final long TEST_LOG_COMPACTION_INTERVAL_MS = TimeUnit.SECONDS.toMillis(1);
private static final long TEST_LOG_COMPACTION_TIMEOUT = TEST_LOG_COMPACTION_INTERVAL_MS * 10; // ms
private static final long TEST_VERSION_STALENESS_THRESHOLD_MS = 0;
/**
* IMPORTANT NOTE: if you use this sharedVenice cluster, please do not close it. The {@link #cleanUp()} function
* will take care of it. Besides, if any backend component of the shared cluster is stopped in
* the middle of the test, please restart them at the end of your test.
*/
private VeniceClusterWrapper sharedVenice;
/**
* This cluster is re-used by some of the tests, in order to speed up the suite. Some other tests require
* certain specific characteristics which makes it awkward to re-use, though not necessarily impossible.
* Further reuse of this shared cluster can be attempted later.
*/
@BeforeClass(alwaysRun = true)
public void setUp() {
sharedVenice = setUpCluster(false);
}
@AfterClass(alwaysRun = true)
public void cleanUp() {
Utils.closeQuietlyWithErrorLogged(sharedVenice);
}
/**
* N.B.: Non-L/F does not support chunking, so this permutation is skipped.
*/
@DataProvider(name = "testPermutations", parallel = false)
public static Object[][] testPermutations() {
return new Object[][] { { false, false, REWIND_FROM_EOP }, { false, true, REWIND_FROM_EOP },
{ true, false, REWIND_FROM_EOP }, { true, true, REWIND_FROM_EOP }, { false, false, REWIND_FROM_SOP },
{ false, true, REWIND_FROM_SOP }, { true, false, REWIND_FROM_SOP }, { true, true, REWIND_FROM_SOP } };
}
/**
* This test validates the hybrid batch + streaming semantics and verifies that configured rewind time works as expected.
*
* TODO: This test needs to be refactored in order to leverage {@link TestMockTime},
* which would allow the test to run faster and more deterministically.
*
* @param multiDivStream if false, rewind will happen in the middle of a DIV Segment, which was originally broken.
* if true, two independent DIV Segments will be placed before and after the start of buffer replay.
*
* If this test succeeds with {@param multiDivStream} set to true, but fails with it set to false,
* then there is a regression in the DIV partial segment tolerance after EOP.
* @param chunkingEnabled Whether chunking should be enabled.
*/
@Test(dataProvider = "testPermutations", timeOut = 180 * Time.MS_PER_SECOND, groups = { "flaky" })
public void testHybridEndToEnd(boolean multiDivStream, boolean chunkingEnabled, BufferReplayPolicy bufferReplayPolicy)
throws Exception {
LOGGER.info("About to create VeniceClusterWrapper");
Properties extraProperties = new Properties();
if (chunkingEnabled) {
// We exercise chunking by setting the servers' max size arbitrarily low. For now, since the RT topic
// does not support chunking, and write compute is not merged yet, there is no other way to make the
// store-version data bigger than the RT data and thus have chunked values produced.
int maxMessageSizeInServer = STREAMING_RECORD_SIZE / 2;
extraProperties.setProperty(
VeniceWriter.MAX_SIZE_FOR_USER_PAYLOAD_PER_MESSAGE_IN_BYTES,
Integer.toString(maxMessageSizeInServer));
}
SystemProducer veniceProducer = null;
// N.B.: RF 2 with 2 servers is important, in order to test both the leader and follower code paths
VeniceClusterWrapper venice = sharedVenice;
try {
LOGGER.info("Finished creating VeniceClusterWrapper");
long streamingRewindSeconds = 10L;
long streamingMessageLag = 2L;
String storeName = Utils.getUniqueString("hybrid-store");
File inputDir = getTempDataDirectory();
String inputDirPath = "file://" + inputDir.getAbsolutePath();
Schema recordSchema = TestWriteUtils.writeSimpleAvroFileWithStringToStringSchema(inputDir); // records 1-100
Properties vpjProperties = defaultVPJProps(venice, inputDirPath, storeName);
try (ControllerClient controllerClient = createStoreForJob(venice.getClusterName(), recordSchema, vpjProperties);
AvroGenericStoreClient client = ClientFactory.getAndStartGenericAvroClient(
ClientConfig.defaultGenericClientConfig(storeName).setVeniceURL(venice.getRandomRouterURL()));
TopicManager topicManager =
IntegrationTestPushUtils
.getTopicManagerRepo(
PUBSUB_OPERATION_TIMEOUT_MS_DEFAULT_VALUE,
100,
0l,
venice.getPubSubBrokerWrapper(),
sharedVenice.getPubSubTopicRepository())
.getLocalTopicManager()) {
Cache cacheNothingCache = Mockito.mock(Cache.class);
Mockito.when(cacheNothingCache.getIfPresent(Mockito.any())).thenReturn(null);
topicManager.setTopicConfigCache(cacheNothingCache);
ControllerResponse response = controllerClient.updateStore(
storeName,
new UpdateStoreQueryParams().setHybridRewindSeconds(streamingRewindSeconds)
.setHybridOffsetLagThreshold(streamingMessageLag)
.setChunkingEnabled(chunkingEnabled)
.setHybridBufferReplayPolicy(bufferReplayPolicy));
Assert.assertFalse(response.isError());
// Do a VPJ push
runVPJ(vpjProperties, 1, controllerClient);
// verify the topic compaction policy
PubSubTopic topicForStoreVersion1 =
sharedVenice.getPubSubTopicRepository().getTopic(Version.composeKafkaTopic(storeName, 1));
Assert.assertTrue(
topicManager.isTopicCompactionEnabled(topicForStoreVersion1),
"topic: " + topicForStoreVersion1 + " should have compaction enabled");
// Verify some records (note, records 1-100 have been pushed)
TestUtils.waitForNonDeterministicAssertion(10, TimeUnit.SECONDS, true, () -> {
try {
for (int i = 1; i < 100; i++) {
String key = Integer.toString(i);
Object value = client.get(key).get();
assertNotNull(value, "Key " + i + " should not be missing!");
assertEquals(value.toString(), "test_name_" + key);
}
} catch (Exception e) {
throw new VeniceException(e);
}
});
// write streaming records
veniceProducer = getSamzaProducer(venice, storeName, Version.PushType.STREAM);
for (int i = 1; i <= 10; i++) {
// The batch values are small, but the streaming records are "big" (i.e.: not that big, but bigger than
// the server's max configured chunk size). In the scenario where chunking is disabled, the server's
// max chunk size is not altered, and thus this will be under threshold.
sendCustomSizeStreamingRecord(veniceProducer, storeName, i, STREAMING_RECORD_SIZE);
}
if (multiDivStream) {
veniceProducer.stop(); // close out the DIV segment
}
TestUtils.waitForNonDeterministicAssertion(10, TimeUnit.SECONDS, () -> {
try {
checkLargeRecord(client, 2);
} catch (Exception e) {
throw new VeniceException(e);
}
});
// Update min and max compaction lag
long expectedMinCompactionLagSeconds = TimeUnit.MINUTES.toSeconds(10); // 10mins
long expectedMaxCompactionLagSeconds = TimeUnit.MINUTES.toSeconds(20); // 20mins
controllerClient.updateStore(
storeName,
new UpdateStoreQueryParams().setMinCompactionLagSeconds(expectedMinCompactionLagSeconds)
.setMaxCompactionLagSeconds(expectedMaxCompactionLagSeconds));
// Run one more VPJ
runVPJ(vpjProperties, 2, controllerClient);
// verify the topic compaction policy
PubSubTopic topicForStoreVersion2 =
sharedVenice.getPubSubTopicRepository().getTopic(Version.composeKafkaTopic(storeName, 2));
Assert.assertTrue(
topicManager.isTopicCompactionEnabled(topicForStoreVersion2),
"topic: " + topicForStoreVersion2 + " should have compaction enabled");
long expectedMinCompactionLagMS = TimeUnit.SECONDS.toMillis(expectedMinCompactionLagSeconds);
Assert.assertEquals(
topicManager.getTopicMinLogCompactionLagMs(topicForStoreVersion2),
expectedMinCompactionLagMS,
"topic:" + topicForStoreVersion2 + " should have min compaction lag config set to "
+ expectedMinCompactionLagMS);
long expectedMaxCompactionLagMS = TimeUnit.SECONDS.toMillis(expectedMaxCompactionLagSeconds);
Assert.assertEquals(
topicManager.getTopicMaxLogCompactionLagMs(topicForStoreVersion2).get().longValue(),
expectedMaxCompactionLagMS,
"topic:" + topicForStoreVersion2 + " should have max compaction lag config set to "
+ expectedMaxCompactionLagMS);
// Verify streaming record in second version
checkLargeRecord(client, 2);
assertEquals(client.get("19").get().toString(), "test_name_19");
// TODO: Would be great to eliminate this wait time...
LOGGER.info("***** Sleeping to get outside of rewind time: {} seconds", streamingRewindSeconds);
Utils.sleep(TimeUnit.MILLISECONDS.convert(streamingRewindSeconds, TimeUnit.SECONDS));
// Write more streaming records
if (multiDivStream) {
veniceProducer = getSamzaProducer(venice, storeName, Version.PushType.STREAM); // new producer, new DIV
// segment.
}
for (int i = 10; i <= 20; i++) {
sendCustomSizeStreamingRecord(veniceProducer, storeName, i, STREAMING_RECORD_SIZE);
}
TestUtils.waitForNonDeterministicAssertion(15, TimeUnit.SECONDS, () -> {
try {
checkLargeRecord(client, 19);
} catch (Exception e) {
throw new VeniceException(e);
}
});
// Run VPJ a third Time
runVPJ(vpjProperties, 3, controllerClient);
// verify the topic compaction policy
PubSubTopic topicForStoreVersion3 =
sharedVenice.getPubSubTopicRepository().getTopic(Version.composeKafkaTopic(storeName, 3));
Assert.assertTrue(
topicManager.isTopicCompactionEnabled(topicForStoreVersion3),
"topic: " + topicForStoreVersion3 + " should have compaction enabled");
// Verify new streaming record in third version
TestUtils.waitForNonDeterministicAssertion(15, TimeUnit.SECONDS, () -> {
try {
checkLargeRecord(client, 19);
} catch (Exception e) {
throw new VeniceException(e);
}
});
// But not old streaming record (because we waited the rewind time)
assertEquals(client.get("2").get().toString(), "test_name_2");
TestUtils.waitForNonDeterministicAssertion(30, TimeUnit.SECONDS, true, true, () -> {
StoreResponse storeResponse = controllerClient.getStore(storeName);
assertFalse(storeResponse.isError());
List<Integer> versions =
storeResponse.getStore().getVersions().stream().map(Version::getNumber).collect(Collectors.toList());
assertFalse(versions.contains(1), "After version 3 comes online, version 1 should be retired");
assertTrue(versions.contains(2));
assertTrue(versions.contains(3));
});
controllerClient.listInstancesStatuses(false)
.getInstancesStatusMap()
.keySet()
.forEach(
s -> LOGGER.info(
"Replicas for {}: {}",
s,
Arrays.toString(controllerClient.listStorageNodeReplicas(s).getReplicas())));
// TODO will move this test case to a single fail-over integration test.
// Stop one server
int port = venice.getVeniceServers().get(0).getPort();
venice.stopVeniceServer(port);
TestUtils.waitForNonDeterministicAssertion(15, TimeUnit.SECONDS, true, true, () -> {
// Make sure Helix knows the instance is shutdown
Map<String, String> storeStatus = controllerClient.listStoresStatuses().getStoreStatusMap();
assertEquals(
StoreStatus.UNDER_REPLICATED.toString(),
storeStatus.get(storeName),
"Should be UNDER_REPLICATED");
Map<String, String> instanceStatus = controllerClient.listInstancesStatuses(false).getInstancesStatusMap();
Assert.assertTrue(
instanceStatus.entrySet()
.stream()
.filter(entry -> entry.getKey().contains(Integer.toString(port)))
.map(Map.Entry::getValue)
.allMatch(s -> s.equals(InstanceStatus.DISCONNECTED.toString())),
"Storage Node on port " + port + " should be DISCONNECTED");
});
// Restart one server
venice.restartVeniceServer(port);
TestUtils.waitForNonDeterministicAssertion(15, TimeUnit.SECONDS, true, true, () -> {
// Make sure Helix knows the instance has recovered
Map<String, String> storeStatus = controllerClient.listStoresStatuses().getStoreStatusMap();
assertEquals(
StoreStatus.FULLLY_REPLICATED.toString(),
storeStatus.get(storeName),
"Should be FULLLY_REPLICATED");
});
}
} finally {
if (veniceProducer != null) {
veniceProducer.stop();
}
}
}
private static VeniceCompressor getVeniceCompressor(
CompressionStrategy compressionStrategy,
String storeName,
int storeVersion,
VeniceClusterWrapper venice,
CloseableHttpAsyncClient storageNodeClient) throws IOException, ExecutionException, InterruptedException {
CompressorFactory compressorFactory = new CompressorFactory();
if (compressionStrategy.equals(CompressionStrategy.ZSTD_WITH_DICT)) {
// query the dictionary
VeniceServerWrapper serverWrapper = venice.getVeniceServers().get(0);
StringBuilder sb = new StringBuilder().append("http://")
.append(serverWrapper.getAddress())
.append("/")
.append(QueryAction.DICTIONARY.toString().toLowerCase())
.append("/")
.append(storeName)
.append("/")
.append(storeVersion);
HttpGet getReq = new HttpGet(sb.toString());
try (InputStream bodyStream = storageNodeClient.execute(getReq, null).get().getEntity().getContent()) {
byte[] dictionary = IOUtils.toByteArray(bodyStream);
return compressorFactory.createCompressorWithDictionary(dictionary, Zstd.maxCompressionLevel());
} catch (InterruptedException | ExecutionException e) {
throw e;
}
} else {
return compressorFactory.getCompressor(compressionStrategy);
}
}
private void checkLargeRecord(AvroGenericStoreClient client, int index)
throws ExecutionException, InterruptedException {
String key = Integer.toString(index);
String value = client.get(key).get().toString();
assertEquals(
value.length(),
STREAMING_RECORD_SIZE,
"Expected a large record for key '" + key + "' but instead got: '" + value + "'.");
String expectedChar = Integer.toString(index).substring(0, 1);
for (int i = 0; i < value.length(); i++) {
assertEquals(value.substring(i, i + 1), expectedChar);
}
}
/**
* A comprehensive integration test for RP job. We set up RF to be 2 in the cluster and spin up 3 SNs nodes here.
* 2 RF is required to be the correctness for both leader and follower's behavior. A spare SN is also added for
* testing whether the flow can work while the original leader dies.
*
*/
@Test(timeOut = 180 * Time.MS_PER_SECOND, enabled = false)
public void testSamzaBatchLoad() throws Exception {
Properties extraProperties = new Properties();
extraProperties.setProperty(PERSISTENCE_TYPE, PersistenceType.ROCKS_DB.name());
extraProperties.setProperty(ROCKSDB_PLAIN_TABLE_FORMAT_ENABLED, "false");
SystemProducer veniceBatchProducer = null;
VeniceClusterCreateOptions options = new VeniceClusterCreateOptions.Builder().numberOfControllers(1)
.numberOfServers(3)
.numberOfRouters(1)
.replicationFactor(2)
.partitionSize(1000000)
.sslToStorageNodes(false)
.sslToKafka(false)
.extraProperties(extraProperties)
.build();
try (VeniceClusterWrapper veniceClusterWrapper = ServiceFactory.getVeniceCluster(options)) {
try {
Admin admin = veniceClusterWrapper.getLeaderVeniceController().getVeniceAdmin();
String clusterName = veniceClusterWrapper.getClusterName();
String storeName = Utils.getUniqueString("test-store");
long streamingRewindSeconds = 25L;
long streamingMessageLag = 2L;
// Create empty store
admin.createStore(clusterName, storeName, "tester", "\"string\"", "\"string\"");
admin.updateStore(
clusterName,
storeName,
new UpdateStoreQueryParams().setPartitionCount(1)
.setHybridRewindSeconds(streamingRewindSeconds)
.setHybridOffsetLagThreshold(streamingMessageLag)
.setChunkingEnabled(true));
TestUtils.waitForNonDeterministicAssertion(10, TimeUnit.SECONDS, true, true, () -> {
Assert.assertFalse(admin.getStore(clusterName, storeName).containsVersion(1));
Assert.assertEquals(admin.getStore(clusterName, storeName).getCurrentVersion(), 0);
});
// Batch load from Samza
VeniceSystemFactory factory = new VeniceSystemFactory();
Version.PushType pushType = Version.PushType.STREAM_REPROCESSING;
Map<String, String> samzaConfig = getSamzaProducerConfig(veniceClusterWrapper, storeName, pushType);
veniceBatchProducer = factory.getProducer("venice", new MapConfig(samzaConfig), null);
veniceBatchProducer.start();
if (veniceBatchProducer instanceof VeniceSystemProducer) {
// The default behavior would exit the process
((VeniceSystemProducer) veniceBatchProducer).setExitMode(SamzaExitMode.NO_OP);
}
// Purposefully out of order, because Samza batch jobs should be allowed to write out of order
for (int i = 10; i >= 1; i--) {
sendStreamingRecord(veniceBatchProducer, storeName, i);
}
TestUtils.waitForNonDeterministicAssertion(10, TimeUnit.SECONDS, true, true, () -> {
Assert.assertTrue(admin.getStore(clusterName, storeName).containsVersion(1));
Assert.assertEquals(admin.getStore(clusterName, storeName).getCurrentVersion(), 0);
});
// while running in L/F model, we try to stop the original SN; let Helix elect a new leader and push some extra
// data here. This is for testing "pass-through" mode is working properly
// wait a little time to make sure the leader has re-produced all existing messages
long waitTime = TimeUnit.SECONDS.toMillis(8);
Utils.sleep(waitTime);
String resourceName = Version.composeKafkaTopic(storeName, 1);
HelixBaseRoutingRepository routingDataRepo =
veniceClusterWrapper.getRandomVeniceRouter().getRoutingDataRepository();
TestUtils.waitForNonDeterministicAssertion(10, TimeUnit.SECONDS, true, true, () -> {
Instance leaderNode = routingDataRepo.getLeaderInstance(resourceName, 0);
Assert.assertNotNull(leaderNode);
});
Instance oldLeaderNode = routingDataRepo.getLeaderInstance(resourceName, 0);
veniceClusterWrapper.stopVeniceServer(oldLeaderNode.getPort());
TestUtils.waitForNonDeterministicAssertion(30, TimeUnit.SECONDS, true, true, () -> {
Instance newLeaderNode = routingDataRepo.getLeaderInstance(resourceName, 0);
Assert.assertNotNull(newLeaderNode);
Assert.assertNotEquals(oldLeaderNode.getPort(), newLeaderNode.getPort());
Assert.assertTrue(
routingDataRepo.getPartitionAssignments(resourceName).getPartition(0).getWorkingInstances().size() == 2);
});
for (int i = 21; i <= 30; i++) {
sendCustomSizeStreamingRecord(veniceBatchProducer, storeName, i, ByteUtils.BYTES_PER_MB);
}
for (int i = 31; i <= 40; i++) {
sendStreamingRecord(veniceBatchProducer, storeName, i);
}
// Before EOP, the Samza batch producer should still be in active state
Assert.assertEquals(factory.getNumberOfActiveSystemProducers(), 1);
/**
* Use the same VeniceWriter to write END_OF_PUSH message, which will guarantee the message order in topic
*/
VeniceWriter<byte[], byte[], byte[]> writer =
(VeniceWriter<byte[], byte[], byte[]>) ((VeniceSystemProducer) veniceBatchProducer).getInternalWriter();
writer.broadcastEndOfPush(new HashMap<>());
TestUtils.waitForNonDeterministicAssertion(30, TimeUnit.SECONDS, true, true, () -> {
Assert.assertTrue(admin.getStore(clusterName, storeName).containsVersion(1));
Assert.assertEquals(admin.getStore(clusterName, storeName).getCurrentVersion(), 1);
// After EOP, the push monitor inside the system producer would mark the producer as inactive in the factory
Assert.assertEquals(factory.getNumberOfActiveSystemProducers(), 0);
});
SystemProducer veniceStreamProducer =
getSamzaProducer(veniceClusterWrapper, storeName, Version.PushType.STREAM);
try (AvroGenericStoreClient client = ClientFactory.getAndStartGenericAvroClient(
ClientConfig.defaultGenericClientConfig(storeName)
.setVeniceURL(veniceClusterWrapper.getRandomRouterURL()))) {
TestUtils.waitForNonDeterministicAssertion(30, TimeUnit.SECONDS, true, true, () -> {
// Verify data, note only 1-10 have been pushed so far
for (int i = 1; i <= 10; i++) {
String key = Integer.toString(i);
Object value = client.get(key).get();
Assert.assertNotNull(value);
Assert.assertEquals(value.toString(), "stream_" + key);
}
});
Assert.assertNull(client.get(Integer.toString(11)).get(), "This record should not be found");
// Should find large values
for (int i = 21; i <= 30; i++) {
String key = Integer.toString(i);
Object value = client.get(key).get();
assertNotNull(value, "Key " + i + " should not be missing!");
}
for (int i = 31; i <= 40; i++) {
String key = Integer.toString(i);
Assert.assertEquals(client.get(key).get().toString(), "stream_" + key);
}
// Switch to stream mode and push more data
veniceStreamProducer.start();
for (int i = 11; i <= 20; i++) {
sendStreamingRecord(veniceStreamProducer, storeName, i);
}
Assert.assertThrows(
RecordTooLargeException.class,
() -> sendCustomSizeStreamingRecord(veniceStreamProducer, storeName, 0, ByteUtils.BYTES_PER_MB));
Assert.assertTrue(admin.getStore(clusterName, storeName).containsVersion(1));
Assert.assertFalse(admin.getStore(clusterName, storeName).containsVersion(2));
Assert.assertEquals(admin.getStore(clusterName, storeName).getCurrentVersion(), 1);
// Verify both batch and stream data
/**
* Leader would wait for 5 seconds before switching to real-time topic.
*/
long extraWaitTime = TimeUnit.SECONDS.toMillis(5);
long normalTimeForConsuming = TimeUnit.SECONDS.toMillis(3);
LOGGER.info("normalTimeForConsuming: {} ms; extraWaitTime: {} ms", normalTimeForConsuming, extraWaitTime);
Utils.sleep(normalTimeForConsuming + extraWaitTime);
TestUtils.waitForNonDeterministicAssertion(30, TimeUnit.SECONDS, false, true, () -> {
for (int i = 1; i < 20; i++) {
String key = Integer.toString(i);
Assert.assertEquals(client.get(key).get().toString(), "stream_" + key);
}
Assert.assertNull(client.get(Integer.toString(41)).get(), "This record should not be found");
});
} finally {
veniceStreamProducer.stop();
}
} finally {
if (veniceBatchProducer != null) {
veniceBatchProducer.stop();
}
}
}
}
@Test(timeOut = 180 * Time.MS_PER_SECOND, enabled = false)
public void testMultiStreamReprocessingSystemProducers() {
SystemProducer veniceBatchProducer1 = null, veniceBatchProducer2 = null;
try {
VeniceClusterWrapper veniceClusterWrapper = sharedVenice;
Admin admin = veniceClusterWrapper.getLeaderVeniceController().getVeniceAdmin();
String clusterName = veniceClusterWrapper.getClusterName();
String storeName1 = Utils.getUniqueString("test-store1");
String storeName2 = Utils.getUniqueString("test-store2");
long streamingRewindSeconds = 25L;
long streamingMessageLag = 2L;
// create 2 stores
// Create empty store
admin.createStore(clusterName, storeName1, "tester", "\"string\"", "\"string\"");
admin.createStore(clusterName, storeName2, "tester", "\"string\"", "\"string\"");
UpdateStoreQueryParams storeSettings = new UpdateStoreQueryParams().setHybridRewindSeconds(streamingRewindSeconds)
.setHybridOffsetLagThreshold(streamingMessageLag);
admin.updateStore(clusterName, storeName1, storeSettings);
admin.updateStore(clusterName, storeName2, storeSettings);
veniceClusterWrapper.getVeniceRouters().get(0).refresh();
Assert.assertFalse(admin.getStore(clusterName, storeName1).containsVersion(1));
Assert.assertEquals(admin.getStore(clusterName, storeName1).getCurrentVersion(), 0);
Assert.assertFalse(admin.getStore(clusterName, storeName2).containsVersion(1));
Assert.assertEquals(admin.getStore(clusterName, storeName2).getCurrentVersion(), 0);
// Batch load from Samza to both stores
VeniceSystemFactory factory = new VeniceSystemFactory();
Map<String, String> samzaConfig1 =
getSamzaProducerConfig(veniceClusterWrapper, storeName1, Version.PushType.STREAM_REPROCESSING);
veniceBatchProducer1 = factory.getProducer("venice", new MapConfig(samzaConfig1), null);
veniceBatchProducer1.start();
Map<String, String> samzaConfig2 =
getSamzaProducerConfig(veniceClusterWrapper, storeName2, Version.PushType.STREAM_REPROCESSING);
veniceBatchProducer2 = factory.getProducer("venice", new MapConfig(samzaConfig2), null);
veniceBatchProducer2.start();
if (veniceBatchProducer1 instanceof VeniceSystemProducer) {
// The default behavior would exit the process
((VeniceSystemProducer) veniceBatchProducer1).setExitMode(SamzaExitMode.NO_OP);
}
if (veniceBatchProducer2 instanceof VeniceSystemProducer) {
// The default behavior would exit the process
((VeniceSystemProducer) veniceBatchProducer2).setExitMode(SamzaExitMode.NO_OP);
}
for (int i = 10; i >= 1; i--) {
sendStreamingRecord(veniceBatchProducer1, storeName1, i);
sendStreamingRecord(veniceBatchProducer2, storeName2, i);
}
// Before EOP, there should be 2 active producers
Assert.assertEquals(factory.getNumberOfActiveSystemProducers(), 2);
/**
* Send EOP to the first store, eventually the first SystemProducer will be marked as inactive
* after push monitor poll the latest push job status from router.
*/
Utils.sleep(500);
veniceClusterWrapper.useControllerClient(c -> {
c.writeEndOfPush(storeName1, 1);
TestUtils.waitForNonDeterministicAssertion(30, TimeUnit.SECONDS, true, true, () -> {
Assert.assertTrue(admin.getStore(clusterName, storeName1).containsVersion(1));
Assert.assertEquals(admin.getStore(clusterName, storeName1).getCurrentVersion(), 1);
// The second SystemProducer should still be active
Assert.assertEquals(factory.getNumberOfActiveSystemProducers(), 1);
});
c.writeEndOfPush(storeName2, 1);
TestUtils.waitForNonDeterministicAssertion(30, TimeUnit.SECONDS, true, true, () -> {
Assert.assertTrue(admin.getStore(clusterName, storeName2).containsVersion(1));
Assert.assertEquals(admin.getStore(clusterName, storeName2).getCurrentVersion(), 1);
// There should be no active SystemProducer any more.
Assert.assertEquals(factory.getNumberOfActiveSystemProducers(), 0);
});
});
} finally {
if (veniceBatchProducer1 != null) {
veniceBatchProducer1.stop();
}
if (veniceBatchProducer2 != null) {
veniceBatchProducer2.stop();
}
}
}
@Test(timeOut = 180 * Time.MS_PER_SECOND)
public void testLeaderHonorLastTopicSwitchMessage() throws Exception {
Properties extraProperties = new Properties();
extraProperties.put(SERVER_PROMOTION_TO_LEADER_REPLICA_DELAY_SECONDS, 1L);
VeniceClusterCreateOptions options = new VeniceClusterCreateOptions.Builder().numberOfControllers(1)
.numberOfServers(2)
.numberOfRouters(1)
.replicationFactor(2)
.partitionSize(1000000)
.sslToStorageNodes(false)
.sslToKafka(false)
.extraProperties(extraProperties)
.build();
try (VeniceClusterWrapper venice = ServiceFactory.getVeniceCluster(options);
ControllerClient controllerClient =
new ControllerClient(venice.getClusterName(), venice.getAllControllersURLs())) {
long streamingRewindSeconds = 25L;
long streamingMessageLag = 2L;
String storeName = Utils.getUniqueString("hybrid-store");
// Create store , make it a hybrid store
controllerClient.createNewStore(storeName, "owner", STRING_SCHEMA.toString(), STRING_SCHEMA.toString());
controllerClient.updateStore(
storeName,
new UpdateStoreQueryParams().setStorageQuotaInByte(Store.UNLIMITED_STORAGE_QUOTA)
.setHybridRewindSeconds(streamingRewindSeconds)
.setHybridOffsetLagThreshold(streamingMessageLag));
// Create a new version, and do an empty push for that version
VersionCreationResponse vcr = TestUtils
.assertCommand(controllerClient.emptyPush(storeName, Utils.getUniqueString("empty-hybrid-push"), 1L));
int versionNumber = vcr.getVersion();
Assert.assertEquals(versionNumber, 1, "Version number should become 1 after an empty-push");
int partitionCnt = vcr.getPartitions();
/**
* Write 2 TopicSwitch messages into version topic:
* TS1 (new topic: storeName_tmp1, startTime: {@link rewindStartTime})
* TS2 (new topic: storeName_tmp2, startTime: {@link rewindStartTime})
*
* All messages in TS1 should not be replayed into VT and should not be queryable;
* but messages in TS2 should be replayed and queryable.
*/
PubSubTopic tmpTopic1 = sharedVenice.getPubSubTopicRepository().getTopic(storeName + "_tmp1_rt");
PubSubTopic tmpTopic2 = sharedVenice.getPubSubTopicRepository().getTopic(storeName + "_tmp2_rt");
TopicManager topicManager = venice.getLeaderVeniceController().getVeniceAdmin().getTopicManager();
topicManager.createTopic(tmpTopic1, partitionCnt, 1, true);
topicManager.createTopic(tmpTopic2, partitionCnt, 1, true);
/**
* Build a producer that writes to {@link tmpTopic1}
*/
PubSubBrokerWrapper pubSubBrokerWrapper = venice.getPubSubBrokerWrapper();
Properties veniceWriterProperties = new Properties();
veniceWriterProperties.put(KAFKA_BOOTSTRAP_SERVERS, pubSubBrokerWrapper.getAddress());
veniceWriterProperties.putAll(
PubSubBrokerWrapper.getBrokerDetailsForClients(Collections.singletonList(venice.getPubSubBrokerWrapper())));
AvroSerializer<String> stringSerializer = new AvroSerializer(STRING_SCHEMA);
PubSubProducerAdapterFactory pubSubProducerAdapterFactory =
venice.getPubSubBrokerWrapper().getPubSubClientsFactory().getProducerAdapterFactory();
try (VeniceWriter<byte[], byte[], byte[]> tmpWriter1 = TestUtils
.getVeniceWriterFactory(
veniceWriterProperties,
pubSubProducerAdapterFactory,
pubSubBrokerWrapper.getPubSubPositionTypeRegistry())
.createVeniceWriter(new VeniceWriterOptions.Builder(tmpTopic1.getName()).build())) {
// Write 10 records
for (int i = 0; i < 10; ++i) {
tmpWriter1.put(stringSerializer.serialize("key_" + i), stringSerializer.serialize("value_" + i), 1);
}
}
/**
* Build a producer that writes to {@link tmpTopic2}
*/
try (VeniceWriter<byte[], byte[], byte[]> tmpWriter2 = TestUtils
.getVeniceWriterFactory(
veniceWriterProperties,
pubSubProducerAdapterFactory,
pubSubBrokerWrapper.getPubSubPositionTypeRegistry())
.createVeniceWriter(new VeniceWriterOptions.Builder(tmpTopic2.getName()).build())) {
// Write 10 records
for (int i = 10; i < 20; ++i) {
tmpWriter2.put(stringSerializer.serialize("key_" + i), stringSerializer.serialize("value_" + i), 1);
}
}
/**
* Wait for leader to switch over to real-time topic
*/
TestUtils.waitForNonDeterministicAssertion(30, TimeUnit.SECONDS, true, true, () -> {
StoreResponse store = TestUtils.assertCommand(controllerClient.getStore(storeName));
Assert.assertEquals(store.getStore().getCurrentVersion(), 1);
});
StoreInfo storeInfo = TestUtils.assertCommand(controllerClient.getStore(storeName)).getStore();
/**
* Verify that all messages from {@link tmpTopic2} are in store and no message from {@link tmpTopic1} is in store.
*/
try (
AvroGenericStoreClient<String, Utf8> client = ClientFactory.getAndStartGenericAvroClient(
ClientConfig.defaultGenericClientConfig(storeName).setVeniceURL(venice.getRandomRouterURL()));
VeniceWriter<byte[], byte[], byte[]> realTimeTopicWriter = TestUtils
.getVeniceWriterFactory(
veniceWriterProperties,
pubSubProducerAdapterFactory,
pubSubBrokerWrapper.getPubSubPositionTypeRegistry())
.createVeniceWriter(new VeniceWriterOptions.Builder(Utils.getRealTimeTopicName(storeInfo)).build())) {
// Build a producer to produce 2 TS messages into RT
realTimeTopicWriter.broadcastTopicSwitch(
Collections.singletonList(venice.getPubSubBrokerWrapper().getAddress()),
tmpTopic1.getName(),
-1L,
null);
realTimeTopicWriter.broadcastTopicSwitch(
Collections.singletonList(venice.getPubSubBrokerWrapper().getAddress()),
tmpTopic2.getName(),
-1L,
null);
TestUtils.waitForNonDeterministicAssertion(60, TimeUnit.SECONDS, true, true, () -> {
// All messages from tmpTopic2 should exist
try {
for (int i = 10; i < 20; i++) {
String key = "key_" + i;
Assert.assertEquals(client.get(key).get(), new Utf8("value_" + i));
}
} catch (Exception e) {
LOGGER.error("Caught exception in client.get()", e);
Assert.fail(e.getMessage());
}
// No message from tmpTopic1 should exist
try {
for (int i = 0; i < 10; i++) {
String key = "key_" + i;
Assert.assertNull(client.get(key).get());
}
} catch (Exception e) {
LOGGER.error("Caught exception in client.get()", e);
Assert.fail(e.getMessage());
}
});
}
}
}
@Test(timeOut = 180 * Time.MS_PER_SECOND)
public void testLeaderCanReleaseLatch() {
VeniceClusterWrapper veniceClusterWrapper = sharedVenice;
Admin admin = veniceClusterWrapper.getLeaderVeniceController().getVeniceAdmin();
String clusterName = veniceClusterWrapper.getClusterName();
String storeName = Utils.getUniqueString("test-store");
SystemProducer producer = null;
try (ControllerClient controllerClient =
new ControllerClient(clusterName, veniceClusterWrapper.getAllControllersURLs())) {
controllerClient.createNewStore(storeName, "owner", STRING_SCHEMA.toString(), STRING_SCHEMA.toString());
controllerClient.updateStore(
storeName,
new UpdateStoreQueryParams().setStorageQuotaInByte(Store.UNLIMITED_STORAGE_QUOTA)
.setHybridRewindSeconds(25L)
.setHybridOffsetLagThreshold(1L));
// Create a new version, and do an empty push for that version
controllerClient.emptyPush(storeName, Utils.getUniqueString("empty-hybrid-push"), 1L);
// write a few of messages from the Samza
producer = IntegrationTestPushUtils.getSamzaProducer(veniceClusterWrapper, storeName, Version.PushType.STREAM);
for (int i = 0; i < 10; i++) {
sendStreamingRecord(producer, storeName, i);
}
// make sure the v1 is online and all the writes have been consumed by the SN
try (AvroGenericStoreClient client = ClientFactory.getAndStartGenericAvroClient(
ClientConfig.defaultGenericClientConfig(storeName).setVeniceURL(veniceClusterWrapper.getRandomRouterURL()))) {
TestUtils.waitForNonDeterministicAssertion(
60,
TimeUnit.SECONDS,
true,
true,
() -> Assert.assertEquals(admin.getStore(clusterName, storeName).getCurrentVersion(), 1));
TestUtils.waitForNonDeterministicAssertion(30, TimeUnit.SECONDS, true, true, () -> {
try {
for (int i = 0; i < 10; i++) {
String key = Integer.toString(i);
Object value = client.get(key).get();
Assert.assertNotNull(value, "Did not find key " + i + " in store before restarting SN.");
Assert.assertEquals(value.toString(), "stream_" + key);
}
} catch (Exception e) {
throw new VeniceException(e);
}
});
// stop the SN (leader) and write more messages
VeniceServerWrapper serverWrapper = veniceClusterWrapper.getVeniceServers().get(0);
veniceClusterWrapper.stopVeniceServer(serverWrapper.getPort());
for (int i = 10; i < 20; i++) {
sendStreamingRecord(producer, storeName, i);
}
// restart the SN (leader). The node is supposed to be promoted to leader even with the offset lags.
veniceClusterWrapper.restartVeniceServer(serverWrapper.getPort());
String resourceName = Version.composeKafkaTopic(storeName, 1);
HelixBaseRoutingRepository routingDataRepo = veniceClusterWrapper.getLeaderVeniceController()
.getVeniceHelixAdmin()
.getHelixVeniceClusterResources(clusterName)
.getRoutingDataRepository();
TestUtils.waitForNonDeterministicAssertion(
60,
TimeUnit.SECONDS,
true,
true,
() -> Assert.assertNotNull(routingDataRepo.getLeaderInstance(resourceName, 0)));
TestUtils.waitForNonDeterministicAssertion(30, TimeUnit.SECONDS, true, true, () -> {
try {
for (int i = 10; i < 20; i++) {
String key = Integer.toString(i);
Object value = client.get(key).get();
Assert.assertNotNull(value, "Did not find key " + i + " in store after restarting SN.");
Assert.assertEquals(value.toString(), "stream_" + key);
}
} catch (Exception e) {
throw new VeniceException(e);
}
});
}
} finally {
if (producer != null) {
producer.stop();
}
}
}
@Test(timeOut = 180 * Time.MS_PER_SECOND)
public void testHybridMultipleVersions() throws Exception {
final int partitionCount = 2;
final int keyCount = 10;
VeniceClusterWrapper cluster = sharedVenice;
UpdateStoreQueryParams params = new UpdateStoreQueryParams()
// set hybridRewindSecond to a big number so following versions won't ignore old records in RT
.setHybridRewindSeconds(2000000)
.setHybridOffsetLagThreshold(10)
.setPartitionCount(partitionCount);
String storeName = Utils.getUniqueString("store");
cluster.useControllerClient(client -> {
client.createNewStore(storeName, "owner", DEFAULT_KEY_SCHEMA, DEFAULT_VALUE_SCHEMA);