-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PLAT-16152] Correctly delete PITR configs on A -> B and A -> C xclus…
…ter config setups with same db Summary: Allows PITR config to be correctly deleted for DR/xcluster configurations with A -> B and A -> C setups using the same databases. The databases on A will use the same PITR configs for both replications. Hence, make sure that if A -> B or A -> C is deleted, the pitr configs on A are retained and not deleted. Note that there are still issues with A -> B and A -> C if the pitr params are different which cannot be solved with the current implementation. Test Plan: UTs Manually tested following flow: Create A -> B and A -> C with the same database and pitr params. Check that there is one pitr config for the database on A. Delete A -> C replication. Validate that the pitr conifg Reviewers: hzare, jmak Reviewed By: hzare Subscribers: yugaware Differential Revision: https://phorge.dev.yugabyte.com/D41172
- Loading branch information
1 parent
8eb2b28
commit 0f80d46
Showing
3 changed files
with
116 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
managed/src/test/java/com/yugabyte/yw/models/PitrConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// Copyright (c) YugaByte, Inc. | ||
package com.yugabyte.yw.models; | ||
|
||
import static com.yugabyte.yw.common.ModelFactory.createUniverse; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.yugabyte.yw.common.FakeDBApplication; | ||
import com.yugabyte.yw.common.ModelFactory; | ||
import com.yugabyte.yw.forms.CreatePitrConfigParams; | ||
import com.yugabyte.yw.forms.DrConfigCreateForm.PitrParams; | ||
import com.yugabyte.yw.forms.XClusterConfigCreateFormData.BootstrapParams.BootstrapBackupParams; | ||
import com.yugabyte.yw.models.configs.CustomerConfig; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.yb.CommonTypes.TableType; | ||
import play.libs.Json; | ||
|
||
public class PitrConfigTest extends FakeDBApplication { | ||
|
||
private CustomerConfig config; | ||
|
||
@Before | ||
public void setUp() { | ||
Customer defaultCustomer = ModelFactory.testCustomer(); | ||
config = createData(defaultCustomer); | ||
} | ||
|
||
private CustomerConfig createData(Customer customer) { | ||
JsonNode formData = | ||
Json.parse( | ||
"{\"name\": \"Test\", \"configName\": \"Test\", \"type\": " | ||
+ "\"STORAGE\", \"data\": {\"foo\": \"bar\"}," | ||
+ "\"configUUID\": \"5e8e4887-343b-47dd-a126-71c822904c06\"}"); | ||
return CustomerConfig.createWithFormData(customer.getUuid(), formData); | ||
} | ||
|
||
@Test | ||
public void testPitrConfigXClusterCount() { | ||
|
||
Universe sourceUniverse = createUniverse("source Universe"); | ||
Universe targetUniverse = createUniverse("target Universe"); | ||
|
||
BootstrapBackupParams backupRequestParams; | ||
backupRequestParams = new BootstrapBackupParams(); | ||
backupRequestParams.storageConfigUUID = config.getConfigUUID(); | ||
|
||
Set<String> sourceDbIds = Set.of("db1", "db2"); | ||
DrConfig drConfig1 = | ||
DrConfig.create( | ||
"replication1", | ||
sourceUniverse.getUniverseUUID(), | ||
targetUniverse.getUniverseUUID(), | ||
backupRequestParams, | ||
new PitrParams(), | ||
sourceDbIds); | ||
XClusterConfig xClusterConfig1 = drConfig1.getActiveXClusterConfig(); | ||
|
||
CreatePitrConfigParams createPitrConfigParams = new CreatePitrConfigParams(); | ||
createPitrConfigParams.setUniverseUUID(sourceUniverse.getUniverseUUID()); | ||
createPitrConfigParams.customerUUID = Customer.get(sourceUniverse.getCustomerId()).getUuid(); | ||
createPitrConfigParams.name = null; | ||
createPitrConfigParams.keyspaceName = "mockNamespace"; | ||
createPitrConfigParams.tableType = TableType.PGSQL_TABLE_TYPE; | ||
createPitrConfigParams.retentionPeriodInSeconds = 1; | ||
createPitrConfigParams.xClusterConfig = xClusterConfig1; | ||
createPitrConfigParams.intervalInSeconds = 1; | ||
createPitrConfigParams.createdForDr = true; | ||
|
||
PitrConfig pitrConfig = PitrConfig.create(UUID.randomUUID(), createPitrConfigParams); | ||
xClusterConfig1.addPitrConfig(pitrConfig); | ||
pitrConfig.refresh(); | ||
|
||
assertEquals(1, pitrConfig.getXClusterConfigs().size()); | ||
assertEquals(xClusterConfig1.getUuid(), pitrConfig.getXClusterConfigs().get(0).getUuid()); | ||
|
||
Universe secondTargetUniverse = createUniverse("second target Universe"); | ||
// A -> B and A -> C. | ||
DrConfig drConfig2 = | ||
DrConfig.create( | ||
"replication2", | ||
sourceUniverse.getUniverseUUID(), | ||
secondTargetUniverse.getUniverseUUID(), | ||
backupRequestParams, | ||
new PitrParams(), | ||
sourceDbIds); | ||
XClusterConfig xClusterConfig2 = drConfig2.getActiveXClusterConfig(); | ||
xClusterConfig2.addPitrConfig(pitrConfig); | ||
|
||
// Pitr Config is associated to 2 xcluster configs. | ||
pitrConfig.refresh(); | ||
assertEquals(2, pitrConfig.getXClusterConfigs().size()); | ||
assertEquals(xClusterConfig2.getUuid(), pitrConfig.getXClusterConfigs().get(1).getUuid()); | ||
|
||
// xcluster_pitr should be cascade deleted when xcluster config is deleted. | ||
xClusterConfig2.delete(); | ||
pitrConfig.refresh(); | ||
assertEquals(1, pitrConfig.getXClusterConfigs().size()); | ||
assertEquals(xClusterConfig1.getUuid(), pitrConfig.getXClusterConfigs().get(0).getUuid()); | ||
} | ||
} |