Skip to content

Commit

Permalink
[PLAT-13871] Support deletion of databases in DB scoped DR config
Browse files Browse the repository at this point in the history
Summary:
Allow users to delete databases to the DR config after enabled DB scoped replication on YBA.

Users can enable this feature by enabling the yb.xcluster.db_scoped.enabled runtime flag.

Currently supports deletion of databases without bootstrapping.

Example of the setDatbases API:

```
curl --location --request PUT 'localhost:9000/api/v1/customers/f33e3c9b-75ab-4c30-80ad-cba85646ea39/dr_configs/a4f7f7cb-0206-4385-82bc-8413f09b1fca/set_dbs' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'X-AUTH-YW-API-TOKEN: XYZ' \
--data '{
  "databases": [
    "00004004000030008000000000000000",
    "00004005000030008000000000000000"
  ]
}'
```

Any database that is not in the list of databases in the payload above will be removed from
replication.

Test Plan:
Added UT

Create a source and target universe with db version >= 2.23.0.0-b247.

Create database `trial1` and `trial2` on both source and target universe

Add the following table to the `trial1` and `trial2` db on both source and target universe without any data in it.
```
CREATE TABLE house(
   ID INT PRIMARY KEY     NOT NULL,
   LOCATION           TEXT    NOT NULL
);
```

Make a call to the setDatabases endpoint with dbScoped boolean set as true passing both the
databases `trial1` and `trial2`.
Make sure that the task succeeds.

Add data to the table on the source and check that it reflects on the target in both the databases
`trial1` and `trial2`.

Now, make a call to the setDatabases endpoint with dbScoped boolean set as true passing only the
database `trial1`. This will remove replication for the database `trial2`. Now, add some data to the
table on the source in the database `trial2` and verify that the data won't be replicated. However,
it will be replicated in the database `trial1`.

Reviewers: #yba-api-review!, cwang, hzare, daniel, amindrov, sanketh

Reviewed By: cwang

Subscribers: hsunder, yugaware, cwang, hzare, amindrov, jmak, sanketh

Differential Revision: https://phorge.dev.yugabyte.com/D35798
  • Loading branch information
posriniv committed Jun 21, 2024
1 parent 2a00083 commit 92a1f3c
Show file tree
Hide file tree
Showing 73 changed files with 787 additions and 217 deletions.
2 changes: 1 addition & 1 deletion java/interface-annotations/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>org.yb</groupId>
<artifactId>yb-parent</artifactId>
<version>0.8.89-SNAPSHOT</version>
<version>0.8.90-SNAPSHOT</version>
</parent>

<artifactId>interface-annotations</artifactId>
Expand Down
6 changes: 3 additions & 3 deletions java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

<groupId>org.yb</groupId>
<artifactId>yb-parent</artifactId>
<version>0.8.89-SNAPSHOT</version>
<version>0.8.90-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Yugabyte</name>
Expand Down Expand Up @@ -355,7 +355,7 @@
<dependency>
<groupId>org.yb</groupId>
<artifactId>yb-client</artifactId>
<version>0.8.89-SNAPSHOT</version>
<version>0.8.90-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.yb</groupId>
Expand Down Expand Up @@ -526,7 +526,7 @@
<dependency>
<groupId>org.yb</groupId>
<artifactId>yb-client</artifactId>
<version>0.8.89-SNAPSHOT</version>
<version>0.8.90-SNAPSHOT</version>
<type>test-jar</type>
</dependency>
<dependency>
Expand Down
6 changes: 3 additions & 3 deletions java/yb-cdc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.yb</groupId>
<artifactId>yb-parent</artifactId>
<version>0.8.89-SNAPSHOT</version>
<version>0.8.90-SNAPSHOT</version>
</parent>
<groupId>org.yb</groupId>
<artifactId>yb-cdc</artifactId>
Expand Down Expand Up @@ -43,12 +43,12 @@
<dependency>
<groupId>org.yb</groupId>
<artifactId>yb-client</artifactId>
<version>0.8.89-SNAPSHOT</version>
<version>0.8.90-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.yb</groupId>
<artifactId>yb-client</artifactId>
<version>0.8.89-SNAPSHOT</version>
<version>0.8.90-SNAPSHOT</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
Expand Down
6 changes: 3 additions & 3 deletions java/yb-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<parent>
<groupId>org.yb</groupId>
<artifactId>yb-parent</artifactId>
<version>0.8.89-SNAPSHOT</version>
<version>0.8.90-SNAPSHOT</version>
</parent>

