Skip to content

Commit

Permalink
[CBRD-24781] Added csql option for catalog rebuild (#4325) (#4329)
Browse files Browse the repository at this point in the history
  • Loading branch information
youngjinj authored Apr 26, 2023
1 parent 0d2a20d commit b9bd7af
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 28 deletions.
1 change: 1 addition & 0 deletions src/compat/db_client_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ enum db_client_type
DB_CLIENT_TYPE_SKIP_VACUUM_ADMIN_CSQL = 16,
DB_CLIENT_TYPE_ADMIN_COMPACTDB_WOS = 17, /* admin compactdb that can run on standby */
DB_CLIENT_TYPE_ADMIN_LOADDB_COMPAT = 18, /* loaddb with --no-user-specified-name option */
DB_CLIENT_TYPE_ADMIN_CSQL_REBUILD_CATALOG = 19,

DB_CLIENT_TYPE_MAX
};
Expand Down
10 changes: 8 additions & 2 deletions src/executables/csql.c
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ csql_do_session_cmd (char *line_read, CSQL_ARGUMENT * csql_arg)
{
if (csql_arg->sysadm && au_is_dba_group_member (Au_user))
{
au_sysadm_disable ();
au_disable ();
}
csql_Database_connected = true;

Expand Down Expand Up @@ -2828,6 +2828,12 @@ csql (const char *argv0, CSQL_ARGUMENT * csql_arg)
client_type = DB_CLIENT_TYPE_CSQL;
}

if (csql_arg->sysadm_rebuild_catalog)
{
client_type = DB_CLIENT_TYPE_ADMIN_CSQL_REBUILD_CATALOG;
csql_arg->sysadm = true;
}

if (db_restart_ex (argv0, csql_arg->db_name, csql_arg->user_name, csql_arg->passwd, NULL, client_type) != NO_ERROR)
{
if (!csql_Is_interactive || csql_arg->passwd != NULL || db_error_code () != ER_AU_INVALID_PASSWORD)
Expand Down Expand Up @@ -2882,7 +2888,7 @@ csql (const char *argv0, CSQL_ARGUMENT * csql_arg)

if (csql_arg->sysadm && au_is_dba_group_member (Au_user))
{
au_sysadm_disable ();
au_disable ();
}

/* allow environmental setting of the "-s" command line flag to enable automated testing */
Expand Down
1 change: 1 addition & 0 deletions src/executables/csql.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ extern "C"
bool nopager;
bool continue_on_error;
bool sysadm;
bool sysadm_rebuild_catalog;
bool write_on_standby;
bool trigger_action_flag;
bool plain_output;
Expand Down
21 changes: 20 additions & 1 deletion src/executables/csql_launcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ main (int argc, char *argv[])
{CSQL_NO_PAGER_L, 0, 0, CSQL_NO_PAGER_S},
{CSQL_NO_SINGLE_LINE_L, 0, 0, CSQL_NO_SINGLE_LINE_S},
{CSQL_SYSADM_L, 0, 0, CSQL_SYSADM_S},
{CSQL_SYSADM_REBUILD_CATALOG_L, 0, 0, CSQL_SYSADM_REBUILD_CATALOG_S},
{CSQL_WRITE_ON_STANDBY_L, 0, 0, CSQL_WRITE_ON_STANDBY_S},
{CSQL_STRING_WIDTH_L, 1, 0, CSQL_STRING_WIDTH_S},
{CSQL_NO_TRIGGER_ACTION_L, 0, 0, CSQL_NO_TRIGGER_ACTION_S},
Expand Down Expand Up @@ -257,6 +258,10 @@ main (int argc, char *argv[])
csql_arg.sysadm = true;
break;

case CSQL_SYSADM_REBUILD_CATALOG_S:
csql_arg.sysadm_rebuild_catalog = true;
break;

case CSQL_WRITE_ON_STANDBY_S:
csql_arg.write_on_standby = true;
break;
Expand Down Expand Up @@ -410,7 +415,21 @@ main (int argc, char *argv[])
goto print_usage;
}

