diff --git a/ruoyi-common/ruoyi-common-alibaba-bom/pom.xml b/ruoyi-common/ruoyi-common-alibaba-bom/pom.xml index 207bce6e..ab99d8cd 100644 --- a/ruoyi-common/ruoyi-common-alibaba-bom/pom.xml +++ b/ruoyi-common/ruoyi-common-alibaba-bom/pom.xml @@ -17,7 +17,7 @@ 2.3.0-BETA 2023.0.1.2 1.8.8 - 1.7.1 + 2.3.0 2.5.1 3.3.4 3.3.1 @@ -143,10 +143,15 @@ ${sentinel.version} - io.seata + org.apache.seata seata-spring-boot-starter ${seata.version} + + org.apache.seata + seata-all + ${seata.version} + diff --git a/ruoyi-common/ruoyi-common-seata/pom.xml b/ruoyi-common/ruoyi-common-seata/pom.xml index b2b51f87..aad8a3e5 100644 --- a/ruoyi-common/ruoyi-common-seata/pom.xml +++ b/ruoyi-common/ruoyi-common-seata/pom.xml @@ -25,13 +25,7 @@ org.apache.dubbo.extensions dubbo-filter-seata - 1.0.1 - - - io.seata - seata-core - - + 3.3.1 @@ -47,7 +41,16 @@ org.apache.dubbo.extensions dubbo-filter-seata + + io.seata + seata-spring-boot-starter + + + + org.apache.seata + seata-spring-boot-starter + diff --git a/ruoyi-common/ruoyi-common-seata/src/main/java/com/alibaba/cloud/seata/rest/SeataRestTemplateInterceptor.java b/ruoyi-common/ruoyi-common-seata/src/main/java/com/alibaba/cloud/seata/rest/SeataRestTemplateInterceptor.java new file mode 100644 index 00000000..3ddf72bb --- /dev/null +++ b/ruoyi-common/ruoyi-common-seata/src/main/java/com/alibaba/cloud/seata/rest/SeataRestTemplateInterceptor.java @@ -0,0 +1,47 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.cloud.seata.rest; + +import org.apache.seata.core.context.RootContext; +import org.springframework.http.HttpRequest; +import org.springframework.http.client.ClientHttpRequestExecution; +import org.springframework.http.client.ClientHttpRequestInterceptor; +import org.springframework.http.client.ClientHttpResponse; +import org.springframework.http.client.support.HttpRequestWrapper; +import org.springframework.util.StringUtils; + +import java.io.IOException; + +/** + * @author xiaojing + */ +public class SeataRestTemplateInterceptor implements ClientHttpRequestInterceptor { + + @Override + public ClientHttpResponse intercept(HttpRequest httpRequest, byte[] bytes, + ClientHttpRequestExecution clientHttpRequestExecution) throws IOException { + HttpRequestWrapper requestWrapper = new HttpRequestWrapper(httpRequest); + + String xid = RootContext.getXID(); + + if (StringUtils.hasLength(xid)) { + requestWrapper.getHeaders().add(RootContext.KEY_XID, xid); + } + return clientHttpRequestExecution.execute(requestWrapper, bytes); + } + +} diff --git a/ruoyi-common/ruoyi-common-seata/src/main/java/com/alibaba/cloud/seata/web/SeataHandlerInterceptor.java b/ruoyi-common/ruoyi-common-seata/src/main/java/com/alibaba/cloud/seata/web/SeataHandlerInterceptor.java new file mode 100644 index 00000000..3ddacd67 --- /dev/null +++ b/ruoyi-common/ruoyi-common-seata/src/main/java/com/alibaba/cloud/seata/web/SeataHandlerInterceptor.java @@ -0,0 +1,84 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.cloud.seata.web; + +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import org.apache.seata.common.util.StringUtils; +import org.apache.seata.core.context.RootContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.servlet.HandlerInterceptor; + +/** + * @author xiaojing + * + * Seata HandlerInterceptor, Convert Seata information into + * @see io.seata.core.context.RootContext from http request's header in + * {@link org.springframework.web.servlet.HandlerInterceptor#preHandle(HttpServletRequest, HttpServletResponse, Object)}, + * And clean up Seata information after servlet method invocation in + * {@link org.springframework.web.servlet.HandlerInterceptor#afterCompletion(HttpServletRequest, HttpServletResponse, Object, Exception)} + */ +public class SeataHandlerInterceptor implements HandlerInterceptor { + + private static final Logger log = LoggerFactory + .getLogger(SeataHandlerInterceptor.class); + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, + Object handler) { + String xid = RootContext.getXID(); + String rpcXid = request.getHeader(RootContext.KEY_XID); + if (log.isDebugEnabled()) { + log.debug("xid in RootContext {} xid in RpcContext {}", xid, rpcXid); + } + + if (StringUtils.isBlank(xid) && rpcXid != null) { + RootContext.bind(rpcXid); + if (log.isDebugEnabled()) { + log.debug("bind {} to RootContext", rpcXid); + } + } + + return true; + } + + @Override + public void afterCompletion(HttpServletRequest request, HttpServletResponse response, + Object handler, Exception e) { + if (StringUtils.isNotBlank(RootContext.getXID())) { + String rpcXid = request.getHeader(RootContext.KEY_XID); + + if (StringUtils.isEmpty(rpcXid)) { + return; + } + + String unbindXid = RootContext.unbind(); + if (log.isDebugEnabled()) { + log.debug("unbind {} from RootContext", unbindXid); + } + if (!rpcXid.equalsIgnoreCase(unbindXid)) { + log.warn("xid in change during RPC from {} to {}", rpcXid, unbindXid); + if (unbindXid != null) { + RootContext.bind(unbindXid); + log.warn("bind {} back to RootContext", unbindXid); + } + } + } + } + +} diff --git a/ruoyi-visual/ruoyi-seata-server/pom.xml b/ruoyi-visual/ruoyi-seata-server/pom.xml index 54005124..6e246c17 100644 --- a/ruoyi-visual/ruoyi-seata-server/pom.xml +++ b/ruoyi-visual/ruoyi-seata-server/pom.xml @@ -27,19 +27,72 @@ jar - 1.7.1 - 2.7.18 + 2.3.0 + 2.7.18 + 5.3.39 + 2.0 + 9.0.98 7.2 3.8.0 + 1.9.13 + 3.6.1 - + + + org.springframework + spring-framework-bom + ${spring-framework-for-server.version} + pom + import + + + org.springframework.boot spring-boot-dependencies - ${spring-boot.version} + ${spring-boot-for-server.version} + + + org.apache.kafka + kafka-clients + + + org.apache.tomcat.embed + tomcat-embed-core + + + org.apache.tomcat.embed + tomcat-embed-websocket + + + org.apache.tomcat.embed + tomcat-embed-el + + + org.springframework + spring-framework-bom + + + pom + import + + + org.yaml + snakeyaml + ${snakeyaml-for-server.version} + + + org.apache.tomcat.embed + tomcat-embed-core + ${tomcat-embed.version} + + + org.apache.seata + seata-dependencies + ${seata.version} pom import @@ -47,44 +100,142 @@ - + + org.apache.tomcat.embed + tomcat-embed-core + ${tomcat-embed.version} + + + org.apache.tomcat.embed + tomcat-embed-el + ${tomcat-embed.version} + + + org.apache.tomcat.embed + tomcat-embed-websocket + ${tomcat-embed.version} + + org.springframework.boot spring-boot-starter-web - * + log4j-to-slf4j org.apache.logging.log4j + + org.apache.tomcat.embed + tomcat-embed-core + + + org.apache.tomcat.embed + tomcat-embed-websocket + + + org.apache.tomcat.embed + tomcat-embed-el + + + org.yaml + snakeyaml + - io.seata + org.yaml + snakeyaml + + + + org.apache.seata seata-server ${seata.version} + system + ${project.basedir}/src/main/resources/lib/seata-server-${seata.version}.jar + + + + org.apache.seata + seata-spring-autoconfigure-server + ${seata.version} + + + + org.apache.seata + seata-core + ${seata.version} + + + org.apache.seata + seata-config-all + ${seata.version} - slf4j-reload4j - org.slf4j + log4j + log4j + + org.apache.seata + seata-discovery-all + ${seata.version} + + + org.apache.seata + seata-serializer-all + ${seata.version} + + + org.apache.seata + seata-compressor-all + ${seata.version} + - - org.apache.tomcat.embed - tomcat-embed-websocket - 9.0.98 + org.apache.seata + seata-metrics-all + ${seata.version} + + + + org.apache.seata + seata-console + ${seata.version} + + + + + com.alibaba + druid - org.apache.tomcat.embed - tomcat-embed-core - 9.0.98 + org.apache.commons + commons-dbcp2 - org.apache.tomcat.embed - tomcat-embed-el - 9.0.98 + com.zaxxer + HikariCP + + + com.mysql + mysql-connector-j + + + org.postgresql + postgresql + + + + com.beust + jcommander + + + + + com.google.guava + guava @@ -94,12 +245,64 @@ ${jedis.version} + + com.alibaba + fastjson + + + + + ch.qos.logback + logback-classic + + + ch.qos.logback + logback-core + net.logstash.logback logstash-logback-encoder ${logstash-logback-encoder.version} + + com.github.danielwegener + logback-kafka-appender + + + org.apache.kafka + kafka-clients + + + + + org.apache.kafka + kafka-clients + ${kafka-clients.version} + + + com.alipay.sofa + jraft-core + + + com.alipay.sofa + bolt + + + + + com.alipay.sofa + bolt + + + org.codehaus.janino + janino + + + org.codehaus.jackson + jackson-mapper-asl + ${jackson-mapper.version} + diff --git a/ruoyi-visual/ruoyi-seata-server/src/main/java/io/seata/server/SeataServerApplication.java b/ruoyi-visual/ruoyi-seata-server/src/main/java/io/seata/server/SeataServerApplication.java deleted file mode 100644 index 729e32e7..00000000 --- a/ruoyi-visual/ruoyi-seata-server/src/main/java/io/seata/server/SeataServerApplication.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 1999-2019 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.server; - -import io.seata.common.aot.NativeUtils; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -/** - * @author spilledyear@outlook.com - */ -@SpringBootApplication(scanBasePackages = {"io.seata"}) -public class SeataServerApplication { - - public static void main(String[] args) throws Throwable { - try { - // run the spring-boot application - SpringApplication.run(SeataServerApplication.class, args); - } catch (Throwable t) { - // This exception is used to end `spring-boot-maven-plugin:process-aot`, so ignore it. - if ("org.springframework.boot.SpringApplication$AbandonedRunException".equals(t.getClass().getName())) { - throw t; - } - - // In the `native-image`, if an exception occurs prematurely during the startup process, the exception log will not be recorded, - // so here we sleep for 20 seconds to observe the exception information. - if (NativeUtils.inNativeImage()) { - t.printStackTrace(); - Thread.sleep(20000); - } - - throw t; - } - } - -} diff --git a/ruoyi-visual/ruoyi-seata-server/src/main/java/org/apache/seata/server/SeataServerApplication.java b/ruoyi-visual/ruoyi-seata-server/src/main/java/org/apache/seata/server/SeataServerApplication.java new file mode 100644 index 00000000..cd45fba1 --- /dev/null +++ b/ruoyi-visual/ruoyi-seata-server/src/main/java/org/apache/seata/server/SeataServerApplication.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.seata.server; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +import java.io.IOException; + +/** + */ +@SpringBootApplication(scanBasePackages = {"org.apache.seata"}) +public class SeataServerApplication { + public static void main(String[] args) throws IOException { + // run the spring-boot application + SpringApplication.run(ServerApplication.class, args); + } +} diff --git a/ruoyi-visual/ruoyi-seata-server/src/main/resources/application.yml b/ruoyi-visual/ruoyi-seata-server/src/main/resources/application.yml index e6dd8d2b..663b11d9 100644 --- a/ruoyi-visual/ruoyi-seata-server/src/main/resources/application.yml +++ b/ruoyi-visual/ruoyi-seata-server/src/main/resources/application.yml @@ -53,7 +53,8 @@ seata: #access-key: "" #secret-key: "" security: - secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017 + secretKey: rE7bYayhpvduYwCxuhckybEPDXyna6xwm5m7MZjtjrdXjVxAbXAMccXHyaJvB346 tokenValidityInMilliseconds: 1800000 + csrf-ignore-urls: /metadata/v1/** ignore: - urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.jpeg,/**/*.ico,/api/v1/auth/login + urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.jpeg,/**/*.ico,/api/v1/auth/login,/version.json,/health,/error,/vgroup/v1/** diff --git a/ruoyi-visual/ruoyi-seata-server/src/main/resources/lib/seata-server-2.3.0.jar b/ruoyi-visual/ruoyi-seata-server/src/main/resources/lib/seata-server-2.3.0.jar new file mode 100644 index 00000000..89cff295 Binary files /dev/null and b/ruoyi-visual/ruoyi-seata-server/src/main/resources/lib/seata-server-2.3.0.jar differ diff --git a/ruoyi-visual/ruoyi-seata-server/src/main/resources/logback-spring.xml b/ruoyi-visual/ruoyi-seata-server/src/main/resources/logback-spring.xml index 6770ca35..06c7b148 100644 --- a/ruoyi-visual/ruoyi-seata-server/src/main/resources/logback-spring.xml +++ b/ruoyi-visual/ruoyi-seata-server/src/main/resources/logback-spring.xml @@ -17,7 +17,7 @@ - + diff --git a/script/docker/skywalking/agent/plugins/apm-seata-skywalking-plugin-1.7.1.jar b/script/docker/skywalking/agent/plugins/apm-seata-skywalking-plugin-1.7.1.jar deleted file mode 100644 index 2e944fa4..00000000 Binary files a/script/docker/skywalking/agent/plugins/apm-seata-skywalking-plugin-1.7.1.jar and /dev/null differ diff --git a/script/docker/skywalking/agent/plugins/apm-seata-skywalking-plugin-2.3.0.jar b/script/docker/skywalking/agent/plugins/apm-seata-skywalking-plugin-2.3.0.jar new file mode 100644 index 00000000..6e52867e Binary files /dev/null and b/script/docker/skywalking/agent/plugins/apm-seata-skywalking-plugin-2.3.0.jar differ diff --git a/script/sql/oracle/oracle_ry_cloud.sql b/script/sql/oracle/oracle_ry_cloud.sql index 1a4de2e7..d47ceaf4 100644 --- a/script/sql/oracle/oracle_ry_cloud.sql +++ b/script/sql/oracle/oracle_ry_cloud.sql @@ -1431,8 +1431,15 @@ CREATE TABLE undo_log PRIMARY KEY (id), CONSTRAINT ux_undo_log UNIQUE (xid, branch_id) ); - +CREATE INDEX ix_log_created ON undo_log(log_created); COMMENT ON TABLE undo_log IS 'AT transaction mode undo table'; +COMMENT ON COLUMN undo_log.branch_id is 'branch transaction id'; +COMMENT ON COLUMN undo_log.xid is 'global transaction id'; +COMMENT ON COLUMN undo_log.context is 'undo_log context,such as serialization'; +COMMENT ON COLUMN undo_log.rollback_info is 'rollback info'; +COMMENT ON COLUMN undo_log.log_status is '0:normal status,1:defense status'; +COMMENT ON COLUMN undo_log.log_created is 'create datetime'; +COMMENT ON COLUMN undo_log.log_modified is 'modify datetime'; -- Generate ID using sequence and trigger CREATE SEQUENCE UNDO_LOG_SEQ START WITH 1 INCREMENT BY 1; diff --git a/script/sql/oracle/oracle_ry_config.sql b/script/sql/oracle/oracle_ry_config.sql new file mode 100644 index 00000000..797603b7 --- /dev/null +++ b/script/sql/oracle/oracle_ry_config.sql @@ -0,0 +1,96 @@ +-- +-- Licensed to the Apache Software Foundation (ASF) under one or more +-- contributor license agreements. See the NOTICE file distributed with +-- this work for additional information regarding copyright ownership. +-- The ASF licenses this file to You under the Apache License, Version 2.0 +-- (the "License"); you may not use this file except in compliance with +-- the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +-- -------------------------------- The script used when storeMode is 'db' -------------------------------- +-- the table to store GlobalSession data +CREATE TABLE global_table +( + xid VARCHAR2(128) NOT NULL, + transaction_id NUMBER(19), + status NUMBER(3) NOT NULL, + application_id VARCHAR2(32), + transaction_service_group VARCHAR2(32), + transaction_name VARCHAR2(128), + timeout NUMBER(10), + begin_time NUMBER(19), + application_data VARCHAR2(2000), + gmt_create TIMESTAMP(0), + gmt_modified TIMESTAMP(0), + PRIMARY KEY (xid) +); + +CREATE INDEX idx_status_gmt_modified ON global_table (status, gmt_modified); +CREATE INDEX idx_transaction_id ON global_table (transaction_id); + +-- the table to store BranchSession data +CREATE TABLE branch_table +( + branch_id NUMBER(19) NOT NULL, + xid VARCHAR2(128) NOT NULL, + transaction_id NUMBER(19), + resource_group_id VARCHAR2(32), + resource_id VARCHAR2(256), + branch_type VARCHAR2(8), + status NUMBER(3), + client_id VARCHAR2(64), + application_data VARCHAR2(2000), + gmt_create TIMESTAMP(6), + gmt_modified TIMESTAMP(6), + PRIMARY KEY (branch_id) +); + +CREATE INDEX idx_xid ON branch_table (xid); + +-- the table to store lock data +CREATE TABLE lock_table +( + row_key VARCHAR2(128) NOT NULL, + xid VARCHAR2(128), + transaction_id NUMBER(19), + branch_id NUMBER(19) NOT NULL, + resource_id VARCHAR2(256), + table_name VARCHAR2(32), + pk VARCHAR2(36), + status NUMBER(3) DEFAULT 0 NOT NULL, + gmt_create TIMESTAMP(0), + gmt_modified TIMESTAMP(0), + PRIMARY KEY (row_key) +); + +comment on column lock_table.status is '0:locked ,1:rollbacking'; +CREATE INDEX idx_branch_id ON lock_table (branch_id); +CREATE INDEX idx_lock_table_xid ON lock_table (xid); +CREATE INDEX idx_status ON lock_table (status); + +CREATE TABLE distributed_lock ( + lock_key VARCHAR2(20) NOT NULL, + lock_value VARCHAR2(20) NOT NULL, + expire DECIMAL(18) NOT NULL, + PRIMARY KEY (lock_key) +); + +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('AsyncCommitting', ' ', 0); +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('RetryCommitting', ' ', 0); +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('RetryRollbacking', ' ', 0); +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('TxTimeoutCheck', ' ', 0); + +CREATE TABLE vgroup_table +( + vGroup VARCHAR2(255) PRIMARY KEY, + namespace VARCHAR2(255), + cluster VARCHAR2(255) +); \ No newline at end of file diff --git a/script/sql/postgres/postgres_ry_cloud.sql b/script/sql/postgres/postgres_ry_cloud.sql index f1ec1a18..04e2ba40 100644 --- a/script/sql/postgres/postgres_ry_cloud.sql +++ b/script/sql/postgres/postgres_ry_cloud.sql @@ -1408,7 +1408,7 @@ create cast (varchar as timestamptz) with function cast_varchar_to_timestamp as -- for AT mode you must to init this sql for you business database. the seata server not need it. -CREATE TABLE IF NOT EXISTS undo_log +CREATE TABLE IF NOT EXISTS public.undo_log ( id SERIAL NOT NULL, branch_id BIGINT NOT NULL, @@ -1420,8 +1420,16 @@ CREATE TABLE IF NOT EXISTS undo_log log_modified TIMESTAMP(0) NOT NULL, CONSTRAINT pk_undo_log PRIMARY KEY (id), CONSTRAINT ux_undo_log UNIQUE (xid, branch_id) -); + ); +CREATE INDEX ix_log_created ON undo_log(log_created); -COMMENT on table undo_log is 'AT transaction mode undo table'; +COMMENT ON TABLE public.undo_log IS 'AT transaction mode undo table'; +COMMENT ON COLUMN public.undo_log.branch_id IS 'branch transaction id'; +COMMENT ON COLUMN public.undo_log.xid IS 'global transaction id'; +COMMENT ON COLUMN public.undo_log.context IS 'undo_log context,such as serialization'; +COMMENT ON COLUMN public.undo_log.rollback_info IS 'rollback info'; +COMMENT ON COLUMN public.undo_log.log_status IS '0:normal status,1:defense status'; +COMMENT ON COLUMN public.undo_log.log_created IS 'create datetime'; +COMMENT ON COLUMN public.undo_log.log_modified IS 'modify datetime'; CREATE SEQUENCE IF NOT EXISTS undo_log_id_seq INCREMENT BY 1 MINVALUE 1 ; diff --git a/script/sql/postgres/postgresql_ry_config.sql b/script/sql/postgres/postgresql_ry_config.sql new file mode 100644 index 00000000..91fd2128 --- /dev/null +++ b/script/sql/postgres/postgresql_ry_config.sql @@ -0,0 +1,97 @@ +-- +-- Licensed to the Apache Software Foundation (ASF) under one or more +-- contributor license agreements. See the NOTICE file distributed with +-- this work for additional information regarding copyright ownership. +-- The ASF licenses this file to You under the Apache License, Version 2.0 +-- (the "License"); you may not use this file except in compliance with +-- the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +-- -------------------------------- The script used when storeMode is 'db' -------------------------------- +-- the table to store GlobalSession data +CREATE TABLE IF NOT EXISTS public.global_table +( + xid VARCHAR(128) NOT NULL, + transaction_id BIGINT, + status SMALLINT NOT NULL, + application_id VARCHAR(32), + transaction_service_group VARCHAR(32), + transaction_name VARCHAR(128), + timeout INT, + begin_time BIGINT, + application_data VARCHAR(2000), + gmt_create TIMESTAMP(0), + gmt_modified TIMESTAMP(0), + CONSTRAINT pk_global_table PRIMARY KEY (xid) +); + +CREATE INDEX idx_global_table_status_gmt_modified ON public.global_table (status, gmt_modified); +CREATE INDEX idx_global_table_transaction_id ON public.global_table (transaction_id); + +-- the table to store BranchSession data +CREATE TABLE IF NOT EXISTS public.branch_table +( + branch_id BIGINT NOT NULL, + xid VARCHAR(128) NOT NULL, + transaction_id BIGINT, + resource_group_id VARCHAR(32), + resource_id VARCHAR(256), + branch_type VARCHAR(8), + status SMALLINT, + client_id VARCHAR(64), + application_data VARCHAR(2000), + gmt_create TIMESTAMP(6), + gmt_modified TIMESTAMP(6), + CONSTRAINT pk_branch_table PRIMARY KEY (branch_id) +); + +CREATE INDEX idx_branch_table_xid ON public.branch_table (xid); + +-- the table to store lock data +CREATE TABLE IF NOT EXISTS public.lock_table +( + row_key VARCHAR(128) NOT NULL, + xid VARCHAR(128), + transaction_id BIGINT, + branch_id BIGINT NOT NULL, + resource_id VARCHAR(256), + table_name VARCHAR(32), + pk VARCHAR(36), + status SMALLINT NOT NULL DEFAULT 0, + gmt_create TIMESTAMP(0), + gmt_modified TIMESTAMP(0), + CONSTRAINT pk_lock_table PRIMARY KEY (row_key) +); + +comment on column public.lock_table.status is '0:locked ,1:rollbacking'; +CREATE INDEX idx_lock_table_branch_id ON public.lock_table (branch_id); +CREATE INDEX idx_lock_table_xid ON public.lock_table (xid); +CREATE INDEX idx_lock_table_status ON public.lock_table (status); + +CREATE TABLE distributed_lock ( + lock_key VARCHAR(20) NOT NULL, + lock_value VARCHAR(20) NOT NULL, + expire BIGINT NOT NULL, + CONSTRAINT pk_distributed_lock_table PRIMARY KEY (lock_key) +); + +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('AsyncCommitting', ' ', 0); +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('RetryCommitting', ' ', 0); +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('RetryRollbacking', ' ', 0); +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('TxTimeoutCheck', ' ', 0); + +CREATE TABLE IF NOT EXISTS vgroup_table +( + vGroup VARCHAR(255), + namespace VARCHAR(255), + cluster VARCHAR(255), + PRIMARY KEY (vGroup) +); \ No newline at end of file diff --git a/script/sql/ry-config.sql b/script/sql/ry-config.sql index 801be1ba..21a5c9a1 100644 --- a/script/sql/ry-config.sql +++ b/script/sql/ry-config.sql @@ -1,11 +1,3 @@ -DROP DATABASE IF EXISTS `ry-config`; - -CREATE DATABASE `ry-config` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; - -SET NAMES utf8mb4; -SET FOREIGN_KEY_CHECKS = 0; - -USE `ry-config`; /******************************************/ /* 表名称 = config_info */ diff --git a/script/sql/ry-seata.sql b/script/sql/ry-seata.sql index b95613c4..3d3c0ee3 100644 --- a/script/sql/ry-seata.sql +++ b/script/sql/ry-seata.sql @@ -1,11 +1,3 @@ -DROP DATABASE IF EXISTS `ry-seata`; - -CREATE DATABASE `ry-seata` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; - -SET NAMES utf8mb4; -SET FOREIGN_KEY_CHECKS = 0; - -USE `ry-seata`; -- -------------------------------- The script used when storeMode is 'db' -------------------------------- -- the table to store GlobalSession data @@ -63,7 +55,7 @@ CREATE TABLE IF NOT EXISTS `lock_table` PRIMARY KEY (`row_key`), KEY `idx_status` (`status`), KEY `idx_branch_id` (`branch_id`), - KEY `idx_xid_and_branch_id` (`xid` , `branch_id`) + KEY `idx_xid` (`xid`) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; @@ -80,3 +72,13 @@ INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('AsyncComm INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryCommitting', ' ', 0); INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryRollbacking', ' ', 0); INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('TxTimeoutCheck', ' ', 0); + + +CREATE TABLE IF NOT EXISTS `vgroup_table` +( + `vGroup` VARCHAR(255), + `namespace` VARCHAR(255), + `cluster` VARCHAR(255), + UNIQUE KEY `idx_vgroup_namespace_cluster` (`vGroup`,`namespace`,`cluster`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4;