------------------------------------------------------------
revno: 235
committer: John Deal <bassd...@yahoo.com>
branch nick: dbBackEnd
timestamp: Sun 2011-10-02 11:57:54 -0400
message:
  Corrected loading of default MySQL DB password.  Improved multi-threaded DB 
load tests.  Improved 1 configuration error message.  Removed 1 warning.  Minor 
stuff.
modified:
  mira-server/conf/mysqlInit.sql
  mira-server/src/ConfigParser.cpp
  mira-server/src/directory/db/DbDirectory.cpp
  mira-server/src/directory/db/mysql/DbMySqlDirectory.cpp
  mira-server/src/main.cpp


--
lp:~mira-dev/mira/dbBackEnd
https://code.launchpad.net/~mira-dev/mira/dbBackEnd

You are subscribed to branch lp:~mira-dev/mira/dbBackEnd.
To unsubscribe from this branch go to 
https://code.launchpad.net/~mira-dev/mira/dbBackEnd/+edit-subscription
=== modified file 'mira-server/conf/mysqlInit.sql'
--- mira-server/conf/mysqlInit.sql	2011-09-06 00:59:09 +0000
+++ mira-server/conf/mysqlInit.sql	2011-10-02 15:57:54 +0000
@@ -64,7 +64,7 @@
     constraint foreign key (userID) references users(userID)
         on delete cascade on update cascade,
     constraint foreign key (workplaceID) references workplaces(workplaceID)
-        on delete cascade on update cascade
+        on delete cascade on update cascade,
     constraint foreign key (rolesID) references roles(roleID) on delete cascade
         on update cascade
 )

=== modified file 'mira-server/src/ConfigParser.cpp'
--- mira-server/src/ConfigParser.cpp	2008-07-02 11:06:53 +0000
+++ mira-server/src/ConfigParser.cpp	2011-10-02 15:57:54 +0000
@@ -71,7 +71,7 @@
    	if (!IsItem(strCurrentLine.substr(0, strCurrentLine.find(" "))))
    	{
    	   // handle error "Unrecognizable configuration"
-   	   cout << "Line " << intCurrentLine << ": Unrecognizable configuration." << endl;
+   	   cout << "Line " << intCurrentLine << ": '" << strCurrentLine << "' : Unrecognizable configuration." << endl;
    	   continue;
    	}
 

=== modified file 'mira-server/src/directory/db/DbDirectory.cpp'
--- mira-server/src/directory/db/DbDirectory.cpp	2011-09-06 00:59:09 +0000
+++ mira-server/src/directory/db/DbDirectory.cpp	2011-10-02 15:57:54 +0000
@@ -56,7 +56,7 @@
             "): Obtaining Write lock on DB failed. Error Code: " <<
             lock_error_code << std::endl;
         return false;
-     }
+    }
 
     return true;
 }
@@ -74,7 +74,7 @@
             "): Obtaining read lock on DB failed. Error Code: " <<
             lock_error_code << std::endl;
         return false;
-     }
+    }
 
     return true;
 }
@@ -91,7 +91,7 @@
         std::cout << "Error (DbDirectory::" << module_name <<
             "): Releasing lock on DB failed. Error Code: " <<
             unlock_error_code << std::endl;
-     }
+    }
 }
 
 DbDirectory::DbDirectory()
@@ -110,10 +110,14 @@
     m_db_type           = db_type;
     // m_db_path           = path;
     // m_db_config         = db_config;
-    m_db_config.db_path = ((db_config_struct*) db_config)->db_path;
-    m_db_config.clean   = ((db_config_struct*) db_config)->clean;
-    m_db_config.analyze = ((db_config_struct*) db_config)->analyze;
-    m_db_config.vacuum  = ((db_config_struct*) db_config)->vacuum;
+
+    if ((first_time == true) && (m_db_type == sqlite))
+    {
+        m_db_config.db_path = ((db_config_struct*) db_config)->db_path;
+        m_db_config.clean   = ((db_config_struct*) db_config)->clean;
+        m_db_config.analyze = ((db_config_struct*) db_config)->analyze;
+        m_db_config.vacuum  = ((db_config_struct*) db_config)->vacuum;
+    }
 
   pthread_return = pthread_mutex_init(&m_inst_table_lock, NULL);
 

=== modified file 'mira-server/src/directory/db/mysql/DbMySqlDirectory.cpp'
--- mira-server/src/directory/db/mysql/DbMySqlDirectory.cpp	2011-09-06 00:59:09 +0000
+++ mira-server/src/directory/db/mysql/DbMySqlDirectory.cpp	2011-10-02 15:57:54 +0000
@@ -868,6 +868,8 @@
             cout << "ERROR (DbMySqlDirectory::DbMySqlDirectory): Memory allocation for password failed.";
             exit(-1); // Can't continue.
         }
+
+        strcpy(m_db_password, workStr.c_str());
     } // End if (workStr == "").
 
     workStr = Application::get_configuration().GetConfiguration(

=== modified file 'mira-server/src/main.cpp'
--- mira-server/src/main.cpp	2011-09-06 00:59:09 +0000
+++ mira-server/src/main.cpp	2011-10-02 15:57:54 +0000
@@ -66,7 +66,7 @@
 // Below ONLY for testing DbDirectory.
 // Note user IDs are auto generated.  You will have to adjust user IDs. on 
 // the find_user() calls.
-/*********************************************************************
+/*****************************************************
 static DbDirectory* testDbDirectory;
 
 
@@ -94,30 +94,46 @@
 
         numCalls++;
     }
+
+    return (void*) 0;
  }
 
-void *loopAddUser(void *startUserId)
+void *loopAddUser(void *p_nameId)
 {
     miraserver::User user;
     unsigned int numCalls = 0;
-    // unsigned int id = *((unsigned int*) startUserId);
+    unsigned int nameId = *((unsigned int*) p_nameId);
     unsigned int id = 1;
     char charName[128];
     std::string  userName;
 
-    std::sprintf(charName, "X%d",id);
-    userName = charName;
-    user.set_username(userName);
+    switch (nameId)
+    {
+        case 0:
+            charName[0] = 'X';
+            break;
+
+        case 1:
+            charName[0] = 'Y';
+            break;
+
+        default:
+            charName[0] = 'Z';
+            break;
+    } 
+
+    // userName = charName;
+    // user.set_username(userName);
 
     for (;;)
     {
-        std::sprintf(charName, "X%d",id);
+        std::sprintf(&charName[1], "%d",id);
         userName = charName;
         user.set_username(userName);
 
         if (testDbDirectory->add_user(user) == true)
         {
-            std::cout << "Add user #: " << id << " #Calls: " <<
+            std::cout << "Add user: " << charName << " #Calls: " <<
                 numCalls << std::endl;
         }
         else
@@ -129,6 +145,8 @@
         id++;
         numCalls++;
     }
+
+    return (void*) 0;
  }
 
 
@@ -178,7 +196,7 @@
         }
 
         // Find user #2.
-        user = testDbDirectory->find_user((unsigned int) 4);
+        user = testDbDirectory->find_user((unsigned int) 2);
 
         if (user.is_valid() == true)
         {
@@ -194,36 +212,40 @@
         id++;
         numCalls++;
     }
+
+        return (void*) 0;
  }
 
 void dbLoadTest(DbDirectory* directory)
 {
-    unsigned int findId = 1;
-    // unsigned int addId  = 100;
+    static unsigned int findId_1 = 1;
+    static unsigned int findId_2 = 2;
+    static unsigned int nameId_1 = 0;
+    static unsigned int nameId_2 = 1;
+
     pthread_t loopFindUserThread_1;
     pthread_t loopFindUserThread_2;
     pthread_t loopAddUserThread_1;
-    // pthread_t loopFindAddUserThread_1;
-    unsigned int* startUserId = &findId;
-    // unsigned int* startAddId  = &addId;
     int threadReturn;
 
 
     testDbDirectory = directory;
 
     threadReturn = pthread_create(&loopFindUserThread_1, NULL, loopFindUser,
-        (void*) startUserId);
+        (void*) &findId_1);
 
     std::cout << "Find User Tread #1 return: " << threadReturn << std::endl;
 
-    findId = 4;
     threadReturn = pthread_create(&loopFindUserThread_2, NULL, loopFindUser,
-        (void*) startUserId);
+        (void*) &findId_2);
 
     std::cout << "Find User Tread #2 return: " << threadReturn << std::endl;
 
     threadReturn = pthread_create(&loopAddUserThread_1, NULL, loopAddUser,
-        (void*) NULL);
+        (void*) &nameId_1);
+
+    threadReturn = pthread_create(&loopAddUserThread_1, NULL, loopAddUser,
+        (void*) &nameId_2);
 
     std::cout << "Add User Tread return: " << threadReturn << std::endl;
 
@@ -233,11 +255,11 @@
 //    std::cout << "Find Add User Tread return: " << threadReturn << std::endl;
 }
 // End of DB Testing.
-*********************************************************************/
+*****************************************************/
 
 int main(int argc, char* argv[])
 {
-    std:string workConfig;
+    string workConfig;
 
 
     try
@@ -247,15 +269,29 @@
         Application::get_configuration().InsertItem("PORT");
         Application::get_configuration().InsertItem("NETWORK_THREAD_COUNT");
         Application::get_configuration().InsertItem("NEW_ACCOUNT_CREATOR");
+        // Application::get_configuration().InsertItem("ASIO_INPUT_BUFFER_SIZE");
         Application::get_configuration().InsertItem(
             DbDirectory::getConfigTypeName());
+
+        // SQLite specific configuration items.
         Application::get_configuration().InsertItem(
             DbDirectory::getConfigPathName());
         Application::get_configuration().InsertItem(
             DbDirectory::getConfigAnalyze());
         Application::get_configuration().InsertItem(
             DbDirectory::getConfigRebuild());
-        // Application::get_configuration().InsertItem("ASIO_INPUT_BUFFER_SIZE");
+
+        // MySQL specific configuration items.
+        Application::get_configuration().InsertItem(
+            DbDirectory::getConfigUserName());
+        Application::get_configuration().InsertItem(
+            DbDirectory::getConfigHostName());
+        Application::get_configuration().InsertItem(
+            DbDirectory::getConfigPassword());
+        Application::get_configuration().InsertItem(
+            DbDirectory::getConfigPort());
+        Application::get_configuration().InsertItem(
+            DbDirectory::getConfigSocket());
 
         Application::get_configuration().ParseConfigFile();
 
@@ -300,7 +336,7 @@
                 db_config.vacuum = false;
             }
 
-            // dbLoadTest(new DbDirectory(sqlite, workConfig)); // TEST!  DB load test.
+            // dbLoadTest(new DbDirectory(sqlite, workConfig)); // TEST!!!!  DB load test.
             Application::set_directory(new DbDirectory(sqlite,
                  (void *) &db_config));
         }
@@ -309,6 +345,7 @@
             if (workConfig.compare(DbMySqlDirectory::configTypeName)
                 == 0)
             { // MySql specified.
+                // dbLoadTest(new DbDirectory(mysql, (void*) NULL)); // TEST!!!!  DB load test.
                 Application::set_directory(new DbDirectory(mysql,
                     (void*) NULL));
             }

------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2dcopy2
_______________________________________________
Mira-development mailing list
Mira-development@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mira-development

Reply via email to