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

Improve ASSERT_IS_VALID_CHUNK macro #5135

Merged
merged 1 commit into from Jan 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 20 additions & 8 deletions src/chunk.h
Expand Up @@ -244,13 +244,25 @@ extern TSDLLEXPORT void ts_chunk_merge_on_dimension(Chunk *chunk, const Chunk *m
CurrentMemoryContext, \
fail_if_not_found)

#define IS_VALID_CHUNK(chunk) \
((chunk) && !(chunk)->fd.dropped && (chunk)->fd.id > 0 && (chunk)->fd.hypertable_id > 0 && \
OidIsValid((chunk)->table_id) && OidIsValid((chunk)->hypertable_relid) && \
(chunk)->constraints && (chunk)->cube && \
(chunk)->cube->num_slices == (chunk)->constraints->num_dimension_constraints && \
((chunk)->relkind == RELKIND_RELATION || ((chunk)->relkind == RELKIND_FOREIGN_TABLE)))

#define ASSERT_IS_VALID_CHUNK(chunk) Assert(IS_VALID_CHUNK(chunk))
/*
* Sanity checks for chunk.
*
* The individual checks are split into separate Asserts so it's
* easier to tell from a stacktrace which one failed.
*/
#define ASSERT_IS_VALID_CHUNK(chunk) \
do \
{ \
Assert(chunk); \
Assert(!(chunk)->fd.dropped); \
Assert((chunk)->fd.id > 0); \
Assert((chunk)->fd.hypertable_id > 0); \
Assert(OidIsValid((chunk)->table_id)); \
Assert(OidIsValid((chunk)->hypertable_relid)); \
Assert((chunk)->constraints); \
Assert((chunk)->cube); \
Assert((chunk)->cube->num_slices == (chunk)->constraints->num_dimension_constraints); \
Assert((chunk)->relkind == RELKIND_RELATION || (chunk)->relkind == RELKIND_FOREIGN_TABLE); \
} while (0)

#endif /* TIMESCALEDB_CHUNK_H */