<artifactId>yb-cli</artifactId>
Expand All @@ -40,12 +40,12 @@
<dependency>
<groupId>org.yb</groupId>
<artifactId>yb-client</artifactId>
<version>0.8.89-SNAPSHOT</version>
<version>0.8.90-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.yb</groupId>
<artifactId>yb-client</artifactId>
<version>0.8.89-SNAPSHOT</version>
<version>0.8.90-SNAPSHOT</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
Expand Down
4 changes: 2 additions & 2 deletions java/yb-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
<parent>
<groupId>org.yb</groupId>
<artifactId>yb-parent</artifactId>
<version>0.8.89-SNAPSHOT</version>
<version>0.8.90-SNAPSHOT</version>
</parent>

<artifactId>yb-client</artifactId>
<name>YB Java Client</name>
<version>0.8.89-SNAPSHOT</version>
<version>0.8.90-SNAPSHOT</version>
<properties>
<yb.thirdparty.dir>${project.basedir}/../../thirdparty</yb.thirdparty.dir>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@ public class AlterUniverseReplicationRequest extends YRpc<AlterUniverseReplicati
private final Set<HostPortPB> sourceMasterAddresses;
private final String newReplicationGroupName;
private final boolean removeTableIgnoreErrors;
private final String producerNamespaceIdToRemove;

AlterUniverseReplicationRequest(
YBTable table,
String replicationGroupName,
String producerNamespaceIdToRemove) {
super(table);
this.replicationGroupName = replicationGroupName;
this.sourceTableIdsToAddBootstrapIdMap = new HashMap<>();
this.sourceTableIdsToRemove = new HashSet<>();
this.sourceMasterAddresses = new HashSet<>();
this.newReplicationGroupName = null;
this.removeTableIgnoreErrors = true;
this.producerNamespaceIdToRemove = producerNamespaceIdToRemove;
}


AlterUniverseReplicationRequest(
YBTable table,
Expand All @@ -46,6 +62,7 @@ public class AlterUniverseReplicationRequest extends YRpc<AlterUniverseReplicati
this.sourceMasterAddresses = sourceMasterAddresses;
this.newReplicationGroupName = newReplicationGroupName;
this.removeTableIgnoreErrors = removeTableIgnoreErrors;
this.producerNamespaceIdToRemove = "";
}

@Override
Expand All @@ -67,6 +84,7 @@ ByteBuf serialize(Message header) {
.addAllProducerTableIdsToAdd(sourceTableIdsToAdd)
.addAllProducerTableIdsToRemove(sourceTableIdsToRemove)
.setRemoveTableIgnoreErrors(removeTableIgnoreErrors);

if (newReplicationGroupName != null) {
builder.setNewReplicationGroupId(newReplicationGroupName);
}
Expand All @@ -76,6 +94,10 @@ ByteBuf serialize(Message header) {
builder.addAllProducerBootstrapIdsToAdd(sourceBootstrapIdstoAdd);
}

if (producerNamespaceIdToRemove != null) {
builder.setProducerNamespaceIdToRemove(producerNamespaceIdToRemove);
}

return toChannelBuffer(header, builder.build());
}

Expand Down
38 changes: 38 additions & 0 deletions java/yb-client/src/main/java/org/yb/client/AsyncYBClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -1679,6 +1679,44 @@ public Deferred<IsCreateXClusterReplicationDoneResponse> isCreateXClusterReplica
return sendRpcToTablet(request);
}

