Bug #10111
All statements are logged to a single text file for P2JQueryLogger and SQLStatementLogger
100%
History
#1 Updated by Andrei Plugaru about 1 year ago
While using SQLStatementLogger for multiple databases, I discovered that all the statements are logged to a single file. The culprit for this is SQLStatementLoggerConfiguration.fileLogger which is kept static. fileLogger is assigned in the constructor, so this means that everytime the constructor is called, that class member is reassigned. As a result, the file logger associated for the last called database will be used for all the databases.
The solution is quite simple: just remove the static keyword in SQLStatementLoggerConfiguration. However, this pattern seems to be used also for P2JQueryLogger, in P2JQueryStatisticsConfiguration, fileLogger is also a static variable.
I will make this simple changes and commit them.
#2 Updated by Andrei Plugaru about 1 year ago
- Status changed from New to WIP
#3 Updated by Andrei Plugaru about 1 year ago
- Status changed from WIP to Review
- reviewer Constantin Asofiei, Ovidiu Maxiniuc added
Committed 10111a/15978. The changes are quite simple: just removing the static keyword for fileLogger in SQLStatementLoggerConfiguration and P2JQueryStatisticsConfiguration.
Ovidiu/Constantin, can, any of you, please take a look over the changes?
#4 Updated by Ovidiu Maxiniuc about 1 year ago
Review of 10111a/15978.
The changes are logical. The reason is explained in 1st note above. Good catch!
The commit log is missing the task's #refid.
- (possible NPE): please add the following change in
P2JQueryLogger.java: insert at line 133 areturnstatement after printing thenullquerynotification. Probably this will not be the case, but if it is, a NPE will occur if execution continue; - (performance issue): in
SQLStatementLogger.log(), whereSQLStatementLoggerConfiguration.getFileLogger()is called: thesbis ALWAYS computed and only at the endfileLogger != nullis tested. This should be done first andsbwill not be constructed if true. Also, line 187 should be rewritten with.append()instead of concatenation. Similar forP2JQueryLogger.log(): the file is checked only after callingprintResultwithsbalready constructed. - (code duplication): the
P2JQueryStatisticsConfigurationandSQLStatementLoggerConfigurationare 95% identical.
#5 Updated by Andrei Plugaru about 1 year ago
- Status changed from Review to WIP
Addressed the 1st and 2nd point in 10111a/15979.
For the 3rd, I am thinking of creating a super class for those 2 and having the common logic there.
#6 Updated by Andrei Plugaru about 1 year ago
I have committed in 10111a/15980 the main refactor for having the common logic from P2JQueryStatisticsConfiguration and SQLStatementLoggerConfiguration in a super class: BaseLoggingConfiguration. However, while doing this, I also realised that SQLLoggingDatabaseHelper and P2JLoggingDatabaseHelper can also be refactored by following the same pattern. So, I will continue with this.
#7 Updated by Andrei Plugaru about 1 year ago
- reviewer deleted (
Constantin Asofiei)
Main changes:
10111a/15982: Moved the common logic fromP2JLoggingDatabaseHelperandSQLLoggingDatabaseHelperinto the abstract classBaseLoggingDatabaseHelper.10111a/15983: Added all the necessary javadocs and history entries.
Ovidiu, please take a look!
#8 Updated by Ovidiu Maxiniuc about 1 year ago
Review of 10111a/r15983
First, why in revno: 15983 the files: src/com/goldencode/p2j/persist/BaseLoggingConfiguration.java and src/com/goldencode/p2j/persist/orm/BaseLoggingDatabaseHelper.java were removed? They seem to be used and although I did not build the project, doing so will certainly fail. I think you can use
bzr revert src/com/goldencode/p2j/persist/BaseLoggingConfiguration.java src/com/goldencode/p2j/persist/orm/BaseLoggingDatabaseHelper.java -r15982to get the last revision and continue to work on them linked in bzr (possible to preserve their history in
bzr). I did revert them from previous revision and included in the below review.
I appreciate the effort to create the new class hierarchies (helpers and configuration) for avoiding the code duplication and specific implementation for each logger type.
BaseLoggingConfiguration, (missing):- this file seems to be in progress. The file header is missing as well as the javadoc for several methods (
initializeLoggers(),loadSpecificDirectoryConfiguration()andcreateDbHelper()). Some indentations (both for parameters and javadoc) should be adjusted; - in
getConfigurationPath()method please move initalization ofglobalPathinsideelsebranch andlocalEnabledintoifblock (it can be inlined);
- this file seems to be in progress. The file header is missing as well as the javadoc for several methods (
P2JQueryStatisticsConfiguration- the access to static
getConfiguration()should also synchronised. getLoggingType()does not have the@Overrideannotation, but it is really identical to its parent so it can be dropped, andloggingTypemadeprivate;- line 13: the secong H entry does not need a new number;
- the access to static
SQLStatementLoggerConfigurationLoggingTypeenum is not used (was move to base class)- static
getConfiguration()should be synchronised;
BaseLoggingDatabaseHelper, (missing):- this file seems to inherit the header from
SQLLoggingDatabaseHelper. Please update it with necessary information; - multiple indentations are broken compared to original file;
dbHelpersfield map does not seem to be used;
- this file seems to inherit the header from
P2JLoggingDatabaseHelper- please indent the string concatenations at lines 154 and 179;
- in the static factory
getDbHelper()method, the access todbHelpersshould be synchronised.
SQLLoggingDatabaseHelper- please indent the string concatenations at lines 145 and 166;
- in the static factory
getDbHelper()method, the access todbHelpersshould be synchronised.
P2JQueryLogger.javaandSQLStatementLogger.java- copyright year needs update
#9 Updated by Andrei Plugaru about 1 year ago
Ovidiu Maxiniuc wrote:
Review of 10111a/r15983
First, why in revno: 15983 the files:
src/com/goldencode/p2j/persist/BaseLoggingConfiguration.javaandsrc/com/goldencode/p2j/persist/orm/BaseLoggingDatabaseHelper.javawere removed? They seem to be used and although I did not build the project, doing so will certainly fail. I think you can use[...]to get the last revision and continue to work on them linked in bzr (possible to preserve their history inbzr). I did revert them from previous revision and included in the below review.
Sorry, I messed up the local branch a little. I deleted the files at a point and forgot to bzr add them back. I will do that tomorrow and will address the review.
#10 Updated by Andrei Plugaru about 1 year ago
- Status changed from WIP to Review
I have committed 10111a/15984 with the missing files and addressed the rest of the review. Ovidiu, please take a look!
#11 Updated by Andrei Plugaru about 1 year ago
I remembered something worth noting. In my current implementation, I have changed the type of the enabled node for sql-logging and p2j-query-logging. Before it was string, I have changed it to boolean, as I find it more intuitive. This implies changes to directory.xml, however I think these logging tools are only used by us internally, so clients shouldn't be affected. After this will get merged, I will update the wikis accordingly.
#12 Updated by Ovidiu Maxiniuc about 1 year ago
- Status changed from Review to Internal Test
I think the changes in 15984 are OK. Can we move to 100% done?
#13 Updated by Andrei Plugaru about 1 year ago
- Assignee set to Andrei Plugaru
- % Done changed from 0 to 100
Thanks, Ovidiu for the review.
Regarding testing, I am thinking of running a test suite of a large customer application just to be sure nothing has regressed, even though there is a really low chance for this. Apart from that, I am thinking of testing the P2JQueryLogger and SQLStatementLogger tools on a large customer application.
#14 Updated by Andrei Plugaru about 1 year ago
I have run a test suite of a large customer application and also tested different options for the logging tools and didn't find any problems.
An important aspect I want to mention again is that I have slightly modified the directory config for these tools. I have changed the type of the enabled node from string to boolean. However, I don't think customers really use these tools, and even if they used it, only a message will be shown in server.log: Node /server/standard/persistence/sql-logging/enabled is expected to have class /meta/class/boolean, but is configured as /meta/class/string. I will just update the corresponding wikis as soon this will be merged.
Ovidiu, do you think there is anything else to be done before merging?
#15 Updated by Ovidiu Maxiniuc about 1 year ago
I understand that your test have a good coverage of the affected code.
Related to node type change. If the node is not present in customer directory.xml, nothing happens, but if the node already exists, what will happen when FWD will try to read the node?
#16 Updated by Andrei Plugaru about 1 year ago
Ovidiu Maxiniuc wrote:
but if the node already exists, what will happen when FWD will try to read the node?
If the node already exists and the type hasn't been changed to boolean, this warning entry will be in server.log: 25/07/15 10:05:40.151+0300 | WARNING | com.goldencode.p2j.util.Utils [Utils.executeLookup()] | ThreadName:main, ThreadId:00000003, User:standard | Node /server/standard/persistence/sql-logging/enabled is expected to have class /meta/class/boolean, but is configured as /meta/class/string.. The logging functionality will, of course, be disabled in this case. However, apart from this, the server will work as before, there shouldn't be any functional difference.
#17 Updated by Ovidiu Maxiniuc about 1 year ago
OK. If there's just a single warning and the tests showed no regressions then I do not see a reason to delay the merge of the branch into trunk.
#18 Updated by Andrei Plugaru about 1 year ago
I have rebased 10111a to the latest trunk.
Ovidiu, please let me know when can it be merged.
#19 Updated by Ovidiu Maxiniuc about 1 year ago
I think so.
Constantin can you queue this branch for merging?
#20 Updated by Constantin Asofiei about 1 year ago
- Status changed from Internal Test to Merge Pending
10111a can be merged now.
#21 Updated by Andrei Plugaru about 1 year ago
- Status changed from Merge Pending to Test
I have merged to trunk as rev. 16047.
#22 Updated by Dănuț Filimon about 1 year ago
10111a changes should also be ported to 7156e.
#23 Updated by Andrei Plugaru about 1 year ago
I have ported the changes to 7156e as rev. 15764.