Skip to content

Commit 2ee7cc1

Browse files
committed
[#3109,#27616] YSQL: Ensure DDL Atomicity is enabled for transactional DDL
Summary: Transactional DDL introduces the ability to run DDLs within a transaction block and interleaving them with DML operations. Without transactional ddl, DDLs run in their own transaction and auto-commit at the end of the statement even if they are executed in an explicit transaction block. With txn ddl, users can also rollback the DDLs via the `ROLLBACK` or `ABORT` statement. This feature is supported by using the earlier introduced DDL atomicity feature. In DDL atomicity, we track the transaction associated with a DDL and upon txn completion, we roll-forward / rollback depending on the transaction outcome (commit or abort). Transactional DDL utilizes the atomicity infra for the rollback feature as it is just the lifetime of the transaction (txn block) which is different vs autonomous ddl transactions (statement level). So transactional DDL depends on DDL atomicity to function correctly. If DDL atomicity is disabled, the rollback feature will not work at all and we'll lose the atomicity guarantees for DDLs. This revision adds a validator for the flag `ysql_yb_ddl_transaction_block_enabled` which ensures that DDL atomicity is enabled when enabling transactional DDL. Test Plan: - Success ``` bin/yugabyted destroy && bin/yugabyted start --ui=false --tserver_flags="ysql_yb_ddl_transaction_block_enabled=true" bin/yugabyted destroy && bin/yugabyted start --ui=false --tserver_flags="ysql_yb_ddl_transaction_block_enabled=false,ysql_yb_ddl_rollback_enabled=false" --master_flags="ysql_yb_ddl_transaction_block_enabled=false,ysql_yb_ddl_rollback_enabled=false" ``` - Failure ``` bin/yugabyted destroy && bin/yugabyted start --ui=false --tserver_flags="ysql_yb_ddl_transaction_block_enabled=true,ysql_yb_ddl_rollback_enabled=false" --master_flags="ysql_yb_ddl_transaction_block_enabled=true,ysql_yb_ddl_rollback_enabled=false" ``` Reviewers: hsunder, patnaik.balivada, pjain, myang, bkolagani Reviewed By: patnaik.balivada Subscribers: ybase Differential Revision: https://phorge.dev.yugabyte.com/D44827
1 parent 6053e29 commit 2ee7cc1

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/yb/common/common_flags.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ constexpr bool kEnableDdlTransactionBlocks = false;
177177
#endif
178178
DEFINE_NON_RUNTIME_PG_FLAG(bool, yb_ddl_transaction_block_enabled, kEnableDdlTransactionBlocks,
179179
"If true, DDL operations in YSQL will execute within the active transaction"
180-
"block instead of their separate transactions.");
180+
"block instead of their separate transactions. Ensure DDL atomicity is "
181+
"enabled via ysql_yb_enable_ddl_atomicity_infra and ysql_yb_ddl_rollback_enabled flags.");
181182

182183
DEFINE_NON_RUNTIME_PG_FLAG(bool, yb_disable_ddl_transaction_block_for_read_committed, false,
183184
"If true, DDL operations in READ COMMITTED mode will be executed in a separate DDL transaction "
@@ -230,6 +231,9 @@ DEFINE_validator(enable_object_locking_for_table_locks,
230231
DEFINE_validator(ysql_enable_db_catalog_version_mode,
231232
FLAG_REQUIRED_BY_FLAG_VALIDATOR(enable_object_locking_for_table_locks));
232233
DEFINE_validator(ysql_yb_ddl_transaction_block_enabled,
234+
FLAG_DELAYED_COND_VALIDATOR(
235+
(!_value || FLAGS_ysql_yb_ddl_rollback_enabled),
236+
"ysql_yb_ddl_rollback_enabled must be enabled"),
233237
FLAG_REQUIRED_BY_FLAG_VALIDATOR(enable_object_locking_for_table_locks));
234238
DEFINE_validator(refresh_waiter_timeout_ms,
235239
FLAG_REQUIRED_NONZERO_BY_FLAG_VALIDATOR(enable_object_locking_for_table_locks));

src/yb/common/common_util.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ int GetInitialNumTabletsPerTable(TableType table_type, size_t tserver_count) {
105105
}
106106

107107
bool YsqlDdlRollbackEnabled() {
108+
// Also change the validator for ysql_yb_ddl_transaction_block_enabled flag in common_flag.cc if
109+
// changing this logic.
108110
return FLAGS_ysql_yb_enable_ddl_atomicity_infra && FLAGS_ysql_yb_ddl_rollback_enabled;
109111
}
110112

0 commit comments

Comments
 (0)