Closed (outdated)
Project:
Drupal core
Version:
7.x-dev
Component:
dblog.module
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
20 Sep 2010 at 15:19 UTC
Updated:
20 Mar 2020 at 16:52 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
scor commentedthis is a bug report
Comment #2
hbergin commentedTo get around the issue of auto_increment value greater than 1 , the queries could be changed to do the following to leave the most recent 1000 records:
Instead of selecting the max(wid) and subtracting 1000
1) select the min(wid) from the most recent 1000 records
2) delete everything less than the resulting min(wid).
SELECT min( wid )
FROM (
SELECT wid
FROM `watchdog`
ORDER BY wid DESC
LIMIT 1000
) AS t1
If this solution addresses your issue correctly, I would be happy to have the bug assigned to me to fix.
Comment #3
bleen commentedonce this lands for D7 ... this will need to be ported to D6 (where I can confirm the problem)
Comment #4
scor commented@hbergin please assign the bug to yourself and roll a patch! Your proposal sounds good.
Comment #5
hbergin commentedGreat, I'll start working on a patch.
I'll likely end up using db_query_range() or other parts of the database abstraction layer, because not all databases agree on the format of the LIMIT syntax.
Comment #6
scor commented@hbergin make sure to use the new D7 database API and in particular the dynamic queries to work around the vendor specific limit issue.
Comment #7
hbergin commentedYep, looking at it now.
Comment #8
hbergin commentedHere's a solution using dynamic queries from the D7 database APIs, which should avoid vendor specific issues. The code looks good so far and I'll roll a patch after further testing.
Comment #9
hbergin commentedHere's the patch, with some additional edits made to the code in my last post regarding coding guidelines and a check for a successful query execution.
I would be happy to help with the D6 port as needed, and have drafted code for that.
Comment #10
hbergin commentedComment #11
scor commentedno need for foreach here, the delete query should only be run once. use a fetchField() or fecthCol() right after the execute() above to get the value directly.
seems we've not using the $num_deleted variable, is it necessary to use this variable then?
Powered by Dreditor.
Comment #12
hbergin commentedMade updates as recommended in this new patch revision, now using fetchField(), and not using $num_deleted variable.
Comment #13
scor commentedHave you tried this patch with a value of auto_increment > 1? just run
set global auto_increment_increment = 2;in a MySQL shell. Try to run the associated test (might need tweaking). restart your sql server to revert this change, or rerun the same command with value 1.also minor whitespace to fix in the patch.
Comment #14
bleen commentedI think this needs a test too
Comment #15
hbergin commentedThanks for the very helpful and speedy feedback. Here's a summary of the tests I have run on the patches submitted:
Running the cron task when:
1) No rows in the watchdog table
2) Less rows than the limit in the watchdog table
3) More rows than the limit in the watchdog table
4) Same number of rows as the limit in the watchdog table
5) Tests 1-4 with the increment value changed to greater than 1
6) Tests 1-4 with the increment value returned to 1
7) Tests 2-4 with rows deleted directly from the table out of wid sequence order (e.g. not oldest or newest rows)
8) DBQuery fails (e.g. returned result is FALSE)
Does this cover the testing scenarios you had in mind?
If so, I'll go ahead and re-roll the patch without the errant white space.
If not, could you give me a pointer or more info on the associated test you mentioned?
Comment #16
bleen commentedhbergin: Those are exactly the test scenarios we should be covering, but we should write some simple tests (http://drupal.org/simpletest) so that this error doesn't resurface. I'm not 100% certain we can write a test that checks how the database performs with an autoimcrement of >1, but we should look into it at the very least
Comment #17
hbergin commentedHere is the patch without the errant white space, as there's no need to hold off on that fix. Simple test is a new area for me, but I'm happy to help investigate as I agree there's great value in automated test suites.
Comment #18
scor commentedThe testcase should be as auto_increment agnostic as possible and not try to change the value of the local db auto_increment. In other words, the test should pass regardless of the value of auto_increment. There is actually a more general issue about that if you are interested: #549662: Core unit tests assume auto_increment values which should uncover plenty of issues like this one where tests don't pass when auto_increment_increment and auto_increment_offset are different from 1.
Comment #19
hbergin commentedGreat, I was reading that general issue thread and was thinking the same thing.
I see the dblog.test file verifyCron() function already includes the test for rows exceeding the limit in the watchdog table, so I could look to complement this test scenario with:
Running the cron task when:
1) No rows in the watchdog table
2) Less rows than the limit in the watchdog table
3) More rows than the limit in the watchdog table (already part of simple test)
4) Same number of rows as the limit in the watchdog table
5) Tests 2-4 with rows deleted directly from the table out of wid sequence order (e.g. not oldest or newest rows)
Comment #20
scor commentedI don't think dblog.test needs any change at all since it relies on COUNT(wid). The test fails when run on a db with auto_increment_increment > 1, but it should now pass with your patch #17.
Comment #21
hbergin commentedI agree the code already in dblog.test works just fine using COUNT(wid).
My thought was that the verifyCron() function only includes one test scenario at the moment, and we could add additional scenarios from the ones listed in #19.
Comment #22
hbergin commentedChecked out the HEAD code today. Here are patches rolled against this latest source code. Both were tested using the D7 development testing feature and run through the coder module.
dblog-cron-watchdogcleanup-917134.patch
Same code changes as in #17, but against latest source code.
dblog-cron-watchdogcleanup-tests-917134.patch
As per #21, this patch adds test variations to dblog.test verifyCron() function, using similar format to the already existing test.
Test were added to check the resulting rows in the watchdog table after running the cron task when:
1) No rows in the watchdog table
2) Less rows than the limit in the watchdog table
3) Same number of rows as the limit in the watchdog table
4) More rows than the limit in the watchdog table, where rows are out of wid sequence order (e.g. due to ad hoc direct deletions from the table)
Comment #23
dries commentedThis code comment is redundant.
Comment #24
hbergin commenteddblog-cron-watchdogcleanup-917134.patch
Redundant comment removed as per #23.
dblog-cron-watchdogcleanup-tests-917134.patch
Comment edits.
Comment #26
hbergin commented#24: dblog-cron-watchdogcleanup-tests-917134.patch queued for re-testing.
Comment #28
hbergin commented#25 had 2 failures in database_test.test related to function testAlterRemoveRange().
#27 had 1 failure in upgrade.test related to function public function testBasicUpgrade()
Could not spot any direct correlation with patch to dblog.test verifyCron() changes which only accesses the watchdog table and runs cron. The fails in #25 and #27 were in different places, with the same patch code.
Requeuing once more.
Comment #29
hbergin commented#24: dblog-cron-watchdogcleanup-tests-917134.patch queued for re-testing.
Comment #30
hbergin commentedD6 equivalent syntax for dblog_cron() solution backport. Tested against D6 install.
Comment #31
dries commentedCommitted to CVS HEAD. Thanks!
Comment #32
andypostThis patch should have follow-up to use
Database::getConnection('default', 'default')except direct db_select()last commit kills ability to use master/slave feature for dblog
also db_select is bad here because it's alterable
Comment #33
bleen commentedandypost ... i would open a new issue for that and just reference this one for more info
this issue should stay open for the backport however
Comment #34
hbergin commentedSimilar tests were run on this d6 backport patch as listed in #15. Also run through coder module.
Comment #35
scor commentedThe tests (second patch in #24) were not committed (nor reviewed).
Comment #36
mr.baileysMarked #551688: Row Limit Doesn't Take auto_increment_offset into account as a duplicate.
Comment #38
andypost@bleen18 I think no reason in different issue because this still needs work
Comment #39
hbergin commented@andypost, does this revised syntax address your concerns? If so, I can look at re-rolling a patch with this syntax.
When I first wrote the patch, some api documentation indicated that db_query_range was going to be deprecated, but I do not see that in the current documentation, so am assuming it's OK to use it now.
Comment #40
hbergin commentedPatch updated to use syntax in #39 to address #32.
Run on local D7 HEAD install using simpletest module and coder module.
Comment #41
hbergin commentedComment #42
hbergin commentedAs per #21, this patch adds test variations to dblog.test verifyCron() function, using similar format to the already existing test.
Test were added to check the resulting rows in the watchdog table after running the cron task when:
1) No rows in the watchdog table
2) Less rows than the limit in the watchdog table
3) Same number of rows as the limit in the watchdog table
4) More rows than the limit in the watchdog table, where rows are out of wid sequence order (e.g. due to ad hoc direct deletions from the table).
Comment #43
andypost@hbergin, please merge #40 and #42 in one patch, I think it's RTBC if both in one
Comment #44
hbergin commentedThanks for the feedback, @andypost. Here is a patch which merges #40 and #42, as requested in #43.
Comment #45
mgiffordPatch no longer applies.
Comment #50
dagmarRelloled.