MaxSem has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/70638


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, 47 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/GeoData 
refs/changes/38/70638/1

diff --git a/GeoData.php b/GeoData.php
index 78681c2..d594ec0 100644
--- a/GeoData.php
+++ b/GeoData.php
@@ -209,6 +209,15 @@
 $wgGeoDataSolrMaster = 'localhost';
 
 /**
+ * @var mixed: Commit policy
+ * Possible values:
+ * - 'never': Never commit explicitly, allow Solr to do it.
+ * - 'immediate': Commit after every change.
+ * - (some number): Commit within this number of milliseconds.
+ */
+$wgGeoDataSolrCommits = '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..2d1f13a 100644
--- a/solrupdate.php
+++ b/solrupdate.php
@@ -37,7 +37,7 @@
         * Called internally
         */
        public function safeExecute() {
-               global $wgGeoDataBackend;
+               global $wgGeoDataBackend, $wgGeoDataSolrCommits;
                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 ( $wgGeoDataSolrCommits === 
'immediate' ) {
+                                               $update->addCommit();
+                                       }
                                        $solr->update( $update );
 
                                        $count += count( $killedIds );
@@ -177,6 +179,12 @@
                                        usleep( self::READ_DELAY );
                                }
                        } while ( $res->numRows() > 0 );
+                       // delete queries don't support commitWithin, so just 
commit after we're done deleting
+                       if ( $count && is_numeric( $wgGeoDataSolrCommits ) ) {
+                               $update = $solr->createUpdate();
+                               $update->addCommit();
+                               $solr->update( $update );
+                       }
                }
 
                $dbw->replace( 'geo_updates',
@@ -187,6 +195,32 @@
        }
 
        /**
+        * @param Solarium_Query_Update $update
+        * @return bool
+        */
+       private function addCommit( $update ) {
+               global $wgGeoDataSolrCommits;
+
+               if ( $wgGeoDataSolrCommits === 'immediate' ) {
+                       $update->addCommit();
+               } elseif ( is_int( $wgGeoDataSolrCommits ) && 
$wgGeoDataSolrCommits > 0 ) {
+                       return false;
+               } elseif ( $wgGeoDataSolrCommits !== 'never' ) {
+                       throw new MWException( "'$wgGeoDataSolrCommits' is not 
a valid \$wgGeoDataSolrCommits value" );
+               }
+               return true;
+       }
+
+       private function commitWithin() {
+               global $wgGeoDataSolrCommits;
+
+               if ( is_int( $wgGeoDataSolrCommits ) ) {
+                       return $wgGeoDataSolrCommits;
+               }
+               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: newchange
Gerrit-Change-Id: I23a2c832ae733a836594a163a018d9f1d44d8b20
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/GeoData
Gerrit-Branch: master
Gerrit-Owner: MaxSem <[email protected]>

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

Reply via email to