Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set status for backend in background jobs #2850

Merged
merged 1 commit into from Feb 2, 2021

Conversation

mkindahl
Copy link
Contributor

@mkindahl mkindahl commented Jan 21, 2021

The status of background workers is recorded using
pgstat_record_activity which allow the status of the worker to be
inspected using the status field in pg_stat_activity. This is used
by the timescaledb_information.job_stats view to show if a job is
running, scheduled, or paused.

However, the activity was never recorded in the code and hence the
field was always NULL. Since this was the default for the job_status
field of timescaledb_information.job_stats it would always show as
Scheduled.

This commit fixes this by adding calls to pgstat_record_activity and
suitable locations and also add a default of Undefined for the
job_status field to capture missing calls of
pgstat_record_activity. This is more of a precaution and is unlikely
to ever show.

Fixes #2831

@mkindahl mkindahl force-pushed the job_status_view branch 3 times, most recently from cdd8cbc to 7382ac5 Compare January 22, 2021 10:19
@mkindahl mkindahl closed this Jan 22, 2021
@mkindahl mkindahl reopened this Jan 22, 2021
@mkindahl mkindahl force-pushed the job_status_view branch 2 times, most recently from 7a7000d to ca9b055 Compare January 22, 2021 21:20
@codecov
Copy link

codecov bot commented Jan 22, 2021

Codecov Report

Merging #2850 (3d59938) into master (99e450d) will increase coverage by 0.14%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2850      +/-   ##
==========================================
+ Coverage   90.09%   90.23%   +0.14%     
==========================================
  Files         212      212              
  Lines       34775    34738      -37     
==========================================
+ Hits        31330    31346      +16     
+ Misses       3445     3392      -53     
Impacted Files Coverage Δ
src/bgw/job_stat.c 88.94% <100.00%> (+0.11%) ⬆️
src/bgw/scheduler.c 82.74% <100.00%> (+0.15%) ⬆️
src/chunk.c 95.73% <100.00%> (+0.01%) ⬆️
tsl/src/bgw_policy/job.c 96.82% <100.00%> (+0.08%) ⬆️
tsl/src/fdw/shippable.c 82.85% <0.00%> (-11.43%) ⬇️
src/loader/bgw_message_queue.c 84.51% <0.00%> (-2.59%) ⬇️
src/process_utility.c 93.86% <0.00%> (+0.12%) ⬆️
tsl/src/chunk_api.c 94.71% <0.00%> (+0.17%) ⬆️
src/chunk_insert_state.c 97.67% <0.00%> (+0.46%) ⬆️
src/chunk_append/explain.c 83.07% <0.00%> (+1.53%) ⬆️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e3c6725...5dd0a95. Read the comment docs.

@mkindahl mkindahl marked this pull request as ready for review January 25, 2021 10:28
@mkindahl mkindahl requested a review from a team as a code owner January 25, 2021 10:28
@mkindahl mkindahl requested review from erimatnor, k-rus, svenklemm and gayyappan and removed request for a team, erimatnor and k-rus January 25, 2021 10:28
query = makeStringInfo();
appendStringInfo(query,
"CALL %s.%s()",
NameStr(job->fd.proc_schema),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it need quotes? in case if name contains spaces, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it is just user viewed output, not something that is used for execution, but changed it anyway since it looks nicer.

"CALL %s.%s()",
NameStr(job->fd.proc_schema),
NameStr(job->fd.proc_name));
pgstat_report_activity(STATE_RUNNING, query->data);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs a test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added one. I actually wanted to add a more elaborate test that shows what statement is being executed inside a custom procedure, but that proved to be difficult.

@mkindahl mkindahl force-pushed the job_status_view branch 3 times, most recently from 6436aba to f7581fa Compare February 2, 2021 08:54
The status of background workers is recorded in PostgreSQL using the
function `pgstat_record_activity` which allow the status of the
background worker to be inspected using the `status` field in
`pg_stat_activity`.  This is used by the TimescaleDB `job_stats` view
to show if a job is running, scheduled, or paused.

