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

Commit d1bc87a

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

3 files changed

Lines changed: 87 additions & 49 deletions

File tree

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

Lines changed: 51 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,52 @@ 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+
fetchSize_ = (int) Math.ceil(FETCH_BYTES_LIMIT / (double) rowLength);
3021+
LOG.trace("Fetch size exceed limit, change it to <{}>.", fetchSize_);
3022+
}
3023+
}
3024+
}
30043025

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

dcs/src/test/jdbc_test/pom.xml.template

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,23 @@
6464
<scope>system</scope>
6565
<systemPath>MY_JDBC_SYS_PATH</systemPath>
6666
</dependency>
67+
<dependency>
68+
<groupId>org.slf4j</groupId>
69+
<artifactId>slf4j-api</artifactId>
70+
<version>1.7.5</version>
71+
<scope>test</scope>
72+
<exclusions>
73+
<exclusion>
74+
<groupId>*</groupId>
75+
<artifactId>*</artifactId>
76+
</exclusion>
77+
</exclusions>
78+
</dependency>
79+
<dependency>
80+
<groupId>org.slf4j</groupId>
81+
<artifactId>slf4j-log4j12</artifactId>
82+
<version>1.7.5</version>
83+
<scope>test</scope>
84+
</dependency>
6785
</dependencies>
6886
</project>

tests/phx/pom.xml.template

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -174,24 +174,6 @@
174174
</exclusion>
175175
</exclusions>
176176
</dependency>
177-
<dependency>
178-
<groupId>org.slf4j</groupId>
179-
<artifactId>slf4j-api</artifactId>
180-
<version>1.7.5</version>
181-
<scope>test</scope>
182-
<exclusions>
183-
<exclusion>
184-
<groupId>*</groupId>
185-
<artifactId>*</artifactId>
186-
</exclusion>
187-
</exclusions>
188-
</dependency>
189-
<dependency>
190-
<groupId>org.slf4j</groupId>
191-
<artifactId>slf4j-log4j12</artifactId>
192-
<version>1.7.5</version>
193-
<scope>test</scope>
194-
</dependency>
195177

196178
<!-- Trafodion specific test dependencies -->
197179

@@ -247,7 +229,24 @@
247229
<version>2.6</version>
248230
<scope>test</scope>
249231
</dependency>
250-
232+
<dependency>
233+
<groupId>org.slf4j</groupId>
234+
<artifactId>slf4j-api</artifactId>
235+
<version>1.7.5</version>
236+
<scope>test</scope>
237+
<exclusions>
238+
<exclusion>
239+
<groupId>*</groupId>
240+
<artifactId>*</artifactId>
241+
</exclusion>
242+
</exclusions>
243+
</dependency>
244+
<dependency>
245+
<groupId>org.slf4j</groupId>
246+
<artifactId>slf4j-log4j12</artifactId>
247+
<version>1.7.5</version>
248+
<scope>test</scope>
249+
</dependency>
251250
</dependencies>
252251

253252
<build>

0 commit comments

Comments
 (0)