Pārlūkot izejas kodu

merge code to ralb

stanley-king 3 gadi atpakaļ
vecāks
revīzija
ddf2b88fd6

+ 5 - 12
core/framework/db/comysqli.php

@@ -16,8 +16,6 @@ class Db
     const ErrUnConnect = 2006;
     const ErrLock = 1205;
 
-    private static $ifTransacting = false;
-
     private function __construct()
     {
         if (!extension_loaded('mysqli')) {
@@ -111,8 +109,7 @@ class Db
 
     public static function ping($host = 'master')
     {
-        $cid = Co::getCid();
-        $link = CoMysqliPool::instance()->find($cid);
+        $link = CoMysqliPool::instance()->find(Co::getCid());
 
         if (is_object($link[$host])) {
             return $link[$host]->ping();
@@ -145,7 +142,7 @@ class Db
                 if ($eno == self::ErrUnConnect) {
                     if ($count > 0) return false;
                     $link = self::connect($link,$host);
-                    CoMysqliPool::instance()->reset($cid,$link);
+                    CoMysqliPool::instance()->reset(Co::getCid(),$link);
                     $count++;
                 } elseif (C('debug')) {
                     throw_exception($error . '<br/>' . $sql);
@@ -155,7 +152,7 @@ class Db
                 {
                     if ($count > 0) return false;
                     $link = self::connect($link,$host);
-                    CoMysqliPool::instance()->reset($cid,$link);
+                    CoMysqliPool::instance()->reset(Co::getCid(),$link);
                     $count++;
                 }
                 else {
@@ -632,11 +629,10 @@ class Db
             $result = $link[$host]->autocommit(false);
             if ($result == false) {
                 $link = self::connect($host);
-                CoMysqliPool::instance()->reset($cid,$link);
-                Log::record("autocommit start 2", Log::DEBUG);
+                CoMysqliPool::instance()->reset(Co::getCid(),$link);
                 $link[$host]->autocommit(false);
             } else {
-                Log::record("autocommit start 1", Log::DEBUG);
+                Log::record("autocommit fail", Log::DEBUG);
             }
         }
         CoMysqliPool::instance()->begin(Co::getCid());
@@ -649,7 +645,6 @@ class Db
         if ($ifTransacting)
         {
             $result = $link[$host]->commit();
-            Log::record("autocommit end commit", Log::DEBUG);
             $link[$host]->autocommit(true);
             CoMysqliPool::instance()->commit(Co::getCid());
 
@@ -669,8 +664,6 @@ class Db
         {
             $result = $link[$host]->rollback();
             CoMysqliPool::instance()->rollback(Co::getCid());
-
-            Log::record("autocommit end rollback", Log::DEBUG);
             $fsuccess = $link[$host]->autocommit(true);
 
             if (!$result || !$fsuccess) {

+ 1 - 3
core/framework/db/mysqli.php

@@ -610,11 +610,9 @@ class Db
             if ($result == false) {
                 self::connect($host);
                 self::$ifTransacting = false;
-
-                Log::record("autocommit start 2", Log::DEBUG);
                 self::$link[$host]->autocommit(false);
             } else {
-                Log::record("autocommit start 1", Log::DEBUG);
+                Log::record("autocommit fail", Log::DEBUG);
             }
         }
         self::$ifTransacting = true;

+ 0 - 4
core/framework/libraries/CoPool.php

@@ -32,7 +32,6 @@ abstract class CoPool
         }
         $this->mUsingCount++;
 
-//        Log::record("redis get mUsingCount={$this->mUsingCount}",Log::DEBUG);
         return $client;
     }
 
@@ -44,9 +43,6 @@ abstract class CoPool
         if($cid > 0) {
             Co::resume($cid);
         }
-//        $count = count($this->mFreeClients);
-//        $waitings = count($this->mSuspendCIDS);
-//        Log::record("redis resume cid={$cid} mUsingCount={$this->mUsingCount} frees={$count} waitings={$waitings}",Log::DEBUG);
     }
 
     private function getSuspend()

+ 4 - 12
core/framework/libraries/model.php

@@ -81,10 +81,8 @@ class Model
 
 	public function __construct($table = null)
     {
-        if(defined('USE_COROUTINE') && USE_COROUTINE && defined('COROUTINE_HOOK_TCP') && COROUTINE_HOOK_TCP)
-        {
-            $cid = Co::getCid();
-            CoMysqliPool::instance()->get($cid);
+        if (defined('USE_COROUTINE') && USE_COROUTINE && defined('COROUTINE_HOOK_TCP') && COROUTINE_HOOK_TCP) {
+            CoMysqliPool::instance()->get(Co::getCid());
         }
 
         $this->table_prefix = DBPRE;
@@ -93,14 +91,8 @@ class Model
 
 	public function __destruct()
     {
-//        Log::record("{$this->table_name} __destruct",Log::DEBUG);
-        if(defined('USE_COROUTINE') && USE_COROUTINE && defined('COROUTINE_HOOK_TCP') && COROUTINE_HOOK_TCP)
-        {
-            if(!CoMysqliPool::instance()->stoped())
-            {
-                $cid = Co::getCid();
-                CoMysqliPool::instance()->put($cid);
-            }
+        if (defined('USE_COROUTINE') && USE_COROUTINE && defined('COROUTINE_HOOK_TCP') && COROUTINE_HOOK_TCP) {
+            CoMysqliPool::instance()->put(Co::getCid());
         }
     }
 

+ 12 - 10
helper/queue/iqueue.php

@@ -216,7 +216,7 @@ class IServer
 abstract class ILooper
 {
     private $_stop = false;
-    private $_pause = 0;
+    private $_pause = 0; // 0,正常运行,1,申请暂停,2,暂停成功
     private $_cid = 0;
 
     private $mServer;
@@ -240,24 +240,27 @@ abstract class ILooper
 
     public function pause()
     {
-        Log::record("pause start subcoroutine cid={$this->_cid} pause={$this->_pause}",Log::DEBUG);
+        if($this->_pause != 0) {
+            Log::record("subcoroutine pause state={$this->_pause} cannot pause.",Log::DEBUG);
+            return;
+        }
+
         $this->_pause = 1;
         do{
             Swoole\Coroutine::sleep(1);
         } while($this->_pause == 1);
-        Log::record("pause end subcoroutine cid={$this->_cid} pause={$this->_pause}",Log::DEBUG);
-
         $this->wait();
+
+        Log::record("subcoroutine pause state={$this->_pause} success.",Log::DEBUG);
     }
 
     public function resume()
     {
-        Log::record("resume start subcoroutine cid={$this->_cid} pause={$this->_pause}",Log::DEBUG);
         if($this->_pause == 2) {
             $this->_pause = 0;
             Swoole\Coroutine::resume($this->_cid);
         }
-        Log::record("resume end subcoroutine cid={$this->_cid} pause={$this->_pause}",Log::DEBUG);
+        Log::record("subcoroutine resume success.",Log::DEBUG);
     }
 
     public function stop()
@@ -269,7 +272,6 @@ abstract class ILooper
 
     private function wait()
     {
-        Log::record("wait start subcoroutine cid={$this->_cid} pause={$this->_pause}",Log::DEBUG);
         do {
             $res = Swoole\Coroutine::stats();
             $num = $res['coroutine_num'];
@@ -296,7 +298,7 @@ abstract class ILooper
             Log::record("wait running subcoroutine count = {$count} quit.",Log::DEBUG);
         }
         while($count > 0);
-        Log::record("wait end subcoroutine quit all",Log::DEBUG);
+        Log::record("subcoroutine wait: quit all",Log::DEBUG);
     }
 
     public function run()
@@ -312,10 +314,10 @@ abstract class ILooper
                 if ($this->_stop) break;
 
                 if($this->_pause == 1) {
-                    Log::record("runlooper subcoroutine pause",Log::DEBUG);
+                    Log::record("subcoroutine runlooper pause.",Log::DEBUG);
                     $this->_pause = 2;
                     Swoole\Coroutine::suspend();
-                    Log::record("runlooper subcoroutine resume",Log::DEBUG);
+                    Log::record("subcoroutine runlooper resume success.",Log::DEBUG);
                 }
 
                 perfor_clear();

+ 0 - 1
helper/refill/policy/merchant_price.php

@@ -52,7 +52,6 @@ class merchant_price
                 }
             }
         }
-
     }
 
     public function price($mchid,$card_type,$spec,$quality,$pcode)

+ 2 - 4
rdispatcher/processor.php

@@ -38,8 +38,7 @@ class processor extends queue\ILooper
                     if (empty($channel) || empty($params))
                         continue;
                     $this->mProxy->notify($channel, $input);
-                }
-                elseif ($method == 'notify_mechant') {
+                } elseif ($method == 'notify_mechant') {
                     $order_id = intval($params['order_id']);
                     $manual = $params['manual'] ?? false;
                     $this->mProxy->notify_merchant($order_id, $manual);
@@ -57,8 +56,7 @@ class processor extends queue\ILooper
                     $this->mProxy->manual_cancel($order_id);
                 } elseif ($method == 'addthird') {
                     $this->mProxy->addthird($params);
-                }
-                else {
+                } else {
                     Log::record("Error Method={$method}", Log::DEBUG);
                 }
             }

+ 0 - 4
test/log

@@ -1,4 +0,0 @@
-Foo
-Bar
-Foo
-Bar