However, the activity was never recorded in the code and hence the
field was always NULL. Since this was the default for the `job_status`
field of `timescaledb_information.job_stats` it would always show as
`Scheduled`.

This commit fixes this by adding calls to `pgstat_record_activity` at
suitable locations.

Fixes timescale#2831
@mkindahl mkindahl merged commit 954c775 into timescale:master Feb 2, 2021
@mkindahl mkindahl deleted the job_status_view branch February 2, 2021 16:03
erimatnor added a commit to erimatnor/timescaledb that referenced this pull request Feb 18, 2021
This maintenance release contains bugfixes since the 2.0.2 release. We
deem it high priority for upgrading.

The bug fixes in this release address issues with joins, the status of
background jobs, and disabling compression. It also includes
enhancements to continuous aggregates, including improved validation
of policies and optimizations for faster refreshes when there are a
lot of invalidations.

**Bugfixes**

* timescale#2850 Set status for backend in background jobs
* timescale#2883 Fix join qual propagation for nested joins
* timescale#2884 Add GUC to control join qual propagation
* timescale#2885 Fix compressed chunk check when disabling compression
* timescale#2908 Fix changing column type of clustered hypertables

**Thanks**
* @zeeshanshabbir93 for reporting an issue with joins
* @diego-hermida for reporting the issue about being unable to disable
  compression
* @mtin for reporting the issue about wrong job status
* @zeeshanshabbir93 for reporting the issue with full outer joins
@erimatnor erimatnor mentioned this pull request Feb 18, 2021
erimatnor added a commit to erimatnor/timescaledb that referenced this pull request Feb 19, 2021
This maintenance release contains bugfixes since the 2.0.2 release. We
deem it high priority for upgrading.

The bug fixes in this release address issues with joins, the status of
background jobs, and disabling compression. It also includes
enhancements to continuous aggregates, including improved validation
of policies and optimizations for faster refreshes when there are a
lot of invalidations.

**Bugfixes**

* timescale#2850 Set status for backend in background jobs
* timescale#2883 Fix join qual propagation for nested joins
* timescale#2884 Add GUC to control join qual propagation
* timescale#2885 Fix compressed chunk check when disabling compression
* timescale#2908 Fix changing column type of clustered hypertables
* timescale#2942 Validate continuous aggregate policy

**Thanks**
* @zeeshanshabbir93 for reporting the issue with full outer joins
* @Antiarchitect for reporting the issue with slow refreshes of
* @diego-hermida for reporting the issue about being unable to disable
  compression
* @mtin for reporting the issue about wrong job status
erimatnor added a commit that referenced this pull request Feb 19, 2021
This maintenance release contains bugfixes since the 2.0.2 release. We
deem it high priority for upgrading.

The bug fixes in this release address issues with joins, the status of
background jobs, and disabling compression. It also includes
enhancements to continuous aggregates, including improved validation
of policies and optimizations for faster refreshes when there are a
lot of invalidations.

**Bugfixes**

* #2850 Set status for backend in background jobs
* #2883 Fix join qual propagation for nested joins
* #2884 Add GUC to control join qual propagation
* #2885 Fix compressed chunk check when disabling compression
* #2908 Fix changing column type of clustered hypertables
* #2942 Validate continuous aggregate policy

**Thanks**
* @zeeshanshabbir93 for reporting the issue with full outer joins
* @Antiarchitect for reporting the issue with slow refreshes of
* @diego-hermida for reporting the issue about being unable to disable
  compression
* @mtin for reporting the issue about wrong job status
erimatnor added a commit to erimatnor/timescaledb that referenced this pull request Feb 19, 2021
This maintenance release contains bugfixes since the 2.0.2 release. We
deem it high priority for upgrading.

