Skip to content

Commit

Permalink
[#4525] CREATE/DROP Tablegroup Plumbing/RPCs
Browse files Browse the repository at this point in the history
Summary:
Depends on D8747
This diff has functionality related to tablegroups - primarily passing information about tablegroup
DDL from the Postgres layer down to the catalog manager. Catalog manager changes (i.e. storing
tablegroup info / tablegroup-to-tablet mappings) will be included in another diff.

In ybccmds there are two new tablegroup DDL functions:
- YBCCreateTablegroup
- YBCDropTablegroup
Which are called by tablegroup.c (implemented in D8747) and pass tablegroup oid and name to ybc
pggate. This information (along with the name of the connected database) is eventually passed down
to the yb client.

There are two new RPCs:
- CreateTablegroup which takes CreateTablegroupRequestPB and returns CreateTablegroupResponsePB
- DeleteTablegroup which takes DeleteTablegroupRequestPB and returns DeleteTablegroupResponsePB

Test Plan:
Ensure that this test does not break:
```
./yb_build.sh --java-test org.yb.pgsql.TestPgRegressTablegroup
```

Reviewers: jason, nicolas

Reviewed By: nicolas

Subscribers: jenkins-bot, bogdan, neha, ybase

Differential Revision: https://phabricator.dev.yugabyte.com/D8830
  • Loading branch information
vvkgopalan committed Jul 30, 2020
1 parent 13cacff commit 88529b4
Show file tree
Hide file tree
Showing 22 changed files with 417 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/postgres/src/backend/commands/tablegroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
#include "utils/tqual.h"
#include "utils/varlena.h"

/* YB includes. */
#include "commands/ybccmds.h"
#include "yb/yql/pggate/ybc_pggate.h"
#include "pg_yb_utils.h"

/*
Expand Down Expand Up @@ -159,6 +162,11 @@ CreateTableGroup(CreateTableGroupStmt *stmt)

heap_freetuple(tuple);

if (IsYugaByteEnabled())
{
YBCCreateTablegroup(tablegroupoid, stmt->tablegroupname);
}

/* We keep the lock on pg_tablegroup until commit */
heap_close(rel, NoLock);

Expand Down Expand Up @@ -288,6 +296,11 @@ DropTableGroup(DropTableGroupStmt *stmt)

heap_endscan(scandesc);

if (IsYugaByteEnabled())
{
YBCDropTablegroup(tablegroupoid, stmt->tablegroupname);
}

/* We keep the lock on pg_tablegroup until commit */
heap_close(rel, NoLock);
}
Expand Down
23 changes: 23 additions & 0 deletions src/postgres/src/backend/commands/ybccmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,29 @@ YBCReserveOids(Oid dboid, Oid next_oid, uint32 count, Oid *begin_oid, Oid *end_o
end_oid));
}

/* ------------------------------------------------------------------------- */
/* Tablegroup Functions. */
void
YBCCreateTablegroup(Oid grpoid, const char *grpname)
{
YBCPgStatement handle;
char *db_name = get_database_name(MyDatabaseId);

HandleYBStatus(YBCPgNewCreateTablegroup(db_name, MyDatabaseId, grpname,
grpoid, &handle));
HandleYBStatus(YBCPgExecCreateTablegroup(handle));
}

void
YBCDropTablegroup(Oid grpoid, const char *grpname)
{
YBCPgStatement handle;

HandleYBStatus(YBCPgNewDropTablegroup(grpname, MyDatabaseId, grpoid, &handle));
HandleYBStatus(YBCPgExecDropTablegroup(handle));
}


/* ------------------------------------------------------------------------- */
/* Table Functions. */

Expand Down
6 changes: 6 additions & 0 deletions src/postgres/src/include/commands/ybccmds.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ extern void YBCDropDatabase(Oid dboid, const char *dbname);

extern void YBCReserveOids(Oid dboid, Oid next_oid, uint32 count, Oid *begin_oid, Oid *end_oid);

/* Tablegroup Functions ------------------------------------------------------------------------ */

