]> git.stg.codes - stg.git/commitdiff
Змімено спосіб зберігання TRAFF_STATS після невдалого запису
authorMaxim Mamontov <faust@gts.dp.ua>
Fri, 24 Dec 2010 14:56:19 +0000 (16:56 +0200)
committerMaxim Mamontov <faust@gts.dp.ua>
Fri, 24 Dec 2010 14:56:19 +0000 (16:56 +0200)
projects/stargazer/user.cpp
projects/stargazer/user.h

index 989d11b5e6d7c5edc29aaf569a6a3808cbd2c140..48b8094c2c8e4af01535aea52c7d52df05646fb2 100644 (file)
@@ -940,22 +940,18 @@ Run();
 //-----------------------------------------------------------------------------
 int USER::WriteDetailStat(bool hard)
 {
-printfd(__FILE__, "USER::WriteDetailedStat() - queue size = %d\n", traffStatQueue.size());
+printfd(__FILE__, "USER::WriteDetailedStat() - saved size = %d\n", traffStatSaved.second.size());
 
-if (!traffStatQueue.empty())
+if (!traffStatSaved.second.empty())
     {
-    std::list<std::pair<time_t, TRAFF_STAT> >::iterator it;
-    for (it = traffStatQueue.begin(); it != traffStatQueue.end(); ++it)
+    if (store->WriteDetailedStat(traffStatSaved.second, traffStatSaved.first, login))
         {
-        if (store->WriteDetailedStat(it->second, it->first, login))
-            {
-            printfd(__FILE__, "USER::WriteDetailStat() - failed to write detail stat from queue\n");
-            WriteServLog("Cannot write detail stat from queue (of size %d recs) for user %s.", traffStatQueue.size(), login.c_str());
-            WriteServLog("%s", store->GetStrError().c_str());
-            return -1;
-            }
-        traffStatQueue.erase(it++);
+        printfd(__FILE__, "USER::WriteDetailStat() - failed to write detail stat from queue\n");
+        WriteServLog("Cannot write detail stat from queue (of size %d recs) for user %s.", traffStatSaved.second.size(), login.c_str());
+        WriteServLog("%s", store->GetStrError().c_str());
+        return -1;
         }
+    traffStatSaved.second.erase(traffStatSaved.second.begin(), traffStatSaved.second.end());
     }
 
 TRAFF_STAT ts;
@@ -977,8 +973,11 @@ if (ts.size() && !disabledDetailStat)
         if (!hard)
             {
             printfd(__FILE__, "USER::WriteDetailStat() - pushing detail stat to queue\n");
-            traffStatQueue.push_back(std::make_pair(lastWriteDeatiledStat, ts));
+            STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+            traffStatSaved.second.swap(ts);
+            traffStatSaved.first = lastWriteDeatiledStat;
             }
+        return -1;
         }
     }
 lastWriteDeatiledStat = stgTime;
index 8e33846329949c346e40465a3a9ac37392bb2200..392a121b7f6b81da490ea908a69da7d89a3834a9 100644 (file)
@@ -233,7 +233,7 @@ private:
     const TARIFF *  tariff;
 
     TRAFF_STAT      traffStat;
-    std::list<std::pair<time_t, TRAFF_STAT> > traffStatQueue;
+    std::pair<time_t, TRAFF_STAT> traffStatSaved;
 
     const SETTINGS * settings;