Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/backend/utils/workfile_manager/workfile_mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,42 @@ int gp_workfile_max_entries = 8192;

typedef struct workfile_set WorkFileSetSharedEntry;

struct workfile_set
{
/* Session id for the query creating the workfile set */
int session_id;

/* Command count for the query creating the workfile set */
int command_count;

/* Number of files in set */
uint32 num_files;

/* Size in bytes of the files in this workfile set */
int64 total_bytes;

/* Prefix of files in the workfile set */
char prefix[WORKFILE_PREFIX_LEN];

/* Type of operator creating the workfile set */
char operator[NAMEDATALEN];

/* Slice in which the spilling operator was */
int slice_id;

WorkFileUsagePerQuery *perquery;

dlist_node node;

bool active;

/* If the workfile is pinned, don't free it unless call workfile_mgr_close_set */
bool pinned;

/* Used to track workfile_set created in current process */
dlist_node local_node;
};

/*
* Protected by WorkFileManagerLock (except for sizes, which use atomics)
*/
Expand Down Expand Up @@ -941,3 +977,12 @@ WorkfileSegspace_GetSize(void)

return result;
}

/*
* Get Workfile Active Attribute.
*/
bool
workfile_is_active(workfile_set *workfile)
{
return workfile ? workfile->active : false;
}
38 changes: 3 additions & 35 deletions src/include/utils/workfile_mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,41 +53,8 @@ typedef struct WorkFileUsagePerQuery

} WorkFileUsagePerQuery;

typedef struct workfile_set
{
/* Session id for the query creating the workfile set */
int session_id;

/* Command count for the query creating the workfile set */
int command_count;

/* Number of files in set */
uint32 num_files;

/* Size in bytes of the files in this workfile set */
int64 total_bytes;

/* Prefix of files in the workfile set */
char prefix[WORKFILE_PREFIX_LEN];

/* Type of operator creating the workfile set */
char operator[NAMEDATALEN];

/* Slice in which the spilling operator was */
int slice_id;

WorkFileUsagePerQuery *perquery;

dlist_node node;

bool active;

/* If the workfile is pinned, don't free it unless call workfile_mgr_close_set */
bool pinned;

/* Used to track workfile_set created in current process */
dlist_node local_node;
} workfile_set;
struct workfile_set;
typedef struct workfile_set workfile_set;

/* Workfile Set operations */

Expand All @@ -105,5 +72,6 @@ extern void workfile_mgr_close_set(workfile_set *work_set);
extern Datum gp_workfile_mgr_cache_entries_internal(PG_FUNCTION_ARGS);
extern workfile_set *workfile_mgr_cache_entries_get_copy(int* num_actives);
extern uint64 WorkfileSegspace_GetSize(void);
extern bool workfile_is_active(workfile_set *workfile);

#endif /* __WORKFILE_MGR_H__ */
12 changes: 6 additions & 6 deletions src/test/isolation2/workfile_mgr_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ gp_workfile_mgr_create_workset(PG_FUNCTION_ARGS)
BufFile *buffile;

workfile_set *work_set = workfile_mgr_create_set(worksetName, NULL, holdPin);
Assert(work_set->active);
Assert(workfile_is_active(work_set));

if (!emptySet)
{
Expand Down Expand Up @@ -674,7 +674,7 @@ workfile_create_and_set_cleanup(void)
elog(LOG, "Running sub-test: Closing Workset");
workfile_mgr_close_set(work_set);

unit_test_result(!work_set->active);
unit_test_result(!workfile_is_active(work_set));

return unit_test_summary();
}
Expand Down Expand Up @@ -719,7 +719,7 @@ workfile_made_in_temp_tablespace(void)

BufFileClose(bufFile);

unit_test_result(!work_set->active);
unit_test_result(!workfile_is_active(work_set));

return unit_test_summary();
}
Expand Down Expand Up @@ -776,7 +776,7 @@ workfile_create_and_individual_cleanup(void)
unit_test_result(success);

/* the workfile_set should be freed since all it's files are closed */
unit_test_result(!work_set->active);
unit_test_result(!workfile_is_active(work_set));

return unit_test_summary();
}
Expand Down Expand Up @@ -834,12 +834,12 @@ workfile_create_and_individual_cleanup_with_pinned_workfile_set(void)
unit_test_result(success);

/* the workfile_set should not be freed since it gets pinned */
unit_test_result(work_set->active);
unit_test_result(workfile_is_active(work_set));

/* free the workfile_set */
workfile_mgr_close_set(work_set);

unit_test_result(!work_set->active);
unit_test_result(!workfile_is_active(work_set));

return unit_test_summary();
}
Expand Down