You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by "pegasas (via GitHub)" <gi...@apache.org> on 2023/12/16 14:29:06 UTC

[I] [DSIP-22][TriggerPlugin] Introduce Trigger Plugin [dolphinscheduler]

pegasas opened a new issue, #15330:
URL: https://github.com/apache/dolphinscheduler/issues/15330

   ### Search before asking
   
   - [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar feature requirement.
   
   
   ### Description
   
   After seeing all local & large distributed job-scheduling framework, 
   I found that we may consider extending a key process in job-scheduling ---- **Trigger**, which allows user to defines their custom trigger in distributed runtime environment.
   
   Apparently quartz has considered this situation, but not extend into distributed environment.
   seeing https://www.quartz-scheduler.org/documentation/quartz-2.1.7/tutorials/tutorial-lesson-04.html
   
   Also seeing our community is ready to support streaming task.
   streaming task is unbounded, which means that if we wants to combine it with bounded batch job, we must defined a new trigger type for that.
   With this mechanism, we could do better with combining streaming task & batch task.
   
   Here's our architecture.
   
   
   Benefits from the best plugin in dolphinscheduler.
   We should consider to add trigger SPI plugin.
   
   Overview:
   
   - All trigger should trigger by **Event**
   - **Event Delivery** should based either **Push** or **Pull** mode.
   - Trigger only at the start on the workflow for easy implementation.
   
   still needs to consider consistency between master/worker.
   
   ### Use case
   
   - Use case #1: TimerTrigger
   This is common case. which is currently widely supported by dophinscheduler and all other job-scheduling framework
   - Use case #2: MQTrigger
   for example, after receive a message with some pattern, we should start a new workflow.
   - Use case #3: HTTPTrigger/TCPTrigger/SMTPTrigger
   very popular. after we make a HTTP call with dophinscheduler-api, we should start a new workflow. even we can trigger pipeline after we receive an email from external 3p team.
   
   - Use case #4: Combine Streaming & Batch Job
   In common scenarios, we often use streaming to do some near-real-time OLAP job, which requires batch job for backfill supplyment in case some unexpected error happens in streaming.
   
   ### Related issues
   
   [[DSIP-16][Task] Support stream task](https://github.com/apache/dolphinscheduler/issues/11352)
   
   ### Are you willing to submit a PR?
   
   - [X] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [DSIP-22][TriggerPlugin] Introduce Trigger Plugin [dolphinscheduler]

Posted by "pegasas (via GitHub)" <gi...@apache.org>.
pegasas commented on issue #15330:
URL: https://github.com/apache/dolphinscheduler/issues/15330#issuecomment-1868505972

   ![image](https://github.com/apache/dolphinscheduler/assets/13224827/9da0253e-ba69-434e-96eb-d81318bca715)
   
   Now architecture quartz scheduler uses db as Pessimistic Concurrency Control, 
   when job is execute we insert command into DB.
   
   Deep dive if we can leverage quartz interface or we needs to implement ourselves in `TriggerService`. If so, we should leverage current master failover mechanism.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [DSIP-22][TriggerPlugin] Introduce Trigger Plugin [dolphinscheduler]

Posted by "DenisBalan (via GitHub)" <gi...@apache.org>.
DenisBalan commented on issue #15330:
URL: https://github.com/apache/dolphinscheduler/issues/15330#issuecomment-2558085807

   Any eta on at least http trigger to invoke a workflow on demand?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [DSIP-22][TriggerPlugin] Introduce Trigger Plugin [dolphinscheduler]

Posted by "ruanwenjun (via GitHub)" <gi...@apache.org>.
ruanwenjun commented on issue #15330:
URL: https://github.com/apache/dolphinscheduler/issues/15330#issuecomment-1869533719

   We have table `t_ds_command` table, or trigger event should transform to command.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [DSIP-22][TriggerPlugin] Introduce Trigger Plugin [dolphinscheduler]

Posted by "pegasas (via GitHub)" <gi...@apache.org>.
pegasas commented on issue #15330:
URL: https://github.com/apache/dolphinscheduler/issues/15330#issuecomment-2308393142

   - master fetch `t_ds_trigger_definition` table for trigger
   - execute trigger, if it meets user-custom condition, insert a command into `t_ds_command`, note that this operation needs to be transactional
   
   Here's the question,
   currently our command fetching are based on id-based algorithm, the key point is when ProcessInstance is generated, we delete related command record.
   https://github.com/apache/dolphinscheduler/blob/dev/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessServiceImpl.java#L299
   but we should not delete `t_ds_trigger_definition` in this scenario.
   
   One solution is we add one more table to record offset for fetching, once master is alive, every time master will firstly acquire lock, then fetching `t_ds_trigger_definition` table for trigger and execute, finally we update offset into db with trigger_instance within one transaction.
   
   for more gracefully, we can do it in consistent-hash way. just like memcached & brpc. https://github.com/apache/brpc/blob/master/src/brpc/policy/dynpart_load_balancer.cpp#L83consider to its complexity, I will use method #1 for implementation.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [DSIP-22][TriggerPlugin] Introduce Trigger Plugin [dolphinscheduler]

Posted by "pegasas (via GitHub)" <gi...@apache.org>.
pegasas commented on issue #15330:
URL: https://github.com/apache/dolphinscheduler/issues/15330#issuecomment-1871819435

   My current design is as below:
   
   ```
   ┌─────────────────────┬────────────────────┬────────────────────┬────────────────────────┬───────────────────────────────┐
   │                     │                    │                    │                        │                               │
   │         UI          │        API         │         DB         │       Registry         │        Master                 │
   │                     │                    │                    │                        │                               │
   ├─────────────────────┼────────────────────┼────────────────────┼────────────────────────┼───────────────────────────────┤
   │                     │                    │                    │                        │                               │
   │   ┌─────────────┐   │   ┌─────────────┐  │   ┌─────────────┐  │                        │  ┌─────────────────────────┐  │
   │   │             │   │   │             │  │   │             │  │                        │  │                         │  │
   │   │    User     ├───┼──►│  Create     ├──┼──►│   Trigger   ├──┼──────────Pull──────────┼──► TriggerTaskThreadPool   │  │
   │   │             │   │   │  Trigger    │  │   │             │  │                        │  │                         │  │
   │   └─────┬───────┘   │   └─────────────┘  │   └─────────────┘  │                        │  └───────────┬─────────────┘  │
   │         │           │                    │                    │                        │              │                │
   │         │           │   ┌─────────────┐  │   ┌─────────────┐  │                        │              │                │
   │         │           │   │             │  │   │             │  │                        │              │                │
   │         └─Push──────┼──►│  Request    ├──┼──►│  Schedule   ◄──┼────────────────────────┼──────────────┘                │
   │                     │   │             │  │   │             │  │                        │                               │
   │                     │   └─────────────┘  │   └─────┬───────┘  │                        │                               │
   │                     │                    │         │          │                        │                               │
   │                     │                    │         │          │                        │   ┌────────────────────────┐  │
   │                     │                    │         │          │                        │   │                        │  │
   │                     │                    │         └──────────┼────────────────────────┼───►      SchedulerApi      │  │
   │                     │                    │                    │                        │   │                        │  │
   │                     │                    │                    │                        │   └───────────┬────────────┘  │
   │                     │                    │                    │                        │               │               │
   │                     │                    │   ┌─────────────┐  │                        │               │               │
   │                     │                    │   │             │  │                        │               │               │
   │                     │                    │   │  Command    ◄──┼────────────────────────┼───────────────┘               │
   │                     │                    │   │             │  │                        │                               │
   │                     │                    │   └─────┬───────┘  │                        │                               │
   │                     │                    │         │          │                        │                               │
   │                     │                    │         │          │                        │                               │
   │                     │                    │         │          │                        │ ┌─────────────────────────┐   │
   │                     │                    │         │          │                        │ │                         │   │
   │                     │                    │         └──────────┼────────────────────────┼─►MasterSchedulerBootStrap │   │
   │                     │                    │                    │                        │ └─────────────────────────┘   │
   │                     │                    │                    │                        │                               │
   │                     │                    │                    │                        │                               │
   │                     │                    │                    │                        │                               │
   │                     │                    │                    │                        │                               │
   │                     │                    │                    │                        │                               │
   │                     │                    │                    │                        │                               │
   │                     │                    │                    │                        │                               │
   │                     │                    │                    │                        │                               │
   │                     │                    │                    │                        │                               │
   │                     │                    │                    │                        │                               │
   └─────────────────────┴────────────────────┴────────────────────┴────────────────────────┴───────────────────────────────┘
   ```
   
   - API, TriggerController, TriggerService: CURD Trigger, Create new Trigger Instance(which currently is correspond to Schedule/Command in DB)
   - Start a `TriggerTaskExecutorThreadPool` in master, which should align with logic task executor
       + For push trigger, directly accept request from api(or any other signal from master) and directly create trigger_instance into DB
       + For pull trigger, it should be handled as a poll task with priortity & timeout. I suggest to put it into master due to we may not wants user create complex IO logic in trigger.
   - Scheduler takes trigger instance for scheduling, which could be scheduled by master host & priortity.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [DSIP-22][TriggerPlugin] Introduce Trigger Plugin [dolphinscheduler]

Posted by "davidzollo (via GitHub)" <gi...@apache.org>.
davidzollo commented on issue #15330:
URL: https://github.com/apache/dolphinscheduler/issues/15330#issuecomment-2322792593

   > * master fetch `t_ds_trigger_definition` table for trigger
   > * execute trigger, if it meets user-custom condition, insert a command into `t_ds_command`, note that this operation needs to be transactional
   > 
   > Here's the question, currently our command fetching are based on id-based algorithm, the key point is when ProcessInstance is generated, we delete related command record. https://github.com/apache/dolphinscheduler/blob/dev/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessServiceImpl.java#L299 but we should not delete `t_ds_trigger_definition` in this scenario.
   > 
   > One solution is we add one more table to record offset for fetching, once master is alive, every time master will firstly acquire lock, then fetching `t_ds_trigger_definition` table for trigger and execute, finally we update offset into db with trigger_instance within one transaction.
   > 
   > for more gracefully, we can do it in consistent-hash way. just like memcached & brpc. https://github.com/apache/brpc/blob/master/src/brpc/policy/dynpart_load_balancer.cpp#L83consider to its complexity, I will use method #1 for implementation.
   
   @ruanwenjun Can you help guide this design? 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [DSIP-22][TriggerPlugin] Introduce Trigger Plugin [dolphinscheduler]

Posted by "ruanwenjun (via GitHub)" <gi...@apache.org>.
ruanwenjun commented on issue #15330:
URL: https://github.com/apache/dolphinscheduler/issues/15330#issuecomment-1859041424

   Good idea, we may need to design the `TriggerAPI` and `TriggerEvent` structure first.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [DSIP-22][TriggerPlugin] Introduce Trigger Plugin [dolphinscheduler]

Posted by "pegasas (via GitHub)" <gi...@apache.org>.
pegasas commented on issue #15330:
URL: https://github.com/apache/dolphinscheduler/issues/15330#issuecomment-1869961927

   Thanks wenjun.
   
   These days I've been thinking the relationship of trigger & scheduler service responsibility in new architecture.
   In my current high-level design.
   
   1. host 2 trigger related table: trigger -> trigger instance, which currently may be host by quartz scheduler
   2. Push: HTTPTrigger -> push -> create trigger instance
   3. Pull: ThreadPool -> pull -> onevent -> create trigger instance
   
   Pull mode is more common and needs resource, I am thinking integrate pull trigger into a special task type, which could be dispatched by master/worker, leverage current task architecture which can master/server failover.
   
   Scheduler: pull trigger instance on this master host -> command


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [DSIP-22][TriggerPlugin] Introduce Trigger Plugin [dolphinscheduler]

Posted by "pegasas (via GitHub)" <gi...@apache.org>.
pegasas commented on issue #15330:
URL: https://github.com/apache/dolphinscheduler/issues/15330#issuecomment-1895598640

   > We need to define how to assign the trigger to Master, since we use `pull` mode, so all Master will pull the trigger from DB, we need to make sure one trigger will only be consumed by one Master.
   
   ![image](https://github.com/apache/dolphinscheduler/assets/13224827/c9410b25-fa20-4002-b933-032bf1ba12e9)
   
   Here's current quartz architecture. DolphinScheduler uses quartz scheduled by timer trigger and insert command into DB. For quartz scheduler, it use [exclusive lock](https://github.com/quartz-scheduler/quartz/blob/a5c4d27e963f51097f9b2777489d310a88897ca4/quartz/src/main/java/org/quartz/impl/jdbcjobstore/StdRowLockSemaphore.java#L42) while [acquiring Triggers](https://github.com/quartz-scheduler/quartz/blob/main/quartz/src/main/java/org/quartz/impl/jdbcjobstore/JobStoreSupport.java#L2793-L2827) and [fired them to get JobDetails for executing](https://github.com/quartz-scheduler/quartz/blob/main/quartz/src/main/java/org/quartz/impl/jdbcjobstore/JobStoreSupport.java#L2976-L3020) in hosted threadpool.
   
   see https://github.com/quartz-scheduler/quartz/blob/main/quartz/src/main/java/org/quartz/core/QuartzSchedulerThread.java#L291-L381
   
   Currently quartz not share public interface for us for implementation our own trigger mechanism.
   
   Here's the high-level steps we implement this feature:
   
   - (Required) dolphinscheduler-ui & dolphinscheduler-api: add trigger controller: CURD trigger & push trigger implementation by inserting command directly
   - (Required) dolphinscheduler-scheduler-plugin: Implement new scheduler plugin 
       - acquire distributed lock from `RegistryClient`
       - get triggers from db and wrap them into threadpool
       - if trigger success, callback will insert command into DB waiting for picking up to build workflow & processinstance.
   - (Optional) Consider unifying trigger and task or we just set them working individually.
   
   I am still considering a better solution that we can compatible with quart scheduler in first version, but it seems a bit hard. 
   Luckily ds has few steps on it.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [DSIP-22][TriggerPlugin] Introduce Trigger Plugin [dolphinscheduler]

Posted by "ruanwenjun (via GitHub)" <gi...@apache.org>.
ruanwenjun commented on issue #15330:
URL: https://github.com/apache/dolphinscheduler/issues/15330#issuecomment-1891201419

   We need to define how to assign the trigger to Master, since we use `pull` mode, so all Master will pull the trigger from DB, we need to make sure one trigger will only be consumed by one Master.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [DSIP-22][TriggerPlugin] Introduce Trigger Plugin [dolphinscheduler]

Posted by "davidzollo (via GitHub)" <gi...@apache.org>.
davidzollo commented on issue #15330:
URL: https://github.com/apache/dolphinscheduler/issues/15330#issuecomment-2245032767

   > Step #1: create related table schema for review Step #2: create trigger load plugin manager Step #3: backend development, add a test api for local testing, draft api review for testing Step #4: frontend development
   
   Is there any progress? ^_^


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [DSIP-22][TriggerPlugin] Introduce Trigger Plugin [dolphinscheduler]

Posted by "pegasas (via GitHub)" <gi...@apache.org>.
pegasas commented on issue #15330:
URL: https://github.com/apache/dolphinscheduler/issues/15330#issuecomment-2119702466

   Step #1: create related table schema for review
   Step #2: create trigger load plugin manager
   Step #3: backend development, add a test api for local testing, draft api review for testing
   Step #4: frontend development


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org