Skip to content

Commit

Permalink
[PLAT-15297][dr] GET /configs fails with java.lang.IllegalStateExcept…
Browse files Browse the repository at this point in the history
…ion: DrConfig iTest-dr(uuid) does not have any corresponding xCluster config

Summary:
This diff moves the delete DR config entry to a transaction with deleting the last xCluster config entry of that DR config.

It also removes `XClusterConfigTaskBase.getTableInfoList(ybService, sourceUniverse);` from the failover controller.

Test Plan:
- Made sure a failover task succeeds when the source universe is down.
- Made sure the DR config is deleted properly when the source universe is deleted even when the dr config has two xCluster config entries.

Reviewers: #yba-api-review!, vbansal, cwang, jmak, sanketh

Reviewed By: vbansal

Subscribers: yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D38151
  • Loading branch information
shahrooz1997 committed Sep 18, 2024
1 parent 6b34652 commit 6dcfce6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import com.yugabyte.yw.commissioner.BaseTaskDependencies;
import com.yugabyte.yw.commissioner.UserTaskDetails;
import com.yugabyte.yw.commissioner.UserTaskDetails.SubTaskGroupType;
import com.yugabyte.yw.common.XClusterUniverseService;
import com.yugabyte.yw.forms.DrConfigTaskParams;
import com.yugabyte.yw.models.DrConfig;
Expand Down Expand Up @@ -84,8 +83,8 @@ public void run() {
: null);
}

createDeleteDrConfigEntryTask(drConfig)
.setSubTaskGroupType(SubTaskGroupType.DeleteDrConfig);
// When the last xCluster config associated with this DR config is deleted, the dr config
// entry will be deleted as well.

if (targetUniverse != null) {
createMarkUniverseUpdateSuccessTasks(targetUniverse.getUniverseUUID())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
Expand Down Expand Up @@ -351,11 +350,11 @@ private void createDeleteXClusterConfigSubtasksAndLockOtherUniverse(
false /* keepEntry */,
params().isForceDelete,
true /* deletePitrConfigs */);
if (Objects.nonNull(drConfig) && drConfig.getXClusterConfigs().size() == 1) {
createDeleteDrConfigEntryTask(drConfig)
.setSubTaskGroupType(SubTaskGroupType.DeleteDrConfig);
}
});

// When the last xCluster config associated with this DR config is deleted, the dr config
// entry will be deleted as well.

log.debug("Subtasks created to delete these xCluster configs: {}", xClusterConfigs);
} catch (Exception e) {
log.error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1120,9 +1120,6 @@ public Result failover(UUID customerUUID, UUID drConfigUuid, Http.Request reques
List<MasterDdlOuterClass.ListTablesResponsePB.TableInfo> targetTableInfoList =
XClusterConfigTaskBase.getTableInfoList(ybService, targetUniverse);

List<MasterDdlOuterClass.ListTablesResponsePB.TableInfo> sourceTableInfoList =
XClusterConfigTaskBase.getTableInfoList(ybService, sourceUniverse);

// Because during failover, the source universe could be down, we should rely on the target
// universe to get the table map between source to target.
Map<String, String> sourceTableIdTargetTableIdMap =
Expand Down
13 changes: 13 additions & 0 deletions managed/src/main/java/com/yugabyte/yw/models/DrConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,17 @@ public XClusterConfigRestartFormData.RestartBootstrapParams getBootstrapBackupPa
public boolean isHalted() {
return state == State.Halted;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
DrConfig drConfig = (DrConfig) o;
return Objects.equals(uuid, drConfig.uuid);
}

@Override
public int hashCode() {
return Objects.hash(uuid);
}
}
10 changes: 10 additions & 0 deletions managed/src/main/java/com/yugabyte/yw/models/XClusterConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,16 @@ public void update() {
super.update();
}

@Transactional
@Override
public boolean delete() {
// If the dr config has no other xCluster configs, then delete the dr config as well.
if (this.drConfig != null && this.drConfig.getXClusterConfigs().size() == 1) {
this.drConfig.delete();
}
return super.delete();
}

public static XClusterConfig getValidConfigOrBadRequest(
Customer customer, UUID xClusterConfigUUID) {
XClusterConfig xClusterConfig = getOrBadRequest(xClusterConfigUUID);
Expand Down

0 comments on commit 6dcfce6

Please sign in to comment.