The bug fixes in this release address issues with joins, the status of
background jobs, and disabling compression. It also includes
enhancements to continuous aggregates, including improved validation
of policies and optimizations for faster refreshes when there are a
lot of invalidations.

**Minor features**
* timescale#2926 Optimize cagg refresh for small invalidations

**Bugfixes**
* timescale#2850 Set status for backend in background jobs
* timescale#2883 Fix join qual propagation for nested joins
* timescale#2884 Add GUC to control join qual propagation
* timescale#2885 Fix compressed chunk check when disabling compression
* timescale#2908 Fix changing column type of clustered hypertables
* timescale#2942 Validate continuous aggregate policy

**Thanks**
* @zeeshanshabbir93 for reporting the issue with full outer joins
* @Antiarchitect for reporting the issue with slow refreshes of
* @diego-hermida for reporting the issue about being unable to disable
  compression
* @mtin for reporting the issue about wrong job status
erimatnor added a commit to erimatnor/timescaledb that referenced this pull request Feb 19, 2021
This maintenance release contains bugfixes since the 2.0.1 release. We
deem it high priority for upgrading.

The bug fixes in this release address issues with joins, the status of
background jobs, and disabling compression. It also includes
enhancements to continuous aggregates, including improved validation
of policies and optimizations for faster refreshes when there are a
lot of invalidations.

**Minor features**
* timescale#2926 Optimize cagg refresh for small invalidations

**Bugfixes**
* timescale#2850 Set status for backend in background jobs
* timescale#2883 Fix join qual propagation for nested joins
* timescale#2884 Add GUC to control join qual propagation
* timescale#2885 Fix compressed chunk check when disabling compression
* timescale#2908 Fix changing column type of clustered hypertables
* timescale#2942 Validate continuous aggregate policy

**Thanks**
* @zeeshanshabbir93 for reporting the issue with full outer joins
* @Antiarchitect for reporting the issue with slow refreshes of
* @diego-hermida for reporting the issue about being unable to disable
  compression
* @mtin for reporting the issue about wrong job status
erimatnor added a commit to erimatnor/timescaledb that referenced this pull request Feb 19, 2021
This maintenance release contains bugfixes since the 2.0.1 release. We
deem it high priority for upgrading.

The bug fixes in this release address issues with joins, the status of
background jobs, and disabling compression. It also includes
enhancements to continuous aggregates, including improved validation
of policies and optimizations for faster refreshes when there are a
lot of invalidations.

**Minor features**
* timescale#2926 Optimize cagg refresh for small invalidations

**Bugfixes**
* timescale#2850 Set status for backend in background jobs
* timescale#2883 Fix join qual propagation for nested joins
* timescale#2884 Add GUC to control join qual propagation
* timescale#2885 Fix compressed chunk check when disabling compression
* timescale#2908 Fix changing column type of clustered hypertables
* timescale#2942 Validate continuous aggregate policy

**Thanks**
* @zeeshanshabbir93 for reporting the issue with full outer joins
* @Antiarchitect for reporting the issue with slow refreshes of
* @diego-hermida for reporting the issue about being unable to disable
  compression
* @mtin for reporting the issue about wrong job status
erimatnor added a commit that referenced this pull request Feb 19, 2021
This maintenance release contains bugfixes since the 2.0.1 release. We
deem it high priority for upgrading.

The bug fixes in this release address issues with joins, the status of
background jobs, and disabling compression. It also includes
enhancements to continuous aggregates, including improved validation
of policies and optimizations for faster refreshes when there are a
lot of invalidations.

**Minor features**
* #2926 Optimize cagg refresh for small invalidations

**Bugfixes**
* #2850 Set status for backend in background jobs
* #2883 Fix join qual propagation for nested joins
* #2884 Add GUC to control join qual propagation
* #2885 Fix compressed chunk check when disabling compression
* #2908 Fix changing column type of clustered hypertables
* #2942 Validate continuous aggregate policy

