[9.2] Before a user is getting scanned the database connection is re-establ… #25853

Merged
merged 1 commit into from Aug 22, 2016

Projects

None yet

4 participants

@DeepDiver1975
Member

…ished

refs #25480

@DeepDiver1975 DeepDiver1975 Before a user is getting scanned the database connection is re-establ…
…ished
891c531
@mention-bot

@DeepDiver1975, thanks for your PR! By analyzing the annotation information on this pull request, we identified @icewind1991, @mmattel and @bartv2 to be potential reviewers

@DeepDiver1975 DeepDiver1975 added this to the 9.2 milestone Aug 18, 2016
@PVince81 PVince81 commented on the diff Aug 18, 2016
apps/files/lib/Command/Scan.php
@@ -317,4 +320,26 @@ protected function formatExecTime() {
return date('H:i:s', $secs);
}
+ /**
+ * @return \OCP\IDBConnection
+ */
+ protected function reconnectToDatabase(OutputInterface $output) {
+ /** @var Connection | IDBConnection $connection*/
+ $connection = \OC::$server->getDatabaseConnection();
+ try {
+ $connection->close();
+ } catch (\Exception $ex) {
+ $output->writeln("<info>Error while disconnecting from database: {$ex->getMessage()}</info>");
+ }
+ while (!$connection->isConnected()) {
+ try {
+ $connection->connect();
@PVince81
PVince81 Aug 18, 2016 Collaborator

please add a max retries count to avoid infinite loops

@PVince81
PVince81 Aug 18, 2016 Collaborator

in which case the exception is rethrown to the outside

@DeepDiver1975
DeepDiver1975 Aug 18, 2016 Member

I'd leave this to the admin then to decide if/when he wants to terminate the scan

@PVince81
PVince81 Aug 18, 2016 Collaborator

Ah yes, in my mind I saw this method as part of DBConnection but it isn't. Since this loop is only in the context of file scanning then it's fine.

@DeepDiver1975 DeepDiver1975 changed the title from Before a user is getting scanned the database connection is re-establ… to [9.2] Before a user is getting scanned the database connection is re-establ… Aug 18, 2016
@georgehrke
Contributor

👍

@PVince81
Collaborator

@DeepDiver1975 any chance to have a little unit test that covers the reconnection part, so that CI can tell us that all databases are ok with it ?

@DeepDiver1975
Member

so that CI can tell us that all databases are ok with it ?

there is not much dbms specific in here - doctrine unsets the connection on close and creates a new connection within connect.

@PVince81
Collaborator

Another concern of mine is whether reconnecting a thousand times is slower than keeping the connection open. If slower, a possible strategy would be to keep track of elapsed time and after every user check if the time is more than a minute or so. If yes, then reconnecting.

But if you think the overhead is negligible then I'm fine with this.

@PVince81
Collaborator

@DeepDiver1975 can you check my previous comment ? Would be good to get this merged and backported soon, unless you think this is too risky

@DeepDiver1975
Member

But if you think the overhead is negligible then I'm fine with this.

Form my pov this can be ignored

@PVince81
Collaborator

👍 tested with LDAP and 100 users

@PVince81
Collaborator

Jenkins unpublished success message -> merge

@PVince81 PVince81 merged commit 27a5be9 into master Aug 22, 2016

3 of 4 checks passed

continuous-integration/jenkins/pr This commit is being built
Details
Scrutinizer 1 new issues, 2 updated code elements
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
licence/cla Contributor License Agreement is signed.
Details
@PVince81 PVince81 deleted the files-scan-reconnect-database-before-each-user-master branch Aug 22, 2016
@PVince81
Collaborator

@DeepDiver1975 please send the backports, thanks

@DeepDiver1975
Member
DeepDiver1975 commented Aug 22, 2016 edited

will backport

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment