Skip to content

Commit 018cb15

Browse files
committed
start needs to be at least a configurable number of hours in the future (default 24)
Signed-off-by: Dorin Hogea <dhogea@bloomberg.net>
1 parent ff8c6f6 commit 018cb15

File tree

6 files changed

+21
-0
lines changed

6 files changed

+21
-0
lines changed

db/db_tunables.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,7 @@ extern int gbl_transaction_grace_period;
595595
extern int gbl_partition_sc_reorder;
596596
extern int gbl_retro_tpt;
597597
extern int gbl_retro_tpt_verbose;
598+
extern int gbl_retro_tpt_start;
598599
extern int gbl_dohsql_joins;
599600
extern int gbl_altersc_latency;
600601
extern int gbl_altersc_delay_usec;

db/db_tunables.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2534,6 +2534,10 @@ REGISTER_TUNABLE("partition_retroactively",
25342534
REGISTER_TUNABLE("partition_retroactively_verbose",
25352535
"Disable/enable data routing debugging for retroactively time partitioning (Default: OFF)",
25362536
TUNABLE_BOOLEAN, &gbl_retro_tpt_verbose, 0, NULL, NULL, NULL, NULL);
2537+
REGISTER_TUNABLE(
2538+
"partition_retroactively_start",
2539+
"Block any retroactively time partitioning if start is earlier that that many hours in the future (Default: 24)",
2540+
TUNABLE_INTEGER, &gbl_retro_tpt_start, 0, NULL, NULL, NULL, NULL);
25372541

25382542
REGISTER_TUNABLE("dohsql_joins", "Enable to support joins in parallel sql execution (default: on)", TUNABLE_BOOLEAN,
25392543
&gbl_dohsql_joins, 0, NULL, NULL, NULL, NULL);

db/views.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ int gbl_partitioned_table_enabled = 1;
4444
int gbl_merge_table_enabled = 1;
4545
int gbl_retro_tpt = 1;
4646
int gbl_retro_tpt_verbose = 0;
47+
int gbl_retro_tpt_start = 24; /* default 24 hours in the future */
4748

4849
struct timepart_shard {
4950
char *tblname; /* name of the table covering the shard, can be an alias */

sqlite/src/comdb2build.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ extern int gbl_lightweight_rename;
4545
extern int gbl_transactional_drop_plus_rename;
4646
extern int gbl_gen_shard_verbose;
4747
extern int gbl_sc_protobuf;
48+
extern int gbl_retro_tpt_start;
4849
int gbl_view_feature = 1;
4950
int gbl_disable_sql_table_replacement = 0;
5051

@@ -7892,6 +7893,18 @@ void comdb2CreateTimePartition(Parse* pParse, Token* period, Token* retention,
78927893
(int64_t*)&partition->u.tpt.start)) {
78937894
free_ddl_context(pParse);
78947895
}
7896+
7897+
/* if retroactively partitioning, make sure the start is one day in the future */
7898+
if (retro) {
7899+
time_t crtTime = time(NULL);
7900+
int startTime = partition->u.tpt.start;
7901+
if (gbl_retro_tpt_start > 0) {
7902+
if (crtTime >= (startTime - 3600 * gbl_retro_tpt_start)) {
7903+
setError(pParse, SQLITE_ABORT, "Bad start argument, please check partition_retroactively_start tunable");
7904+
return;
7905+
}
7906+
}
7907+
}
78957908
}
78967909

78977910
/**
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
table t t.csc2
22
init_with_genid48 0
33
partition_retroactively_verbose 1
4+
partition_retroactively_start 1

tests/tunables.test/t00_all_tunables.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,7 @@
704704
(name='parallel_sync', description='Run checkpoint/memptrickle code with parallel writes', type='BOOLEAN', value='ON', read_only='N')
705705
(name='participantid_bits', description='Number of bits allocated for the participant stripe ID (remaining bits are used for the update ID).', type='INTEGER', value='0', read_only='N')
706706
(name='partition_retroactively', description='Disable/enable time partition syntax to retroactively partition an existing table (Default: ON)', type='BOOLEAN', value='ON', read_only='N')
707+
(name='partition_retroactively_start', description='Block any retroactively time partitioning if start is earlier that that many hours in the future (Default: 24)', type='INTEGER', value='24', read_only='N')
707708
(name='partition_retroactively_verbose', description='Disable/enable data routing debugging for retroactively time partitioning (Default: OFF)', type='BOOLEAN', value='OFF', read_only='N')
708709
(name='partition_sc_reorder', description='If the schema change is serialized for a partition, run current shard last', type='BOOLEAN', value='ON', read_only='N')
709710
(name='partitioned_table_enabled', description='Allow syntax create/alter table ... partitioned by ...', type='BOOLEAN', value='ON', read_only='N')

0 commit comments

Comments
 (0)