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

Change subject: Use file handle caching in newSequentialPerNodeIDs()
......................................................................


Use file handle caching in newSequentialPerNodeIDs()

* This is now similar to the other methods in that regard

Change-Id: I36163fa7f1bc13d493df9d77b139a99881d0de45
---
M includes/utils/UIDGenerator.php
1 file changed, 23 insertions(+), 2 deletions(-)

Approvals:
  Ori.livneh: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/utils/UIDGenerator.php b/includes/utils/UIDGenerator.php
index 47cef8b..e60293b 100644
--- a/includes/utils/UIDGenerator.php
+++ b/includes/utils/UIDGenerator.php
@@ -243,6 +243,21 @@
         * @since 1.23
         */
        public static function newSequentialPerNodeIDs( $bucket, $bits, $count, 
$flags = 0 ) {
+               $gen = self::singleton();
+               return $gen->getSequentialPerNodeIDs( $bucket, $bits, $count, 
$flags );
+       }
+
+       /**
+        * Return IDs that are sequential *only* for this node and bucket
+        *
+        * @see UIDGenerator::newSequentialPerNodeID()
+        * @param string $bucket Arbitrary bucket name (should be ASCII)
+        * @param integer $bits Bit size (16 to 48) of resulting numbers before 
wrap-around
+        * @param integer $count Number of IDs to return (1 to 10000)
+        * @param integer $flags (supports UIDGenerator::QUICK_VOLATILE)
+        * @return array Ordered list of float integer values
+        */
+       protected function getSequentialPerNodeIDs( $bucket, $bits, $count, 
$flags ) {
                if ( $count <= 0 ) {
                        return array(); // nothing to do
                } elseif ( $count > 10000 ) {
@@ -274,7 +289,13 @@
                // Note: use of fmod() avoids "division by zero" on 32 bit 
machines
                if ( $counter === null ) {
                        $path = wfTempDir() . '/mw-' . __CLASS__ . '-' . 
rawurlencode( $bucket ) . '-48';
-                       $handle = fopen( $path, 'cb+' );
+                       // Get the UID lock file handle
+                       if ( isset( $this->fileHandles[$path] ) ) {
+                               $handle = $this->fileHandles[$path];
+                       } else {
+                               $handle = fopen( $path, 'cb+' );
+                               $this->fileHandles[$path] = $handle ?: null; // 
cache
+                       }
                        // Acquire the UID lock file
                        if ( $handle === false ) {
                                throw new MWException( "Could not open 
'{$path}'." );
@@ -292,8 +313,8 @@
                        fflush( $handle );
                        // Release the UID lock file
                        flock( $handle, LOCK_UN );
-                       fclose( $handle );
                }
+
                $ids = array();
                $divisor = pow( 2, $bits );
                $currentId = floor( $counter - $count ); // pre-increment 
counter value

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I36163fa7f1bc13d493df9d77b139a99881d0de45
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Ori.livneh <o...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to