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

Remove cascade_to_materialization #2163

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions sql/bgw_scheduler.sql
Expand Up @@ -32,8 +32,7 @@ ON CONFLICT (id) DO NOTHING;
CREATE OR REPLACE FUNCTION add_retention_policy(
hypertable REGCLASS,
retention_window "any",
if_not_exists BOOL = false,
cascade_to_materializations BOOL = false
if_not_exists BOOL = false
)
RETURNS INTEGER AS '@MODULE_PATHNAME@', 'ts_add_retention_policy'
LANGUAGE C VOLATILE STRICT;
Expand Down
3 changes: 1 addition & 2 deletions sql/ddl_api.sql
Expand Up @@ -95,8 +95,7 @@ CREATE OR REPLACE FUNCTION drop_chunks(
hypertable_or_cagg REGCLASS,
older_than "any" = NULL,
newer_than "any" = NULL,
verbose BOOLEAN = FALSE,
cascade_to_materializations BOOLEAN = NULL
verbose BOOLEAN = FALSE
) RETURNS SETOF TEXT AS '@MODULE_PATHNAME@', 'ts_chunk_drop_chunks'
LANGUAGE C VOLATILE PARALLEL UNSAFE;

Expand Down
1 change: 0 additions & 1 deletion sql/pre_install/tables.sql
Expand Up @@ -233,7 +233,6 @@ CREATE TABLE IF NOT EXISTS _timescaledb_config.bgw_policy_drop_chunks (
job_id INTEGER PRIMARY KEY REFERENCES _timescaledb_config.bgw_job(id) ON DELETE CASCADE,
hypertable_id INTEGER UNIQUE NOT NULL REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE,
older_than _timescaledb_catalog.ts_interval NOT NULL,
cascade_to_materializations BOOLEAN,
CONSTRAINT valid_older_than CHECK(_timescaledb_internal.valid_ts_interval(older_than))
);
SELECT pg_catalog.pg_extension_config_dump('_timescaledb_config.bgw_policy_drop_chunks', '');
Expand Down
5 changes: 1 addition & 4 deletions sql/updates/latest-dev.sql
Expand Up @@ -85,15 +85,13 @@ CREATE TABLE _timescaledb_config.bgw_policy_drop_chunks_tmp (
REFERENCES _timescaledb_catalog.hypertable(id)
ON DELETE CASCADE,
older_than _timescaledb_catalog.ts_interval NOT NULL,
cascade_to_materializations BOOLEAN,
CONSTRAINT valid_older_than CHECK(_timescaledb_internal.valid_ts_interval(older_than))
);

INSERT INTO _timescaledb_config.bgw_policy_drop_chunks_tmp (
SELECT job_id,
hypertable_id,
older_than,
cascade_to_materializations
older_than
FROM _timescaledb_config.bgw_policy_drop_chunks
);

