Skip to content

Commit

Permalink
[PLAT-13870] Support addition of databases in DB scoped DR config
Browse files Browse the repository at this point in the history
Summary:
Allow users to add 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 addition 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"
  ]
}'
```
The schema of the table `xcluster_namespace_config` is modified to include the replication status:
```
                             Table "public.xcluster_namespace_config"
       Column        |         Type          | Collation | Nullable |           Default
---------------------+-----------------------+-----------+----------+------------------------------
 config_uuid         | uuid                  |           | not null |
 source_namespace_id | character varying(64) |           | not null |
 status              | character varying(32) |           | not null | 'Running'::character varying
Indexes:
    "pk_xcluster_namespace_config" PRIMARY KEY, btree (config_uuid, source_namespace_id)
Check constraints:
    "ck_xcluster_namespace_config_table_status" CHECK (status::text = ANY (ARRAY['Validated'::character varying, 'Running'::character varying, 'Updating'::character varying, 'Bootstrapping'::character varying, 'Failed'::character varying]::text[]))
Foreign-key constraints:
    "fk_xcluster_namespace_config_config_uuid" FOREIGN KEY (config_uuid) REFERENCES xcluster_config(uuid) ON UPDATE CASCADE ON DELETE CASCADE
```

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.
Make sure that the task succeeds.

Add data to the table on the source and check that it reflects on the target database.

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

Reviewed By: cwang, hzare

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

Differential Revision: https://phorge.dev.yugabyte.com/D35498
  • Loading branch information
shahrooz1997 committed Jun 10, 2024
1 parent f97d0d3 commit 10f24bd
Show file tree
Hide file tree
Showing 51 changed files with 2,920 additions and 1,617 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright (c) YugaByte, Inc.

package org.yb.client;

import com.google.protobuf.Message;
import io.netty.buffer.ByteBuf;
import java.util.Set;
import org.yb.CommonNet.HostPortPB;
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 AddNamespaceToXClusterReplicationRequest
extends YRpc<AddNamespaceToXClusterReplicationResponse> {
private final String replicationGroupId;

// If target addresses are set, will delete replication on both source and target.
// If target addresses is null, will only delete outbound replication from the source.
private final Set<HostPortPB> targetMasterAddresses;

private final String namespaceId;

public AddNamespaceToXClusterReplicationRequest(
YBTable table,
String replicationGroupId,
Set<HostPortPB> targetMasterAddresses,
String namespaceId) {
super(table);
this.replicationGroupId = replicationGroupId;
this.targetMasterAddresses = targetMasterAddresses;
this.namespaceId = namespaceId;
}

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

@Override
String serviceName() {
return MASTER_SERVICE_NAME;
}

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

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

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

AddNamespaceToXClusterReplicationResponse response =
new AddNamespaceToXClusterReplicationResponse(
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 AddNamespaceToXClusterReplicationResponse extends YRpcResponse {
private final MasterErrorPB error;

public AddNamespaceToXClusterReplicationResponse(
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();
}
}
Loading

0 comments on commit 10f24bd

Please sign in to comment.