Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit19750e1

Browse files
author
Vladimir Ershov
committed
memory fix
1 parent4ab6060 commit19750e1

File tree

5 files changed

+502
-259
lines changed

5 files changed

+502
-259
lines changed

‎src/scheduler_executor.c

Lines changed: 69 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ int do_one_job(schd_executor_share_t *shared, schd_executor_status_t *status)
161161
char*error=NULL;
162162
inti;
163163
job_t*job;
164-
intret;
164+
spi_response_t*r;
165165

166166
EE.n=0;
167167
EE.errors=NULL;
@@ -230,27 +230,27 @@ int do_one_job(schd_executor_share_t *shared, schd_executor_status_t *status)
230230
}
231231
if(job->type==AtJob&&i==0&&job->sql_params_n>0)
232232
{
233-
ret=execute_spi_params_prepared(job->dosql[i],job->sql_params_n,job->sql_params,&error);
233+
r=execute_spi_params_prepared(job->dosql[i],job->sql_params_n,job->sql_params);
234234
}
235235
else
236236
{
237-
ret=execute_spi(job->dosql[i],&error);
237+
r=execute_spi(job->dosql[i]);
238238
}
239-
if(ret<0)
239+
if(r->retval<0)
240240
{
241241
/* success = false; */
242242
*status=SchdExecutorError;
243-
if(error)
243+
if(r->error)
244244
{
245245
push_executor_error(&EE,"error in command #%d: %s",
246-
i+1,error);
247-
pfree(error);
246+
i+1,r->error);
248247
}
249248
else
250249
{
251250
push_executor_error(&EE,"error in command #%d: code: %d",
252-
i+1,ret);
251+
i+1,r->retval);
253252
}
253+
destroy_spi_data(r);
254254
ABORT_SPI_SNAP();
255255
SetConfigOption("schedule.transaction_state","failure",PGC_INTERNAL,PGC_S_SESSION);
256256
executor_onrollback(job,&EE);
@@ -264,6 +264,7 @@ int do_one_job(schd_executor_share_t *shared, schd_executor_status_t *status)
264264
STOP_SPI_SNAP();
265265
}
266266
}
267+
destroy_spi_data(r);
267268
}
268269
if(*status!=SchdExecutorError)
269270
{
@@ -331,27 +332,36 @@ int set_session_authorization(char *username, char **error)
331332
Oiduseroid;
332333
Datumvalues[1];
333334
boolis_superuser;
334-
intret;
335+
spi_response_t*r;
336+
intrv;
335337
char*sql="select oid, rolsuper from pg_catalog.pg_roles where rolname = $1";
336338
charbuff[1024];
337339

338340
values[0]=CStringGetTextDatum(username);
339341
START_SPI_SNAP();
340-
ret=execute_spi_sql_with_args(sql,1,types,values,NULL,error);
342+
r=execute_spi_sql_with_args(sql,1,types,values,NULL);
341343

342-
if(ret<0)returnret;
343-
if(SPI_processed==0)
344+
if(r->retval<0)
345+
{
346+
rv=r->retval;
347+
*error=_copy_string(r->error);
348+
destroy_spi_data(r);
349+
returnrv;
350+
}
351+
if(r->n_rows==0)
344352
{
345353
STOP_SPI_SNAP();
346354
sprintf(buff,"Cannot find user with name: %s",username);
347355
*error=_copy_string(buff);
356+
destroy_spi_data(r);
348357

349358
return-200;
350359
}
351-
useroid=get_oid_from_spi(0,1,0);
352-
is_superuser=get_boolean_from_spi(0,2, false);
360+
useroid=get_oid_from_spi(r,0,1,0);
361+
is_superuser=get_boolean_from_spi(r,0,2, false);
353362

354363
STOP_SPI_SNAP();
364+
destroy_spi_data(r);
355365

356366
SetSessionAuthorization(useroid,is_superuser);
357367

@@ -399,42 +409,43 @@ void set_shared_message(schd_executor_share_t *shared, executor_error_t *ee)
399409

400410
TimestampTzget_next_excution_time(char*sql,executor_error_t*ee)
401411
{
402-
char*error;
403-
intret;
404412
TimestampTzts=0;
405413
Datumd;
406-
boolisnull;
414+
spi_response_t*r;
407415

408416
START_SPI_SNAP();
409417
pgstat_report_activity(STATE_RUNNING,"culc next time execution time");
410-
ret=execute_spi(sql,&error);
411-
if(ret<0)
418+
r=execute_spi(sql);
419+
if(r->retval<0)
412420
{
413-
if(error)
421+
if(r->error)
414422
{
415-
push_executor_error(ee,"next time error: %s",error);
416-
pfree(error);
423+
push_executor_error(ee,"next time error: %s",r->error);
417424
}
418425
else
419426
{
420-
push_executor_error(ee,"next time error: code = %d",ret);
427+
push_executor_error(ee,"next time error: code = %d",r->retval);
421428
}
429+
destroy_spi_data(r);
422430
ABORT_SPI_SNAP();
423431
return0;
424432
}
425-
if(SPI_processed==0)
433+
if(r->n_rows==0)
426434
{
427435
push_executor_error(ee,"next time statement returns 0 rows");
428436
}
429-
elseif(SPI_gettypeid(SPI_tuptable->tupdesc,1)!=TIMESTAMPTZOID)
437+
elseif(r->types[0]!=TIMESTAMPTZOID)
430438
{
431439
push_executor_error(ee,"next time statement column 1 type is not timestamp with timezone");
432440
}
441+
elseif(r->rows[0][0].null)
442+
{
443+
push_executor_error(ee,"next time statement column 1 is null");
444+
}
433445
else
434446
{
435-
d=SPI_getbinval(SPI_tuptable->vals[0],SPI_tuptable->tupdesc,
436-
1,&isnull);
437-
if(isnull)
447+
d=r->rows[0][0].dat;
448+
if(!d)
438449
{
439450
push_executor_error(ee,"next time statement row 0 column 1 ihas NULL value");
440451
}
@@ -443,65 +454,67 @@ TimestampTz get_next_excution_time(char *sql, executor_error_t *ee)
443454
ts=DatumGetTimestampTz(d);
444455
}
445456
}
457+
destroy_spi_data(r);
446458

447459
STOP_SPI_SNAP();
448460
returnts;
449461
}
450462

451463
intexecutor_onrollback(job_t*job,executor_error_t*ee)
452464
{
453-
char*error=NULL;
454-
intret;
465+
intrv;
466+
spi_response_t*r;
455467

456468
if(!job->onrollback)return0;
457469
pgstat_report_activity(STATE_RUNNING,"execure onrollback");
458470

459471
START_SPI_SNAP();
460-
ret=execute_spi(job->onrollback,&error);
461-
if(ret<0)
472+
r=execute_spi(job->onrollback);
473+
if(r->retval<0)
462474
{
463-
if(error)
475+
if(r->error)
464476
{
465-
push_executor_error(ee,"onrollback error: %s",error);
466-
pfree(error);
477+
push_executor_error(ee,"onrollback error: %s",r->error);
467478
}
468479
else
469480
{
470-
push_executor_error(ee,"onrollback error: unknown: %d",ret);
481+
push_executor_error(ee,"onrollback error: unknown: %d",r->retval);
471482
}
472483
ABORT_SPI_SNAP();
473484
}
474485
else
475486
{
476487
STOP_SPI_SNAP();
477488
}
478-
returnret;
489+
rv=r->retval;
490+
destroy_spi_data(r);
491+
returnrv;
479492
}
480493

481494
voidset_pg_var(boolresult,executor_error_t*ee)
482495
{
483496
char*sql="select pgv_set_text('pgpro_scheduler', 'transaction', $1)";
484497
Oidargtypes[1]= {TEXTOID };
485498
Datumvals[1];
486-
char*error=NULL;
487-
intret;
499+
spi_response_t*r;
488500

489501
pgstat_report_activity(STATE_RUNNING,"set pg_valiable");
490502

491503
vals[0]=PointerGetDatum(cstring_to_text(result ?"success":"failure"));
492504

493-
ret=execute_spi_sql_with_args(sql,1,argtypes,vals,NULL,&error);
494-
if(ret<0)
505+
r=execute_spi_sql_with_args(sql,1,argtypes,vals,NULL);
506+
if(r->retval<0)
495507
{
496-
if(error)
508+
if(r->error)
497509
{
498-
push_executor_error(ee,"set variable: %s",error);
510+
push_executor_error(ee,"set variable: %s",r->error);
499511
}
500512
else
501513
{
502-
push_executor_error(ee,"set variable error code: %d",ret);
514+
push_executor_error(ee,"set variable error code: %d",r->retval);
503515
}
504516
}
517+
destroy_spi_data(r);
505518
}
506519

