-
Notifications
You must be signed in to change notification settings - Fork 121
Expand file tree
/
Copy pathTestDeferredVersionSwapWithSequentialRolloutWithDvc.java
More file actions
306 lines (271 loc) · 14.3 KB
/
TestDeferredVersionSwapWithSequentialRolloutWithDvc.java
File metadata and controls
306 lines (271 loc) · 14.3 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
package com.linkedin.venice.endToEnd;
import static com.linkedin.venice.ConfigKeys.CLIENT_SYSTEM_STORE_REPOSITORY_REFRESH_INTERVAL_SECONDS;
import static com.linkedin.venice.ConfigKeys.CONTROLLER_DEFERRED_VERSION_SWAP_SERVICE_ENABLED;
import static com.linkedin.venice.ConfigKeys.CONTROLLER_DEFERRED_VERSION_SWAP_SLEEP_MS;
import static com.linkedin.venice.ConfigKeys.DATA_BASE_PATH;
import static com.linkedin.venice.ConfigKeys.DEFERRED_VERSION_SWAP_FOR_EMPTY_PUSH_ENABLED;
import static com.linkedin.venice.ConfigKeys.DEFERRED_VERSION_SWAP_REGION_ROLL_FORWARD_ORDER;
import static com.linkedin.venice.ConfigKeys.LOCAL_REGION_NAME;
import static com.linkedin.venice.utils.IntegrationTestPushUtils.createStoreForJob;
import static com.linkedin.venice.utils.TestWriteUtils.NAME_RECORD_V3_SCHEMA;
import static com.linkedin.venice.utils.TestWriteUtils.getTempDataDirectory;
import static com.linkedin.venice.vpj.VenicePushJobConstants.TARGETED_REGION_PUSH_LIST;
import static com.linkedin.venice.vpj.VenicePushJobConstants.TARGETED_REGION_PUSH_WITH_DEFERRED_SWAP;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import com.linkedin.davinci.client.DaVinciClient;
import com.linkedin.davinci.client.DaVinciConfig;
import com.linkedin.venice.common.VeniceSystemStoreType;
import com.linkedin.venice.controllerapi.ControllerClient;
import com.linkedin.venice.controllerapi.ControllerResponse;
import com.linkedin.venice.controllerapi.StoreResponse;
import com.linkedin.venice.controllerapi.UpdateStoreQueryParams;
import com.linkedin.venice.controllerapi.VersionCreationResponse;
import com.linkedin.venice.integration.utils.DaVinciTestContext;
import com.linkedin.venice.integration.utils.ServiceFactory;
import com.linkedin.venice.integration.utils.VeniceClusterWrapper;
import com.linkedin.venice.integration.utils.VeniceMultiClusterWrapper;
import com.linkedin.venice.meta.StoreInfo;
import com.linkedin.venice.meta.Version;
import com.linkedin.venice.meta.VersionStatus;
import com.linkedin.venice.utils.IntegrationTestPushUtils;
import com.linkedin.venice.utils.TestUtils;
import com.linkedin.venice.utils.TestWriteUtils;
import com.linkedin.venice.utils.Utils;
import com.linkedin.venice.utils.VeniceProperties;
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;
import org.testng.Assert;
import org.testng.annotations.Test;
public class TestDeferredVersionSwapWithSequentialRolloutWithDvc extends AbstractMultiRegionTest {
private static final String REGION1 = "dc-0";
private static final String REGION2 = "dc-1";
private static final String REGION3 = "dc-2";
private static final String[] CLUSTER_NAMES =
IntStream.range(0, 1).mapToObj(i -> "venice-cluster" + i).toArray(String[]::new);
private static final int TEST_TIMEOUT = 180_000;
@Override
protected int getNumberOfRegions() {
return 3;
}
@Override
protected int getNumberOfServers() {
return 1;
}
@Override
protected int getReplicationFactor() {
return 1;
}
@Override
protected Properties getExtraControllerProperties() {
Properties controllerProps = new Properties();
controllerProps.put(CONTROLLER_DEFERRED_VERSION_SWAP_SLEEP_MS, 100);
controllerProps.put(CONTROLLER_DEFERRED_VERSION_SWAP_SERVICE_ENABLED, true);
controllerProps.put(DEFERRED_VERSION_SWAP_REGION_ROLL_FORWARD_ORDER, REGION1 + "," + REGION2 + "," + REGION3);
controllerProps.put(DEFERRED_VERSION_SWAP_FOR_EMPTY_PUSH_ENABLED, true);
return controllerProps;
}
@Test(timeOut = TEST_TIMEOUT)
public void testDvcDelayedIngestionWithTargetRegionSequentialRollout() throws Exception {
// Setup job properties
UpdateStoreQueryParams storeParms = new UpdateStoreQueryParams().setUnusedSchemaDeletionEnabled(true);
storeParms.setTargetRegionSwapWaitTime(1);
String parentControllerURLs = multiRegionMultiClusterWrapper.getControllerConnectString();
String keySchemaStr = "\"int\"";
String valueSchemaStr = "\"int\"";
// Create store + start a normal push
int keyCount = 100;
File inputDir = getTempDataDirectory();
TestWriteUtils.writeSimpleAvroFileWithIntToIntSchema(inputDir, keyCount);
String inputDirPath = "file://" + inputDir.getAbsolutePath();
String storeName = Utils.getUniqueString("testDvcDelayedIngestionWithTargetRegion");
Properties props =
IntegrationTestPushUtils.defaultVPJProps(multiRegionMultiClusterWrapper, inputDirPath, storeName);
try (ControllerClient parentControllerClient = new ControllerClient(CLUSTER_NAMES[0], parentControllerURLs)) {
createStoreForJob(CLUSTER_NAMES[0], keySchemaStr, valueSchemaStr, props, storeParms).close();
IntegrationTestPushUtils.runVPJ(props);
TestUtils.waitForNonDeterministicPushCompletion(
Version.composeKafkaTopic(storeName, 1),
parentControllerClient,
30,
TimeUnit.SECONDS);
// Version should only be swapped in all regions
TestUtils.waitForNonDeterministicAssertion(1, TimeUnit.MINUTES, () -> {
Map<String, Integer> coloVersions =
parentControllerClient.getStore(storeName).getStore().getColoToCurrentVersions();
coloVersions.forEach((colo, version) -> {
Assert.assertEquals((int) version, 1);
});
});
}
verifyThatPushStatusStoreIsOnline(storeName);
verifyThatMetaStoreIsOnline(storeName);
// Create dvc client in target region
List<VeniceMultiClusterWrapper> childDatacenters = multiRegionMultiClusterWrapper.getChildRegions();
VeniceClusterWrapper cluster1 = childDatacenters.get(0).getClusters().get(CLUSTER_NAMES[0]);
VeniceProperties backendConfig = DaVinciTestContext.getDaVinciPropertyBuilder(cluster1.getZk().getAddress())
.put(DATA_BASE_PATH, Utils.getTempDataDirectory().getAbsolutePath())
.put(LOCAL_REGION_NAME, REGION1)
.put(CLIENT_SYSTEM_STORE_REPOSITORY_REFRESH_INTERVAL_SECONDS, 1)
.build();
DaVinciClient<Object, Object> client1 =
ServiceFactory.getGenericAvroDaVinciClient(storeName, cluster1, new DaVinciConfig(), backendConfig);
client1.subscribeAll().get();
// Check that v1 is ingested
for (int i = 1; i <= keyCount; i++) {
assertNotNull(client1.get(i).get());
}
// Do another push with target region enabled
int keyCount2 = 200;
File inputDir2 = getTempDataDirectory();
String inputDirPath2 = "file://" + inputDir2.getAbsolutePath();
TestWriteUtils.writeSimpleAvroFileWithIntToIntSchema(inputDir2, keyCount2);
Properties props2 =
IntegrationTestPushUtils.defaultVPJProps(multiRegionMultiClusterWrapper, inputDirPath2, storeName);
try (ControllerClient parentControllerClient = new ControllerClient(CLUSTER_NAMES[0], parentControllerURLs)) {
props2.put(TARGETED_REGION_PUSH_WITH_DEFERRED_SWAP, true);
props2.put(TARGETED_REGION_PUSH_LIST, REGION1);
IntegrationTestPushUtils.runVPJ(props2);
TestUtils.waitForNonDeterministicPushCompletion(
Version.composeKafkaTopic(storeName, 2),
parentControllerClient,
30,
TimeUnit.SECONDS);
// Data should be automatically ingested in target region for dvc
TestUtils.waitForNonDeterministicAssertion(30, TimeUnit.SECONDS, () -> {
for (int i = 101; i <= keyCount2; i++) {
assertNotNull(client1.get(i).get());
}
});
// Close dvc client in target region
client1.close();
// Create dvc client in non target region
VeniceClusterWrapper cluster2 = childDatacenters.get(1).getClusters().get(CLUSTER_NAMES[0]);
VeniceProperties backendConfig2 = DaVinciTestContext.getDaVinciPropertyBuilder(cluster2.getZk().getAddress())
.put(DATA_BASE_PATH, Utils.getTempDataDirectory().getAbsolutePath())
.put(LOCAL_REGION_NAME, REGION2)
.put(CLIENT_SYSTEM_STORE_REPOSITORY_REFRESH_INTERVAL_SECONDS, 1)
.build();
DaVinciClient<Object, Object> client2 =
ServiceFactory.getGenericAvroDaVinciClient(storeName, cluster2, new DaVinciConfig(), backendConfig2);
client2.subscribeAll().get();
// Version should be swapped in all regions
TestUtils.waitForNonDeterministicAssertion(1, TimeUnit.MINUTES, () -> {
Map<String, Integer> coloVersions =
parentControllerClient.getStore(storeName).getStore().getColoToCurrentVersions();
coloVersions.forEach((colo, version) -> {
Assert.assertEquals((int) version, 2);
});
});
// Check that v2 is ingested in dvc non target region
TestUtils.waitForNonDeterministicAssertion(30, TimeUnit.SECONDS, () -> {
for (int i = 101; i <= keyCount2; i++) {
assertNotNull(client2.get(i).get());
}
});
client2.close();
// Verify targetRegionPromoted=true on parent and all child controllers.
// DeferredVersionSwapService sets the field once the target region's push completes
// and propagates it to children via the updateStore admin path.
TestUtils.waitForNonDeterministicAssertion(30, TimeUnit.SECONDS, () -> {
Optional<Version> parentVersion = parentControllerClient.getStore(storeName).getStore().getVersion(2);
Assert.assertTrue(parentVersion.isPresent(), "Version 2 must exist on parent");
Assert.assertTrue(
parentVersion.get().isTargetRegionPromoted(),
"Parent controller must set targetRegionPromoted=true after target region push completes");
});
for (VeniceMultiClusterWrapper childDatacenter: childDatacenters) {
try (ControllerClient childControllerClient =
new ControllerClient(CLUSTER_NAMES[0], childDatacenter.getControllerConnectString())) {
TestUtils.waitForNonDeterministicAssertion(30, TimeUnit.SECONDS, () -> {
Optional<Version> childVersion = childControllerClient.getStore(storeName).getStore().getVersion(2);
Assert.assertTrue(childVersion.isPresent(), "Version 2 must exist in child controller");
Assert.assertTrue(
childVersion.get().isTargetRegionPromoted(),
"Child controller must reflect targetRegionPromoted=true via admin message propagation");
});
}
}
}
}
@Test(timeOut = TEST_TIMEOUT)
public void testDeferredVersionSwapForEmptyPush() throws Exception {
File inputDir = getTempDataDirectory();
TestWriteUtils.writeSimpleAvroFileWithStringToV3Schema(inputDir, 100, 100);
// Setup job properties
String inputDirPath = "file://" + inputDir.getAbsolutePath();
String storeName = Utils.getUniqueString("testDeferredVersionSwap");
Properties props =
IntegrationTestPushUtils.defaultVPJProps(multiRegionMultiClusterWrapper, inputDirPath, storeName);
String keySchemaStr = "\"string\"";
UpdateStoreQueryParams storeParms = new UpdateStoreQueryParams().setTargetRegionSwapWaitTime(1);
String parentControllerURLs = multiRegionMultiClusterWrapper.getControllerConnectString();
try (ControllerClient parentControllerClient = new ControllerClient(CLUSTER_NAMES[0], parentControllerURLs)) {
createStoreForJob(CLUSTER_NAMES[0], keySchemaStr, NAME_RECORD_V3_SCHEMA.toString(), props, storeParms).close();
parentControllerClient.emptyPush(storeName, "test", 100000);
// Release the swap wait time so DeferredVersionSwapService fires as soon as ingestion completes
ControllerResponse updateResp =
parentControllerClient.updateStore(storeName, new UpdateStoreQueryParams().setTargetRegionSwapWaitTime(0));
Assert.assertFalse(updateResp.isError(), "Failed to update targetRegionSwapWaitTime: " + updateResp.getError());
TestUtils.waitForNonDeterministicAssertion(60, TimeUnit.SECONDS, () -> {
Map<String, Integer> coloVersions =
parentControllerClient.getStore(storeName).getStore().getColoToCurrentVersions();
coloVersions.forEach((colo, version) -> {
Assert.assertEquals((int) version, 1);
});
});
TestUtils.waitForNonDeterministicAssertion(30, TimeUnit.SECONDS, () -> {
StoreResponse parentStore = parentControllerClient.getStore(storeName);
Assert.assertNotNull(parentStore);
StoreInfo storeInfo = parentStore.getStore();
Assert.assertEquals(storeInfo.getVersion(1).get().getStatus(), VersionStatus.ONLINE);
});
TestUtils.waitForNonDeterministicAssertion(30, TimeUnit.SECONDS, () -> {
// Verify that we can create a new version
VersionCreationResponse versionCreationResponse = parentControllerClient.requestTopicForWrites(
storeName,
1000,
Version.PushType.BATCH,
Version.guidBasedDummyPushId(),
true,
true,
false,
Optional.empty(),
Optional.empty(),
Optional.empty(),
false,
-1);
assertFalse(versionCreationResponse.isError());
});
}
}
private void verifyThatPushStatusStoreIsOnline(String storeName) {
for (VeniceMultiClusterWrapper childDatacenter: childDatacenters) {
String pushStatusStoreName = VeniceSystemStoreType.DAVINCI_PUSH_STATUS_STORE.getSystemStoreName(storeName);
ControllerClient childControllerClient =
new ControllerClient(CLUSTER_NAMES[0], childDatacenter.getControllerConnectString());
TestUtils.waitForNonDeterministicAssertion(30, TimeUnit.SECONDS, () -> {
StoreResponse storeResponse = childControllerClient.getStore(pushStatusStoreName);
Assert.assertFalse(storeResponse.isError());
Assert.assertTrue(storeResponse.getStore().getCurrentVersion() > 0, pushStatusStoreName + " is not ready");
});
}
}
private void verifyThatMetaStoreIsOnline(String storeName) {
for (VeniceMultiClusterWrapper childDatacenter: childDatacenters) {
String metaStoreName = VeniceSystemStoreType.META_STORE.getSystemStoreName(storeName);
ControllerClient childControllerClient =
new ControllerClient(CLUSTER_NAMES[0], childDatacenter.getControllerConnectString());
TestUtils.waitForNonDeterministicAssertion(30, TimeUnit.SECONDS, () -> {
StoreResponse storeResponse = childControllerClient.getStore(metaStoreName);
Assert.assertFalse(storeResponse.isError());
Assert.assertTrue(storeResponse.getStore().getCurrentVersion() > 0, metaStoreName + " is not ready");
});
}
}
}