Expand All @@ -110,7 +108,6 @@ CREATE TABLE _timescaledb_config.bgw_policy_drop_chunks (
REFERENCES _timescaledb_catalog.hypertable(id)
ON DELETE CASCADE,
older_than _timescaledb_catalog.ts_interval NOT NULL,
cascade_to_materializations BOOLEAN,
CONSTRAINT valid_older_than CHECK(_timescaledb_internal.valid_ts_interval(older_than))
);
INSERT INTO _timescaledb_config.bgw_policy_drop_chunks (
Expand Down
2 changes: 1 addition & 1 deletion sql/views.sql
Expand Up @@ -47,7 +47,7 @@ CREATE OR REPLACE VIEW timescaledb_information.license AS

CREATE OR REPLACE VIEW timescaledb_information.drop_chunks_policies as
SELECT format('%1$I.%2$I', ht.schema_name, ht.table_name)::regclass as hypertable, p.older_than, p.job_id, j.schedule_interval,
j.max_runtime, j.max_retries, j.retry_period, p.cascade_to_materializations
j.max_runtime, j.max_retries, j.retry_period
FROM _timescaledb_config.bgw_policy_drop_chunks p
INNER JOIN _timescaledb_catalog.hypertable ht ON p.hypertable_id = ht.id
INNER JOIN _timescaledb_config.bgw_job j ON p.job_id = j.id;
Expand Down
22 changes: 0 additions & 22 deletions src/bgw_policy/drop_chunks.c
Expand Up @@ -50,15 +50,6 @@ bgw_policy_drop_chunks_tuple_found(TupleInfo *ti, void *const data)
(*policy)->older_than = *ts_interval_from_tuple(
values[AttrNumberGetAttrOffset(Anum_bgw_policy_drop_chunks_older_than)]);

if (nulls[AttrNumberGetAttrOffset(Anum_bgw_policy_drop_chunks_cascade_to_materializations)])
(*policy)->cascade_to_materializations = CASCADE_TO_MATERIALIZATION_UNKNOWN;
else
(*policy)->cascade_to_materializations =
(DatumGetBool(values[AttrNumberGetAttrOffset(
Anum_bgw_policy_drop_chunks_cascade_to_materializations)]) ?
CASCADE_TO_MATERIALIZATION_TRUE :
CASCADE_TO_MATERIALIZATION_FALSE);

if (should_free)
heap_freetuple(tuple);

Expand Down Expand Up @@ -160,19 +151,6 @@ ts_bgw_policy_drop_chunks_insert_with_relation(Relation rel, BgwPolicyDropChunks
values[AttrNumberGetAttrOffset(Anum_bgw_policy_drop_chunks_older_than)] =
HeapTupleGetDatum(ht_older_than);

if (policy->cascade_to_materializations == CASCADE_TO_MATERIALIZATION_UNKNOWN)
{
nulls[AttrNumberGetAttrOffset(Anum_bgw_policy_drop_chunks_cascade_to_materializations)] =
true;
}
else
{
values[AttrNumberGetAttrOffset(Anum_bgw_policy_drop_chunks_cascade_to_materializations)] =
BoolGetDatum((policy->cascade_to_materializations == CASCADE_TO_MATERIALIZATION_TRUE ?
true :
false));
}

ts_catalog_database_info_become_owner(ts_catalog_database_info_get(), &sec_ctx);
ts_catalog_insert_values(rel, tupdesc, values, nulls);
ts_catalog_restore_user(&sec_ctx);
Expand Down
1 change: 0 additions & 1 deletion src/bgw_policy/drop_chunks.h
Expand Up @@ -16,7 +16,6 @@ typedef struct BgwPolicyDropChunks
int32 job_id;
int32 hypertable_id;
FormData_ts_interval older_than;
CascadeToMaterializationOption cascade_to_materializations;
} BgwPolicyDropChunks;

extern TSDLLEXPORT BgwPolicyDropChunks *ts_bgw_policy_drop_chunks_find_by_job(int32 job_id);
Expand Down
4 changes: 0 additions & 4 deletions src/catalog.h
Expand Up @@ -832,15 +832,11 @@ typedef enum Anum_bgw_policy_drop_chunks
Anum_bgw_policy_drop_chunks_job_id = 1,
Anum_bgw_policy_drop_chunks_hypertable_id,
Anum_bgw_policy_drop_chunks_older_than,
Anum_bgw_policy_drop_chunks_cascade_to_materializations,
_Anum_bgw_policy_drop_chunks_max,
} Anum_bgw_policy_drop_chunks;

#define Natts_bgw_policy_drop_chunks (_Anum_bgw_policy_drop_chunks_max - 1)

/* Do NOT define FormData here because cascade_to_materializations as bool is semantically wrong
* this is a tri-state variable. NULL matters here. */

