Skip to content

Commit

Permalink
Resolve three scenarios that may cause workload to fail
Browse files Browse the repository at this point in the history
  • Loading branch information
qinjingyuan committed Aug 23, 2023
1 parent c3a7ce5 commit f914614
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 4 deletions.
25 changes: 24 additions & 1 deletion src/backend/commands/prepare.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ static void InitQueryHashTable(void);
static ParamListInfo EvaluateParams(PreparedStatement *pstmt, List *params,
const char *queryString, EState *estate);
static Datum build_regtype_array(Oid *param_types, int num_params);

// store prepare params info
char current_prepared_params_string[MAX_PREPARED_PARAMS_LEN];
/*
* Implements the 'PREPARE' utility statement.
*/
Expand Down Expand Up @@ -530,6 +531,28 @@ FetchPreparedStatement(const char *stmt_name, bool throwError)
NULL);
else
entry = NULL;
// get prepare params for solving parameterization problem
if(entry){
StringInfoData current_prepared_params;
Oid* oid_list ;

initStringInfo(&current_prepared_params);
oid_list = entry->plansource->param_types;
appendStringInfoString(&current_prepared_params,entry->stmt_name);
for(int i=0;i<entry->plansource->num_params;i++){
Type tmp = typeidType(oid_list[i]);
char * typname = typeTypeName(tmp);
ReleaseSysCache(tmp);
appendStringInfoChar(&current_prepared_params,',');
appendStringInfoString(&current_prepared_params,typname);
}
if(current_prepared_params.len < MAX_PREPARED_PARAMS_LEN)
memcpy(current_prepared_params_string,current_prepared_params.data,current_prepared_params.len);
else
memcpy(current_prepared_params_string,current_prepared_params.data,MAX_PREPARED_PARAMS_LEN);
}else{
current_prepared_params_string[0] = '\0';
}

