Apache Seata

repository·2.x·Indexed 12 days ago

https://github.com/apache/incubator-seata

A distributed transaction solution for microservices designed to ensure data consistency across distributed environments. It utilizes three primary roles—Transaction Coordinator (TC), Transaction Manager (TM), and Resource Manager (RM)—to manage global transactions via a unique XID. Supports multiple transaction modes including AT and TCC, and provides a visual graph designer for Saga StateMachines.

Tokens
24K
Snippets
69
Records
125
Agent score
98%

What's inside Seata

  1. What is Apache Seata (incubating)?

    2.x
    Apache Seata is a distributed transaction solution designed for microservices architectures. It provides high performance and ease of use to solve the data consistency challenges that arise when business logic is split across multiple services, each using its own local data source (the 'Database per service' pattern).
  2. New features in Seata 1.5.0

    2.x

    Seata 1.5.0 introduced several key capabilities for distributed transaction management, including:

    • Console Management: Support for Seata console management and front-end page implementation.
    • TCC Mode Enhancements:
      • Support for idempotency and anti-hanging.
      • Ability to share phase-1 parameters with phase-2.
      • Support for customized parameter lists for methods in phase two.
      • Implicit passing of BusinessActionContext in the try method.
    • Storage & Locking:
      • Support for mixed use of different storages for locks and sessions.
      • Added redisLocker in Lua mode.
      • Added Redis distributed lock to prevent multi-TC competition.
      • Added DB realization for distributed locks.
    • Configuration & Deployment:
      • Support for starting the server with Spring Boot using application.yaml.
      • Support for retrieving configuration from environment variables.
      • Interactive scripts for uploading configurations to Nacos, Etcd3, Apollo, Consul, and Zookeeper.
      • Support for reading YML configuration from Nacos, Zookeeper, Consul, and Etcd3.
    • Observability & RPC:
      • Support for APM with SkyWalking.
      • Support for various RPC frameworks including edas-hsf and brpc-java.
      • Support for Kotlin coroutines.
    • Saga Mode: Support for auto-configuration in Spring Boot projects.
  3. New features in Seata 1.4.2

    2.x

    Seata 1.4.2 introduced several new capabilities for transaction management and infrastructure support:

    • AT Mode: Added support for undo_loge compression mode to reduce storage overhead.
    • Saga Mode: Added support for customizing whether to update the last retry log and support for loop execution on states.
    • TC (Transaction Coordinator) Storage: Added support for redis sentinel storage mode.
    • Configuration & Registry:
      • Support for seata server thread pool parameter configuration.
      • Support for acl-token when using Consul as a registry and configuration center.
      • Support for configuring apolloService and apolloCluster.
      • Support for obtaining multiple configurations through a single node when using Zookeeper.
      • Support for reading all configurations from a single Nacos dataId.
    • Security: Added password decryption support when using DB and Redis storage modes.
    • Observability & Logging:
      • Ability to send seata-server logs to Logstash or Kafka.
      • Added transaction service group for metrics.
      • Support for printing Transaction context in the logging framework.
    • Extensibility: Added a distributed lock interface and support for custom serialization plugins.
  4. New features in Seata 1.6.0

    2.x

    Seata 1.6.0 introduced several key features for expanded environment support and enhanced transaction modes:

    • Database Support: Added support for multi-primary keys in Oracle and PostgreSQL, Oracle timestamp types, Oracle nclob types, and MySQL update join SQL.
    • Registry & Frameworks: seata-server now supports multiple registries. Added support for Apache Dubbo3 and Nacos contextPath.
    • TCC Mode: TCC annotations can now be marked on both the interface and the implementation class.
    • Runtime & Infrastructure: seata-client supports JDK 17, and Dockerfiles now support arm64 architectures.
  5. New features in Seata 2.6.0

    2.x

    The 2.6.0 release introduces several significant capabilities:

    • Transaction Management: Support for managing transaction groups and displaying cluster information in the console.
    • Protocol & Transport: Upgraded HTTP client to support HTTP/2 and enhanced HttpClient to support h2c. Added an HTTP request filter for seata-server.
    • Database Support: Added support for DM Database (including XAUtils), Shentongdatabase (XA mode), and Oracle Batch Insert. Improved PostgreSQL support for Jackson and Fastjson serialization of array types.
    • Serialization: Added support for fory serializer and fory undolog parser (replacing fury).
    • Tooling: Introduced MCP (Model Context Protocol) custom configuration, authentication, and tools for managing global/branch sessions and locks.
    • Infrastructure: Automatic calculation of JVM parameters and support for JDK 25 in CI configurations.
  6. How TCC dynamic proxy works

    2.x

    Seata uses dynamic proxies to manage TCC services. When the GlobalTransactionScanner detects a TCC service 'reference', it applies a dynamic proxy to it.

    The primary functions of the TCC dynamic proxy are:

    1. Generating the TCC runtime context.
    2. Passing through business parameters.
    3. Registering branch transaction records.
  7. Extend the Editor with Providers

    2.x

    The designer uses a provider pattern to populate UI elements from the diagram-js toolbox:

    • PaletteProvider: Controls the left-side palette. It defines which elements (e.g., ServiceTask, Fail, Success, Start) can be dragged onto the canvas. It also provides a lasso tool for bulk selection.
    • ContextPadProvider: Controls the contextual menu that appears when an element is selected. For example, it provides 'connect' and 'delete' actions for Shapes, and only 'delete' for Edges.
  8. How Apache Seata roles and transaction lifecycle work

    2.x

    Seata manages distributed transactions through three primary roles and a specific lifecycle involving a Global Transaction ID (XID):

    Roles

    • Transaction Coordinator (TC): Maintains the status of global and branch transactions; drives the global commit or rollback.
    • Transaction Manager (TM): Defines the scope of the global transaction by initiating the begin, commit, or rollback operations.
    • Resource Manager (RM): Manages the resources used by branch transactions; registers branch transactions with the TC and reports their status.

    Transaction Lifecycle

    1. Begin: The TM asks the TC to begin a new global transaction. The TC generates a unique XID.
    2. Propagation: The XID is propagated through the microservices' invocation chain.
    3. Registration: The RM registers the local transaction as a branch of the global transaction (identified by the XID) to the TC.
    4. Completion Request: The TM asks the TC to either commit or rollback the global transaction associated with the XID.
    5. Execution: The TC drives all registered branch transactions under that XID to complete their respective commit or rollback operations.
  9. Use seata-integration-tx-api for TCC transactions

    2.x
    In Seata 2.0.0, the seata-integration-tx-api module provides an integration layer for TCC (Try-Confirm-Cancel) transactions. This module allows for transaction process definition and proxy enhancement, enabling more structured API access to the TCC workflow.
  10. Understand the TCC transaction model

    2.x

    TCC (Try-Confirm-Cancel) is a transaction resource type in Seata that follows a two-phase commit (2PC) protocol. Unlike the AT mode which is automatic, TCC requires the developer to manually implement the business logic for three distinct operations based on their specific business scenario:

    1. Try: Performs resource checking and reservation. This corresponds to the first phase of the distributed transaction.
    2. Confirm: Executes the actual business operation using the resources reserved during the Try phase. Requirement: If Try succeeds, Confirm must be guaranteed to succeed.
    3. Cancel: Releases the resources that were reserved during the Try phase.

    The Seata Transaction Manager coordinates these calls: it invokes Try in the first phase, and then invokes either Confirm (for commit) or Cancel (for rollback) in the second phase.

  11. Concept: diagram-js Data Model

    2.x

    The diagram-js data model is composed of Shape and Connection elements:

    • Shape: Contains a parent, a list of children, and lists of incoming and outgoing Connections.
    • Connection: Contains a parent and references to a source and target (both being Shape elements).

    The ElementRegistry creates these based on the model, and the Modeling service updates their relationships during user interaction.

  12. Hook into diagram-js lifecycle events

    2.x

    diagram-js uses an event-driven architecture. You can access the eventBus service from the diagram instance to subscribe to lifecycle events, such as modeling changes or element updates.

    • Use commandStack.changed to detect when a user performs a modeling operation or an undo/redo action.
    • Use element.changed to detect when a specific element is modified.
    diagram.get('eventBus').on('commandStack.changed', () => {
      // User modeled something or
      // performed an undo/redo operation
    });
    
    modeler.on('element.changed', (event) => {
      const element = event.element;
    
      // The element was changed by the user
    });