enum
{
BGW_POLICY_DROP_CHUNKS_HYPERTABLE_ID_KEY = 0,
Expand Down
62 changes: 13 additions & 49 deletions src/chunk.c
Expand Up @@ -3216,10 +3216,9 @@ ts_chunk_drop_preserve_catalog_row(Chunk *chunk, DropBehavior behavior, int32 lo
}

static void
ts_chunk_drop_process_materialization(Oid hypertable_relid,
CascadeToMaterializationOption cascade_to_materializations,
Datum older_than_datum, Oid older_than_type,
Oid newer_than_type, Chunk *chunks, int num_chunks)
ts_chunk_drop_process_invalidations(Oid hypertable_relid, Datum older_than_datum,
Oid older_than_type, Oid newer_than_type, Chunk *chunks,
int num_chunks)
{
Dimension *time_dimension;
int64 older_than_time;
Expand All @@ -3234,12 +3233,6 @@ ts_chunk_drop_process_materialization(Oid hypertable_relid,

FormData_continuous_agg cagg;

/* nothing to do if also dropping materializations */
if (cascade_to_materializations == CASCADE_TO_MATERIALIZATION_TRUE)
return;

Assert(cascade_to_materializations == CASCADE_TO_MATERIALIZATION_FALSE);

if (OidIsValid(newer_than_type))
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
Expand Down Expand Up @@ -3289,7 +3282,7 @@ ts_chunk_drop_process_materialization(Oid hypertable_relid,
cagg.user_view_name.data)));

/* Lock all chunks in Exclusive mode, blocking everything but selects on the table. We have to
* block all modifications so that we cant get new invalidation entries. This makes sure that
* block all modifications so that we can't get new invalidation entries. This makes sure that
* all future modifying txns on this data region will have a now() that higher than ours and
* thus will not invalidate. Otherwise, we could have an old txn with a now() in the past that
* all of a sudden decides to to insert data right after we process_invalidations. */
Expand Down Expand Up @@ -3357,9 +3350,8 @@ lock_referenced_tables(Oid table_relid)
*/
List *
ts_chunk_do_drop_chunks(Hypertable *ht, Datum older_than_datum, Datum newer_than_datum,
Oid older_than_type, Oid newer_than_type,
CascadeToMaterializationOption cascades_to_materializations,
int32 log_level, List **affected_data_nodes)
Oid older_than_type, Oid newer_than_type, int32 log_level,
List **affected_data_nodes)

{
uint64 i = 0;
Expand Down Expand Up @@ -3397,18 +3389,10 @@ ts_chunk_do_drop_chunks(Hypertable *ht, Datum older_than_datum, Datum newer_than
has_continuous_aggs = true;
break;
case HypertableIsRawTable:
if (cascades_to_materializations == CASCADE_TO_MATERIALIZATION_UNKNOWN)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("cascade_to_materializations options must be set explicitly"),
errhint("Hypertables with continuous aggs must have the "
"cascade_to_materializations option set to either true or false "
"explicitly.")));
has_continuous_aggs = true;
break;
default:
has_continuous_aggs = false;
cascades_to_materializations = CASCADE_TO_MATERIALIZATION_TRUE;
break;
}

Expand All @@ -3423,13 +3407,12 @@ ts_chunk_do_drop_chunks(Hypertable *ht, Datum older_than_datum, Datum newer_than
&tuplock);

if (has_continuous_aggs)
ts_chunk_drop_process_materialization(ht->main_table_relid,
cascades_to_materializations,
older_than_datum,
older_than_type,
newer_than_type,
chunks,
num_chunks);
ts_chunk_drop_process_invalidations(ht->main_table_relid,
older_than_datum,
older_than_type,
newer_than_type,
chunks,
num_chunks);

