Skip to content

Commit

Permalink
[PLAT-15097]: Delete System platform DB table while disabling ysql
Browse files Browse the repository at this point in the history
Summary: Add changes to drop write_read_test table, consistency_check table while disabling ysql

Test Plan: Tested manually on k8s and VM-based universe and verified that table no longer exists from master UI

Reviewers: #yba-api-review!, sneelakantan, svarshney, muthu

Reviewed By: svarshney, muthu

Subscribers: muthu, yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D37892
  • Loading branch information
vipul-yb committed Sep 17, 2024
1 parent a913524 commit 41f5afd
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package com.yugabyte.yw.commissioner.tasks;

import static com.yugabyte.yw.common.Util.SYSTEM_PLATFORM_DB;
import static com.yugabyte.yw.common.Util.WRITE_READ_TABLE;
import static com.yugabyte.yw.common.Util.getUUIDRepresentation;
import static play.mvc.Http.Status.INTERNAL_SERVER_ERROR;

Expand Down Expand Up @@ -56,6 +57,7 @@
import com.yugabyte.yw.commissioner.tasks.subtasks.DeleteTablesFromUniverse;
import com.yugabyte.yw.commissioner.tasks.subtasks.DestroyEncryptionAtRest;
import com.yugabyte.yw.commissioner.tasks.subtasks.DisableEncryptionAtRest;
import com.yugabyte.yw.commissioner.tasks.subtasks.DropTable;
import com.yugabyte.yw.commissioner.tasks.subtasks.EnableEncryptionAtRest;
import com.yugabyte.yw.commissioner.tasks.subtasks.FreezeUniverse;
import com.yugabyte.yw.commissioner.tasks.subtasks.HardRebootServer;
Expand Down Expand Up @@ -1431,6 +1433,39 @@ public SubTaskGroup createChangeAdminPasswordTask(
return subTaskGroup;
}

private SubTaskGroup createDropTableTask(
Universe universe, CommonTypes.TableType tableType, String dbName, String tableName) {
SubTaskGroup subTaskGroup = createSubTaskGroup("DropTable");
DropTable.Params dropTableParams = new DropTable.Params();
dropTableParams.setUniverseUUID(universe.getUniverseUUID());
dropTableParams.dbName = dbName;
dropTableParams.tableName = tableName;
dropTableParams.tableType = tableType;
DropTable task = createTask(DropTable.class);
task.initialize(dropTableParams);
task.setUserTaskUUID(getUserTaskUUID());
subTaskGroup.addSubTask(task);
getRunnableTask().addSubTaskGroup(subTaskGroup);
return subTaskGroup;
}

public void createDropSystemPlatformDBTablesTask(
Universe universe, SubTaskGroupType subTaskGroupType) {
createDropTableTask(
universe,
CommonTypes.TableType.PGSQL_TABLE_TYPE,
Util.SYSTEM_PLATFORM_DB,
Util.WRITE_READ_TABLE)
.setSubTaskGroupType(subTaskGroupType);

createDropTableTask(
universe,
CommonTypes.TableType.PGSQL_TABLE_TYPE,
Util.SYSTEM_PLATFORM_DB,
Util.CONSISTENCY_CHECK)
.setSubTaskGroupType(subTaskGroupType);
}

