Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/expirate records: tablename and max selected records at one #2281

Merged
merged 10 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
- [cygnus-ngsi] Removes "_" in schema name for DM -schema family (#2270, #2201 reopens for Postgis)

- [cygnus-common][SQL] Fix expiration records tablename used by delete and select (#2265)
- [cygnus-common][SQL] Fix expiraton records select with a limit to avoid java out of memory error (#2273)
- [cygnus-ngsi] Removes "_" in schema name for DM -schema family (#2270, #2201 reopens for Postgis)
fgalan marked this conversation as resolved.
Show resolved Hide resolved

Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class SQLBackendImpl implements SQLBackend{
private final int maxLatestErrors;
private static final String DEFAULT_ERROR_TABLE_SUFFIX = "_error_log";
private static final int DEFAULT_MAX_LATEST_ERRORS = 100;
private static final String DEFAULT_LIMIT_SELECT_EXP_RECORDS = "4096";
private String nlsTimestampFormat;
private String nlsTimestampTzFormat;

Expand Down Expand Up @@ -308,14 +309,14 @@ private CachedRowSet select(String dataBase, String schema, String tableName, St
Connection con = driver.getConnection(dataBase);
String query = "";
if (sqlInstance == SQLInstance.MYSQL) {
query = "select " + selection + " from `" + tableName + "` order by recvTime";
query = "select " + selection + " from `" + tableName + "` order by recvTime desc limit " + DEFAULT_LIMIT_SELECT_EXP_RECORDS;
} else if (sqlInstance == SQLInstance.POSTGRESQL) {
if (schema != null) {
if (schema != null && (!tableName.startsWith(schema))) {
tableName = schema + '.' + tableName;
}
query = "select " + selection + " from " + tableName + " order by recvTime";
query = "select " + selection + " from " + tableName + " order by recvTime desc limit " + DEFAULT_LIMIT_SELECT_EXP_RECORDS;
} else {
query = "select " + selection + " from " + tableName + " order by recvTime";
query = "select " + selection + " from " + tableName + " order by recvTime desc limit " + DEFAULT_LIMIT_SELECT_EXP_RECORDS;
}

try {
Expand All @@ -336,6 +337,7 @@ private CachedRowSet select(String dataBase, String schema, String tableName, St
CachedRowSet crs = new CachedRowSetImpl();
crs.populate(rs); // FIXME: close Resultset Objects??
closeSQLObjects(con, stmt);
rs.close();
return crs;
} catch (SQLTimeoutException e) {
throw new CygnusPersistenceError(sqlInstance.toString().toUpperCase() + " Data select error. Query " + query, "SQLTimeoutException", e.getMessage());
Expand All @@ -356,7 +358,7 @@ private void delete(String dataBase, String schema, String tableName, String fil
if (sqlInstance == SQLInstance.MYSQL) {
query = "delete from `" + tableName + "` where " + filters;
} else if (sqlInstance == SQLInstance.POSTGRESQL) {
if (schema != null) {
if (schema != null && (!tableName.startsWith(schema))) {
tableName = schema + '.' + tableName;
}
query = "delete from " + tableName + " where " + filters;
Expand All @@ -376,7 +378,7 @@ private void delete(String dataBase, String schema, String tableName, String fil
stmt.executeUpdate(query);
} catch (SQLTimeoutException e) {
throw new CygnusPersistenceError(sqlInstance.toString().toUpperCase() + " Data delete error. Query " + query, "SQLTimeoutException", e.getMessage());
}catch (SQLException e) {
} catch (SQLException e) {
closeSQLObjects(con, stmt);
persistError(dataBase, schema, query, e);
throw new CygnusPersistenceError(sqlInstance.toString().toUpperCase() + " Deleting error", "SQLException", e.getMessage());
Expand Down
Loading