SSISDB4:当前正在运行的Package及其Executable

SSISDB 系列随笔汇总:

 

PM问:“Vic,现在ETL Job跑到哪一个Package了,正在执行哪个Task?”,第一次遇到这个问题时,一下就懵逼了,只能硬着头皮说:“我看看”。

在做项目开发时,这个问题很常见,但是,被很多ETL开发工程师忽略了,可能是因为,这不是一个直接可以给出答案的命题。

在做大数据处理时,ETL Package开发工程师经常会用到管理者模式(Manager Mode)设计Package,也就是说,管理者Package调用子Package,通过优先约束控制子Package的并发调用和执行顺序,这种模式在管理大量Package的ETL工程时十分有用。当使用该模式的Packages被部署到SQL Server时,开发人员只需要创建一个Job,设置调度(Schedule),那么大管家(Agent)就会自动调用Package,完成数据的处理,高枕无忧。

除了部署方便之外,管理者模式也能缩短ETL整体运行的时间。在ETL Package调度的设计上,经常会使用并发执行模式:Task 并发执行,Package并发执行。对于Package的并发执行模式,实现方式是:在SSIS Server上部署Package Job,每个Job Step执行一个Manager Package ,该Manager Package 以并发方式调用Execute Package Task,因此,在同一时间存在多个Child Packages同时运行,每一个子Package都是一个Executable文件,并发执行的Executable的最大值是CPU的数量。

通常情况下,查看Job的执行情况,都会使用Job Activity Monitor,但是,只能看到单个Job的执行的历史消息,当Package 运行出现异常时,开发人员单纯通过Monitor,看不到当前正在运行的Package和其他更底层的消息。那么,在Job运行的过程中,如何查看正在运行的Package呢? 答案是通过SSISDB记录的消息。在Project 部署模式下,在任何一个Package执行时,SSIS引擎都会记录Executable(Task,Container)在执行过程中产生的历史消息,因此,可以通过SSIS记录的operation message 和 executable 名字来判断当前正在运行的Package。

SSIS 执行引擎使用SSISDB存储Package执行的历史消息,SSIS引擎把Package的执行抽象成一个操作(opertion),operation的类型主要是Project的部署,package执行和消息的清理(cleanup)。每次执行Package,SSIS执行引擎都会创建operation_type=200的operation,使用catalog.operations记录对Package执行的operation,使用catalog.operation_messages视图,记录每个Package在执行过程中产生的历史消息,消息描述的对象是Executable,每一个Executable是Package中的一个可执行组件,主要是Task和Container,通过Executable的名字,事件名称,以及创建消息的时间,能够推断出当前正在执行的Executable,进而推断出当前正在执行的Package。

如果有人看过我之前的博客,应该记得catalog.executables视图,但是,从该视图中,只能推断出已经执行完成(Executed)的Executable,而不能推断出正在执行(Executing)的Executable,所以,没有捷径直接得出结论,那我们就按部就班,上干货,代码多,文章有点枯燥,还请手下留情。

1,查看正在运行的operation

Integration Service Catalogs中Package执行的任何操作,都会记录在 catalog.operations 视图中,该视图的关键字段是:

  • operation_type:operation_type=200  表示 create_execution and start_execution
  • Status:The status of the operation. The possible values are created (1), running (2), canceled (3), failed (4), pending (5), ended unexpectedly (6), succeeded (7), stopping (8), and completed (9).
  • object_type:The type of object affected by the operation. The object may be a folder (10), project (20), package (30), environment (40), or instance of execution (50).

懒得翻译了,相信大家的英语水平,要查看当前正在运行的pperation,可以设置查询条件:operation_type=200,status=2或5,object_type=20,每个opertion都有一个唯一的标识ID,通过该ID和opertaion message关联,查询脚本是:

select top 11 
    op.operation_id,
    opt.operation_type_descr,
    op.created_time,
    obt.object_type_descr as object_affected,
    op.object_id,
    op.object_name,
    ops.operation_status_descr as status,
    op.start_time,
    op.end_time,
    op.caller_name
from catalog.operations op with(nolock)
inner join helper.OperationType opt with(nolock)
    on op.operation_type=opt.operation_type
inner join helper.ObjectType obt with(nolock)
    on op.object_type=obt.object_type
inner join helper.OperationStatus ops with(nolock)
    on op.status=ops.operation_status
where op.operation_type=200  --create_execution and start_execution(200)
and op.object_type=20        -- project (20)
and op.status in(2,5)        -- running (2), pending (5)
order by op.created_time desc

2,查看SSIS Engine 记录的Operation Message

SSIS 引擎是根据Executable触发的事件(Event)来记录Operation Message的,从message_type_descr能够查看消息的 Event 类型,从message_source_descr中能够看到触发事件的Task 类型:Control Flow tasks 或 Data Flow task。

通过operation_id,关联operation message,查看在package执行时,SSIS引擎记录的Executable名字,确定当前正在执行的Executable,进而确定正在执行的Package。

MSDN对 catalog.operation_messages 的描述是:

This view displays a row for each message that is logged during an operation in the catalog. The message can be generated by the server, by the package execution process, or by the execution engine.

用来查看事件和组件名称的查询脚本是:

select top 111
    om.message,
    om.message_time,
    mt.message_type_descr,
    mst.message_source_descr
from catalog.operation_messages om with(nolock)
inner join helper.MessageType mt with(nolock)
    on om.message_type=mt.message_type
inner join helper.MessageSourceType mst with(nolock)
    on om.message_source_type=mst.message_source_type
where om.operation_id=104627
order by om.message_time desc

Message字段提供的信息非常详细,格式大概是:Task组件名称+事件名称+其他,通过组件名称,推测正在运行的Package和组件。如果Task 组件的名称具有代表性,就能很容易推断出正在运行的Package 和 Package中正在运行的task。

3,helper 辅助表

关于helper 辅助表,请参考《SSISDB2:Operation》的“Appendix”

 

参考doc:

catalog.operation_messages (SSISDB Database)

catalog.operations (SSISDB Database)

posted @ 2017-06-09 15:48  悦光阴  阅读(1674)  评论(0编辑  收藏  举报