if (csql_arg.sysadm && (csql_arg.user_name == NULL || strcasecmp (csql_arg.user_name, "DBA")))
if (csql_arg.sysadm_rebuild_catalog)
{
if (!csql_arg.sa_mode)
{
goto print_usage;
}

if (csql_arg.in_file_name == NULL && csql_arg.command == NULL)
{
goto print_usage;
}
}

if ((csql_arg.sysadm || csql_arg.sysadm_rebuild_catalog)
&& (csql_arg.user_name == NULL || strcasecmp (csql_arg.user_name, "DBA")))
{
/* sysadm is allowed only to DBA */
goto print_usage;
Expand Down
2 changes: 2 additions & 0 deletions src/executables/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -1430,6 +1430,8 @@ typedef struct _ha_config
#define CSQL_QUERY_COLUMN_ENCLOSURE_L "enclosure"
#define CSQL_LOADDB_OUTPUT_S 'd'
#define CSQL_LOADDB_OUTPUT_L "loaddb-output"
#define CSQL_SYSADM_REBUILD_CATALOG_S 12020
#define CSQL_SYSADM_REBUILD_CATALOG_L "sysadm-rebuild-catalog"

#define COMMDB_SERVER_LIST_S 'P'
#define COMMDB_SERVER_LIST_L "server-list"
Expand Down
23 changes: 6 additions & 17 deletions src/object/authenticate.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ MOP Au_root = NULL;
* use the AU_DISABLE, AU_ENABLE macros instead.
*/
int Au_disable = 1;
bool Au_sysadm = false;

/*
* Au_ignore_passwords
Expand Down Expand Up @@ -6402,9 +6401,13 @@ check_authorization (MOP classobj, SM_CLASS * sm_class, DB_AUTH type)
* Callers generally check Au_disable already to avoid the function call.
* Check it again to be safe, at this point, it isn't going to add anything.
*/
if (Au_disable && (!Au_sysadm || !(sm_class->flags & SM_CLASSFLAG_SYSTEM)))
if (Au_disable)
{
return NO_ERROR;
int client_type = db_get_client_type ();
if (!BOOT_ADMIN_CSQL_CLIENT_TYPE (client_type) || !(sm_class->flags & SM_CLASSFLAG_SYSTEM))
{
return NO_ERROR;
}
}

/* try to catch attempts by even the DBA to update a protected class */
Expand Down Expand Up @@ -9199,19 +9202,6 @@ au_disable (void)
return save;
}

/*
* au_sysadm_disable - set Au_disable for sysadm
* return: original Au_disable value
*/
int
au_sysadm_disable (void)
{
int save = Au_disable;
Au_disable = 1;
Au_sysadm = true;
return save;
}

