jenkins-bot has submitted this change and it was merged.

Change subject: Allow to adjust commit mode
......................................................................


Allow to adjust commit mode

This will allow us to take advantage of new Solr configuration with autocommit

Change-Id: I23a2c832ae733a836594a163a018d9f1d44d8b20
---
M GeoData.php
M solrupdate.php
2 files changed, 48 insertions(+), 4 deletions(-)

Approvals:
  Nikerabbit: Looks good to me, approved
  Manybubbles: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/GeoData.php b/GeoData.php
index 78681c2..6c0244b 100644
--- a/GeoData.php
+++ b/GeoData.php
@@ -209,6 +209,15 @@
 $wgGeoDataSolrMaster = 'localhost';
 
 /**
+ * @var int|string: Commit policy
+ * Possible values:
+ * - 'never': Never commit explicitly, let Solr decide on its own.
+ * - 'immediate': Commit after every change.
+ * - (some number): Commit within this number of milliseconds.
+ */
+$wgGeoDataSolrCommitPolicy = 'immediate';
+
+/**
  * Whether search index should be updated via jobs. Supported only for Solr.
  */
 $wgGeoDataUpdatesViaJob = false;
diff --git a/solrupdate.php b/solrupdate.php
index 60ef1af..eb6b298 100644
--- a/solrupdate.php
+++ b/solrupdate.php
@@ -37,7 +37,7 @@
         * Called internally
         */
        public function safeExecute() {
-               global $wgGeoDataBackend;
+               global $wgGeoDataBackend, $wgGeoDataSolrCommitPolicy;
                if ( $wgGeoDataBackend != 'solr' ) {
                        $this->error( "This script is only for wikis with Solr 
GeoData backend", true );
                }
@@ -134,8 +134,8 @@
                                        $docs[] = $doc;
                                }
                                if ( $docs ) {
-                                       $update->addDocuments( $docs );
-                                       $update->addCommit();
+                                       $update->addDocuments( $docs, null, 
$this->commitWithin() );
+                                       $this->addCommit( $update );
                                        $solr->update( $update );
 
                                        $count += count( $docs );
@@ -169,7 +169,9 @@
                                }
                                if ( $killedIds ) {
                                        $update->addDeleteByIds( $killedIds );
-                                       $update->addCommit();
+                                       if ( $wgGeoDataSolrCommitPolicy === 
'immediate' ) {
+                                               $update->addCommit();
+                                       }
                                        $solr->update( $update );
 
                                        $count += count( $killedIds );
@@ -177,6 +179,13 @@
                                        usleep( self::READ_DELAY );
                                }
                        } while ( $res->numRows() > 0 );
+                       // delete queries don't support commitWithin, so if 
we're in commitWithin mode,
+                       // just commit after we're done deleting
+                       if ( $count && is_int( $wgGeoDataSolrCommitPolicy ) ) {
+                               $update = $solr->createUpdate();
+                               $update->addCommit();
+                               $solr->update( $update );
+                       }
                }
 
                $dbw->replace( 'geo_updates',
@@ -187,6 +196,32 @@
        }
 
        /**
+        * @param Solarium_Query_Update $update
+        */
+       private function addCommit( $update ) {
+               global $wgGeoDataSolrCommitPolicy;
+
+               if ( $wgGeoDataSolrCommitPolicy === 'immediate' ) {
+                       $update->addCommit();
+               } elseif ( !( is_int( $wgGeoDataSolrCommitPolicy ) && 
$wgGeoDataSolrCommitPolicy > 0 )
+                       && $wgGeoDataSolrCommitPolicy !== 'never' ) {
+                       throw new MWException( "'$wgGeoDataSolrCommitPolicy' is 
not a valid \$wgGeoDataSolrCommitPolicy value" );
+               }
+       }
+
+       /**
+        * @return int|null: Number of milliseconds to commit within or null if 
not applicable
+        */
+       private function commitWithin() {
+               global $wgGeoDataSolrCommitPolicy;
+
+               if ( is_int( $wgGeoDataSolrCommitPolicy ) ) {
+                       return $wgGeoDataSolrCommitPolicy;
+               }
+               return null;
+       }
+
+       /**
         * Overrides Maintenace::error() to throw exceptions instead of writing 
to stderr when called from a job
         * @param String $err
         * @param int $die

-- 
To view, visit https://gerrit.wikimedia.org/r/70638
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I23a2c832ae733a836594a163a018d9f1d44d8b20
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/GeoData
Gerrit-Branch: master
Gerrit-Owner: MaxSem <[email protected]>
Gerrit-Reviewer: Demon <[email protected]>
Gerrit-Reviewer: Manybubbles <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to