507520
job_t*initializeExecutorJob(schd_executor_share_t*data)
@@ -696,8 +709,9 @@ int process_one_job(schd_executor_share_state_t *shared, schd_executor_status_t
696709
char*error=NULL;
697710
char*set_error=NULL;
698711
job_t*job;
699-
intret,set_ret;
712+
intset_ret;
700713
charbuff[512];
714+
spi_response_t*r;
701715

702716
*status=shared->status=SchdExecutorWork;
703717

@@ -728,7 +742,6 @@ int process_one_job(schd_executor_share_state_t *shared, schd_executor_status_t
728742
return -1;
729743
} */
730744
STOP_SPI_SNAP();/* Commit changes */
731-
elog(LOG,"JOB MOVED TO PROCESSED");
732745
pgstat_report_activity(STATE_RUNNING,"job initialized");
733746
START_SPI_SNAP();
734747

@@ -767,11 +780,11 @@ int process_one_job(schd_executor_share_state_t *shared, schd_executor_status_t
767780

768781
if(job->sql_params_n>0)
769782
{
770-
ret=execute_spi_params_prepared(job->dosql[0],job->sql_params_n,job->sql_params,&error);
783+
r=execute_spi_params_prepared(job->dosql[0],job->sql_params_n,job->sql_params);
771784
}
772785
else
773786
{
774-
ret=execute_spi(job->dosql[0],&error);
787+
r=execute_spi(job->dosql[0]);
775788
}
776789
if(job->timelimit)
777790
{
@@ -780,23 +793,25 @@ int process_one_job(schd_executor_share_state_t *shared, schd_executor_status_t
780793
ResetAllOptions();
781794
SetConfigOption("enable_seqscan","off",PGC_USERSET,PGC_S_SESSION);
782795
SetSessionAuthorization(BOOTSTRAP_SUPERUSERID, true);
783-
if(ret<0)
796+
if(r->retval<0)
784797
{
785-
if(error)
798+
if(r->error)
786799
{
787-
set_ret=set_at_job_done(job,error,resubmit_current_job,&set_error);
788-
pfree(error);
800+
set_ret=set_at_job_done(job,r->error,resubmit_current_job,
801+
&set_error);
789802
}
790803
else
791804
{
792-
sprintf(buff,"error in command: code: %d",ret);
793-
set_ret=set_at_job_done(job,buff,resubmit_current_job,&set_error);
805+
sprintf(buff,"error in command: code: %d",r->retval);
806+
set_ret=set_at_job_done(job,buff,resubmit_current_job,
807+
&set_error);
794808
}
795809
}
796810
else
797811
{
798812
set_ret=set_at_job_done(job,NULL,resubmit_current_job,&set_error);
799813
}
814+
destroy_spi_data(r);
800815

801816
resubmit_current_job=0;
802817
current_job_id=-1;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp