pull/6763/head^2
Gokhan Gulbiz 2023-03-13 14:31:41 +03:00
parent 21298f6661
commit e9a6f8a7c5
No known key found for this signature in database
GPG Key ID: 608EF06B6BD1B45B
1 changed files with 23 additions and 20 deletions

View File

@ -65,7 +65,7 @@ static int CreateTenantStats(MultiTenantMonitor *monitor, time_t queryTime);
static int FindTenantStats(MultiTenantMonitor *monitor); static int FindTenantStats(MultiTenantMonitor *monitor);
static size_t MultiTenantMonitorshmemSize(void); static size_t MultiTenantMonitorshmemSize(void);
static char * extractTopComment(const char *inputString); static char * extractTopComment(const char *inputString);
static char* get_substring(const char* str, int start, int end); static char * get_substring(const char *str, int start, int end);
int MultiTenantMonitoringLogLevel = CITUS_LOG_LEVEL_OFF; int MultiTenantMonitoringLogLevel = CITUS_LOG_LEVEL_OFF;
int CitusStatsTenantsPeriod = (time_t) 60; int CitusStatsTenantsPeriod = (time_t) 60;
@ -221,9 +221,9 @@ AttributeQueryIfAnnotated(const char *query_string, CmdType commandType)
if (MultiTenantMonitoringLogLevel != CITUS_LOG_LEVEL_OFF) if (MultiTenantMonitoringLogLevel != CITUS_LOG_LEVEL_OFF)
{ {
ereport(NOTICE, (errmsg( ereport(NOTICE, (errmsg(
"attributing query to tenant: %s, colocationGroupId: %d", "attributing query to tenant: %s, colocationGroupId: %d",
quote_literal_cstr(attributeToTenant), quote_literal_cstr(attributeToTenant),
colocationGroupId))); colocationGroupId)));
} }
} }
} }
@ -675,12 +675,13 @@ static char *
extractTopComment(const char *inputString) extractTopComment(const char *inputString)
{ {
int commentStartCharsLength = 2; int commentStartCharsLength = 2;
if (strlen(inputString) < commentStartCharsLength ) if (strlen(inputString) < commentStartCharsLength)
{ {
return NULL; return NULL;
} }
int i = 0; int i = 0;
/* If query starts with a comment */ /* If query starts with a comment */
if (inputString[i] == '/' && inputString[i + 1] == '*') if (inputString[i] == '/' && inputString[i + 1] == '*')
{ {
@ -702,24 +703,26 @@ extractTopComment(const char *inputString)
} }
} }
static char*
get_substring(const char* str, int start, int end) {
int len = strlen(str);
char* substr = NULL;
// Ensure start and end are within the bounds of the string static char *
if (start < 0 || end > len || start > end) { get_substring(const char *str, int start, int end)
return NULL; {
} int len = strlen(str);
// Allocate memory for the substring /* Ensure start and end are within the bounds of the string */
substr = (char*) palloc((end - start + 1) * sizeof(char)); if (start < 0 || end > len || start > end)
{
return NULL;
}
// Copy the substring to the new memory location /* Allocate memory for the substring */
strncpy_s(substr, end - start + 1, str + start, end - start); char *substr = (char *) palloc((end - start + 1) * sizeof(char));
// Add null terminator to end the substring /* Copy the substring to the new memory location */
substr[end - start] = '\0'; strncpy_s(substr, end - start + 1, str + start, end - start);
return substr; /* Add null terminator to end the substring */
substr[end - start] = '\0';
return substr;
} }