mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -37,6 +37,7 @@ import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.locks.Condition;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
@@ -247,6 +248,7 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
private boolean asyncCloseConnectionEnable = false;
|
||||
protected int maxCreateTaskCount = 3;
|
||||
protected boolean failFast = false;
|
||||
protected AtomicBoolean failContinuous = new AtomicBoolean(false);
|
||||
protected ScheduledExecutorService destroyScheduler;
|
||||
protected ScheduledExecutorService createScheduler;
|
||||
|
||||
@@ -1516,6 +1518,10 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
protected void setFailContinuous(boolean fail) {
|
||||
failContinuous.set(fail);
|
||||
}
|
||||
|
||||
public void initPhysicalConnection(Connection conn) throws SQLException {
|
||||
if (conn.getAutoCommit() != defaultAutoCommit) {
|
||||
|
||||
@@ -1509,7 +1509,7 @@ public class DruidDataSource extends DruidAbstractDataSource
|
||||
while (poolingCount == 0) {
|
||||
emptySignal(); // send signal to CreateThread create connection
|
||||
|
||||
if (failFast && createError != null) {
|
||||
if (failFast && failContinuous.get()) {
|
||||
throw new DataSourceNotAvailableException(createError);
|
||||
}
|
||||
|
||||
@@ -1549,7 +1549,7 @@ public class DruidDataSource extends DruidAbstractDataSource
|
||||
if (poolingCount == 0) {
|
||||
emptySignal(); // send signal to CreateThread create connection
|
||||
|
||||
if (failFast && createError != null) {
|
||||
if (failFast && failContinuous.get()) {
|
||||
throw new DataSourceNotAvailableException(createError);
|
||||
}
|
||||
|
||||
@@ -1885,21 +1885,23 @@ public class DruidDataSource extends DruidAbstractDataSource
|
||||
|
||||
try {
|
||||
physicalConnection = createPhysicalConnection();
|
||||
setFailContinuous(false);
|
||||
} catch (SQLException e) {
|
||||
LOG.error("create connection error, url: " + jdbcUrl, e);
|
||||
|
||||
errorCount++;
|
||||
|
||||
if (failFast) {
|
||||
lock.lock();
|
||||
try {
|
||||
notEmpty.signalAll();
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
if (errorCount > connectionErrorRetryAttempts && timeBetweenConnectErrorMillis > 0) {
|
||||
// fail over retry attempts
|
||||
setFailContinuous(true);
|
||||
if (failFast) {
|
||||
lock.lock();
|
||||
try {
|
||||
notEmpty.signalAll();
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
if (breakAfterAcquireFailure) {
|
||||
lock.lock();
|
||||
try {
|
||||
@@ -1916,6 +1918,8 @@ public class DruidDataSource extends DruidAbstractDataSource
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
LOG.error("create connection error", e);
|
||||
// unknow fatal exception
|
||||
setFailContinuous(true);
|
||||
continue;
|
||||
} catch (Error e) {
|
||||
lock.lock();
|
||||
@@ -1925,6 +1929,8 @@ public class DruidDataSource extends DruidAbstractDataSource
|
||||
lock.unlock();
|
||||
}
|
||||
LOG.error("create connection error", e);
|
||||
// unknow fatal exception
|
||||
setFailContinuous(true);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1993,21 +1999,23 @@ public class DruidDataSource extends DruidAbstractDataSource
|
||||
|
||||
try {
|
||||
connection = createPhysicalConnection();
|
||||
setFailContinuous(false);
|
||||
} catch (SQLException e) {
|
||||
LOG.error("create connection error, url: " + jdbcUrl + ", errorCode " + e.getErrorCode() + ", state " + e.getSQLState(), e);
|
||||
|
||||
errorCount++;
|
||||
|
||||
if (failFast) {
|
||||
lock.lock();
|
||||
try {
|
||||
notEmpty.signalAll();
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
if (errorCount > connectionErrorRetryAttempts && timeBetweenConnectErrorMillis > 0) {
|
||||
// fail over retry attempts
|
||||
setFailContinuous(true);
|
||||
if (failFast) {
|
||||
lock.lock();
|
||||
try {
|
||||
notEmpty.signalAll();
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
if (breakAfterAcquireFailure) {
|
||||
break;
|
||||
}
|
||||
@@ -2020,9 +2028,11 @@ public class DruidDataSource extends DruidAbstractDataSource
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
LOG.error("create connection error", e);
|
||||
setFailContinuous(true);
|
||||
continue;
|
||||
} catch (Error e) {
|
||||
LOG.error("create connection error", e);
|
||||
setFailContinuous(true);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
+33
-13
@@ -2442,23 +2442,43 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
stmt.addItem(item);
|
||||
} else if (identifierEquals("MODIFY")) {
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.token() == Token.COLUMN) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
MySqlAlterTableModifyColumn item = new MySqlAlterTableModifyColumn();
|
||||
item.setNewColumnDefinition(this.exprParser.parseColumn());
|
||||
if (identifierEquals("AFTER")) {
|
||||
lexer.nextToken();
|
||||
item.setAfterColumn(this.exprParser.name());
|
||||
} else if (identifierEquals("FIRST")) {
|
||||
lexer.nextToken();
|
||||
if (lexer.token() == Token.IDENTIFIER) {
|
||||
item.setFirstColumn(this.exprParser.name());
|
||||
} else {
|
||||
item.setFirst(true);
|
||||
}
|
||||
|
||||
boolean paren = false;
|
||||
if (lexer.token() == Token.LPAREN) {
|
||||
paren = true;
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
MySqlAlterTableModifyColumn item = new MySqlAlterTableModifyColumn();
|
||||
item.setNewColumnDefinition(this.exprParser.parseColumn());
|
||||
if (identifierEquals("AFTER")) {
|
||||
lexer.nextToken();
|
||||
item.setAfterColumn(this.exprParser.name());
|
||||
} else if (identifierEquals("FIRST")) {
|
||||
lexer.nextToken();
|
||||
if (lexer.token() == Token.IDENTIFIER) {
|
||||
item.setFirstColumn(this.exprParser.name());
|
||||
} else {
|
||||
item.setFirst(true);
|
||||
}
|
||||
}
|
||||
stmt.addItem(item);
|
||||
|
||||
if (paren && lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (paren) {
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
stmt.addItem(item);
|
||||
} else if (lexer.token() == Token.DISABLE) {
|
||||
lexer.nextToken();
|
||||
|
||||
|
||||
@@ -299,8 +299,12 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
|
||||
public boolean visit(SQLColumnDefinition x) {
|
||||
x.getName().accept(this);
|
||||
print(' ');
|
||||
x.getDataType().accept(this);
|
||||
|
||||
SQLDataType dataType = x.getDataType();
|
||||
if (dataType != null) {
|
||||
print(' ');
|
||||
dataType.accept(this);
|
||||
}
|
||||
|
||||
if (x.getCharsetExpr() != null) {
|
||||
print0(ucase ? " CHARSET " : " charset ");
|
||||
|
||||
Reference in New Issue
Block a user