update seata 1.7.1 => 2.3.0
parent
d2fb7da4aa
commit
6dc7519bdb
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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)
|
||||
);
|
||||
@ -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)
|
||||
);
|
||||
Loading…
Reference in New Issue