Skip to content
This repository has been archived by the owner on Jun 7, 2021. It is now read-only.

[TRAFODION-3280] Reduce path length in Trafodion for improved performance and scalability #1824

Merged
merged 10 commits into from Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -60,6 +60,10 @@ class InputOutput {
// socket
// factory

// This is minimum time the socket read and write will wait
// All other timeouts will be multiple of this timeout
private int m_networkTimeout;

static {
try {
String factStr = System.getProperty("t4jdbc.socketFactoryClass");
Expand Down Expand Up @@ -118,6 +122,10 @@ void setConnectionIdleTimeout(int timeout) {
m_connectionIdleTimeout = timeout;
}

void setNetworkTimeout(int timeout) {
m_networkTimeout = timeout;
}

String getRemoteHost() {
return this.m_addr.getIPorName();
}
Expand Down Expand Up @@ -161,7 +169,10 @@ synchronized void openIO() throws SQLException {
// can immediately
// reused if connection
// is lost.
m_socket.setSoTimeout(0);
//Set the network timeout to be at least 10 seconds
if (m_networkTimeout == 0)
m_networkTimeout = 10;
m_socket.setSoTimeout(m_networkTimeout * 1000);
// disable/enable Nagle's algorithm
m_socket.setTcpNoDelay(this.m_addr.m_t4props.getTcpNoDelay());
//
Expand Down Expand Up @@ -271,7 +282,6 @@ synchronized void openIO() throws SQLException {
//
// If m_socket is not null, then we will assume it is already open.
//

} // end openIO

// ----------------------------------------------------------
Expand Down Expand Up @@ -570,36 +580,43 @@ void send_nblk(byte[] buf, int offset, int len) throws SQLException {
// ----------------------------------------------------------
int recv_nblk(byte[] buf, int offset) throws SQLException {
int num_read = 0;

boolean retry = false;

do {
try {
m_socket.setSoTimeout(m_timeout * 1000);

num_read = m_is.read(buf, offset, buf.length - offset);

// if the socket.read returns -1 then return 0 instead of -1
if (num_read < 0) {
num_read = 0;
}
m_socket.setSoTimeout(0); // set timeout back to infinite
retry = false;

boolean innerRetry = true;
int pendingTimeout = m_timeout;
if (pendingTimeout == 0)
pendingTimeout = Integer.MAX_VALUE;
do {
try {
num_read = m_is.read(buf, offset, buf.length - offset);
// if the socket.read returns -1 then return 0 instead of -1
if (num_read < 0)
num_read = 0;
innerRetry = false;
retry = false;
}
catch (SocketTimeoutException ste) {
pendingTimeout -= m_networkTimeout;
if (pendingTimeout < 0) {
innerRetry = false;
throw ste;
}
}
} while (innerRetry);
} catch (SocketTimeoutException ste) {
// the first exception should try to cancel and wait for the cancel message from the server
if(retry == false) {
if (retry == false) {
this.m_t4conn.m_ic.cancel();
retry = true;
continue;
}
}

// if cancel didnt work the first time, clean everything up
try {
m_socket.close();
this.m_t4conn.m_ic.setIsClosed(true);
this.m_t4conn.m_ic.cancel();

throw ste;
} catch (Exception e) {
SQLException se = TrafT4Messages
Expand All @@ -609,13 +626,12 @@ int recv_nblk(byte[] buf, int offset) throws SQLException {
}
} catch (Exception e) {
SQLException se = TrafT4Messages.createSQLException(null, m_locale, "socket_read_error", e.getMessage());

se.initCause(e);
throw se;
} finally {
resetTimedOutConnection();
}
}while(retry);
} while(retry);

return num_read;
} // recv_nblk
Expand Down
Expand Up @@ -41,6 +41,7 @@
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.util.Hashtable;
import java.util.HashMap;
import java.util.Locale;
import java.util.Properties;
import java.util.logging.Handler;
Expand Down Expand Up @@ -84,8 +85,8 @@ class InterfaceConnection {
T4Properties t4props_;
SQLWarning sqlwarning_;

Hashtable encoders = new Hashtable(11);
Hashtable decoders = new Hashtable(11);
HashMap encoders = new HashMap(11);
HashMap decoders = new HashMap(11);

// static fields from odbc_common.h and sql.h
static final int SQL_TXN_READ_UNCOMMITTED = 1;
Expand Down Expand Up @@ -1245,16 +1246,13 @@ void close() throws SQLException {

void endTransaction(short commitOption) throws SQLException {
EndTransactionReply etr_ = null;
if (autoCommit && !_t4Conn.isBeginTransaction()) {
if (autoCommit) {
throw TrafT4Messages.createSQLException(t4props_, locale, "invalid_commit_mode", null);
}

isConnectionOpen();
// XA_RESUMETRANSACTION();

try {
etr_ = t4connection_.EndTransaction(commitOption);
_t4Conn.setBeginTransaction(false);
} catch (SQLException tex) {
if (t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
Object p[] = T4LoggingUtilities.makeParams(t4props_, commitOption);
Expand Down