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

Commit baa12a5

Browse files
author
Aven
committed
[TRAFODION-3183] fetch huge data give rise to core
1 parent 923f0a9 commit baa12a5

1 file changed

Lines changed: 52 additions & 30 deletions

File tree

core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4ResultSet.java

Lines changed: 52 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,16 @@
5555
import java.util.Map;
5656
import java.util.logging.Level;
5757
import java.util.logging.LogRecord;
58+
import org.slf4j.Logger;
59+
import org.slf4j.LoggerFactory;
5860

5961
// ----------------------------------------------------------------------------
6062
// This class partially implements the result set class as defined in
6163
// java.sql.ResultSet.
6264
// ----------------------------------------------------------------------------
6365
public class TrafT4ResultSet extends TrafT4Handle implements java.sql.ResultSet {
64-
66+
private static final Logger LOG = LoggerFactory.getLogger(TrafT4ResultSet.class);
67+
private static final long FETCH_BYTES_LIMIT = 1024 * 1024 * 1024;
6568
// java.sql.ResultSet interface methods
6669
public boolean absolute(int row) throws SQLException {
6770
if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) {
@@ -2772,7 +2775,7 @@ public boolean next() throws SQLException {
27722775
maxRows = 0;
27732776
queryTimeout = 0;
27742777
}
2775-
2778+
setFetchSizeIfExceedLimit();
27762779
if (maxRows == 0 || maxRows > totalRowsFetched_ + fetchSize_) {
27772780
maxRowCnt = fetchSize_;
27782781
} else {
@@ -2973,34 +2976,53 @@ public void setFetchDirection(int direction) throws SQLException {
29732976
}
29742977
}
29752978

2976-
public void setFetchSize(int rows) throws SQLException {
2977-
if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) {
2978-
Object p[] = T4LoggingUtilities.makeParams(connection_.props_, rows);
2979-
connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4ResultSet", "setFetchSize", "", p);
2980-
}
2981-
if (connection_.props_.getLogWriter() != null) {
2982-
LogRecord lr = new LogRecord(Level.FINE, "");
2983-
Object p[] = T4LoggingUtilities.makeParams(connection_.props_, rows);
2984-
lr.setParameters(p);
2985-
lr.setSourceClassName("TrafT4ResultSet");
2986-
lr.setSourceMethodName("setFetchSize");
2987-
T4LogFormatter lf = new T4LogFormatter();
2988-
String temp = lf.format(lr);
2989-
connection_.props_.getLogWriter().println(temp);
2990-
}
2991-
if (isClosed_) {
2992-
throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_cursor_state",
2993-
null);
2994-
}
2995-
if (rows < 0) {
2996-
throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_fetch_size",
2997-
null);
2998-
} else if (rows == 0) {
2999-
fetchSize_ = DEFAULT_FETCH_SIZE;
3000-
} else {
3001-
fetchSize_ = rows;
3002-
}
3003-
}
2979+
public void setFetchSize(int rows) throws SQLException {
2980+
if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) {
2981+
Object p[] = T4LoggingUtilities.makeParams(connection_.props_, rows);
2982+
connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4ResultSet", "setFetchSize", "", p);
2983+
}
2984+
if (connection_.props_.getLogWriter() != null) {
2985+
LogRecord lr = new LogRecord(Level.FINE, "");
2986+
Object p[] = T4LoggingUtilities.makeParams(connection_.props_, rows);
2987+
lr.setParameters(p);
2988+
lr.setSourceClassName("TrafT4ResultSet");
2989+
lr.setSourceMethodName("setFetchSize");
2990+
T4LogFormatter lf = new T4LogFormatter();
2991+
String temp = lf.format(lr);
2992+
connection_.props_.getLogWriter().println(temp);
2993+
}
2994+
if (isClosed_) {
2995+
throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(),
2996+
"invalid_cursor_state", null);
2997+
}
2998+
if (rows < 0) {
2999+
throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(),
3000+
"invalid_fetch_size", null);
3001+
} else if (rows == 0) {
3002+
fetchSize_ = DEFAULT_FETCH_SIZE;
3003+
} else {
3004+
fetchSize_ = rows;
3005+
}
3006+
3007+
setFetchSizeIfExceedLimit();
3008+
}
3009+
3010+
/**
3011+
* if (row width) * (fetch rows) too large, there will have core in server side. once fetch
3012+
* bytes bigger than 1GB, divide it into several times to fetch, each time fetch bytes less than
3013+
* 1GB.
3014+
*/
3015+
private void setFetchSizeIfExceedLimit() {
3016+
if (outputDesc_ != null && outputDesc_[0] != null) {
3017+
long rowLength = outputDesc_[0].rowLength_;
3018+
long fetchBytes = rowLength * fetchSize_;
3019+
if (fetchBytes >= FETCH_BYTES_LIMIT) {
3020+
double multi = Math.ceil(fetchBytes / (double) FETCH_BYTES_LIMIT); // divide to several times to fetch
3021+
fetchSize_ = (int) (fetchSize_ / multi);
3022+
LOG.trace("fetch size <{}> exceed limit, change it to <{}>.", fetchSize_, fetchSize_);
3023+
}
3024+
}
3025+
}
30043026

30053027
public void updateArray(int columnIndex, Array x) throws SQLException {
30063028
if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) {

0 commit comments

Comments
 (0)