Skip to content

Commit 67dece0

Browse files
Merge remote-tracking branch 'origin/2.23.x' into HEAD
2 parents bcfa54d + a19747a commit 67dece0

File tree

3 files changed

+32
-37
lines changed

3 files changed

+32
-37
lines changed

.unreleased/pr_8873

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixes: #8873 Don't error on failure to update job stats

sql/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ set(MOD_FILES
5959

6060
# The downgrade file to generate a downgrade script for the current version, as
6161
# specified in version.config
62-
set(CURRENT_REV_FILE 2.23.0--2.22.1.sql)
62+
set(CURRENT_REV_FILE 2.23.1--2.23.0.sql)
6363

6464
set(MODULE_PATHNAME "$libdir/timescaledb-${PROJECT_VERSION_MOD}")
6565
set(LOADER_PATHNAME "$libdir/timescaledb")

src/bgw/job_stat_history.c

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -155,16 +155,26 @@ bgw_job_stat_history_mark_start(BgwJobStatHistoryContext *context)
155155
bgw_job_stat_history_insert(context, false);
156156
}
157157

158-
static bool
159-
bgw_job_stat_history_scan_one(int indexid, ScanKeyData scankey[], int nkeys,
160-
tuple_found_func tuple_found, tuple_filter_func tuple_filter,
161-
void *data, LOCKMODE lockmode)
158+
static void
159+
bgw_job_stat_history_update_entry(int64 bgw_job_history_id, tuple_found_func tuple_found,
160+
tuple_filter_func tuple_filter, void *data, LOCKMODE lockmode)
162161
{
162+
if (bgw_job_history_id == INVALID_BGW_JOB_STAT_HISTORY_ID)
163+
return;
164+
165+
ScanKeyData scankey[1];
166+
167+
ScanKeyInit(&scankey[0],
168+
Anum_bgw_job_stat_history_pkey_idx_id,
169+
BTEqualStrategyNumber,
170+
F_INT8EQ,
171+
Int64GetDatum(bgw_job_history_id));
172+
163173
Catalog *catalog = ts_catalog_get();
164174
ScannerCtx scanctx = {
165175
.table = catalog_get_table_id(catalog, BGW_JOB_STAT_HISTORY),
166-
.index = catalog_get_index(catalog, BGW_JOB_STAT_HISTORY, indexid),
167-
.nkeys = nkeys,
176+
.index = catalog_get_index(catalog, BGW_JOB_STAT_HISTORY, BGW_JOB_STAT_HISTORY_PKEY_IDX),
177+
.nkeys = 1,
168178
.scankey = scankey,
169179
.flags = SCANNER_F_KEEPLOCK,
170180
.tuple_found = tuple_found,
@@ -174,31 +184,18 @@ bgw_job_stat_history_scan_one(int indexid, ScanKeyData scankey[], int nkeys,
174184
.scandirection = ForwardScanDirection,
175185
};
176186

177-
return ts_scanner_scan_one(&scanctx, false, "bgw job stat");
178-
}
179-
180-
static inline bool
181-
bgw_job_stat_history_scan_id(int64 bgw_job_history_id, tuple_found_func tuple_found,
182-
tuple_filter_func tuple_filter, void *data, LOCKMODE lockmode)
183-
{
184-
if (bgw_job_history_id == INVALID_BGW_JOB_STAT_HISTORY_ID)
185-
return true;
186-
187-
ScanKeyData scankey[1];
188-
189-
ScanKeyInit(&scankey[0],
190-
Anum_bgw_job_stat_history_pkey_idx_id,
191-
BTEqualStrategyNumber,
192-
F_INT8EQ,
193-
Int64GetDatum(bgw_job_history_id));
194-
195-
return bgw_job_stat_history_scan_one(BGW_JOB_STAT_HISTORY_PKEY_IDX,
196-
scankey,
197-
1,
198-
tuple_found,
199-
tuple_filter,
200-
data,
201-
lockmode);
187+
int num_found = ts_scanner_scan(&scanctx);
188+
189+
/* We do not want to raise an error in case there is something wrong with history entries */
190+
if (num_found == 0)
191+
/* This might happen due to job history retention deleting entries */
192+
ereport(DEBUG1,
193+
(errmsg("could not find job stat history entry with id " INT64_FORMAT,
194+
bgw_job_history_id)));
195+
else if (num_found > 1)
196+
ereport(DEBUG1,
197+
(errmsg("found multiple job stat history entries with id " INT64_FORMAT,
198+
bgw_job_history_id)));
202199
}
203200

204201
static ScanTupleResult
@@ -291,14 +288,11 @@ bgw_job_stat_history_update(BgwJobStatHistoryContext *context)
291288
else
292289
{
293290
/* Mark the end of the previous inserted start execution */
294-
if (!bgw_job_stat_history_scan_id(new_job->job_history.id,
291+
bgw_job_stat_history_update_entry(new_job->job_history.id,
295292
bgw_job_stat_history_tuple_update,
296293
NULL,
297294
context,
298-
RowExclusiveLock))
299-
ereport(ERROR,
300-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
301-
errmsg("unable to find job history " INT64_FORMAT, new_job->job_history.id)));
295+
RowExclusiveLock);
302296
}
303297
}
304298

0 commit comments

Comments
 (0)