/**
* Removes the namespace from the outbound replication group.
*
* @param replicationGroupId name of the replication group
* @param namespaceId namespace id to add to the replication group
* @return A deferred object that yields a {@link
* XClusterRemoveNamespaceFromOutboundReplicationGroupResponse}
*/
public Deferred<XClusterRemoveNamespaceFromOutboundReplicationGroupResponse>
xClusterRemoveNamespaceFromOutboundReplicationGroup(
String replicationGroupId, String namespaceId) {
checkIsClosed();
XClusterRemoveNamespaceFromOutboundReplicationGroupRequest request =
new XClusterRemoveNamespaceFromOutboundReplicationGroupRequest(
this.masterTable, replicationGroupId, namespaceId);
request.setTimeoutMillis(defaultAdminOperationTimeoutMs);
return sendRpcToTablet(request);
}

/**
* Used to remove namespace from replication group on ther target.
*
* @param replicationGroupId name of the replication group
* @param namespaceId namespace id to add to the replication group
* @return A deferred object that yields a {@link
* AlterUniverseReplicationResponse}
*/
public Deferred<AlterUniverseReplicationResponse>
alterUniverseReplicationRemoveNamespace(
String replicationGroupId, String namespaceId) {
checkIsClosed();
AlterUniverseReplicationRequest request =
new AlterUniverseReplicationRequest(
this.masterTable, replicationGroupId, namespaceId);
request.setTimeoutMillis(defaultAdminOperationTimeoutMs);
return sendRpcToTablet(request);
}

/**
* Adds the namespace to the xcluster replication.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright (c) YugaByte, Inc.

package org.yb.client;

import com.google.protobuf.Message;
import io.netty.buffer.ByteBuf;
import org.yb.annotations.InterfaceAudience;
import org.yb.master.MasterReplicationOuterClass;
import org.yb.master.MasterTypes.MasterErrorPB;
import org.yb.util.Pair;

@InterfaceAudience.Public
public class XClusterRemoveNamespaceFromOutboundReplicationGroupRequest
extends YRpc<XClusterRemoveNamespaceFromOutboundReplicationGroupResponse> {

private final String replicationGroupId;
private final String namespaceId;

public XClusterRemoveNamespaceFromOutboundReplicationGroupRequest(
YBTable table, String replicationGroupId, String namespaceId) {
super(table);
this.replicationGroupId = replicationGroupId;
this.namespaceId = namespaceId;
}

@Override
ByteBuf serialize(Message header) {
assert header.isInitialized();
final MasterReplicationOuterClass.XClusterRemoveNamespaceFromOutboundReplicationGroupRequestPB
.Builder
builder =
MasterReplicationOuterClass.XClusterRemoveNamespaceFromOutboundReplicationGroupRequestPB
.newBuilder();
builder.setReplicationGroupId(this.replicationGroupId);
builder.setNamespaceId(this.namespaceId);
return toChannelBuffer(header, builder.build());
}

@Override
String serviceName() {
return MASTER_SERVICE_NAME;
}

@Override
String method() {
return "XClusterRemoveNamespaceFromOutboundReplicationGroup";
}

@Override
Pair<XClusterRemoveNamespaceFromOutboundReplicationGroupResponse, Object> deserialize(
CallResponse callResponse, String tsUUID) throws Exception {
final MasterReplicationOuterClass.XClusterRemoveNamespaceFromOutboundReplicationGroupResponsePB
.Builder
builder =
MasterReplicationOuterClass.
XClusterRemoveNamespaceFromOutboundReplicationGroupResponsePB
.newBuilder();

readProtobuf(callResponse.getPBMessage(), builder);
final MasterErrorPB error = builder.hasError() ? builder.getError() : null;

XClusterRemoveNamespaceFromOutboundReplicationGroupResponse response =
new XClusterRemoveNamespaceFromOutboundReplicationGroupResponse(
deadlineTracker.getElapsedMillis(), tsUUID, error);
return new Pair<>(response, error);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) YugaByte, Inc.

package org.yb.client;

import org.yb.annotations.InterfaceAudience;
import org.yb.master.MasterTypes.MasterErrorPB;

@InterfaceAudience.Public
public class XClusterRemoveNamespaceFromOutboundReplicationGroupResponse extends YRpcResponse {
private final MasterErrorPB error;

public XClusterRemoveNamespaceFromOutboundReplicationGroupResponse(
long elapsedMillis, String tsUUID, MasterErrorPB error) {
super(elapsedMillis, tsUUID);
this.error = error;
}

public boolean hasError() {
return error != null;
}

public String errorMessage() {
if (error == null) {
return "";
}
return error.getStatus().getMessage();
}
}
24 changes: 24 additions & 0 deletions java/yb-client/src/main/java/org/yb/client/YBClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2308,6 +2308,30 @@ public XClusterDeleteOutboundReplicationGroupResponse xClusterDeleteOutboundRepl
return d.join(getDefaultAdminOperationTimeoutMs());
}

/**
* @see AsyncYBClient#xClusterRemoveNamespaceFromOutboundReplicationGroup(String, String)
*/
public XClusterRemoveNamespaceFromOutboundReplicationGroupResponse
xClusterRemoveNamespaceFromOutboundReplicationGroup(
String replicationGroupId, String namespaceId)
throws Exception {
Deferred<XClusterRemoveNamespaceFromOutboundReplicationGroupResponse> d =
asyncClient.xClusterRemoveNamespaceFromOutboundReplicationGroup(
replicationGroupId, namespaceId);
return d.join(getDefaultAdminOperationTimeoutMs());
}

