Skip to content
This repository has been archived by the owner on Jun 12, 2020. It is now read-only.

Commit

Permalink
MariaDB connection pool is now a stack
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyberboss committed Jun 6, 2018
1 parent ddcace5 commit 58716cf
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/BSQL/BSQL.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <deque>
#include <map>
#include <memory>
#include <queue>
#include <stack>
#include <string>
#include <thread>

Expand Down
4 changes: 2 additions & 2 deletions src/BSQL/MySqlConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ MySqlConnection::~MySqlConnection() {
operations.clear();
//and release them
while (!availableConnections.empty()) {
auto front(availableConnections.front());
auto front(availableConnections.top());
mysql_close(front);
if (front == firstSuccessfulConnection)
firstSuccessfulConnection = nullptr;
Expand Down Expand Up @@ -57,7 +57,7 @@ MYSQL* MySqlConnection::RequestConnection() {
if (availableConnections.empty() && !LoadNewConnection())
return nullptr;

auto front(availableConnections.front());
auto front(availableConnections.top());
availableConnections.pop();
if (availableConnections.empty())
LoadNewConnection();
Expand Down
2 changes: 1 addition & 1 deletion src/BSQL/MySqlConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class MySqlConnection : public Connection {
std::string database;
unsigned short port;

std::queue<MYSQL*> availableConnections;
std::stack<MYSQL*> availableConnections;
MYSQL* firstSuccessfulConnection;
MySqlConnectOperation* newestConnectionAttempt;
private:
Expand Down
2 changes: 2 additions & 0 deletions src/DMAPI/BSQL.dm
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Properly quotes a string for use by the database. The connection must be open fo
Starts an operation for a query
query: The text of the query. Only one query allowed per invocation, no semicolons
Returns: A /datum/BSQL_Operation/Query representing the running query and subsequent result set or null if an error occurred
Note for MariaDB: The underlying connection is pooled. In order to use connection state based properties (i.e. LAST_INSERT_ID()) you can guarantee multiple queries will use the same connection by running BSQL_DEL_CALL(query) on the finished /datum/BSQL_Operation/Query and then creating the next one with another call to BeginQuery() with no sleeps in between
*/
/datum/BSQL_Connection/proc/BeginQuery(query)
return
Expand Down

0 comments on commit 58716cf

Please sign in to comment.