-
Notifications
You must be signed in to change notification settings - Fork 425
OAK-11967: RDBDocumentStore: code cleanup #2555
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
base: trunk
Are you sure you want to change the base?
Conversation
|
joerghoh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a lot of minor nits, which I think the code could benefit from, mostly when it comes to readability.
+1 for the rest
| + (isolation < Connection.TRANSACTION_READ_COMMITTED ? "lower" : "higher") + " than expected " | ||
| + RDBJDBCTools.isolationLevelToString(Connection.TRANSACTION_READ_COMMITTED) | ||
| + " - check datasource configuration"); | ||
| LOG.info("Detected transaction isolation level {} is {} than expected {} - check datasource configuration", isolationDiags, isolation < Connection.TRANSACTION_READ_COMMITTED ? "lower" : "higher", RDBJDBCTools.isolationLevelToString(Connection.TRANSACTION_READ_COMMITTED)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mixing the the simple varag parameters with the ternary expression in a single line? I would split it up into multiple lines, so it's more readable.
| LOG.info("RDBBlobStore (" + getModuleVersion() + ") instantiated for database " + dbDesc + ", using driver: " | ||
| + driverDesc + ", connecting to: " + dbUrl + (diag.isEmpty() ? "" : (", properties: " + diag.toString())) | ||
| + ", transaction isolation level: " + isolationDiags + ", " + tableInfo); | ||
| LOG.info("RDBBlobStore ({}) instantiated for database {}, using driver: {}, connecting to: {}{}, transaction isolation level: {}, {}", getModuleVersion(), dbDesc, driverDesc, dbUrl, diag.isEmpty() ? "" : (", properties: " + diag), isolationDiags, tableInfo); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so above
| // the meta is YOUNGER than x | ||
| dataStatement.append(" and not exists(select * from " + this.tnMeta + " where " + this.tnMeta + ".ID = " | ||
| + this.tnData + ".ID and LASTMOD > ?)"); | ||
| dataStatement.append(" and not exists(select * from ").append(this.tnMeta).append(" where ").append(this.tnMeta).append(".ID = ").append(this.tnData).append(".ID and LASTMOD > ?)"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahhh, don't know. That StringBuilder makes it much harder to understand. Personally I would prefer a String.format() approach, but I would be fine, if you just add some newlines into this statement.
| long elapsed = System.currentTimeMillis() - ts; | ||
| if (elapsed >= 20) { | ||
| LOG.debug("Obtaining a new connection from " + this.ds + " took " + elapsed + "ms", new Exception("call stack")); | ||
| LOG.debug("Obtaining a new connection from {} took {}ms", this.ds, elapsed, new Exception("call stack")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case this code line is reached and the loglevel is not set to DEBUG, the exception is created (expensive!) but not used. I would guard this debug statement here, so the exception is only created when the log statement is actually printed.
| LOG.debug("Obtaining a new connection from {} took {}ms", this.ds, elapsed, new Exception("call stack")); | |
| if (LOG.isDebugEnabled()) { | |
| LOG.debug("Obtaining a new connection from {} took {}ms", this.ds, elapsed, new Exception("call stack")); | |
| } |
| } catch (SQLException ex) { | ||
| LOG.error("Connection class " + c.getClass() | ||
| + " erroneously throws SQLException on setReadOnly(false); not trying again"); | ||
| LOG.error("Connection class {} erroneously throws SQLException on setReadOnly(false); not trying again", c.getClass()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it make sense to log ex.getMessage() as well to give some more diagnostics?
| if (oldDoc == null) { | ||
| // document was there but is now gone | ||
| LOG.debug("failed to apply update because document is gone in the meantime: " + update.getId(), new Exception("call stack")); | ||
| LOG.debug("failed to apply update because document is gone in the meantime: {}", update.getId(), new Exception("call stack")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should guard this log statement also with a check if the DEBUG log is enabled, otherweise we create the exception object without using it.
| int[] batchResults = new int[0]; | ||
|
|
||
| PreparedStatement stmt = connection.prepareStatement("update " + tmd.getName() | ||
| String statement = "update " + tmd.getName() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that is very hard to read ... would a String.format(...) help here?
| if (maj < dbmax || (maj == dbmax && min < dbmin)) { | ||
| result.append( | ||
| "Unsupported " + dbname + " version: " + maj + "." + min + ", expected at least " + dbmax + "." + dbmin); | ||
| result.append("Unsupported ").append(dbname).append(" version: ").append(maj).append(".").append(min).append(", expected at least ").append(dbmax).append(".").append(dbmin); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| result.append("Unsupported ").append(dbname).append(" version: ").append(maj).append(".").append(min).append(", expected at least ").append(dbmax).append(".").append(dbmin); | |
| result.append("Unsupported ").append(dbname) | |
| .append(" version: ").append(maj).append(".").append(min) | |
| .append(", expected at least ").append(dbmax).append(".").append(dbmin); |
| } | ||
| result.append("Unsupported " + dbname + " driver version: " + md.getDriverName() + " " + maj + "." + min | ||
| + ", expected at least " + drmax + "." + drmin); | ||
| result.append("Unsupported ").append(dbname).append(" driver version: ").append(md.getDriverName()).append(" ").append(maj).append(".").append(min).append(", expected at least ").append(drmax).append(".").append(drmin); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| result.append("Unsupported ").append(dbname).append(" driver version: ").append(md.getDriverName()).append(" ").append(maj).append(".").append(min).append(", expected at least ").append(drmax).append(".").append(drmin); | |
| result.append("Unsupported ").append(dbname) | |
| .append(" driver version: ").append(md.getDriverName()) | |
| .append(" ").append(maj).append(".").append(min) | |
| .append(", expected at least ").append(drmax).append(".").append(drmin); |
| return String.format("Strategy for %s set to %s (via system property %s)", RDBMissingLastRevSeeker.class.getName(), | ||
| name, value); | ||
| }).get(); | ||
| .loggingTo(LOG).validateWith(value -> (value == 1 || value == 2)).formatSetMessage((name, value) -> String.format("Strategy for %s set to %s (via system property %s)", RDBMissingLastRevSeeker.class.getName(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hard to understand ... maybe some more newlines?


No description provided.