/*
* au_enable - restore Au_disable
* return:
Expand All @@ -9221,7 +9211,6 @@ void
au_enable (int save)
{
Au_disable = save;
Au_sysadm = false;
}

/*
Expand Down
1 change: 0 additions & 1 deletion src/object/authenticate.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ extern const char *AU_DBA_USER_NAME;


int au_disable (void);
int au_sysadm_disable (void);
void au_enable (int save);
MOP au_get_public_user (void);
MOP au_get_dba_user (void);
Expand Down
8 changes: 8 additions & 0 deletions src/query/execute_schema.c
Original file line number Diff line number Diff line change
Expand Up @@ -9034,6 +9034,14 @@ do_create_entity (PARSER_CONTEXT * parser, PT_NODE * node)
break;
}

if (db_get_client_type () == DB_CLIENT_TYPE_ADMIN_CSQL_REBUILD_CATALOG)
{
if (sm_check_system_class_by_name (class_name))
{
sm_mark_system_class (class_obj, 1);
}
}

if (do_flush_class_mop == true)
{
assert (error == NO_ERROR);
Expand Down
27 changes: 20 additions & 7 deletions src/transaction/boot.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,35 @@

#define BOOT_ADMIN_CLIENT_TYPE(client_type) \
((client_type) == DB_CLIENT_TYPE_ADMIN_UTILITY \
|| (client_type) == DB_CLIENT_TYPE_ADMIN_COMPACTDB_WOS \
|| (client_type) == DB_CLIENT_TYPE_ADMIN_CSQL \
|| (client_type) == DB_CLIENT_TYPE_ADMIN_CSQL_REBUILD_CATALOG \
|| (client_type) == DB_CLIENT_TYPE_ADMIN_CSQL_WOS \
|| (client_type) == DB_CLIENT_TYPE_SKIP_VACUUM_ADMIN_CSQL)
|| (client_type) == DB_CLIENT_TYPE_SKIP_VACUUM_ADMIN_CSQL \
|| (client_type) == DB_CLIENT_TYPE_ADMIN_COMPACTDB_WOS \
|| (client_type) == DB_CLIENT_TYPE_ADMIN_LOADDB_COMPAT)

#define BOOT_LOG_REPLICATOR_TYPE(client_type) \
((client_type) == DB_CLIENT_TYPE_LOG_COPIER \
|| (client_type) == DB_CLIENT_TYPE_LOG_APPLIER)

#define BOOT_CSQL_CLIENT_TYPE(client_type) \
((client_type) == DB_CLIENT_TYPE_CSQL \
|| (client_type) == DB_CLIENT_TYPE_READ_ONLY_CSQL \
|| (client_type) == DB_CLIENT_TYPE_SKIP_VACUUM_CSQL \
|| (client_type) == DB_CLIENT_TYPE_SKIP_VACUUM_ADMIN_CSQL \
|| (client_type) == DB_CLIENT_TYPE_ADMIN_CSQL \
|| (client_type) == DB_CLIENT_TYPE_ADMIN_CSQL_WOS)
|| (client_type) == DB_CLIENT_TYPE_READ_ONLY_CSQL \
|| (client_type) == DB_CLIENT_TYPE_ADMIN_CSQL \
|| (client_type) == DB_CLIENT_TYPE_ADMIN_CSQL_REBUILD_CATALOG \
|| (client_type) == DB_CLIENT_TYPE_ADMIN_CSQL_WOS \
|| (client_type) == DB_CLIENT_TYPE_SKIP_VACUUM_CSQL \
|| (client_type) == DB_CLIENT_TYPE_SKIP_VACUUM_ADMIN_CSQL)

/* DB_CLIENT_TYPE_ADMIN_CSQL_REBUILD_CATALOG is excluded
* for using the `--sysadm_rebuild_catalog` option of the csql utility.
*
* See CBRD-24781 for the details.
*/
#define BOOT_ADMIN_CSQL_CLIENT_TYPE(client_type) \
((client_type) == DB_CLIENT_TYPE_ADMIN_CSQL \
|| (client_type) == DB_CLIENT_TYPE_ADMIN_CSQL_WOS \
|| (client_type) == DB_CLIENT_TYPE_SKIP_VACUUM_ADMIN_CSQL)

#define BOOT_BROKER_AND_DEFAULT_CLIENT_TYPE(client_type) \
((client_type) == DB_CLIENT_TYPE_DEFAULT \
Expand Down
6 changes: 6 additions & 0 deletions src/transaction/boot_sr.c
Original file line number Diff line number Diff line change
Expand Up @@ -5987,6 +5987,8 @@ boot_client_type_to_string (BOOT_CLIENT_TYPE type)
return "ADMIN_UTILITY";
case DB_CLIENT_TYPE_ADMIN_CSQL:
return "ADMIN_CSQL";
case DB_CLIENT_TYPE_ADMIN_CSQL_REBUILD_CATALOG:
return "ADMIN_CSQL_REBUILD_CATALOG";
case DB_CLIENT_TYPE_LOG_COPIER:
return "LOG_COPIER";
case DB_CLIENT_TYPE_LOG_APPLIER:
Expand All @@ -6003,6 +6005,10 @@ boot_client_type_to_string (BOOT_CLIENT_TYPE type)
return "SKIP_VACUUM_CSQL";
case DB_CLIENT_TYPE_SKIP_VACUUM_ADMIN_CSQL:
return "SKIP_VACUUM_ADMIN_CSQL";
case DB_CLIENT_TYPE_ADMIN_COMPACTDB_WOS:
return "ADMIN_COMPACTDB_WOS";
case DB_CLIENT_TYPE_ADMIN_LOADDB_COMPAT:
return "ADMIN_LOADDB_COMPAT";
case DB_CLIENT_TYPE_UNKNOWN:
default:
return "UNKNOWN";
Expand Down

0 comments on commit b9bd7af

Please sign in to comment.