**Thanks**
* @zeeshanshabbir93 for reporting the issue with full outer joins
* @Antiarchitect for reporting the issue with slow refreshes of
* @diego-hermida for reporting the issue about being unable to disable
  compression
* @mtin for reporting the issue about wrong job status
erimatnor added a commit that referenced this pull request Feb 19, 2021
This maintenance release contains bugfixes since the 2.0.1 release. We
deem it high priority for upgrading.

The bug fixes in this release address issues with joins, the status of
background jobs, and disabling compression. It also includes
enhancements to continuous aggregates, including improved validation
of policies and optimizations for faster refreshes when there are a
lot of invalidations.

**Minor features**
* #2926 Optimize cagg refresh for small invalidations

**Bugfixes**
* #2850 Set status for backend in background jobs
* #2883 Fix join qual propagation for nested joins
* #2884 Add GUC to control join qual propagation
* #2885 Fix compressed chunk check when disabling compression
* #2908 Fix changing column type of clustered hypertables
* #2942 Validate continuous aggregate policy

**Thanks**
* @zeeshanshabbir93 for reporting the issue with full outer joins
* @Antiarchitect for reporting the issue with slow refreshes of
* @diego-hermida for reporting the issue about being unable to disable
  compression
* @mtin for reporting the issue about wrong job status
erimatnor added a commit that referenced this pull request Feb 19, 2021
This maintenance release contains bugfixes since the 2.0.1 release. We
deem it high priority for upgrading.

The bug fixes in this release address issues with joins, the status of
background jobs, and disabling compression. It also includes
enhancements to continuous aggregates, including improved validation
of policies and optimizations for faster refreshes when there are a
lot of invalidations.

**Minor features**
* #2926 Optimize cagg refresh for small invalidations

**Bugfixes**
* #2850 Set status for backend in background jobs
* #2883 Fix join qual propagation for nested joins
* #2884 Add GUC to control join qual propagation
* #2885 Fix compressed chunk check when disabling compression
* #2908 Fix changing column type of clustered hypertables
* #2942 Validate continuous aggregate policy

**Thanks**
* @zeeshanshabbir93 for reporting the issue with full outer joins
* @Antiarchitect for reporting the issue with slow refreshes of
* @diego-hermida for reporting the issue about being unable to disable
  compression
* @mtin for reporting the issue about wrong job status
erimatnor added a commit to erimatnor/timescaledb that referenced this pull request Feb 19, 2021
This maintenance release contains bugfixes since the 2.0.1 release. We
deem it high priority for upgrading.

The bug fixes in this release address issues with joins, the status of
background jobs, and disabling compression. It also includes
enhancements to continuous aggregates, including improved validation
of policies and optimizations for faster refreshes when there are a
lot of invalidations.

**Minor features**
* timescale#2926 Optimize cagg refresh for small invalidations

**Bugfixes**
* timescale#2850 Set status for backend in background jobs
* timescale#2883 Fix join qual propagation for nested joins
* timescale#2884 Add GUC to control join qual propagation
* timescale#2885 Fix compressed chunk check when disabling compression
* timescale#2908 Fix changing column type of clustered hypertables
* timescale#2942 Validate continuous aggregate policy

**Thanks**
* @zeeshanshabbir93 for reporting the issue with full outer joins
* @Antiarchitect for reporting the issue with slow refreshes of
* @diego-hermida for reporting the issue about being unable to disable
  compression
* @mtin for reporting the issue about wrong job status
erimatnor added a commit to erimatnor/timescaledb that referenced this pull request Feb 19, 2021
This maintenance release contains bugfixes since the 2.0.1 release. We
deem it high priority for upgrading.

The bug fixes in this release address issues with joins, the status of
background jobs, and disabling compression. It also includes
enhancements to continuous aggregates, including improved validation
of policies and optimizations for faster refreshes when there are a
lot of invalidations.

**Minor features**
* timescale#2926 Optimize cagg refresh for small invalidations

