@@ -162,6 +162,10 @@ int do_one_job(schd_executor_share_t *shared, schd_executor_status_t *status)
162
162
int i ;
163
163
job_t * job ;
164
164
spi_response_t * r ;
165
+ MemoryContext old ;
166
+ MemoryContext mem = init_mem_ctx ("executor" );
167
+
168
+ old = MemoryContextSwitchTo (mem );
165
169
166
170
EE .n = 0 ;
167
171
EE .errors = NULL ;
@@ -230,11 +234,11 @@ int do_one_job(schd_executor_share_t *shared, schd_executor_status_t *status)
230
234
}
231
235
if (job -> type == AtJob && i == 0 && job -> sql_params_n > 0 )
232
236
{
233
- r = execute_spi_params_prepared (job -> dosql [i ], job -> sql_params_n , job -> sql_params );
237
+ r = execute_spi_params_prepared (mem , job -> dosql [i ], job -> sql_params_n , job -> sql_params );
234
238
}
235
239
else
236
240
{
237
- r = execute_spi (job -> dosql [i ]);
241
+ r = execute_spi (mem , job -> dosql [i ]);
238
242
}
239
243
if (r -> retval < 0 )
240
244
{
@@ -321,6 +325,8 @@ int do_one_job(schd_executor_share_t *shared, schd_executor_status_t *status)
321
325
322
326
SetSessionAuthorization (BOOTSTRAP_SUPERUSERID , true);
323
327
ResetAllOptions ();
328
+ MemoryContextSwitchTo (old );
329
+ MemoryContextDelete (mem );
324
330
325
331
return 1 ;
326
332
}
@@ -336,23 +342,24 @@ int set_session_authorization(char *username, char **error)
336
342
int rv ;
337
343
char * sql = "select oid, rolsuper from pg_catalog.pg_roles where rolname = $1" ;
338
344
char buff [1024 ];
345
+ MemoryContext mem = CurrentMemoryContext ;
339
346
340
347
values [0 ] = CStringGetTextDatum (username );
341
348
START_SPI_SNAP ();
342
- r = execute_spi_sql_with_args (sql , 1 , types , values , NULL );
349
+ r = execute_spi_sql_with_args (mem , sql , 1 , types , values , NULL );
343
350
344
351
if (r -> retval < 0 )
345
352
{
346
353
rv = r -> retval ;
347
- * error = _copy_string ( r -> error );
354
+ * error = _mcopy_string ( mem , r -> error );
348
355
destroy_spi_data (r );
349
356
return rv ;
350
357
}
351
358
if (r -> n_rows == 0 )
352
359
{
353
360
STOP_SPI_SNAP ();
354
361
sprintf (buff , "Cannot find user with name: %s" , username );
355
- * error = _copy_string ( buff );
362
+ * error = _mcopy_string ( mem , buff );
356
363
destroy_spi_data (r );
357
364
358
365
return -200 ;
@@ -415,7 +422,7 @@ TimestampTz get_next_excution_time(char *sql, executor_error_t *ee)
415
422
416
423
START_SPI_SNAP ();
417
424
pgstat_report_activity (STATE_RUNNING , "culc next time execution time" );
418
- r = execute_spi (sql );
425
+ r = execute_spi (CurrentMemoryContext , sql );
419
426
if (r -> retval < 0 )
420
427
{
421
428
if (r -> error )
@@ -469,7 +476,7 @@ int executor_onrollback(job_t *job, executor_error_t *ee)
469
476
pgstat_report_activity (STATE_RUNNING , "execure onrollback" );
470
477
471
478
START_SPI_SNAP ();
472
- r = execute_spi (job -> onrollback );
479
+ r = execute_spi (CurrentMemoryContext , job -> onrollback );
473
480
if (r -> retval < 0 )
474
481
{
475
482
if (r -> error )
@@ -502,7 +509,7 @@ void set_pg_var(bool result, executor_error_t *ee)
502
509
503
510
vals [0 ] = PointerGetDatum (cstring_to_text (result ? "success" : "failure" ));
504
511
505
- r = execute_spi_sql_with_args (sql , 1 , argtypes , vals , NULL );
512
+ r = execute_spi_sql_with_args (NULL , sql , 1 , argtypes , vals , NULL );
506
513
if (r -> retval < 0 )
507
514
{
508
515
if (r -> error )
@@ -712,14 +719,16 @@ int process_one_job(schd_executor_share_state_t *shared, schd_executor_status_t
712
719
int set_ret ;
713
720
char buff [512 ];
714
721
spi_response_t * r ;
722
+ MemoryContext old ;
723
+ MemoryContext mem = init_mem_ctx ("at job processor" );
724
+ old = MemoryContextSwitchTo (mem );
715
725
716
726
* status = shared -> status = SchdExecutorWork ;
717
727
718
728
pgstat_report_activity (STATE_RUNNING , "initialize at job" );
719
729
START_SPI_SNAP ();
720
730
721
- /* job = get_next_at_job_with_lock(shared->nodename, &error); */
722
- job = get_at_job_for_process (shared -> nodename , & error );
731
+ job = get_at_job_for_process (mem , shared -> nodename , & error );
723
732
if (!job )
724
733
{
725
734
if (error )
@@ -765,7 +774,8 @@ int process_one_job(schd_executor_share_state_t *shared, schd_executor_status_t
765
774
return -1 ;
766
775
}
767
776
STOP_SPI_SNAP ();
768
- elog (LOG , "JOB MOVED TO DONE" );
777
+ MemoryContextSwitchTo (old );
778
+ MemoryContextDelete (mem );
769
779
return 1 ;
770
780
}
771
781
@@ -780,11 +790,11 @@ int process_one_job(schd_executor_share_state_t *shared, schd_executor_status_t
780
790
781
791
if (job -> sql_params_n > 0 )
782
792
{
783
- r = execute_spi_params_prepared (job -> dosql [0 ], job -> sql_params_n , job -> sql_params );
793
+ r = execute_spi_params_prepared (mem , job -> dosql [0 ], job -> sql_params_n , job -> sql_params );
784
794
}
785
795
else
786
796
{
787
- r = execute_spi (job -> dosql [0 ]);
797
+ r = execute_spi (mem , job -> dosql [0 ]);
788
798
}
789
799
if (job -> timelimit )
790
800
{
@@ -819,6 +829,8 @@ int process_one_job(schd_executor_share_state_t *shared, schd_executor_status_t
819
829
if (set_ret > 0 )
820
830
{
821
831
STOP_SPI_SNAP ();
832
+ MemoryContextSwitchTo (old );
833
+ MemoryContextDelete (mem );
822
834
return 1 ;
823
835
}
824
836
if (set_error )
@@ -831,6 +843,8 @@ int process_one_job(schd_executor_share_state_t *shared, schd_executor_status_t
831
843
elog (LOG , "AT_EXECUTOR ERROR: set log: unknown error" );
832
844
}
833
845
ABORT_SPI_SNAP ();
846
+ MemoryContextSwitchTo (old );
847
+ MemoryContextDelete (mem );
834
848
835
849
return -1 ;
836
850
}
@@ -846,7 +860,7 @@ Oid set_session_authorization_by_name(char *rolename, char **error)
846
860
if (!HeapTupleIsValid (roleTup ))
847
861
{
848
862
snprintf (buffer , 512 , "There is no user name: %s" , rolename );
849
- * error = _copy_string ( buffer );
863
+ * error = _mcopy_string ( NULL , buffer );
850
864
return InvalidOid ;
851
865
}
852
866
rform = (Form_pg_authid ) GETSTRUCT (roleTup );
0 commit comments