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

Remove pagination from the repair step #30989

Merged
merged 2 commits into from
Apr 6, 2018

Conversation

sharidas
Copy link
Contributor

@sharidas sharidas commented Apr 3, 2018

The pagination is not required as the
rows are deleted during the operation.

Signed-off-by: Sujith H sharidasan@owncloud.com

Description

The pagination should be removed from this repair step. Because if the pagination is there, then the changes will not be taken after the first removal in the loop. The second iteration might omit changes which have broken links.

Related Issue

#30653 (comment)

Motivation and Context

If the rows are deleted on the fly, then its better to avoid pagination and use the pagelimit .

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@sharidas sharidas added this to the development milestone Apr 3, 2018
@sharidas sharidas self-assigned this Apr 3, 2018
@sharidas sharidas requested a review from PVince81 April 3, 2018 10:58
@PVince81
Copy link
Contributor

PVince81 commented Apr 3, 2018

Please add a unit test that proves that it works. The test should fail without this commit.

You could add an attribute to set pagination to smaller values if it makes it easier to test.

@PVince81 PVince81 mentioned this pull request Apr 3, 2018
9 tasks
@PVince81
Copy link
Contributor

PVince81 commented Apr 3, 2018

  • add unit tests

@codecov
Copy link

codecov bot commented Apr 3, 2018

Codecov Report

Merging #30989 into master will increase coverage by 0.14%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #30989      +/-   ##
============================================
+ Coverage      62.3%   62.45%   +0.14%     
- Complexity    18208    18229      +21     
============================================
  Files          1142     1145       +3     
  Lines         68229    68275      +46     
  Branches       1234     1234              
============================================
+ Hits          42511    42641     +130     
+ Misses        25357    25273      -84     
  Partials        361      361
Flag Coverage Δ Complexity Δ
#javascript 52% <ø> (ø) 0 <ø> (ø) ⬇️
#phpunit 63.64% <100%> (+0.16%) 18229 <1> (+21) ⬆️
Impacted Files Coverage Δ Complexity Δ
lib/private/Repair/RepairOrphanedSubshare.php 86.66% <100%> (-7.28%) 3 <1> (-3)
core/Migrations/Version20170221114437.php 0% <0%> (ø) 2% <0%> (ø) ⬇️
lib/private/User/Sync/SeenUsersIterator.php 100% <0%> (ø) 4% <0%> (?)
lib/private/User/Sync/AllUsersIterator.php 100% <0%> (ø) 4% <0%> (?)
lib/private/User/Sync/UsersIterator.php 100% <0%> (ø) 5% <0%> (?)
lib/private/User/SyncService.php 74.83% <0%> (+1.71%) 56% <0%> (-1%) ⬇️
lib/private/User/AccountMapper.php 77.77% <0%> (+4.3%) 31% <0%> (+6%) ⬆️
core/Command/User/SyncBackend.php 55.17% <0%> (+55.17%) 42% <0%> (+6%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bedfb50...14edb80. Read the comment docs.

@sharidas
Copy link
Contributor Author

sharidas commented Apr 3, 2018

Added unit tests:

  1. One of the test proves that if pagination is there then the code would fail to remove all orphan shares (i.e, without this change).
  2. Another test to prove that with this change all orphan shares could be removed.

Will see how the tests progress in the CI.

@sharidas sharidas force-pushed the remove-pagination-repair-orphansubshare branch 9 times, most recently from c8f303f to 25a6225 Compare April 4, 2018 09:27
* This test will have more orphan shares and will check if the repair
* test is working properly.
*/
public function testOrphanSharesFailsWithPagination() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the test is only testing pagination itself, not a failure

@sharidas sharidas force-pushed the remove-pagination-repair-orphansubshare branch 2 times, most recently from 71d3fe2 to 63ab8a4 Compare April 4, 2018 10:38
@sharidas sharidas force-pushed the remove-pagination-repair-orphansubshare branch from 958c7aa to 11b82ee Compare April 4, 2018 16:00
$this->missingParents->where($this->missingParents->expr()->isNotNull('parent'));
$this->missingParents->andWhere($this->missingParents->expr()->notIn('parent', $this->missingParents->createFunction($qb->getSQL())));
$this->missingParents->andWhere($this->missingParents->createFunction('NOT EXISTS (' . $qb->getSQL() . ')'));
Copy link
Contributor Author

@sharidas sharidas Apr 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated query builder from -> #30989 (comment).
Also resumed $this->deleteOrphanReshares ( which was omitted in the previous version of the PR).

//Check if the row is there before deleting
$result = $qb->select('id')
->from('share')
->where($qb->expr()->eq('id', $qb->createNamedParameter($randomRow + $pareReshareCountRest)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is very unreliable and will likely not work on Oracle: please store the ids of all inserted entries from the above query and then delete a few selected ones.

you cannot assume that the share ids will start at 1 here as not all DBs reset their autoincrement to zero

please implement this in a proper way.

also see owncloud-archive/documentation#3805 (comment) when retrieving inserted ids

'stime' => $qb->expr()->literal($time),
])
->execute();
if (($parentReshareCount - $pareReshareCountRest) >= 3000) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why ?

$randomRow++;
}

//Now run the repair step and prove that this test fails
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, we don't prove that a test fail. a test must always pass.

what I said about failing tests is based on Test Driven Development (TDD) where you first write a test that reproduces an issue. the test will fail at first and then you implement the code to make it pass.

it doesn't mean that the test exists to prove that something fails

$this->assertTrue($testFail);
}

public function mockRepairOrphanShareMethodWithPagination() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks wrong as you reimplemented the same code as the repair step

a much better approach is to keep track of what entries you "destroyed" when creating your test set and then writing a query that checks that exactly these entries were cleant up

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for example if your test code destroyed the parents of the share ids 5, 15, 18 then in your assertion code after running the repair step, you'll query whether the sub-shares with parents 5, 15 and 18 are gone.

this is better than using count. Maybe we should move away from just counting as it's not accurate enough.

@sharidas sharidas force-pushed the remove-pagination-repair-orphansubshare branch 3 times, most recently from 6edd6ec to 5ee7920 Compare April 5, 2018 12:08
@sharidas
Copy link
Contributor Author

sharidas commented Apr 5, 2018

We need to consider following PR's:

The backport PR should be considered last: #31004

The pagination is not required as the
rows are deleted during the operation.

Signed-off-by: Sujith H <sharidasan@owncloud.com>
@sharidas sharidas force-pushed the remove-pagination-repair-orphansubshare branch from 5ee7920 to 8fb942f Compare April 5, 2018 13:34
@sharidas
Copy link
Contributor Author

sharidas commented Apr 5, 2018

Added commit: #31014 to this PR.

@@ -286,4 +286,128 @@ public function testLargeSharesWithOrphans() {
} while(count($results) > 0);
$this->assertEquals($totalParents - 20, $result);
}

/**
* A new approach
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the approach is not new, this is "the" approach

if you want to write "new approach" the text needs to be in the PR comment

please replace the comment with whatever the test is testing

what does "no more pagination" means ? no more compared to what ?

}

//Lets check rance of 1 to 9
foreach (range(1, 9) as $adminIndex) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like the same loop code like line 391, maybe you can put these together

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intention here was to see the first 9 indexes are there or not. A proof that first 9 parents are not deleted according to the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the duplicated code and updated with a loop so that it look better. So if one has to check if the index is there or not in this large scenario, appending the array $checkRandomAvailableEntries is enough.

/**
* A new approach
*/
public function testOrphanSharesNoMorePagination() {
Copy link
Contributor

@PVince81 PVince81 Apr 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the test is not testing a code change, it's testing a behavior: what behavior are you testing ?

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
@sharidas sharidas force-pushed the remove-pagination-repair-orphansubshare branch from 8fb942f to 14edb80 Compare April 6, 2018 10:51
@sharidas
Copy link
Contributor Author

sharidas commented Apr 6, 2018

@PVince81 Ready for review.

Copy link
Contributor

@PVince81 PVince81 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@PVince81 PVince81 merged commit a996a23 into master Apr 6, 2018
@PVince81 PVince81 deleted the remove-pagination-repair-orphansubshare branch April 6, 2018 12:00
@PVince81
Copy link
Contributor

PVince81 commented Apr 6, 2018

@sharidas please backport as part of #30653 (comment), all in a single PR

@sharidas
Copy link
Contributor Author

sharidas commented Apr 6, 2018

Updated the backport PR : #31004 to a single PR. It includes the changes we have made so far mentioned here... #30653 (comment)

@lock
Copy link

lock bot commented Jul 31, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jul 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants