Skip to content

Commit

Permalink
Clean up catalog code
Browse files Browse the repository at this point in the history
Organize catalog.c so that functions that access the Catalog struct are physically separate from the functions that modify the actual catalog tables on disk. Also added macros and made static some functions that aren't used outside the catalog files. Also refactored out the CatalogDatabaseInfo struct, which is independent of the Catalog struct and will be reused in the future.
  • Loading branch information
Amy Tai authored and RobAtticus committed Dec 4, 2018
1 parent ecd1465 commit c2bdaa7
Show file tree
Hide file tree
Showing 15 changed files with 251 additions and 209 deletions.
6 changes: 3 additions & 3 deletions src/bgw/job.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ bgw_job_get_all(size_t alloc_size, MemoryContext mctx)
.alloc_size = alloc_size,
};
ScannerCtx scanctx = {
.table = catalog->tables[BGW_JOB].id,
.table = catalog_get_table_id(catalog, BGW_JOB),
.index = InvalidOid,
.data = &list_data,
.tuple_found = bgw_job_accum_tuple_found,
Expand All @@ -141,8 +141,8 @@ bgw_job_scan_one(int indexid, ScanKeyData scankey[], int nkeys,
{
Catalog *catalog = catalog_get();
ScannerCtx scanctx = {
.table = catalog->tables[BGW_JOB].id,
.index = CATALOG_INDEX(catalog, BGW_JOB, indexid),
.table = catalog_get_table_id(catalog, BGW_JOB),
.index = catalog_get_index(catalog, BGW_JOB, indexid),
.nkeys = nkeys,
.scankey = scankey,
.tuple_found = tuple_found,
Expand Down
1 change: 1 addition & 0 deletions src/bgw/job.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ extern BgwJob *bgw_job_find(int job_id, MemoryContext mctx);
extern bool bgw_job_has_timeout(BgwJob *job);
extern TimestampTz bgw_job_timeout_at(BgwJob *job, TimestampTz start_time);

bool bgw_job_delete_by_id(int32 job_id);

bool bgw_job_execute(BgwJob *job);

Expand Down
8 changes: 4 additions & 4 deletions src/bgw/job_stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ bgw_job_stat_scan_one(int indexid, ScanKeyData scankey[], int nkeys,
{
Catalog *catalog = catalog_get();
ScannerCtx scanctx = {
.table = catalog->tables[BGW_JOB_STAT].id,
.index = CATALOG_INDEX(catalog, BGW_JOB_STAT, indexid),
.table = catalog_get_table_id(catalog, BGW_JOB_STAT),
.index = catalog_get_index(catalog, BGW_JOB_STAT, indexid),
.nkeys = nkeys,
.scankey = scankey,
.tuple_found = tuple_found,
Expand Down Expand Up @@ -268,7 +268,7 @@ bgw_job_stat_insert_mark_start_relation(Relation rel,
values[AttrNumberGetAttrOffset(Anum_bgw_job_stat_total_crashes)] = Int64GetDatum(1);
values[AttrNumberGetAttrOffset(Anum_bgw_job_stat_consecutive_crashes)] = Int32GetDatum(1);

catalog_become_owner(catalog_get(), &sec_ctx);
catalog_database_info_become_owner(catalog_database_info_get(), &sec_ctx);
catalog_insert_values(rel, desc, values, nulls);
catalog_restore_user(&sec_ctx);

Expand All @@ -282,7 +282,7 @@ bgw_job_stat_insert_mark_start(int32 bgw_job_id)
Relation rel;
bool result;

rel = heap_open(catalog->tables[BGW_JOB_STAT].id, RowExclusiveLock);
rel = heap_open(catalog_get_table_id(catalog, BGW_JOB_STAT), RowExclusiveLock);
result = bgw_job_stat_insert_mark_start_relation(rel, bgw_job_id);
heap_close(rel, RowExclusiveLock);

Expand Down

0 comments on commit c2bdaa7

Please sign in to comment.