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

Commit

Permalink
[TRAFODION-3183] fetch huge data give rise to core
Browse files Browse the repository at this point in the history
  • Loading branch information
Aven committed Dec 24, 2018
1 parent 923f0a9 commit baa12a5
Showing 1 changed file with 52 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,16 @@
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

// ----------------------------------------------------------------------------
// This class partially implements the result set class as defined in
// java.sql.ResultSet.
// ----------------------------------------------------------------------------
public class TrafT4ResultSet extends TrafT4Handle implements java.sql.ResultSet {

private static final Logger LOG = LoggerFactory.getLogger(TrafT4ResultSet.class);
private static final long FETCH_BYTES_LIMIT = 1024 * 1024 * 1024;
// java.sql.ResultSet interface methods
public boolean absolute(int row) throws SQLException {
if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) {
Expand Down Expand Up @@ -2772,7 +2775,7 @@ public boolean next() throws SQLException {
maxRows = 0;
queryTimeout = 0;
}

setFetchSizeIfExceedLimit();
if (maxRows == 0 || maxRows > totalRowsFetched_ + fetchSize_) {
maxRowCnt = fetchSize_;
} else {
Expand Down Expand Up @@ -2973,34 +2976,53 @@ public void setFetchDirection(int direction) throws SQLException {
}
}

public void setFetchSize(int rows) throws SQLException {
if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) {
Object p[] = T4LoggingUtilities.makeParams(connection_.props_, rows);
connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4ResultSet", "setFetchSize", "", p);
}
if (connection_.props_.getLogWriter() != null) {
LogRecord lr = new LogRecord(Level.FINE, "");
Object p[] = T4LoggingUtilities.makeParams(connection_.props_, rows);
lr.setParameters(p);
lr.setSourceClassName("TrafT4ResultSet");
lr.setSourceMethodName("setFetchSize");
T4LogFormatter lf = new T4LogFormatter();
String temp = lf.format(lr);
connection_.props_.getLogWriter().println(temp);
}
if (isClosed_) {
throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_cursor_state",
null);
}
if (rows < 0) {
throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_fetch_size",
null);
} else if (rows == 0) {
fetchSize_ = DEFAULT_FETCH_SIZE;
} else {
fetchSize_ = rows;
}
}
public void setFetchSize(int rows) throws SQLException {
if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) {
Object p[] = T4LoggingUtilities.makeParams(connection_.props_, rows);
connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4ResultSet", "setFetchSize", "", p);
}
if (connection_.props_.getLogWriter() != null) {
LogRecord lr = new LogRecord(Level.FINE, "");
Object p[] = T4LoggingUtilities.makeParams(connection_.props_, rows);
lr.setParameters(p);
lr.setSourceClassName("TrafT4ResultSet");
lr.setSourceMethodName("setFetchSize");
T4LogFormatter lf = new T4LogFormatter();
String temp = lf.format(lr);
connection_.props_.getLogWriter().println(temp);
}
if (isClosed_) {
throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(),
"invalid_cursor_state", null);
}
if (rows < 0) {
throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(),
"invalid_fetch_size", null);
} else if (rows == 0) {
fetchSize_ = DEFAULT_FETCH_SIZE;
} else {
fetchSize_ = rows;
}

setFetchSizeIfExceedLimit();
}

/**
* if (row width) * (fetch rows) too large, there will have core in server side. once fetch
* bytes bigger than 1GB, divide it into several times to fetch, each time fetch bytes less than
* 1GB.
*/
private void setFetchSizeIfExceedLimit() {
if (outputDesc_ != null && outputDesc_[0] != null) {
long rowLength = outputDesc_[0].rowLength_;
long fetchBytes = rowLength * fetchSize_;
if (fetchBytes >= FETCH_BYTES_LIMIT) {
double multi = Math.ceil(fetchBytes / (double) FETCH_BYTES_LIMIT); // divide to several times to fetch
fetchSize_ = (int) (fetchSize_ / multi);
LOG.trace("fetch size <{}> exceed limit, change it to <{}>.", fetchSize_, fetchSize_);
}
}
}

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

0 comments on commit baa12a5

Please sign in to comment.