if (!entry && throwError)
ereport(ERROR,
Expand Down
45 changes: 43 additions & 2 deletions src/backend/utils/error/elog.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
#include "utils/guc.h"
#include "utils/memutils.h"
#include "utils/ps_status.h"
#include "catalog/namespace.h"
#include "commands/prepare.h"

/* POLAR */
#include "utils/polar_backtrace.h"
Expand Down Expand Up @@ -116,8 +118,9 @@ char *Log_destination_string = NULL;
bool syslog_sequence_numbers = true;
bool syslog_split_messages = true;
/* POLAR */
#define LOG_CHANNEL_WRITE_BUFFER_SIZE 128 * 1024 /* 128k */
#define LOG_CHANNEL_WRITE_BUFFER_SIZE 64 * 1024 /* 64k */
int polar_auditlog_max_query_length = POLAR_DEFAULT_MAX_AUDIT_LOG_LEN;
bool polar_auditlog_max_query_length_limit = true;
int polar_audit_log_flush_timeout = 0;
/* POLAR end */

Expand Down Expand Up @@ -2603,6 +2606,19 @@ log_line_prefix(StringInfo buf, ErrorData *edata)
appendStringInfoString(buf, formatted_log_time);
break;
/* POLAR: new format for polar */
case 'L':
if (padding != 0)
appendStringInfo(buf, "%*s", padding, current_prepared_params_string);
else
appendStringInfoString(buf, current_prepared_params_string);
current_prepared_params_string[0] = '\0';
break;
case 'N':
if (padding != 0)
appendStringInfo(buf, "%*s", padding, namespace_search_path);
else
appendStringInfoString(buf, namespace_search_path);
break;
case 'S':
if (edata->is_audit_log || edata->is_slow_log)
{
Expand Down Expand Up @@ -4246,7 +4262,8 @@ polar_construct_logdata_postprocess(StringInfoData *logbuf, ErrorData *edata)
else
{
// NOTE(wormhole.gl): make sure logbuf length is not larger than PIPE_MAX_PAYLOAD
polar_shrink_audit_log(logbuf, 0);
if (polar_auditlog_max_query_length_limit)
polar_shrink_audit_log(logbuf, 0);
}

appendStringInfoChar(logbuf, '\n');
Expand Down Expand Up @@ -4287,6 +4304,8 @@ polar_write_audit_log(ErrorData *edata, const char *fmt, ...)
int dest;
char *logbuf_base = NULL;
int logbuf_len = 0;
int residual_buf_len = 0;
int writed_buf_len = 0;

StringInfoData logbuf;

Expand Down Expand Up @@ -4333,6 +4352,28 @@ polar_write_audit_log(ErrorData *edata, const char *fmt, ...)
log_channel_write_buffer_pos);
log_channel_write_buffer_pos = 0;
polar_last_audit_log_flush_time = GetCurrentTimestamp();
// solving incomplete audit sql log problem
writed_buf_len = logbuf_len - PIPE_HEADER_SIZE;
residual_buf_len = logbuf.len - writed_buf_len;
while (residual_buf_len > 0)
{
logbuf_base = log_channel_write_buffer + log_channel_write_buffer_pos;
logbuf_len = LOGBUF_MIN_LEN(residual_buf_len, LOG_CHANNEL_WRITE_BUFFER_SIZE - PIPE_HEADER_SIZE - log_channel_write_buffer_pos);
memcpy(logbuf_base + PIPE_HEADER_SIZE, logbuf.data + writed_buf_len, logbuf_len);
// build pipechunk header
dest = polar_log_dest(edata);
polar_construct_pipechunk_header((PipeProtoChunk *)logbuf_base, logbuf_len, dest);
writed_buf_len += logbuf_len;
residual_buf_len = residual_buf_len - logbuf_len;

logbuf_len = logbuf_len + PIPE_HEADER_SIZE;
log_channel_write_buffer_pos += logbuf_len;
polar_write_channel((PipeProtoChunk *)log_channel_write_buffer,
log_channel_write_buffer_pos);
log_channel_write_buffer_pos = 0;
polar_last_audit_log_flush_time = GetCurrentTimestamp();
}

break;
case LOG_DESTINATION_POLAR_SLOWLOG:
default:
Expand Down
10 changes: 10 additions & 0 deletions src/backend/utils/misc/guc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1402,6 +1402,16 @@ static bool update_session_external_guc_index(struct config_generic *var);

static struct config_bool ConfigureNamesBool[] =
{
{
{"polar_auditlog_max_query_length_limit",PGC_SIGHUP,LOGGING,
gettext_noop("whether to limit polar_auditlog_max_query_length"),
NULL
},
&polar_auditlog_max_query_length_limit,
true,
NULL,NULL,NULL
},

{
{"polar_enable_flashback_drop",PGC_SUSET,UNGROUPED,
gettext_noop("whether to open flashback_drop"),
Expand Down
3 changes: 2 additions & 1 deletion src/include/commands/prepare.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
#ifndef PREPARE_H
#define PREPARE_H
#define MAX_PREPARED_PARAMS_LEN 200

#include "commands/explain.h"
#include "datatype/timestamp.h"
Expand Down Expand Up @@ -56,5 +57,5 @@ extern TupleDesc FetchPreparedStatementResultDesc(PreparedStatement *stmt);
extern List *FetchPreparedStatementTargetList(PreparedStatement *stmt);

extern void DropAllPreparedStatements(void);

extern char current_prepared_params_string[MAX_PREPARED_PARAMS_LEN];
#endif /* PREPARE_H */
1 change: 1 addition & 0 deletions src/include/utils/guc.h
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ extern bool polar_enable_pread;
extern bool polar_enable_parallel_replay_standby_mode;
extern bool polar_enable_fallocate_walfile;
extern bool polar_skip_fill_walfile_zero_page;
extern bool polar_auditlog_max_query_length_limit;
extern int polar_auditlog_max_query_length;
extern int polar_audit_log_flush_timeout;
extern int polar_clog_max_local_cache_segments;
Expand Down

0 comments on commit f914614

Please sign in to comment.