public void checkAndCreateChangeAdminPasswordTask(Cluster primaryCluster) {
boolean changeYCQLAdminPass =
primaryCluster.userIntent.enableYCQL
Expand Down Expand Up @@ -2770,7 +2805,7 @@ public SubTaskGroup createReadWriteTestTableTask(int numPartitions, boolean ifNo
idColumn.sortOrder = SortOrder.ASC;

TableDetails details = new TableDetails();
details.tableName = "write_read_test";
details.tableName = WRITE_READ_TABLE;
details.keyspace = SYSTEM_PLATFORM_DB;
details.columns = new ArrayList<>();
details.columns.add(idColumn);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright (c) YugaByte, Inc.

package com.yugabyte.yw.commissioner.tasks.subtasks;

import com.yugabyte.yw.commissioner.BaseTaskDependencies;
import com.yugabyte.yw.commissioner.tasks.UniverseTaskBase;
import com.yugabyte.yw.common.PlatformServiceException;
import com.yugabyte.yw.common.YcqlQueryExecutor;
import com.yugabyte.yw.common.YsqlQueryExecutor;
import com.yugabyte.yw.forms.UniverseTaskParams;
import com.yugabyte.yw.models.Universe;
import java.time.Duration;
import javax.inject.Inject;
import lombok.extern.slf4j.Slf4j;
import org.yb.CommonTypes;

@Slf4j
public class DropTable extends UniverseTaskBase {
@Inject
protected DropTable(BaseTaskDependencies baseTaskDependencies) {
super(baseTaskDependencies);
}

private static long WAIT_TIME_IN_MILLIS = 5000;

@Inject YsqlQueryExecutor ysqlQueryExecutor;
@Inject YcqlQueryExecutor ycqlQueryExecutor;

public static class Params extends UniverseTaskParams {
public String dbName;
public String tableName;
public CommonTypes.TableType tableType;
}

protected Params taskParams() {
return (Params) taskParams;
}

@Override
public String getName() {
return super.getName() + "(" + taskParams().getUniverseUUID() + ")";
}

@Override
public void run() {
try {
log.info("Running {}", getName());
Universe universe = Universe.getOrBadRequest(taskParams().getUniverseUUID());
if (taskParams().tableType.equals(CommonTypes.TableType.PGSQL_TABLE_TYPE)) {
try {
ysqlQueryExecutor.dropTable(universe, taskParams().dbName, taskParams().tableName);
waitFor(Duration.ofMillis(WAIT_TIME_IN_MILLIS));
} catch (PlatformServiceException e) {
log.error("Error dropping table: " + e.getMessage());
throw e;
}
} else if (taskParams().tableType.equals(CommonTypes.TableType.YQL_TABLE_TYPE)) {
throw new UnsupportedOperationException(
"Un-implemented table type: " + taskParams().tableType);
} else {
throw new IllegalArgumentException("Unsupported table type: " + taskParams().tableType);
}
} catch (Exception e) {
String msg = getName() + " failed with exception " + e.getMessage();
log.warn(msg, e.getMessage());
throw new RuntimeException(msg, e);
}
log.info("Completed {}", getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ public void run() {
() -> {
Universe universe = getUniverse();

// Drop system_platform tables while disabling YSQL.
if (!taskParams().enableYSQL
&& universe.getUniverseDetails().getPrimaryCluster().userIntent.enableYSQL) {
createDropSystemPlatformDBTablesTask(universe, getTaskSubGroupType());
}

// Reset password to default before disable.
createResetAPIPasswordTask(taskParams(), getTaskSubGroupType());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ public void run() {
// by the tasks below.
syncTaskParamsToUserIntent();

// Drop system_platform.write_read_table while disabling YSQL.
if (!taskParams().enableYSQL
&& universe.getUniverseDetails().getPrimaryCluster().userIntent.enableYSQL) {
createDropSystemPlatformDBTablesTask(universe, getTaskSubGroupType());
}

// Reset password to default before disable.
createResetAPIPasswordTask(taskParams(), getTaskSubGroupType());

Expand Down
1 change: 1 addition & 0 deletions managed/src/main/java/com/yugabyte/yw/common/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public class Util {
public static final String REDACT = "REDACTED";
public static final String KEY_LOCATION_SUFFIX = "/backup_keys.json";
public static final String SYSTEM_PLATFORM_DB = "system_platform";
public static final String WRITE_READ_TABLE = "write_read_table";
public static final int YB_SCHEDULER_INTERVAL = 2;
public static final String DEFAULT_YB_SSH_USER = "yugabyte";
public static final String DEFAULT_SUDO_SSH_USER = "centos";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,4 +581,9 @@ public void updateAdminPassword(Universe universe, DatabaseSecurityFormData data
allQueries.append(query);
runUserDbCommands(allQueries.toString(), data.dbName, universe);
}

public void dropTable(Universe universe, String dbName, String tableName) {
String query = String.format("DROP TABLE if exists %s;", tableName);
runUserDbCommands(query, dbName, universe);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,8 @@ public enum TaskType {

ChangeAdminPassword(com.yugabyte.yw.commissioner.tasks.subtasks.ChangeAdminPassword.class),

DropTable(com.yugabyte.yw.commissioner.tasks.subtasks.DropTable.class),

CreateTable(com.yugabyte.yw.commissioner.tasks.subtasks.CreateTable.class),

DeleteNode(com.yugabyte.yw.commissioner.tasks.subtasks.DeleteNode.class),
Expand Down
Loading

0 comments on commit 41f5afd

Please sign in to comment.