extern void YBCCreateTablegroup(Oid grpoid, const char *grpname);

extern void YBCDropTablegroup(Oid grpoid, const char *grpname);

/* Table Functions ----------------------------------------------------------------------------- */

extern void YBCCreateTable(CreateStmt *stmt,
Expand Down
2 changes: 2 additions & 0 deletions src/yb/client/client-internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ YB_CLIENT_SPECIALIZE_SIMPLE(CreateCDCStream);
YB_CLIENT_SPECIALIZE_SIMPLE(DeleteCDCStream);
YB_CLIENT_SPECIALIZE_SIMPLE(ListCDCStreams);
YB_CLIENT_SPECIALIZE_SIMPLE(GetCDCStream);
YB_CLIENT_SPECIALIZE_SIMPLE(CreateTablegroup);
YB_CLIENT_SPECIALIZE_SIMPLE(DeleteTablegroup);
// These are not actually exposed outside, but it's nice to auto-add using directive.
YB_CLIENT_SPECIALIZE_SIMPLE(AlterTable);
YB_CLIENT_SPECIALIZE_SIMPLE(FlushTables);
Expand Down
34 changes: 34 additions & 0 deletions src/yb/client/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ using yb::master::CreateTableRequestPB;
using yb::master::CreateTableResponsePB;
using yb::master::DeleteTableRequestPB;
using yb::master::DeleteTableResponsePB;
using yb::master::CreateTablegroupRequestPB;
using yb::master::CreateTablegroupResponsePB;
using yb::master::DeleteTablegroupRequestPB;
using yb::master::DeleteTablegroupResponsePB;
using yb::master::GetNamespaceInfoRequestPB;
using yb::master::GetNamespaceInfoResponsePB;
using yb::master::GetTableSchemaRequestPB;
Expand Down Expand Up @@ -857,6 +861,36 @@ Result<bool> YBClient::NamespaceIdExists(const std::string& namespace_id,
return false;
}

Status YBClient::CreateTablegroup(const std::string& namespace_name,
const std::string& namespace_id,
const std::string& tablegroup_name,
const std::string& tablegroup_id) {
CreateTablegroupRequestPB req;
CreateTablegroupResponsePB resp;
req.set_name(tablegroup_name);
req.set_id(tablegroup_id);
req.set_namespace_id(namespace_id);
req.set_namespace_name(namespace_name);

CALL_SYNC_LEADER_MASTER_RPC(req, resp, CreateTablegroup);

return Status::OK();
}

Status YBClient::DeleteTablegroup(const std::string& tablegroup_name,
const std::string& namespace_id,
const std::string& tablegroup_id) {
DeleteTablegroupRequestPB req;
DeleteTablegroupResponsePB resp;
req.set_name(tablegroup_name);
req.set_id(tablegroup_id);
req.set_namespace_id(namespace_id);

CALL_SYNC_LEADER_MASTER_RPC(req, resp, DeleteTablegroup);

return Status::OK();
}

Status YBClient::GetUDType(const std::string& namespace_name,
const std::string& type_name,
std::shared_ptr<QLType>* ql_type) {
Expand Down
11 changes: 11 additions & 0 deletions src/yb/client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,17 @@ class YBClient {
Result<bool> NamespaceIdExists(const std::string& namespace_id,
const boost::optional<YQLDatabase>& database_type = boost::none);

// Create a new tablegroup.
CHECKED_STATUS CreateTablegroup(const std::string& namespace_name,
const std::string& namespace_id,
const std::string& tablegroup_name,
const std::string& tablegroup_id);

// Delete a tablegroup.
CHECKED_STATUS DeleteTablegroup(const std::string& tablegroup_name,
const std::string& namespace_id,
const std::string& tablegroup_id);

// Authentication and Authorization
// Create a new role.
CHECKED_STATUS CreateRole(const RoleName& role_name,
Expand Down
4 changes: 4 additions & 0 deletions src/yb/common/entity_ids.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ TableId GetPgsqlTableId(const uint32_t database_oid, const uint32_t table_oid) {
return UuidToString(&id);
}

TablegroupId GetPgsqlTablegroupId(const uint32_t database_oid, const uint32_t tablegroup_oid) {
return GetPgsqlTableId(database_oid, tablegroup_oid);
}

bool IsPgsqlId(const string& id) {
if (id.size() != 32) return false; // Ignore non-UUID id like "sys.catalog.uuid"
try {
Expand Down
4 changes: 4 additions & 0 deletions src/yb/common/entity_ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ using PeerId = std::string;
using SnapshotId = std::string;
using TabletServerId = PeerId;
using TabletId = std::string;
using TablegroupId = std::string;

YB_STRONGLY_TYPED_STRING(KvStoreId);

Expand All @@ -64,6 +65,9 @@ NamespaceId GetPgsqlNamespaceId(uint32_t database_oid);
// Get YB table id for a Postgres table.
TableId GetPgsqlTableId(uint32_t database_oid, uint32_t table_oid);

// Get YB tablegroup id for a Postgres tablegroup.
TablegroupId GetPgsqlTablegroupId(uint32_t database_oid, uint32_t tablegroup_oid);

// Is the namespace/table id a Postgres database or table id?
bool IsPgsqlId(const string& id);

Expand Down
12 changes: 12 additions & 0 deletions src/yb/master/catalog_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4699,6 +4699,18 @@ Status CatalogManager::ProcessTabletReport(TSDescriptor* ts_desc,
return Status::OK();
}

Status CatalogManager::CreateTablegroup(const CreateTablegroupRequestPB* req,
CreateTablegroupResponsePB* resp,
rpc::RpcContext* rpc) {
return Status::OK();
}

Status CatalogManager::DeleteTablegroup(const DeleteTablegroupRequestPB* req,
DeleteTablegroupResponsePB* resp,
rpc::RpcContext* rpc) {
return Status::OK();
}

Status CatalogManager::CreateNamespace(const CreateNamespaceRequestPB* req,
CreateNamespaceResponsePB* resp,
rpc::RpcContext* rpc) {
Expand Down
8 changes: 8 additions & 0 deletions src/yb/master/catalog_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,14 @@ class CatalogManager : public tserver::TabletPeerLookupIf {
RedisConfigGetResponsePB* resp,
rpc::RpcContext* rpc);

CHECKED_STATUS CreateTablegroup(const CreateTablegroupRequestPB* req,
CreateTablegroupResponsePB* resp,
rpc::RpcContext* rpc);

CHECKED_STATUS DeleteTablegroup(const DeleteTablegroupRequestPB* req,
DeleteTablegroupResponsePB* resp,
rpc::RpcContext* rpc);

// Create a new User-Defined Type with the specified attributes.
//
// The RPC context is provided for logging/tracing purposes,
Expand Down
31 changes: 31 additions & 0 deletions src/yb/master/master.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1424,6 +1424,33 @@ message GetNamespaceInfoResponsePB {
optional bool colocated = 3;
}

// ============================================================================
// Tablegroup
// ============================================================================

message CreateTablegroupRequestPB {
required string name = 1;
required bytes id = 2;
required bytes namespace_id = 3;
optional string namespace_name = 4;
}

message CreateTablegroupResponsePB {
// The error, if an error occurred with this request.
optional MasterErrorPB error = 1;
}

message DeleteTablegroupRequestPB {
required string name = 1;
required bytes id = 2;
required bytes namespace_id = 3;
}

message DeleteTablegroupResponsePB {
// The error, if an error occurred with this request.
optional MasterErrorPB error = 1;
}

// ============================================================================
// Authentication and Authorization
// ============================================================================
Expand Down Expand Up @@ -1827,6 +1854,10 @@ service MasterService {
rpc ListNamespaces(ListNamespacesRequestPB) returns (ListNamespacesResponsePB);
rpc GetNamespaceInfo(GetNamespaceInfoRequestPB) returns (GetNamespaceInfoResponsePB);

// For Tablegroup:
rpc CreateTablegroup(CreateTablegroupRequestPB) returns (CreateTablegroupResponsePB);
rpc DeleteTablegroup(DeleteTablegroupRequestPB) returns (DeleteTablegroupResponsePB);

// For Postgres:
rpc ReservePgsqlOids(ReservePgsqlOidsRequestPB) returns (ReservePgsqlOidsResponsePB);
rpc GetYsqlCatalogConfig(GetYsqlCatalogConfigRequestPB) returns (GetYsqlCatalogConfigResponsePB);
Expand Down
16 changes: 16 additions & 0 deletions src/yb/master/master_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,22 @@ void MasterServiceImpl::GetYsqlCatalogConfig(const GetYsqlCatalogConfigRequestPB
HandleIn(req, resp, &rpc, &CatalogManager::GetYsqlCatalogConfig);
}

// ------------------------------------------------------------------------------------------------
// Tablegroup
// ------------------------------------------------------------------------------------------------

void MasterServiceImpl::CreateTablegroup(const CreateTablegroupRequestPB* req,
CreateTablegroupResponsePB* resp,
rpc::RpcContext rpc) {
HandleIn(req, resp, &rpc, &CatalogManager::CreateTablegroup);
}

void MasterServiceImpl::DeleteTablegroup(const DeleteTablegroupRequestPB* req,
DeleteTablegroupResponsePB* resp,
rpc::RpcContext rpc) {
HandleIn(req, resp, &rpc, &CatalogManager::DeleteTablegroup);
}

// ------------------------------------------------------------------------------------------------
// Permissions
// ------------------------------------------------------------------------------------------------
Expand Down
8 changes: 8 additions & 0 deletions src/yb/master/master_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ class MasterServiceImpl : public MasterServiceIf,
GetYsqlCatalogConfigResponsePB* resp,
rpc::RpcContext rpc) override;

void CreateTablegroup(const CreateTablegroupRequestPB* req,
CreateTablegroupResponsePB* resp,
rpc::RpcContext rpc) override;

void DeleteTablegroup(const DeleteTablegroupRequestPB* req,
DeleteTablegroupResponsePB* resp,
rpc::RpcContext rpc) override;

void CreateRole(const CreateRoleRequestPB* req,
CreateRoleResponsePB* resp,
rpc::RpcContext rpc) override;
Expand Down
41 changes: 41 additions & 0 deletions src/yb/yql/pggate/pg_ddl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,47 @@ Status PgAlterDatabase::RenameDatabase(const char *newname) {
return Status::OK();
}

//--------------------------------------------------------------------------------------------------
// PgCreateTablegroup / PgDropTablegroup
//--------------------------------------------------------------------------------------------------

PgCreateTablegroup::PgCreateTablegroup(PgSession::ScopedRefPtr pg_session,
const char *database_name,
const PgOid database_oid,
const char *tablegroup_name,
const PgOid tablegroup_oid)
: PgDdl(pg_session),
database_name_(database_name),
database_oid_(database_oid),
tablegroup_name_(tablegroup_name),
tablegroup_oid_(tablegroup_oid) {
}

PgCreateTablegroup::~PgCreateTablegroup() {
}

Status PgCreateTablegroup::Exec() {
return pg_session_->CreateTablegroup(database_name_, database_oid_,
tablegroup_name_, tablegroup_oid_);
}

PgDropTablegroup::PgDropTablegroup(PgSession::ScopedRefPtr pg_session,
const char *tablegroup_name,
const PgOid database_oid,
const PgOid tablegroup_oid)
: PgDdl(pg_session),
tablegroup_name_(tablegroup_name),
database_oid_(database_oid),
tablegroup_oid_(tablegroup_oid) {
}

PgDropTablegroup::~PgDropTablegroup() {
}

Status PgDropTablegroup::Exec() {
return pg_session_->DropTablegroup(tablegroup_name_, database_oid_, tablegroup_oid_);
}

//--------------------------------------------------------------------------------------------------
// PgCreateTable
//--------------------------------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 88529b4

Please sign in to comment.