### Cluster Deployment Command Example Source: https://github.com/apache/incubator-seata/wiki/ctl-survey Example of how to invoke seatactl for a Seata cluster deployed with a specific registry and application name. ```bash $ seatactl [action] [type] -r registry-1 -a cluster-1 ... ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/apache/incubator-seata/blob/2.x/saga/seata-saga-statemachine-designer/README.md Run this command to install all necessary dependencies for the project. This is typically the first step before building or running the project. ```bash npm install ``` -------------------------------- ### SAGA Mode Usage Example Source: https://github.com/apache/incubator-seata/blob/2.x/compatible/README.md Example demonstrating the initialization of the StateMachineEngine for SAGA mode. ```APIDOC ## SAGA Mode Usage Example ### Description This example shows how to initialize and configure the `StateMachineEngine` for executing SAGA mode state machines. ### Class `io.seata.saga.engine.StateMachineEngine` ### Configuration Use `@Bean` to define the `StateMachineEngine` in your Spring configuration. ### Usage Example ```java import io.seata.saga.engine.StateMachineEngine; @Bean public StateMachineEngine stateMachineEngine() { // Configure state machine engine return stateMachineEngineImpl; } ``` ``` -------------------------------- ### Start Seata Server with Test Environment (Shell) Source: https://github.com/apache/incubator-seata/wiki/Multi-configuration-Isolation Use this command to start the Seata server and specify the 'test' environment for configuration isolation. This method is for server-side configuration. ```shell sh seata-server.sh -e test ``` -------------------------------- ### Seata Naming Server Directory Structure Example Source: https://github.com/apache/incubator-seata/blob/2.x/distribution/NOTICE.md Example directory structure for the Seata Naming Server, showing the placement of executable scripts, configuration files, and libraries. ```text . ├── DISCLAIMER ├── seata-namingserver │ ├── Dockerfile │ ├── LICENSE │ ├── NOTICE │ ├── bin │ │ ├── seata-namingserver-setup.sh │ │ ├── seata-namingserver.bat │ │ └── seata-namingserver.sh │ ├── conf │ │ ├── application.yml │ │ ├── logback │ │ │ ├── console-appender.xml │ │ │ └── file-appender.xml │ │ └── logback-spring.xml │ └── lib │ ├── caffeine-2.9.3.jar │ ├── checker-qual-3.37.0.jar │ ├── commons-codec-1.15.jar │ ├── commons-compiler-3.1.10.jar │ ├── commons-io-2.8.0.jar │ ├── commons-lang-2.6.jar │ └── commons-lang3-3.12.0.jar ``` -------------------------------- ### Start Development Server Source: https://github.com/apache/incubator-seata/blob/2.x/saga/seata-saga-statemachine-designer/README.md Starts the development server, which includes opening the application and automatically rebuilding the project whenever changes are detected. This is ideal for active development. ```bash npm run start ``` -------------------------------- ### Cluster Information Response Example Source: https://github.com/apache/incubator-seata/wiki/NamingServer-Api-docs Example JSON response for the 'Get All Cluster Information' endpoint, detailing cluster names, types, and instance information. ```json [ { "clusterName": "cluster1", "clusterType": "default", "vGroupMapping": { "my_test_tx_group": null }, "unitData": [ { "unitName": "810fc53f-3452-4ff2-9eb5-e2f19016005e", "namingInstanceList": [ { "ip": "172.31.31.191", "port": 8092, "nettyPort": 0, "grpcPort": 0, "weight": 1, "healthy": true, "timeStamp": 1695265270713, "role": null, "metadata": { "weight": 1, "cluster-type": "default" } } ] } ] }, { "clusterName": "cluster2", "clusterType": "default", "vGroupMapping": { "my_test_tx_group21": null }, "unitData": [ { "unitName": "bd2879e9-a342-4e19-b686-3b573b68106c", "namingInstanceList": [ { "ip": "172.31.31.191", "port": 8091, "nettyPort": 0, "grpcPort": 0, "weight": 1, "healthy": true, "timeStamp": 1695265338862, "role": null, "metadata": { "weight": 1, "cluster-type": "default" } } ] } ] } ] ``` -------------------------------- ### Seata Benchmark YAML Configuration Example Source: https://github.com/apache/incubator-seata/blob/2.x/test-suite/seata-benchmark-cli/README.md An example of a YAML configuration file for the Seata benchmark tool. This file allows for persistent configuration of benchmark parameters, which can be overridden by CLI arguments. ```yaml # benchmark.yaml server: 127.0.0.1:8091 mode: AT targetTps: 100 threads: 10 duration: 60 warmupDuration: 10 rollbackPercentage: 2 branches: 0 applicationId: benchmark-app txServiceGroup: default_tx_group ``` -------------------------------- ### Watch List Response Example Source: https://github.com/apache/incubator-seata/wiki/NamingServer-Api-docs Example JSON response for the 'Get All Watch List Information' endpoint, showing virtual groups and their associated watcher IPs. ```json [ { "vGroup": "group1", "watcherIp": ["192.168.1.1", "192.168.1.2", "192.168.1.3"] }, { "vGroup": "group2", "watcherIp": ["10.0.0.1", "10.0.0.2"] } ] ``` -------------------------------- ### Seata Naming Server Setup Script Source: https://github.com/apache/incubator-seata/blob/2.x/distribution/NOTICE.md Shell script for setting up and running the Seata Naming Server. This script handles the initialization process. ```bash #!/bin/bash # Set JAVA_HOME environment variable if not already set # export JAVA_HOME=/path/to/your/jdk # Navigate to the directory containing the Seata Naming Server JAR # cd /path/to/seata-namingserver/bin # Execute the Seata Naming Server setup script # ./seata-namingserver.sh start echo "Seata Naming Server setup script executed (simulated)." ``` -------------------------------- ### Registry Configuration Examples Source: https://github.com/apache/incubator-seata/wiki/ctl-survey Configuration examples for different service registries like Eureka and Nacos. Use -r and -a to specify the registry and application name for cluster operations. ```ini [registry-1] type=eureka service-url=http://localhost:8761/eureka [registry-2] type=nacos server-addr=127.0.0.1:8848 group="SEATA_GROUP" namespace="" username="nacos" password="nacos" ... ``` -------------------------------- ### Compare SAGA vs SAGA_ANNOTATION Mode Performance Source: https://github.com/apache/incubator-seata/blob/2.x/test-suite/seata-benchmark-cli/README.md This example demonstrates how to compare the performance of state-machine SAGA and annotation-based SAGA_ANNOTATION modes under high load. ```bash # State-machine Saga java -jar seata-benchmark-cli.jar --server 127.0.0.1:8091 \ --mode SAGA --tps 10000 --threads 50 --duration 60 --branches 3 # Annotation-based Saga java -jar seata-benchmark-cli.jar --server 127.0.0.1:8091 \ --mode SAGA_ANNOTATION --tps 10000 --threads 50 --duration 60 --branches 3 ``` -------------------------------- ### Create DataSourceProxy Bean Source: https://github.com/apache/incubator-seata/blob/2.x/compatible/README.md Provides an example of creating a DataSourceProxy bean, which is essential for Seata's AT mode to intercept SQL statements and manage transactions. ```java import io.seata.rm.datasource.DataSourceProxy; @Bean public DataSourceProxy dataSourceProxy(DataSource dataSource) { return new DataSourceProxy(dataSource); } ``` -------------------------------- ### Resource Identifier Example Source: https://github.com/apache/incubator-seata/wiki/20240302‐EN Illustrates a resource identifier. Ensure uniqueness to prevent distribution issues. ```plaintext resource-id ``` -------------------------------- ### Get All Cluster Information Source: https://github.com/apache/incubator-seata/wiki/NamingServer-Api-docs Use this GET request to retrieve all cluster information from the naming service. Requires a namespace parameter. ```http GET http://127.0.0.1:8080/naming/v1/clusters?namespace=public ``` -------------------------------- ### TCC Mode Usage Example Source: https://github.com/apache/incubator-seata/blob/2.x/compatible/README.md Example demonstrating the usage of TCC (Try-Confirm-Cancel) mode annotations for defining two-phase business operations. ```APIDOC ## TCC Mode Usage Example ### Description This example shows how to use `@LocalTCC` and `@TwoPhaseBusinessAction` annotations to define business actions that participate in TCC transactions. It includes the Try, Commit, and Rollback methods. ### Interface `io.seata.rm.tcc.api.OrderService` ### Annotations - `@LocalTCC`: Marks the service as a TCC business service. - `@TwoPhaseBusinessAction`: Defines the name of the action and the commit and rollback methods. ### Methods - `createOrder(BusinessActionContext context, Order order)`: The 'Try' method to initiate the business operation. - `confirmCreateOrder(BusinessActionContext context, Order order)`: The 'Commit' method to confirm the business operation. - `cancelCreateOrder(BusinessActionContext context, Order order)`: The 'Rollback' method to cancel the business operation. ### Request Example ```java import io.seata.rm.tcc.api.LocalTCC; import io.seata.rm.tcc.api.TwoPhaseBusinessAction; import io.seata.rm.tcc.api.BusinessActionContext; @LocalTCC public interface OrderService { @TwoPhaseBusinessAction(name = "createOrder", commitMethod = "confirmCreateOrder", rollbackMethod = "cancelCreateOrder") boolean createOrder(BusinessActionContext context, Order order); boolean confirmCreateOrder(BusinessActionContext context, Order order); boolean cancelCreateOrder(BusinessActionContext context, Order order); } ``` ``` -------------------------------- ### Get All Watch List Information Source: https://github.com/apache/incubator-seata/wiki/NamingServer-Api-docs Use this GET request to retrieve all cluster subscription relationships from the naming service. No parameters are required. ```http GET http://127.0.0.1:8080/naming/v1/watchList ``` -------------------------------- ### Seata Benchmark CLI Options Source: https://github.com/apache/incubator-seata/blob/2.x/test-suite/seata-benchmark-cli/README.md Lists all available command-line options for configuring and running the Seata benchmark tool. Use these to override configuration file settings or for quick adjustments. ```bash Usage: seata-benchmark [-hV] [--application-id=] [-d=] [--export-csv=] [-m=] [-s=] [-t=] [--saga-shape=] [--saga-workload=] [--saga-fail-step=] [--saga-random-seed=] [--saga-timeout-step=] [--saga-timeout-ms=] [--threads=] [--tx-service-group=] [--warmup-duration=] [--rollback-percentage=] [--branches=] Options: -s, --server= Seata Server address (host:port) -m, --mode= Transaction mode: AT, TCC, SAGA, XA, or SAGA_ANNOTATION -t, --tps= Target TPS (default: 100) --threads= Concurrent threads (default: 10) -d, --duration= Duration in seconds (default: 60) --warmup-duration= Warmup duration in seconds (default: 0) --rollback-percentage= Rollback percentage for fault injection (0-100, default: 2) --saga-shape= Select SAGA state machine shape: simple or order. If omitted, the benchmark keeps the existing branches-based compatibility behavior. --saga-workload= Select SAGA workload implementation: mock or db. The default is mock. The db workload uses Testcontainers MySQL for DB-backed order, inventory, and payment actions. --saga-fail-step= Restrict SAGA failure injection to one forward step: inventory, payment, or order. The failure ratio is still controlled by --rollback-percentage. --saga-random-seed= Optional random seed for reproducible SAGA failure injection behavior. --saga-timeout-step= Simulate SAGA timeout at one forward step: inventory, payment, or order. --saga-timeout-ms= Simulated timeout delay in milliseconds for SAGA timeout injection (default: 3000). --branches= Number of branch transactions 0 = empty mode (protocol overhead only) >=1 = real mode (actual execution) --export-csv= Export metrics to CSV file --application-id= Seata application ID (default: benchmark-app) --tx-service-group= Seata tx service group (default: default_tx_group) -h, --help Show this help message -V, --version Print version information ``` -------------------------------- ### Get NodePort Service URL Source: https://github.com/apache/incubator-seata/blob/2.x/script/server/helm/seata-server/templates/NOTES.txt Use this command to get the application URL when the service type is NodePort. It exports the NodePort and Node IP to environment variables. ```bash export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "seata-server.fullname" . }}) export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") echo http://$NODE_IP:$NODE_PORT ``` -------------------------------- ### Test Service Availability with 'try' Command Source: https://github.com/apache/incubator-seata/wiki/ctl-report Use the 'try begin' command to submit a sample transaction and verify service availability. You will be prompted to confirm the commit. This command helps in testing the Seata service's ability to handle transactions. ```shell 127.0.0.1:7091 > try begin Try an example txn successfully, xid=192.168.163.1:8091:522856277732237313 Commit it? (`yes` or `no`, default is `yes`) yes Commit successfully! ``` ```shell 127.0.0.1:7091 > try begin Try an example txn successfully, xid=192.168.163.1:8091:522856277732237313 Commit it? (`yes` or `no`, default is `yes`) no Rollback successfully! ``` -------------------------------- ### Get Configuration Center Configuration Source: https://github.com/apache/incubator-seata/wiki/ctl-design Retrieves the public configuration from the configuration center. Accessing any TC node is sufficient to get the configuration. Requires a connection configuration. ```bash $ seatactl get config -d '' -c ``` -------------------------------- ### Run AT Mode Benchmark with Warmup Source: https://github.com/apache/incubator-seata/blob/2.x/test-suite/seata-benchmark-cli/README.md Execute an AT mode benchmark with a specified duration and warmup period. This allows the system to stabilize before collecting metrics. ```bash java -jar seata-benchmark-cli.jar \ --server 127.0.0.1:8091 \ --mode AT \ --tps 200 \ --threads 1 \ --duration 120 \ --warmup-duration 30 ``` -------------------------------- ### Begin Transaction in AT Mode Source: https://github.com/apache/incubator-seata/wiki/Seate‐go-data-source-proxy-design Initiates a transaction in AT mode by calling `driver.Conn.BeginTx`. This function creates and returns a proxied `driver.Tx` object, setting up a transaction context to record transaction details. ```go func (c *Conn) Begin() (driver.Tx, error) { tx, err := c.conn.Begin() if err != nil { return nil, err } // 创建一个 事务上下文,仅在 driver 中流转,主要记录整个事务过程中涉及的一切 // 1. 前后数据镜像 // 2. 分支事务ID // 3. 资源ID // 4. SQL中涉及的 lockey 列表 // 5. 事务ID c.txCtx = types.NewTxCtx() c.txCtx.DBType = c.res.dbType c.txCtx.TxOpt = driver.TxOptions{} return newTx( withDriverConn(c), withTxCtx(c.txCtx), withOriginTx(tx), ) } ``` -------------------------------- ### TCC Mode Order Service Example Source: https://github.com/apache/incubator-seata/blob/2.x/compatible/README.md Example of an OrderService interface for TCC mode, defining create, confirm, and cancel methods. Ensure the service is annotated with @LocalTCC. ```java import io.seata.rm.tcc.api.LocalTCC; import io.seata.rm.tcc.api.TwoPhaseBusinessAction; import io.seata.rm.tcc.api.BusinessActionContext; @LocalTCC public interface OrderService { @TwoPhaseBusinessAction(name = "createOrder", commitMethod = "confirmCreateOrder", rollbackMethod = "cancelCreateOrder") boolean createOrder(BusinessActionContext context, Order order); boolean confirmCreateOrder(BusinessActionContext context, Order order); boolean cancelCreateOrder(BusinessActionContext context, Order order); } ``` -------------------------------- ### Editor Initialization Source: https://github.com/apache/incubator-seata/blob/2.x/saga/seata-saga-statemachine-designer/README.md Demonstrates how to create a new `Editor` object and mount it to a specified DOM element, including additional modules. ```APIDOC ## Editor Initialization ### Description Creates a new `Editor` object and mounts it to the `canvas` block. It also configures keyboard bindings and the properties panel, adding `PropertiesPanel` and `PropertiesProvider` as additional modules. ### Code Example ```javascript const editor = new Editor({ container: document.querySelector('#canvas'), keyboard: { bindTo: document }, propertiesPanel: { parent: '#properties' }, // Add properties panel as additional modules additionalModules: [ PropertiesPanel, PropertiesProvider, ], }); control(editor); ``` ``` -------------------------------- ### Client-side Configuration Example Source: https://github.com/apache/incubator-seata/wiki/NamingServer-support-design This configuration is used on the client side to define service groups, their mappings to clusters, and registry settings. Ensure the service-url points to your naming server and the namespace is correctly set. ```yaml seata: tx-service-group: groupA service: vgroup-mapping: groupA: cluster1 # Corresponds to the cluster in the group model, later consider giving control plane authority to this mapping registry: type: namingserver namingserver: service-url: address server domain namespace: dev # Corresponds to the namespace in the group model ``` -------------------------------- ### Create Table in PolarDB AUTO Mode with KEY Partitioning Source: https://github.com/apache/incubator-seata/wiki/polardb-support-acceptance-report This SQL example demonstrates creating a table in PolarDB's AUTO mode using KEY partitioning on multiple columns, with a specified number of partitions. ```sql CREATE TABLE key_tbl( id bigint not null auto_increment, bid int, name varchar(30), birthday datetime not null, primary key(id) ) PARTITION BY KEY(name, id) PARTITIONS 8; ``` -------------------------------- ### Run AT Mode with Advanced Options Source: https://github.com/apache/incubator-seata/blob/2.x/test-suite/seata-benchmark-cli/README.md Configures an AT mode benchmark with extended options including warmup duration, rollback percentage, CSV export, and custom application/transaction group names. ```bash java -jar seata-benchmark-cli.jar \ --server 127.0.0.1:8091 \ --mode AT \ --tps 100000 \ --threads 50 \ --duration 300 \ --warmup-duration 30 \ --rollback-percentage 2 \ --branches 3 \ --export-csv results.csv \ --application-id my-benchmark-app \ --tx-service-group my_tx_group ``` -------------------------------- ### Install PolarDB JDBC Driver with Maven Source: https://github.com/apache/incubator-seata/wiki/polardb-support-survey Use this command to install the PolarDB JDBC driver JAR package into your local Maven repository. Replace placeholders with your JAR's actual name and path. ```bash mvn install:install-file -DgroupId=com.aliyun -DartifactId=<安装的Jar包名> -Dversion=1.1.2 -Dpackaging=jar -Dfile=/usr/local/polardb/share/java/<安装的Jar包名.jar> ``` -------------------------------- ### Run Benchmark with Warmup Source: https://github.com/apache/incubator-seata/blob/2.x/test-suite/seata-benchmark-cli/README.md Execute the Seata benchmark CLI with a specified warmup duration. The first 30 seconds of the test will be excluded from the final statistics. ```bash java -jar seata-benchmark-cli.jar \ --server 127.0.0.1:8091 \ --mode AT \ --tps 100 \ --duration 120 \ --warmup-duration 30 # First 30 seconds excluded from final stats ``` -------------------------------- ### Get LoadBalancer Service URL Source: https://github.com/apache/incubator-seata/blob/2.x/script/server/helm/seata-server/templates/NOTES.txt This snippet retrieves the application URL for a LoadBalancer service type. It may take a few minutes for the LoadBalancer IP to become available. You can monitor the status using 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "seata-server.fullname" . }}'. ```bash export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "seata-server.fullname" . }} --template "{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}") echo http://$SERVICE_IP:{{ .Values.service.port }} ``` -------------------------------- ### HTTP Transaction Propagation Interceptor Source: https://github.com/apache/incubator-seata/blob/2.x/compatible/README.md Example demonstrating the integration of the HTTP transaction propagation interceptor. ```APIDOC ## HTTP Transaction Propagation Interceptor ### Description This example shows how to configure the `TransactionPropagationInterceptor` for HTTP requests to propagate global transaction IDs. ### Class `io.seata.integration.http.TransactionPropagationInterceptor` ### Configuration Use `@Bean` to define the `TransactionPropagationInterceptor` in your Spring configuration. ### Usage Example ```java import io.seata.integration.http.TransactionPropagationInterceptor; @Bean public TransactionPropagationInterceptor transactionPropagationInterceptor() { return new TransactionPropagationInterceptor(); } ``` ``` -------------------------------- ### Initialize TM and RM Clients Source: https://github.com/apache/incubator-seata/blob/2.x/compatible/README.md Shows how to initialize the Transaction Manager (TM) and Resource Manager (RM) clients for Seata. Ensure these clients are initialized before use. ```java import io.seata.tm.TMClient; import io.seata.rm.RMClient; // Initialize TM and RM clients TMClient.init("seata-tm", "default"); RMClient.init("seata-rm", "default"); ``` -------------------------------- ### Nacos Interactive Shell Script Prompts Source: https://github.com/apache/incubator-seata/blob/2.x/script/config-center/README.md Example of the prompts displayed when running the Nacos interactive configuration script. ```bash Please enter the host of nacos. 请输入nacos的host [localhost]: >>> Please enter the port of nacos. 请输入nacos的port [8848]: >>> Please enter the group of nacos. 请输入nacos的group [SEATA_GROUP]: >>> Please enter the tenant of nacos. 请输入nacos的tenant: >>> Please enter the username of nacos. 请输入nacos的username: >>> Please enter the password of nacos. 请输入nacos的password: >>> Are you sure to continue? [y/n] ```