generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 30
Add pgactive worker error reporting facility #285
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
Merged
BRupireddy2
merged 1 commit into
main
from
add_pgactive_worker_error_reporting_facility_WIP
Sep 13, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| /* ------------------------------------------------------------------------- | ||
| * | ||
| * pgactive_elog.h | ||
| * pgactive error reporting facility | ||
| * | ||
| * Copyright (C) 2024, PostgreSQL Global Development Group | ||
| * | ||
| * IDENTIFICATION | ||
| * pgactive_elog.h | ||
| * | ||
| * ------------------------------------------------------------------------- | ||
| */ | ||
| #ifndef pgactive_ELOG_H | ||
| #define pgactive_ELOG_H | ||
|
|
||
| #include "datatype/timestamp.h" | ||
|
|
||
| /* | ||
| * Define pgactive error codes for which last error info needs to be tracked. | ||
| * When adding new error code, remember to add corresponding entry in | ||
| * pgactiveErrorMessages. | ||
| * | ||
| * NB: If ever changing start and end limits for one worker, adjust other | ||
| * workers' start and end limits. | ||
| */ | ||
|
|
||
| #define PGACTIVE_TRACKED_ERRORS_CHUNK 64 | ||
| typedef enum pgactiveTrackedErrorCodes | ||
| { | ||
| PGACTIVE_ERRCODE_NONE = 0, | ||
|
|
||
| /* perdb worker error codes start --> */ | ||
| PGACTIVE_PERDB_WORKER_ERROR_CODE_START = 1, | ||
| PGACTIVE_ERROR_CODE_MAX_NODES_PARAM_MISMATCH = 2, | ||
|
|
||
| /* add new perdb worker error codes here */ | ||
|
|
||
| PGACTIVE_PERDB_WORKER_ERROR_CODE_END = PGACTIVE_TRACKED_ERRORS_CHUNK, | ||
| /* <-- perdb worker error codes end */ | ||
|
|
||
| /* apply worker error codes start --> */ | ||
| PGACTIVE_APPLY_WORKER_ERROR_CODE_START = PGACTIVE_TRACKED_ERRORS_CHUNK + 1, | ||
| PGACTIVE_ERROR_CODE_APPLY_FAILURE, | ||
|
|
||
| /* add new apply worker error codes here */ | ||
|
|
||
| PGACTIVE_APPLY_WORKER_ERROR_CODE_END = 2 * PGACTIVE_TRACKED_ERRORS_CHUNK, | ||
| /* <-- apply worker error codes end */ | ||
| } pgactiveTrackedErrorCodes; | ||
|
|
||
| extern PGDLLIMPORT const char *const pgactiveErrorMessages[]; | ||
|
|
||
| typedef struct pgactiveLastErrorInfo | ||
| { | ||
| pgactiveTrackedErrorCodes errcode; | ||
| TimestampTz errtime; | ||
| } pgactiveLastErrorInfo; | ||
|
|
||
| #define GET_FIRST_ARG(arg1, ...) arg1 | ||
| #define GET_REST_ARGS(arg1, ...) __VA_ARGS__ | ||
|
|
||
| /* | ||
| * Log the pgactive error message. Either call with pgactiveTrackedErrorCodes: | ||
| * | ||
| * ereport_pgactive(ERROR, | ||
| * PGACTIVE_ERRCODE_XXX, | ||
| * errmsg("....")); | ||
| * | ||
| * or just call: | ||
| * | ||
| * ereport_pgactive(ERROR, | ||
| * errmsg("....")); | ||
| */ | ||
| #define ereport_pgactive(elevel, ...) \ | ||
| do { \ | ||
| pgactive_set_worker_last_error_info(pgactive_worker_slot, \ | ||
| GET_FIRST_ARG(__VA_ARGS__, 0)); \ | ||
| ereport(elevel, GET_REST_ARGS(__VA_ARGS__)); \ | ||
| } while(0) | ||
|
|
||
| /* Forward declaration */ | ||
| struct pgactiveWorker; | ||
|
|
||
| extern void pgactive_set_worker_last_error_info(struct pgactiveWorker *w, | ||
| pgactiveTrackedErrorCodes errcode); | ||
| extern void pgactive_reset_worker_last_error_info(struct pgactiveWorker *w); | ||
|
|
||
| #endif /* pgactive_ELOG_H */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /* ------------------------------------------------------------------------- | ||
| * | ||
| * pgactive_elog.c | ||
| * pgactive error reporting facility | ||
| * | ||
| * Copyright (C) 2024, PostgreSQL Global Development Group | ||
| * | ||
| * IDENTIFICATION | ||
| * pgactive_elog.c | ||
| * | ||
| * ------------------------------------------------------------------------- | ||
| */ | ||
| #include "postgres.h" | ||
|
|
||
| #include "pgactive.h" | ||
| #include "pgactive_elog.h" | ||
|
|
||
| /* | ||
| * Lookup table for pgactive error messages. | ||
| */ | ||
| const char *const pgactiveErrorMessages[] = { | ||
| [PGACTIVE_ERRCODE_NONE] = "none", | ||
| [PGACTIVE_ERROR_CODE_MAX_NODES_PARAM_MISMATCH] = "pgactive_max_nodes_parameter_mismatch", | ||
| [PGACTIVE_ERROR_CODE_APPLY_FAILURE] = "pgactive_apply_failure", | ||
| }; | ||
|
|
||
| void | ||
| pgactive_set_worker_last_error_info(struct pgactiveWorker *w, | ||
| pgactiveTrackedErrorCodes errcode) | ||
| { | ||
| if (w == NULL) | ||
| return; | ||
|
|
||
| Assert(w->worker_type == pgactive_WORKER_PERDB || | ||
| w->worker_type == pgactive_WORKER_APPLY); | ||
|
|
||
| w->last_error_info.errcode = errcode; | ||
| w->last_error_info.errtime = GetCurrentTimestamp(); | ||
| } | ||
|
|
||
| void | ||
| pgactive_reset_worker_last_error_info(struct pgactiveWorker *w) | ||
| { | ||
| int errcode; | ||
|
|
||
| if (w == NULL) | ||
| return; | ||
|
|
||
| Assert(w->worker_type == pgactive_WORKER_PERDB || | ||
| w->worker_type == pgactive_WORKER_APPLY); | ||
|
|
||
| errcode = w->last_error_info.errcode; | ||
|
|
||
| if (w->worker_type == pgactive_WORKER_PERDB) | ||
| { | ||
| if (!(errcode >= PGACTIVE_PERDB_WORKER_ERROR_CODE_START && | ||
| errcode <= PGACTIVE_PERDB_WORKER_ERROR_CODE_END)) | ||
| return; | ||
| } | ||
| else if (w->worker_type == pgactive_WORKER_APPLY) | ||
| { | ||
| if (!(errcode >= PGACTIVE_APPLY_WORKER_ERROR_CODE_START && | ||
| errcode <= PGACTIVE_APPLY_WORKER_ERROR_CODE_END)) | ||
| return; | ||
| } | ||
|
|
||
| w->last_error_info.errcode = PGACTIVE_ERRCODE_NONE; | ||
| w->last_error_info.errtime = 0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.