且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在同一事务中并行运行多个数据流任务?

更新时间:2022-05-18 23:09:14

我同意其他答案,您的问题要求您将封闭容器上的事务范围设置为 Required.除非您更改了内部对象,否则它们的默认事务级别为 Supported,这意味着如果可用,它们将加入事务.Required 设置将启动一个事务,并且为了完整性,NotSupported 表示可执行文件/容器将忽略任何可能导致死锁的现有事务,具体取决于您的设计.

I agree with the other answers, your problem requires you set the transaction scope on an enclosing container to Required. Unless you have altered the inner objects, their default transaction level is Supported which means they will enlist in an transaction if available. A Required settings will start a transaction and for completeness, NotSupported indicates that the Executable/Container will ignore any existing transactions which may result in deadlocks depending on your design.

我构建了一个示例包,该包删除并重新创建目标表以验证交易是否按预期运行.包中有 3 个数据流,每个数据流都向表 (1, 2, 4) 添加一个唯一值,这样这样的查询将指示值是否到达目标表.

I built out a sample package that drops and recreates a target table to verify transactions are behaving as expected. There are 3 data flows in the package, each one adding a unique value to the table (1, 2, 4) so that a query like this will indicate whether values arrived in the destination table.

SELECT count(1) AS rc, sum(T.col1) AS Total FROM dbo.TrxTest T

如您所见,有 7 个变量,3 个成对.FailDataFlow 命名的是布尔值,允许任何唯一的数据流失败/成功.这是通过在相应查询的 where 子句中引起除以 0 异常来实现的.

As you can see, there are 7 variables, 3 in pairs. The FailDataFlow named ones are booleans that allow any of the unique data flows to fail/succeed. This is accomplished by causing a divide by 0 exception in the where clause of the corresponding query.

序列容器具有 Required 的 TransactionOption.各个数据流保留其 Supported.

The Sequence Container has a TransactionOption of Required. The individual data flows retain their default TransactionOption of Supported.

第一次执行导致无法与分布式事务协调器通信,因为它被设置为在此 VM 上手动启动.纠正该问题导致包正确失败,因为DFT 值 2"生成了除以零异常.尽管DFT 值 1"上有一个绿色框,但运行上面的查询方式在我的表中没有显示任何内容.

The first execution resulted in an unable to communicate with the distributed transaction coordinator as it was set to manual startup on this VM. Correcting that problem resulted in the package correctly failing out as "DFT value 2" generated a divide by zero exception. Running the query way above showed nothing in my table despite the presence of a green box on "DFT Value 1".

将 FailDataFlow1 的值切换为 False 并重新运行,在我的查询中分别显示值 3 和 7,这表示所有行都已到达.

Switching the value of FailDataFlow1 to False and re-running showed values of 3 and 7 respectively in my query which indicates all rows arrived.

您可以通过更改各种容器/可执行文件上的事务选项来进一步探索,以确保它们像其他受访者指出的那样工作.

You can further explore by changing transaction options on various containers/executables to assure yourself they are working as the other respondents have indicated.