for (; i < num_chunks; i++)
{
Expand All @@ -3444,7 +3427,7 @@ ts_chunk_do_drop_chunks(Hypertable *ht, Datum older_than_datum, Datum newer_than
chunk_name = psprintf("%s.%s", schema_name, table_name);
dropped_chunk_names = lappend(dropped_chunk_names, chunk_name);

if (has_continuous_aggs && cascades_to_materializations == CASCADE_TO_MATERIALIZATION_FALSE)
if (has_continuous_aggs)
ts_chunk_drop_preserve_catalog_row(chunks + i, DROP_RESTRICT, log_level);
else
ts_chunk_drop(chunks + i, DROP_RESTRICT, log_level);
Expand All @@ -3454,23 +3437,10 @@ ts_chunk_do_drop_chunks(Hypertable *ht, Datum older_than_datum, Datum newer_than
foreach (lc, chunks[i].data_nodes)
{
ChunkDataNode *cdn = lfirst(lc);

data_nodes = list_append_unique_oid(data_nodes, cdn->foreign_server_oid);
}
}

if (has_continuous_aggs && cascades_to_materializations == CASCADE_TO_MATERIALIZATION_TRUE)
{
ts_cm_functions->continuous_agg_drop_chunks_by_chunk_id(hypertable_id,
&chunks,
num_chunks,
older_than_datum,
newer_than_datum,
older_than_type,
newer_than_type,
log_level);
}

if (affected_data_nodes)
*affected_data_nodes = data_nodes;

Expand Down Expand Up @@ -3605,7 +3575,6 @@ ts_chunk_drop_chunks(PG_FUNCTION_ARGS)
Datum older_than_datum, newer_than_datum;
Oid older_than_type, newer_than_type;
bool verbose;
CascadeToMaterializationOption cascades_to_materializations;
int elevel;
List *data_node_oids = NIL;
Cache *hcache;
Expand Down Expand Up @@ -3639,10 +3608,6 @@ ts_chunk_drop_chunks(PG_FUNCTION_ARGS)
older_than_type = PG_ARGISNULL(1) ? InvalidOid : get_fn_expr_argtype(fcinfo->flinfo, 1);
newer_than_type = PG_ARGISNULL(2) ? InvalidOid : get_fn_expr_argtype(fcinfo->flinfo, 2);
verbose = PG_ARGISNULL(3) ? false : PG_GETARG_BOOL(3);
cascades_to_materializations =
(PG_ARGISNULL(4) ? CASCADE_TO_MATERIALIZATION_UNKNOWN :
(PG_GETARG_BOOL(4) ? CASCADE_TO_MATERIALIZATION_TRUE :
CASCADE_TO_MATERIALIZATION_FALSE));
elevel = verbose ? INFO : DEBUG2;

/* Find either the hypertable or view, or error out if the relid is
Expand All @@ -3668,7 +3633,6 @@ ts_chunk_drop_chunks(PG_FUNCTION_ARGS)
newer_than_datum,
older_than_type,
newer_than_type,
cascades_to_materializations,
elevel,
&data_node_oids);
}
Expand Down
16 changes: 4 additions & 12 deletions src/chunk.h
Expand Up @@ -101,13 +101,6 @@ typedef struct ChunkScanEntry
ChunkStub *stub;
} ChunkScanEntry;

typedef enum CascadeToMaterializationOption
{
CASCADE_TO_MATERIALIZATION_UNKNOWN = -1,
CASCADE_TO_MATERIALIZATION_FALSE = 0,
CASCADE_TO_MATERIALIZATION_TRUE = 1
} CascadeToMaterializationOption;

extern Chunk *ts_chunk_create_from_point(Hypertable *ht, Point *p, const char *schema,
const char *prefix);

Expand Down Expand Up @@ -153,11 +146,10 @@ extern TSDLLEXPORT bool ts_chunk_set_compressed_chunk(Chunk *chunk, int32 compre
extern TSDLLEXPORT void ts_chunk_drop(Chunk *chunk, DropBehavior behavior, int32 log_level);
extern TSDLLEXPORT void ts_chunk_drop_preserve_catalog_row(Chunk *chunk, DropBehavior behavior,
int32 log_level);
extern TSDLLEXPORT List *
ts_chunk_do_drop_chunks(Hypertable *ht, Datum older_than_datum, Datum newer_than_datum,
Oid older_than_type, Oid newer_than_type,
CascadeToMaterializationOption cascades_to_materializations,
int32 log_level, List **affected_data_nodes);
extern TSDLLEXPORT List *ts_chunk_do_drop_chunks(Hypertable *ht, Datum older_than_datum,
Datum newer_than_datum, Oid older_than_type,
Oid newer_than_type, int32 log_level,
List **affected_data_nodes);
extern TSDLLEXPORT Chunk *
ts_chunk_get_chunks_in_time_range(Oid table_relid, Datum older_than_datum, Datum newer_than_datum,
Oid older_than_type, Oid newer_than_type, char *caller_name,
Expand Down
8 changes: 1 addition & 7 deletions tsl/src/bgw_policy/drop_chunks_api.c
Expand Up @@ -127,10 +127,6 @@ drop_chunks_add_policy(PG_FUNCTION_ARGS)
Oid ht_oid = PG_GETARG_OID(0);
Datum older_than_datum = PG_GETARG_DATUM(1);
bool if_not_exists = PG_GETARG_BOOL(2);
CascadeToMaterializationOption cascade_to_materializations =
(PG_ARGISNULL(3) ? CASCADE_TO_MATERIALIZATION_UNKNOWN :
(PG_GETARG_BOOL(3) ? CASCADE_TO_MATERIALIZATION_TRUE :
CASCADE_TO_MATERIALIZATION_FALSE));
Oid older_than_type = PG_ARGISNULL(1) ? InvalidOid : get_fn_expr_argtype(fcinfo->flinfo, 1);
BgwPolicyDropChunks policy;
Hypertable *hypertable;
Expand Down Expand Up @@ -163,8 +159,7 @@ drop_chunks_add_policy(PG_FUNCTION_ARGS)
get_rel_name(ht_oid))));
}

if (ts_interval_equal(&existing->older_than, older_than) &&
existing->cascade_to_materializations == cascade_to_materializations)
if (ts_interval_equal(&existing->older_than, older_than))
{
/* If all arguments are the same, do nothing */
ts_cache_release(hcache);
Expand Down Expand Up @@ -210,7 +205,6 @@ drop_chunks_add_policy(PG_FUNCTION_ARGS)
.job_id = job_id,
.hypertable_id = ts_hypertable_relid_to_id(mapped_oid),
.older_than = *older_than,
.cascade_to_materializations = cascade_to_materializations,
};

/* Now, insert a new row in the drop_chunks args table */
Expand Down
1 change: 0 additions & 1 deletion tsl/src/bgw_policy/job.c
Expand Up @@ -285,7 +285,6 @@ execute_drop_chunks_policy(int32 job_id)
InvalidOid,
older_than_type,
InvalidOid,
args->cascade_to_materializations,
DEBUG2,
NULL);
num_dropped = list_length(dc_temp);
Expand Down
4 changes: 1 addition & 3 deletions tsl/src/chunk.c
Expand Up @@ -190,8 +190,7 @@ chunk_set_default_data_node(PG_FUNCTION_ARGS)
* Returns the number of dropped chunks.
*/
int
chunk_invoke_drop_chunks(Oid relid, Datum older_than, Datum older_than_type,
bool cascade_to_materializations)
chunk_invoke_drop_chunks(Oid relid, Datum older_than, Datum older_than_type)
{
EState *estate;
ExprContext *econtext;
Expand All @@ -218,7 +217,6 @@ chunk_invoke_drop_chunks(Oid relid, Datum older_than, Datum older_than_type,
get_typbyval(older_than_type)),
makeNullConst(INT8OID, -1, InvalidOid),
castNode(Const, makeBoolConst(false, true)),
castNode(Const, makeBoolConst(cascade_to_materializations, false))
};

char *const schema_name = ts_extension_schema_name();
Expand Down
3 changes: 1 addition & 2 deletions tsl/src/chunk.h
Expand Up @@ -13,7 +13,6 @@

extern void chunk_update_foreign_server_if_needed(int32 chunk_id, Oid existing_server_id);
extern Datum chunk_set_default_data_node(PG_FUNCTION_ARGS);
extern int chunk_invoke_drop_chunks(Oid relid, Datum older_than, Datum older_than_type,
bool cascade_to_materializations);
extern int chunk_invoke_drop_chunks(Oid relid, Datum older_than, Datum older_than_type);

#endif /* TIMESCALEDB_TSL_CHUNK_H */
1 change: 0 additions & 1 deletion tsl/src/continuous_aggs/drop.c
Expand Up @@ -49,7 +49,6 @@ ts_continuous_agg_drop_chunks_by_chunk_id(int32 raw_hypertable_id, Chunk **chunk
newer_than_datum,
older_than_type,
newer_than_type,
CASCADE_TO_MATERIALIZATION_FALSE,
log_level,
NULL);

Expand Down