Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit fb99fab

Browse files
author
Vladimir Ershov
committed
rework memory managment alot
1 parent 073d5ae commit fb99fab

File tree

5 files changed

+131
-79
lines changed

5 files changed

+131
-79
lines changed

src/memutils.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ void delete_worker_mem_ctx(void)
3939
{
4040
MemoryContextSwitchTo(TopMemoryContext);
4141
MemoryContextDelete(SchedulerWorkerContext);
42+
SchedulerWorkerContext = NULL;
4243
}

src/scheduler_job.c

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ job_t *get_expired_cron_jobs(char *nodename, int *n, int *is_error)
452452
return jobs;
453453
}
454454

455-
job_t *set_job_error(job_t *j, const char *fmt, ...)
455+
job_t *set_job_error(MemoryContext mem, job_t *j, const char *fmt, ...)
456456
{
457457
va_list arglist;
458458
char buf[1024];
@@ -462,7 +462,7 @@ job_t *set_job_error(job_t *j, const char *fmt, ...)
462462
va_end(arglist);
463463

464464
if(j->error) pfree(j->error);
465-
j->error = my_copy_string(buf);
465+
j->error = _mcopy_string(mem, buf);
466466

467467
return j;
468468
}
@@ -771,6 +771,46 @@ int _cron_move_job_to_log(job_t *j, bool status)
771771
return ret;
772772
}
773773

774+
void copy_job(MemoryContext mem, job_t *dst, job_t *src)
775+
{
776+
int i;
777+
778+
memcpy(dst, src, sizeof(job_t));
779+
if(src->node) dst->node = _mcopy_string(mem, src->node);
780+
if(src->executor) dst->executor = _mcopy_string(mem, src->executor);
781+
if(src->owner) dst->owner = _mcopy_string(mem, src->owner);
782+
if(src->onrollback) dst->onrollback = _mcopy_string(mem, src->onrollback);
783+
if(src->next_time_statement) dst->next_time_statement = _mcopy_string(mem, src->next_time_statement);
784+
if(src->error) dst->error = _mcopy_string(mem, src->error);
785+
if(src->dosql_n && src->dosql)
786+
{
787+
src->dosql = MemoryContextAlloc(mem, sizeof(char *) * src->dosql_n);
788+
for(i=0; i < src->dosql_n; i++)
789+
{
790+
if(src->dosql[i])
791+
dst->dosql[i] = _mcopy_string(mem, src->dosql[i]);
792+
else
793+
dst->dosql[i] = NULL;
794+
}
795+
}
796+
if(src->sql_params_n && src->sql_params)
797+
{
798+
src->sql_params = MemoryContextAlloc(mem, sizeof(char *) * src->sql_params_n);
799+
for(i=0; i < src->sql_params_n; i++)
800+
{
801+
if(src->sql_params[i])
802+
dst->sql_params[i] = _mcopy_string(mem, src->sql_params[i]);
803+
else
804+
dst->sql_params[i] = NULL;
805+
}
806+
}
807+
if(src->depends_on_n > 0)
808+
{
809+
dst->depends_on = MemoryContextAlloc(mem, sizeof(int64) * src->depends_on_n);
810+
memcpy(dst->depends_on, src->depends_on, sizeof(int64) * src->depends_on_n);
811+
}
812+
}
813+
774814
void destroy_job(job_t *j, int selfdestroy)
775815
{
776816
int i;

src/scheduler_job.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ job_t *get_expired_at_jobs(char *nodename, int *n, int *is_error);
4848
job_t *_cron_get_jobs_to_do(MemoryContext mem, char *nodename, int *n, int *is_error, int limit);
4949
job_t *_at_get_jobs_to_do(MemoryContext mem, char *nodename, int *n, int *is_error, int limit);
5050
job_t *get_jobs_to_do(MemoryContext mem, char *nodename, task_type_t type, int *n, int *is_error, int limit);
51-
job_t *set_job_error(job_t *j, const char *fmt, ...) pg_attribute_printf(2, 3);
51+
job_t *set_job_error(MemoryContext mem, job_t *j, const char *fmt, ...) pg_attribute_printf(3, 4);
5252
int move_job_to_log(job_t *j, bool status, bool processed);
53+
void copy_job(MemoryContext mem, job_t *dst, job_t *src);
5354
void destroy_job(job_t *j, int selfdestroy);
5455
job_t *get_at_job(int cron_id, char *nodename, char **perror);
5556
job_t *get_cron_job(int cron_id, TimestampTz start_at, char *nodename, char **perror);

0 commit comments

Comments
 (0)