Log startAtomic()/endAtomic() to the query logger
authorTim Starling <tstarling@wikimedia.org>
Wed, 10 Oct 2018 04:03:21 +0000 (15:03 +1100)
committerAaron Schulz <aschulz@wikimedia.org>
Sat, 13 Oct 2018 01:20:32 +0000 (01:20 +0000)
Change-Id: Ife7e292ef42946ec1c5e9121b7be6a90301b3903

includes/libs/rdbms/database/Database.php

index 1b3e6cc..66fc10e 100644 (file)
@@ -3658,6 +3658,8 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
 
                $sectionId = new AtomicSectionIdentifier;
                $this->trxAtomicLevels[] = [ $fname, $sectionId, $savepointId ];
+               $this->queryLogger->debug( 'startAtomic: entering level ' .
+                       ( count( $this->trxAtomicLevels ) - 1 ) . " ($fname)" );
 
                return $sectionId;
        }
@@ -3670,6 +3672,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                // Check if the current section matches $fname
                $pos = count( $this->trxAtomicLevels ) - 1;
                list( $savedFname, $sectionId, $savepointId ) = $this->trxAtomicLevels[$pos];
+               $this->queryLogger->debug( "endAtomic: leaving level $pos ($fname)" );
 
                if ( $savedFname !== $fname ) {
                        throw new DBUnexpectedError(
@@ -3702,6 +3705,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                        throw new DBUnexpectedError( $this, "No atomic section is open (got $fname)." );
                }
 
+               $excisedFnames = [];
                if ( $sectionId !== null ) {
                        // Find the (last) section with the given $sectionId
                        $pos = -1;
@@ -3717,6 +3721,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                        $excisedIds = [];
                        $len = count( $this->trxAtomicLevels );
                        for ( $i = $pos + 1; $i < $len; ++$i ) {
+                               $excisedFnames[] = $this->trxAtomicLevels[$i][0];
                                $excisedIds[] = $this->trxAtomicLevels[$i][1];
                        }
                        $this->trxAtomicLevels = array_slice( $this->trxAtomicLevels, 0, $pos + 1 );
@@ -3727,6 +3732,13 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                $pos = count( $this->trxAtomicLevels ) - 1;
                list( $savedFname, $savedSectionId, $savepointId ) = $this->trxAtomicLevels[$pos];
 
+               if ( $excisedFnames ) {
+                       $this->queryLogger->debug( "cancelAtomic: canceling level $pos ($savedFname) " .
+                               "and descendants " . implode( ', ', $excisedFnames ) );
+               } else {
+                       $this->queryLogger->debug( "cancelAtomic: canceling level $pos ($savedFname)" );
+               }
+
                if ( $savedFname !== $fname ) {
                        throw new DBUnexpectedError(
                                $this,