**Bugfixes**
* timescale#2850 Set status for backend in background jobs
* timescale#2883 Fix join qual propagation for nested joins
* timescale#2884 Add GUC to control join qual propagation
* timescale#2885 Fix compressed chunk check when disabling compression
* timescale#2908 Fix changing column type of clustered hypertables
* timescale#2942 Validate continuous aggregate policy

**Thanks**
* @zeeshanshabbir93 for reporting the issue with full outer joins
* @Antiarchitect for reporting the issue with slow refreshes of
* @diego-hermida for reporting the issue about being unable to disable
  compression
* @mtin for reporting the issue about wrong job status
erimatnor added a commit that referenced this pull request Feb 19, 2021
This maintenance release contains bugfixes since the 2.0.1 release. We
deem it high priority for upgrading.

The bug fixes in this release address issues with joins, the status of
background jobs, and disabling compression. It also includes
enhancements to continuous aggregates, including improved validation
of policies and optimizations for faster refreshes when there are a
lot of invalidations.

**Minor features**
* #2926 Optimize cagg refresh for small invalidations

**Bugfixes**
* #2850 Set status for backend in background jobs
* #2883 Fix join qual propagation for nested joins
* #2884 Add GUC to control join qual propagation
* #2885 Fix compressed chunk check when disabling compression
* #2908 Fix changing column type of clustered hypertables
* #2942 Validate continuous aggregate policy

**Thanks**
* @zeeshanshabbir93 for reporting the issue with full outer joins
* @Antiarchitect for reporting the issue with slow refreshes of
* @diego-hermida for reporting the issue about being unable to disable
  compression
* @mtin for reporting the issue about wrong job status
erimatnor added a commit to erimatnor/timescaledb that referenced this pull request Feb 19, 2021
This maintenance release contains bugfixes since the 2.0.1 release. We
deem it high priority for upgrading.

The bug fixes in this release address issues with joins, the status of
background jobs, and disabling compression. It also includes
enhancements to continuous aggregates, including improved validation
of policies and optimizations for faster refreshes when there are a
lot of invalidations.

**Minor features**
* timescale#2926 Optimize cagg refresh for small invalidations

**Bugfixes**
* timescale#2850 Set status for backend in background jobs
* timescale#2883 Fix join qual propagation for nested joins
* timescale#2884 Add GUC to control join qual propagation
* timescale#2885 Fix compressed chunk check when disabling compression
* timescale#2908 Fix changing column type of clustered hypertables
* timescale#2942 Validate continuous aggregate policy

**Thanks**
* @zeeshanshabbir93 for reporting the issue with full outer joins
* @Antiarchitect for reporting the issue with slow refreshes of
* @diego-hermida for reporting the issue about being unable to disable
  compression
* @mtin for reporting the issue about wrong job status
@erimatnor erimatnor mentioned this pull request Feb 19, 2021
erimatnor added a commit that referenced this pull request Feb 19, 2021
This maintenance release contains bugfixes since the 2.0.1 release. We
deem it high priority for upgrading.

The bug fixes in this release address issues with joins, the status of
background jobs, and disabling compression. It also includes
enhancements to continuous aggregates, including improved validation
of policies and optimizations for faster refreshes when there are a
lot of invalidations.

**Minor features**
* #2926 Optimize cagg refresh for small invalidations

**Bugfixes**
* #2850 Set status for backend in background jobs
* #2883 Fix join qual propagation for nested joins
* #2884 Add GUC to control join qual propagation
* #2885 Fix compressed chunk check when disabling compression
* #2908 Fix changing column type of clustered hypertables
* #2942 Validate continuous aggregate policy

**Thanks**
* @zeeshanshabbir93 for reporting the issue with full outer joins
* @Antiarchitect for reporting the issue with slow refreshes of
* @diego-hermida for reporting the issue about being unable to disable
  compression
* @mtin for reporting the issue about wrong job status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants