Skip to content

Commit 0b3f901

Browse files
committed
Resolve three scenarios that may cause workload to fail
1 parent c3a7ce5 commit 0b3f901

File tree

5 files changed

+82
-4
lines changed

5 files changed

+82
-4
lines changed

src/backend/commands/prepare.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "utils/builtins.h"
3636
#include "utils/snapmgr.h"
3737
#include "utils/timestamp.h"
38+
#include "utils/syscache.h"
3839

3940
/* POLAR: Shared Server */
4041
#include "storage/proc.h"
@@ -51,7 +52,8 @@ static void InitQueryHashTable(void);
5152
static ParamListInfo EvaluateParams(PreparedStatement *pstmt, List *params,
5253
const char *queryString, EState *estate);
5354
static Datum build_regtype_array(Oid *param_types, int num_params);
54-
55+
// store prepare params info
56+
char current_prepared_params_string[MAX_PREPARED_PARAMS_LEN];
5557
/*
5658
* Implements the 'PREPARE' utility statement.
5759
*/
@@ -226,6 +228,29 @@ ExecuteQuery(ExecuteStmt *stmt, IntoClause *intoClause,
226228
/* Look it up in the hash table */
227229
entry = FetchPreparedStatement(stmt->name, true);
228230

231+
// get prepare params for solving parameterization problem
232+
if(entry){
233+
StringInfoData current_prepared_params;
234+
Oid* oid_list ;
235+
236+
initStringInfo(&current_prepared_params);
237+
oid_list = entry->plansource->param_types;
238+
appendStringInfoString(&current_prepared_params,entry->stmt_name);
239+
for(int i=0;i<entry->plansource->num_params;i++){
240+
Type tmp = typeidType(oid_list[i]);
241+
char * typname = typeTypeName(tmp);
242+
ReleaseSysCache(tmp);
243+
appendStringInfoChar(&current_prepared_params,',');
244+
appendStringInfoString(&current_prepared_params,typname);
245+
}
246+
if(current_prepared_params.len < MAX_PREPARED_PARAMS_LEN)
247+
memcpy(current_prepared_params_string,current_prepared_params.data,current_prepared_params.len);
248+
else
249+
memcpy(current_prepared_params_string,current_prepared_params.data,MAX_PREPARED_PARAMS_LEN);
250+
}else{
251+
current_prepared_params_string[0] = '\0';
252+
}
253+
229254
/* Shouldn't find a non-fixed-result cached plan */
230255
if (!entry->plansource->fixed_result)
231256
elog(ERROR, "EXECUTE does not support variable-result cached plans");

src/backend/utils/error/elog.c

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@
7777
#include "utils/guc.h"
7878
#include "utils/memutils.h"
7979
#include "utils/ps_status.h"
80+
#include "catalog/namespace.h"
81+
#include "commands/prepare.h"
8082

8183
/* POLAR */
8284
#include "utils/polar_backtrace.h"
@@ -116,8 +118,9 @@ char *Log_destination_string = NULL;
116118
bool syslog_sequence_numbers = true;
117119
bool syslog_split_messages = true;
118120
/* POLAR */
119-
#define LOG_CHANNEL_WRITE_BUFFER_SIZE 128 * 1024 /* 128k */
121+
#define LOG_CHANNEL_WRITE_BUFFER_SIZE 64 * 1024 /* 64k */
120122
int polar_auditlog_max_query_length = POLAR_DEFAULT_MAX_AUDIT_LOG_LEN;
123+
bool polar_auditlog_max_query_length_limit = true;
121124
int polar_audit_log_flush_timeout = 0;
122125
/* POLAR end */
123126

@@ -2603,6 +2606,19 @@ log_line_prefix(StringInfo buf, ErrorData *edata)
26032606
appendStringInfoString(buf, formatted_log_time);
26042607
break;
26052608
/* POLAR: new format for polar */
2609+
case 'L':
2610+
if (padding != 0)
2611+
appendStringInfo(buf, "%*s", padding, current_prepared_params_string);
2612+
else
2613+
appendStringInfoString(buf, current_prepared_params_string);
2614+
current_prepared_params_string[0] = '\0';
2615+
break;
2616+
case 'N':
2617+
if (padding != 0)
2618+
appendStringInfo(buf, "%*s", padding, namespace_search_path);
2619+
else
2620+
appendStringInfoString(buf, namespace_search_path);
2621+
break;
26062622
case 'S':
26072623
if (edata->is_audit_log || edata->is_slow_log)
26082624
{
@@ -4246,7 +4262,8 @@ polar_construct_logdata_postprocess(StringInfoData *logbuf, ErrorData *edata)
42464262
else
42474263
{
42484264
// NOTE(wormhole.gl): make sure logbuf length is not larger than PIPE_MAX_PAYLOAD
4249-
polar_shrink_audit_log(logbuf, 0);
4265+
if (polar_auditlog_max_query_length_limit)
4266+
polar_shrink_audit_log(logbuf, 0);
42504267
}
42514268

42524269
appendStringInfoChar(logbuf, '\n');
@@ -4287,6 +4304,8 @@ polar_write_audit_log(ErrorData *edata, const char *fmt, ...)
42874304
int dest;
42884305
char *logbuf_base = NULL;
42894306
int logbuf_len = 0;
4307+
int residual_buf_len = 0;
4308+
int writed_buf_len = 0;
42904309

42914310
StringInfoData logbuf;
42924311

@@ -4333,6 +4352,28 @@ polar_write_audit_log(ErrorData *edata, const char *fmt, ...)
43334352
log_channel_write_buffer_pos);
43344353
log_channel_write_buffer_pos = 0;
43354354
polar_last_audit_log_flush_time = GetCurrentTimestamp();
4355+
// solving incomplete audit sql log problem
4356+
writed_buf_len = logbuf_len - PIPE_HEADER_SIZE;
4357+
residual_buf_len = logbuf.len - writed_buf_len;
4358+
while (residual_buf_len > 0)
4359+
{
4360+
logbuf_base = log_channel_write_buffer + log_channel_write_buffer_pos;
4361+
logbuf_len = LOGBUF_MIN_LEN(residual_buf_len, LOG_CHANNEL_WRITE_BUFFER_SIZE - PIPE_HEADER_SIZE - log_channel_write_buffer_pos);
4362+
memcpy(logbuf_base + PIPE_HEADER_SIZE, logbuf.data + writed_buf_len, logbuf_len);
4363+
// build pipechunk header
4364+
dest = polar_log_dest(edata);
4365+
polar_construct_pipechunk_header((PipeProtoChunk *)logbuf_base, logbuf_len, dest);
4366+
writed_buf_len += logbuf_len;
4367+
residual_buf_len = residual_buf_len - logbuf_len;
4368+
4369+
logbuf_len = logbuf_len + PIPE_HEADER_SIZE;
4370+
log_channel_write_buffer_pos += logbuf_len;
4371+
polar_write_channel((PipeProtoChunk *)log_channel_write_buffer,
4372+
log_channel_write_buffer_pos);
4373+
log_channel_write_buffer_pos = 0;
4374+
polar_last_audit_log_flush_time = GetCurrentTimestamp();
4375+
}
4376+
43364377
break;
43374378
case LOG_DESTINATION_POLAR_SLOWLOG:
43384379
default:

src/backend/utils/misc/guc.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,16 @@ static bool update_session_external_guc_index(struct config_generic *var);
14021402

14031403
static struct config_bool ConfigureNamesBool[] =
14041404
{
1405+
{
1406+
{"polar_auditlog_max_query_length_limit",PGC_SIGHUP,LOGGING,
1407+
gettext_noop("whether to limit polar_auditlog_max_query_length"),
1408+
NULL
1409+
},
1410+
&polar_auditlog_max_query_length_limit,
1411+
true,
1412+
NULL,NULL,NULL
1413+
},
1414+
14051415
{
14061416
{"polar_enable_flashback_drop",PGC_SUSET,UNGROUPED,
14071417
gettext_noop("whether to open flashback_drop"),

src/include/commands/prepare.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313
#ifndef PREPARE_H
1414
#define PREPARE_H
15+
#define MAX_PREPARED_PARAMS_LEN 200
1516

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

5859
extern void DropAllPreparedStatements(void);
59-
60+
extern char current_prepared_params_string[MAX_PREPARED_PARAMS_LEN];
6061
#endif /* PREPARE_H */

src/include/utils/guc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ extern bool polar_enable_pread;
396396
extern bool polar_enable_parallel_replay_standby_mode;
397397
extern bool polar_enable_fallocate_walfile;
398398
extern bool polar_skip_fill_walfile_zero_page;
399+
extern bool polar_auditlog_max_query_length_limit;
399400
extern int polar_auditlog_max_query_length;
400401
extern int polar_audit_log_flush_timeout;
401402
extern int polar_clog_max_local_cache_segments;

0 commit comments

Comments
 (0)