/**
* @see AsyncYBClient#alterUniverseReplication(String, String)
*/
public AlterUniverseReplicationResponse
alterUniverseReplicationRemoveNamespace(String replicationGroupId, String namespaceId)
throws Exception {
Deferred<AlterUniverseReplicationResponse> d =
asyncClient.alterUniverseReplicationRemoveNamespace(replicationGroupId, namespaceId);
return d.join(getDefaultAdminOperationTimeoutMs());
}

/**
* @see AsyncYBClient#addNamespaceToXClusterReplication(String, Set<CommonNet.HostPortPB>, String)
*/
Expand Down
2 changes: 1 addition & 1 deletion java/yb-cql-4x/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.yb</groupId>
<artifactId>yb-parent</artifactId>
<version>0.8.89-SNAPSHOT</version>
<version>0.8.90-SNAPSHOT</version>
</parent>
<artifactId>yb-cql-4x</artifactId>
<name>YB CQL Support for 4.x Driver</name>
Expand Down
6 changes: 3 additions & 3 deletions java/yb-cql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.yb</groupId>
<artifactId>yb-parent</artifactId>
<version>0.8.89-SNAPSHOT</version>
<version>0.8.90-SNAPSHOT</version>
</parent>
<artifactId>yb-cql</artifactId>
<name>YB CQL Support</name>
Expand All @@ -16,13 +16,13 @@
<dependency>
<groupId>org.yb</groupId>
<artifactId>yb-client</artifactId>
<version>0.8.89-SNAPSHOT</version>
<version>0.8.90-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.yb</groupId>
<artifactId>yb-client</artifactId>
<version>0.8.89-SNAPSHOT</version>
<version>0.8.90-SNAPSHOT</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
Expand Down
6 changes: 3 additions & 3 deletions java/yb-jedis-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.yb</groupId>
<artifactId>yb-parent</artifactId>
<version>0.8.89-SNAPSHOT</version>
<version>0.8.90-SNAPSHOT</version>
</parent>
<artifactId>yb-jedis-tests</artifactId>
<name>YB Jedis Tests</name>
Expand All @@ -33,13 +33,13 @@
<dependency>
<groupId>org.yb</groupId>
<artifactId>yb-client</artifactId>
<version>0.8.89-SNAPSHOT</version>
<version>0.8.90-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.yb</groupId>
<artifactId>yb-client</artifactId>
<version>0.8.89-SNAPSHOT</version>
<version>0.8.90-SNAPSHOT</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
Expand Down
Loading

0 comments on commit 92a1f3c

Please sign in to comment.