Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added oracle database support #902

Merged
merged 68 commits into from Jul 31, 2019
Merged
Show file tree
Hide file tree
Changes from 64 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
7828822
增加oracle数据库的支持
15168326318 Mar 20, 2019
ca6a13a
修改ORACLEKeywordChecker,按最新MySQLKeywordChecker修改,命名规范化。
15168326318 Mar 25, 2019
d91306d
增加代码注释,规范代码。
15168326318 Mar 25, 2019
e158a84
Merge branch 'feature_oracle' into develop_oracle
15168326318 Apr 2, 2019
ab359d4
报ORACLE开头的类名该为Oracle
15168326318 Apr 2, 2019
99cdcce
.* is an incorrect type,去掉.* 这样的引用。但idea自己会导入这样的引用。
15168326318 Apr 2, 2019
d53f60a
.* is an incorrect type,去掉.* 这样的引用。但idea自己会导入这样的引用。
15168326318 Apr 2, 2019
e9cfa63
修改注释
15168326318 Apr 4, 2019
494af9d
本地环境修改
15168326318 Apr 25, 2019
966fbb9
Merge branch 'develop' of https://github.com/alibaba/fescar into deve…
15168326318 Apr 25, 2019
64e0086
Merge branch 'develop' of https://github.com/seata/seata into develop…
15168326318 Apr 25, 2019
01cd039
Merge branch 'develop' into develop_oracle
lovepoem Apr 25, 2019
df93d81
Merge branch 'develop' into develop_oracle
lovepoem Apr 25, 2019
74aa7a3
支持oracle数据修改
15168326318 Apr 26, 2019
2374132
Merge remote-tracking branch 'ccg/develop_oracle' into develop_seata_…
15168326318 Apr 26, 2019
39bf981
修改一个小问题。
15168326318 Apr 26, 2019
c4f8f3b
还原distributionManagement
15168326318 Apr 26, 2019
aa2a015
Update pom.xml
lovepoem Apr 26, 2019
b4cace4
增加数据库判断处理
15168326318 Apr 26, 2019
d63c35c
Merge remote-tracking branch 'ccg/develop_oracle' into develop_seata_…
15168326318 Apr 26, 2019
8e5b4be
修改日志
15168326318 Apr 26, 2019
b29dd71
Merge branch 'develop' into develop_oracle
lovepoem Apr 28, 2019
b3f5ce6
Merge branch 'develop' into develop_oracle
lovepoem May 7, 2019
f802c0c
Merge branch 'develop' into develop_oracle
lovepoem May 8, 2019
c40fc26
Merge branch 'develop' into develop_oracle
xingfudeshi May 9, 2019
284d180
修改maven本地地址
15168326318 May 13, 2019
0996f7f
Merge branch 'develop_oracle' of https://github.com/15168326318/fesca…
15168326318 May 13, 2019
88eae97
Merge branch 'develop' into develop_oracle
xingfudeshi May 13, 2019
93b7dc4
Merge branch 'develop' of https://github.com/seata/seata into develop…
15168326318 May 13, 2019
62dcc61
去掉guava那个缓存的包
15168326318 May 13, 2019
015615f
Merge remote-tracking branch 'ccg/develop_oracle' into develop_seata_…
15168326318 May 13, 2019
8b1d198
还原pom.xml文件
15168326318 May 13, 2019
b87a56c
Merge branch 'develop' into develop_oracle
xingfudeshi May 13, 2019
c037142
Merge branch 'develop' into develop_oracle
lovepoem May 13, 2019
101bd60
还原file.conf文件和去掉import * 这样的导入
15168326318 May 13, 2019
db07f46
Merge remote-tracking branch 'ccg/develop_oracle' into develop_seata_…
15168326318 May 13, 2019
736b6c2
Merge branch 'develop' into develop_oracle
lovepoem May 14, 2019
ea3f9ae
Merge branch 'develop' into develop_oracle
lovepoem May 14, 2019
23840cf
Merge branch 'develop' into develop_oracle
xingfudeshi May 15, 2019
a04a1a7
Merge branch 'develop' into develop_oracle
lovepoem May 16, 2019
7cc21b9
增加自己公司的需求
15168326318 May 27, 2019
e9a2f5a
Merge branch 'develop' of https://github.com/seata/seata into develop…
15168326318 May 27, 2019
6637fc3
Merge branch 'develop' of https://github.com/seata/seata into develop…
15168326318 May 27, 2019
c7d3b4f
去掉import *
15168326318 May 27, 2019
79377f9
Merge remote-tracking branch 'ccg/develop_oracle' into develop_seata_…
15168326318 May 27, 2019
a3e6347
还原pom.xml
15168326318 May 27, 2019
5a7bd3b
去掉扩展功能的代码
15168326318 May 27, 2019
32aaca4
Merge branch 'develop' into develop_oracle
15168326318 May 27, 2019
d4d002f
合并seata 0.6.0版本
15168326318 May 29, 2019
bf4682e
合并seata 0.6.0版本
15168326318 May 29, 2019
7573630
Merge branch 'develop' into develop_oracle
xingfudeshi Jun 18, 2019
d773dd9
Merge branch 'develop' into develop_oracle
leizhiyuan Jun 19, 2019
1d8de1b
Merge branch 'develop' into develop_oracle
xingfudeshi Jun 26, 2019
8d66d23
Merge branch 'develop' into develop_oracle
lovepoem Jul 2, 2019
286edee
解决BaseTransactionalExecutor冲突
Jul 24, 2019
b31c4f7
增加oracle创建undo表的sql
Jul 24, 2019
0c899f6
Merge branch 'develop' into develop_oracle
15168326318 Jul 24, 2019
5b8c547
增加oracle undo表增加context字段
Jul 24, 2019
6b60cc8
Merge remote-tracking branch 'origin/develop_oracle' into develop_oracle
Jul 24, 2019
fa2fde9
Merge branch 'develop' into develop_oracle
lovepoem Jul 27, 2019
6a076b9
oracle支持跨用户访问,表名大小写。
Jul 29, 2019
7aff7a2
Merge remote-tracking branch 'origin/develop_oracle' into develop_oracle
Jul 29, 2019
fa519d5
去掉read.md中 oracle sql脚本
Jul 29, 2019
cc6b0d7
Merge branch 'develop' into develop_oracle
15168326318 Jul 30, 2019
a85472e
去掉多余的代码
Jul 31, 2019
1d61330
还原file.conf文件
Jul 31, 2019
54f9ba9
还原file.conf文件的driver-class-name = "com.mysql.jdbc.Driver"
Jul 31, 2019
6f58367
Merge branch 'develop' into develop_oracle
lovepoem Jul 31, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -8,10 +8,10 @@
[![maven](https://img.shields.io/maven-central/v/io.seata/seata-parent.svg)](https://search.maven.org/search?q=io.seata)
[![](https://img.shields.io/twitter/follow/seataio.svg?label=Follow&style=social&logoWidth=0)](https://twitter.com/intent/follow?screen_name=seataio)


## What is Seata?

A **distributed transaction solution** with high performance and ease of use for **microservices** architecture.

### Distributed Transaction Problem in Microservices

Let's imagine a traditional monolithic application. Its business is built up with 3 modules. They use a single local data source.
Expand Down
72 changes: 39 additions & 33 deletions rm-datasource/src/main/java/io/seata/rm/datasource/AsyncWorker.java
Expand Up @@ -15,20 +15,7 @@
*/
package io.seata.rm.datasource;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import com.alibaba.druid.util.JdbcConstants;
import io.seata.common.exception.NotSupportYetException;
import io.seata.common.exception.ShouldNeverHappenException;
import io.seata.common.thread.NamedThreadFactory;
Expand All @@ -40,9 +27,24 @@
import io.seata.core.model.ResourceManagerInbound;
import io.seata.rm.DefaultResourceManager;
import io.seata.rm.datasource.undo.UndoLogManager;
import io.seata.rm.datasource.undo.UndoLogManagerOracle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import static io.seata.core.constants.ConfigurationKeys.CLIENT_ASYNC_COMMIT_BUFFER_LIMIT;

/**
Expand All @@ -69,8 +71,7 @@ private static class Phase2Context {
* @param resourceId the resource id
* @param applicationData the application data
*/
public Phase2Context(BranchType branchType, String xid, long branchId, String resourceId,
String applicationData) {
public Phase2Context(BranchType branchType, String xid, long branchId, String resourceId, String applicationData) {
this.xid = xid;
this.branchId = branchId;
this.resourceId = resourceId;
Expand Down Expand Up @@ -102,19 +103,17 @@ public Phase2Context(BranchType branchType, String xid, long branchId, String re
}

private static int ASYNC_COMMIT_BUFFER_LIMIT = ConfigurationFactory.getInstance().getInt(
CLIENT_ASYNC_COMMIT_BUFFER_LIMIT, 10000);
CLIENT_ASYNC_COMMIT_BUFFER_LIMIT, 10000);

private static final BlockingQueue<Phase2Context> ASYNC_COMMIT_BUFFER = new LinkedBlockingQueue<>(ASYNC_COMMIT_BUFFER_LIMIT);

private static final BlockingQueue<Phase2Context> ASYNC_COMMIT_BUFFER = new LinkedBlockingQueue<>(
ASYNC_COMMIT_BUFFER_LIMIT);

private static ScheduledExecutorService timerExecutor;

@Override
public BranchStatus branchCommit(BranchType branchType, String xid, long branchId, String resourceId,
String applicationData) throws TransactionException {
public BranchStatus branchCommit(BranchType branchType, String xid, long branchId, String resourceId, String applicationData) throws TransactionException {
if (!ASYNC_COMMIT_BUFFER.offer(new Phase2Context(branchType, xid, branchId, resourceId, applicationData))) {
LOGGER.warn("Async commit buffer is FULL. Rejected branch [" + branchId + "/" + xid
+ "] will be handled by housekeeping later.");
LOGGER.warn("Async commit buffer is FULL. Rejected branch [" + branchId + "/" + xid + "] will be handled by housekeeping later.");
}
return BranchStatus.PhaseTwo_Committed;
}
Expand All @@ -125,7 +124,7 @@ public BranchStatus branchCommit(BranchType branchType, String xid, long branchI
public synchronized void init() {
LOGGER.info("Async Commit Buffer Limit: " + ASYNC_COMMIT_BUFFER_LIMIT);
timerExecutor = new ScheduledThreadPoolExecutor(1,
new NamedThreadFactory("AsyncWorker", 1, true));
new NamedThreadFactory("AsyncWorker", 1, true));
timerExecutor.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
Expand Down Expand Up @@ -160,11 +159,11 @@ private void doBranchCommits() {

for (Map.Entry<String, List<Phase2Context>> entry : mappedContexts.entrySet()) {
Connection conn = null;
DataSourceProxy dataSourceProxy;
try {
try {
DataSourceManager resourceManager = (DataSourceManager)DefaultResourceManager.get()
.getResourceManager(BranchType.AT);
DataSourceProxy dataSourceProxy = resourceManager.get(entry.getKey());
DataSourceManager resourceManager = (DataSourceManager) DefaultResourceManager.get().getResourceManager(BranchType.AT);
dataSourceProxy = resourceManager.get(entry.getKey());
if (dataSourceProxy == null) {
throw new ShouldNeverHappenException("Failed to find resource on " + entry.getKey());
}
Expand All @@ -180,9 +179,13 @@ private void doBranchCommits() {
xids.add(commitContext.xid);
branchIds.add(commitContext.branchId);
int maxSize = xids.size() > branchIds.size() ? xids.size() : branchIds.size();
if (maxSize == UNDOLOG_DELETE_LIMIT_SIZE) {
if(maxSize == UNDOLOG_DELETE_LIMIT_SIZE){
try {
UndoLogManager.batchDeleteUndoLog(xids, branchIds, conn);
if(JdbcConstants.ORACLE.equalsIgnoreCase(dataSourceProxy.getDbType())) {
UndoLogManagerOracle.batchDeleteUndoLog(xids, branchIds, conn);
} else {
UndoLogManager.batchDeleteUndoLog(xids, branchIds, conn);
}
} catch (Exception ex) {
LOGGER.warn("Failed to batch delete undo log [" + branchIds + "/" + xids + "]", ex);
}
Expand All @@ -196,8 +199,12 @@ private void doBranchCommits() {
}

try {
UndoLogManager.batchDeleteUndoLog(xids, branchIds, conn);
} catch (Exception ex) {
if(JdbcConstants.ORACLE.equalsIgnoreCase(dataSourceProxy.getDbType())) {
UndoLogManagerOracle.batchDeleteUndoLog(xids, branchIds, conn);
} else {
UndoLogManager.batchDeleteUndoLog(xids, branchIds, conn);
}
}catch (Exception ex) {
LOGGER.warn("Failed to batch delete undo log [" + branchIds + "/" + xids + "]", ex);
}

Expand All @@ -214,8 +221,7 @@ private void doBranchCommits() {
}

@Override
public BranchStatus branchRollback(BranchType branchType, String xid, long branchId, String resourceId,
String applicationData) throws TransactionException {
public BranchStatus branchRollback(BranchType branchType, String xid, long branchId, String resourceId, String applicationData) throws TransactionException {
throw new NotSupportYetException();

}
Expand Down
Expand Up @@ -15,6 +15,7 @@
*/
package io.seata.rm.datasource;

import com.alibaba.druid.util.JdbcConstants;
import java.sql.Connection;
import java.sql.SQLException;

Expand All @@ -28,6 +29,7 @@
import io.seata.rm.datasource.exec.LockConflictException;
import io.seata.rm.datasource.undo.SQLUndoLog;
import io.seata.rm.datasource.undo.UndoLogManager;
import io.seata.rm.datasource.undo.UndoLogManagerOracle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -184,7 +186,11 @@ private void processGlobalTransactionCommit() throws SQLException {

try {
if (context.hasUndoLog()) {
UndoLogManager.flushUndoLogs(this);
if(JdbcConstants.ORACLE.equalsIgnoreCase(this.getDbType())) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe some factory class should take care of returning an undo manager. Otherwise you will have this kind of logic at several places.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

io.seata.rm.datasource.undo.*; is a wrong type

UndoLogManagerOracle.flushUndoLogs(this);
} else {
UndoLogManager.flushUndoLogs(this);
}
}
targetConnection.commit();
} catch (Throwable ex) {
Expand Down
Expand Up @@ -15,6 +15,7 @@
*/
package io.seata.rm.datasource;

import com.alibaba.druid.util.JdbcConstants;
import java.net.InetSocketAddress;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -43,8 +44,14 @@
import io.seata.discovery.registry.RegistryFactory;
import io.seata.rm.AbstractResourceManager;
import io.seata.rm.datasource.undo.UndoLogManager;
import io.seata.rm.datasource.undo.UndoLogManagerOracle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.InetSocketAddress;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeoutException;

import static io.seata.common.exception.FrameworkErrorCode.NoAvailableService;

Expand Down Expand Up @@ -176,7 +183,14 @@ public BranchStatus branchRollback(BranchType branchType, String xid, long branc
throw new ShouldNeverHappenException();
}
try {
UndoLogManager.undo(dataSourceProxy, xid, branchId);
if(JdbcConstants.ORACLE.equalsIgnoreCase(dataSourceProxy.getDbType())) {
UndoLogManagerOracle.undo(dataSourceProxy, xid, branchId);
}
else if(JdbcConstants.MYSQL.equalsIgnoreCase(dataSourceProxy.getDbType())){
UndoLogManager.undo(dataSourceProxy, xid, branchId);
} else {
throw new NotSupportYetException("DbType[" + dataSourceProxy.getDbType() + "] is not support yet!");
}
} catch (TransactionException te) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("branchRollback failed reason [{}]", te.getMessage());
Expand Down
Expand Up @@ -31,6 +31,9 @@
import java.util.List;
import java.util.StringJoiner;


import com.alibaba.druid.util.JdbcConstants;
import io.seata.rm.datasource.sql.struct.TableMetaCacheOracle;
/**
* The type Base transactional executor.
*
Expand Down Expand Up @@ -150,8 +153,13 @@ protected TableMeta getTableMeta() {
* @return the table meta
*/
protected TableMeta getTableMeta(String tableName) {
if (tableMeta == null) {
tableMeta = TableMetaCache.getTableMeta(statementProxy.getConnectionProxy().getDataSourceProxy(), tableName);
if (tableMeta != null) {
return tableMeta;
}
if(JdbcConstants.ORACLE.equalsIgnoreCase(statementProxy.getConnectionProxy().getDbType())) {
tableMeta = TableMetaCacheOracle.getTableMeta(statementProxy.getConnectionProxy().getDataSourceProxy(), tableName);
} else {
tableMeta = TableMetaCache.getTableMeta(statementProxy.getConnectionProxy().getDataSourceProxy(), tableName);
}
return tableMeta;
}
Expand Down
Expand Up @@ -15,14 +15,14 @@
*/
package io.seata.rm.datasource.exec;

import java.sql.SQLException;
import java.sql.Statement;

import io.seata.core.context.RootContext;
import io.seata.rm.datasource.StatementProxy;
import io.seata.rm.datasource.sql.SQLRecognizer;
import io.seata.rm.datasource.sql.SQLVisitorFactory;

import java.sql.SQLException;
import java.sql.Statement;

/**
* The type Execute template.
*
Expand Down
Expand Up @@ -26,7 +26,10 @@
import io.seata.rm.datasource.sql.druid.MySQLInsertRecognizer;
import io.seata.rm.datasource.sql.druid.MySQLSelectForUpdateRecognizer;
import io.seata.rm.datasource.sql.druid.MySQLUpdateRecognizer;

import io.seata.rm.datasource.sql.druid.oracle.OracleDeleteRecognizer;
import io.seata.rm.datasource.sql.druid.oracle.OracleInsertRecognizer;
import io.seata.rm.datasource.sql.druid.oracle.OracleSelectForUpdateRecognizer;
import io.seata.rm.datasource.sql.druid.oracle.OracleUpdateRecognizer;
import java.util.List;

/**
Expand Down Expand Up @@ -62,7 +65,19 @@ public static SQLRecognizer get(String sql, String dbType) {
recognizer = new MySQLSelectForUpdateRecognizer(sql, ast);
}
}
} else {
} else if (JdbcConstants.ORACLE.equalsIgnoreCase(dbType)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if equalsIgnoreCase is really required here. Otherwise a switch statement would be a better solution.

if (ast instanceof SQLInsertStatement) {
recognizer = new OracleInsertRecognizer(sql, ast);
} else if (ast instanceof SQLUpdateStatement) {
recognizer = new OracleUpdateRecognizer(sql, ast);
} else if (ast instanceof SQLDeleteStatement) {
recognizer = new OracleDeleteRecognizer(sql, ast);
} else if (ast instanceof SQLSelectStatement) {
if (((SQLSelectStatement) ast).getSelect().getQueryBlock().isForUpdate()) {
recognizer = new OracleSelectForUpdateRecognizer(sql, ast);
}
}
}else {
throw new UnsupportedOperationException("Just support MySQL by now!");
}
return recognizer;
Expand Down