Browse Source

Game uses hikaricp for all connection pooling. Connection count set dynamically.

master
MagicBot 2 years ago
parent
commit
0e4490576a
  1. 19
      src/engine/db/archive/BaneRecord.java
  2. 19
      src/engine/db/archive/CharacterRecord.java
  3. 3
      src/engine/db/archive/CityRecord.java
  4. 37
      src/engine/db/archive/DataWarehouse.java
  5. 3
      src/engine/db/archive/GuildRecord.java
  6. 3
      src/engine/db/archive/MineRecord.java
  7. 9
      src/engine/db/archive/PvpRecord.java
  8. 3
      src/engine/db/archive/RealmRecord.java
  9. 2
      src/engine/db/handlers/dbHandlerBase.java
  10. 56
      src/engine/gameManager/DbManager.java
  11. 3
      src/engine/gameManager/SimulationManager.java
  12. 37
      src/engine/server/login/LoginServer.java
  13. 2
      src/engine/server/world/WorldServer.java
  14. 1
      src/engine/workthreads/HourlyJobThread.java
  15. 4
      src/engine/workthreads/PurgeOprhans.java
  16. 29
      src/engine/workthreads/WarehousePushThread.java

19
src/engine/db/archive/BaneRecord.java

@ -10,6 +10,7 @@
package engine.db.archive; package engine.db.archive;
import engine.Enum; import engine.Enum;
import engine.gameManager.DbManager;
import engine.objects.Bane; import engine.objects.Bane;
import engine.objects.City; import engine.objects.City;
import engine.workthreads.WarehousePushThread; import engine.workthreads.WarehousePushThread;
@ -134,7 +135,7 @@ public class BaneRecord extends DataRecord {
DateTime outDateTime = null; DateTime outDateTime = null;
try (Connection connection = DataWarehouse.connectionPool.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement statement = buildDateTimeQueryStatement(connection, city); PreparedStatement statement = buildDateTimeQueryStatement(connection, city);
ResultSet rs = statement.executeQuery()) { ResultSet rs = statement.executeQuery()) {
@ -145,7 +146,7 @@ public class BaneRecord extends DataRecord {
} }
} catch (SQLException e) { } catch (SQLException e) {
Logger.error( e.toString()); Logger.error(e.toString());
} }
return outDateTime; return outDateTime;
@ -166,13 +167,13 @@ public class BaneRecord extends DataRecord {
if (bane == null) if (bane == null)
return; return;
try (Connection connection = DataWarehouse.connectionPool.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement statement = buildUpdateLiveDateStatement(connection, bane, dateTime)) { PreparedStatement statement = buildUpdateLiveDateStatement(connection, bane, dateTime)) {
statement.execute(); statement.execute();
} catch (SQLException e) { } catch (SQLException e) {
Logger.error( e.toString()); Logger.error(e.toString());
} }
} }
@ -203,7 +204,7 @@ public class BaneRecord extends DataRecord {
public static void updateResolution(Bane bane, RecordEventType eventType) { public static void updateResolution(Bane bane, RecordEventType eventType) {
try (Connection connection = DataWarehouse.connectionPool.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement statement = buildUpdateResolutionStatement(connection, bane, eventType)) { PreparedStatement statement = buildUpdateResolutionStatement(connection, bane, eventType)) {
statement.execute(); statement.execute();
@ -223,7 +224,7 @@ public class BaneRecord extends DataRecord {
dividerString = "--------------------------------" + newLine; dividerString = "--------------------------------" + newLine;
queryString = "CALL `baneHistory`()"; queryString = "CALL `baneHistory`()";
try (Connection connection = DataWarehouse.connectionPool.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement statement = connection.prepareCall(queryString); PreparedStatement statement = connection.prepareCall(queryString);
ResultSet rs = statement.executeQuery()) { ResultSet rs = statement.executeQuery()) {
@ -253,7 +254,7 @@ public class BaneRecord extends DataRecord {
WarehousePushThread.baneDelta = 0; WarehousePushThread.baneDelta = 0;
try (Connection localConnection = DataWarehouse.connectionPool.getConnection(); try (Connection localConnection = DbManager.getConnection();
PreparedStatement statement = localConnection.prepareStatement(queryString, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); // Make this an updatable result set as we'll reset the dirty flag as we go along PreparedStatement statement = localConnection.prepareStatement(queryString, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); // Make this an updatable result set as we'll reset the dirty flag as we go along
ResultSet rs = statement.executeQuery()) { ResultSet rs = statement.executeQuery()) {
@ -338,13 +339,13 @@ public class BaneRecord extends DataRecord {
public void write() { public void write() {
try (Connection connection = DataWarehouse.connectionPool.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement statement = buildBaneInsertStatement(connection)) { PreparedStatement statement = buildBaneInsertStatement(connection)) {
statement.execute(); statement.execute();
} catch (SQLException e) { } catch (SQLException e) {
Logger.error( e.toString()); Logger.error(e.toString());
} }
} }

19
src/engine/db/archive/CharacterRecord.java

@ -10,6 +10,7 @@
package engine.db.archive; package engine.db.archive;
import engine.Enum; import engine.Enum;
import engine.gameManager.DbManager;
import engine.objects.Guild; import engine.objects.Guild;
import engine.objects.PlayerCharacter; import engine.objects.PlayerCharacter;
import engine.workthreads.WarehousePushThread; import engine.workthreads.WarehousePushThread;
@ -109,13 +110,13 @@ public class CharacterRecord extends DataRecord {
public static void advanceKillCounter(PlayerCharacter player) { public static void advanceKillCounter(PlayerCharacter player) {
try (Connection connection = DataWarehouse.connectionPool.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement statement = buildKillCounterStatement(connection, player)) { PreparedStatement statement = buildKillCounterStatement(connection, player)) {
statement.execute(); statement.execute();
} catch (SQLException e) { } catch (SQLException e) {
Logger.error( e.toString()); Logger.error(e.toString());
} }
} }
@ -136,13 +137,13 @@ public class CharacterRecord extends DataRecord {
public static void advanceDeathCounter(PlayerCharacter player) { public static void advanceDeathCounter(PlayerCharacter player) {
try (Connection connection = DataWarehouse.connectionPool.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement statement = buildDeathCounterStatement(connection, player)) { PreparedStatement statement = buildDeathCounterStatement(connection, player)) {
statement.execute(); statement.execute();
} catch (SQLException e) { } catch (SQLException e) {
Logger.error( e.toString()); Logger.error(e.toString());
} }
} }
@ -163,13 +164,13 @@ public class CharacterRecord extends DataRecord {
public static void updatePromotionClass(PlayerCharacter player) { public static void updatePromotionClass(PlayerCharacter player) {
try (Connection connection = DataWarehouse.connectionPool.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement statement = buildUpdatePromotionStatement(connection, player)) { PreparedStatement statement = buildUpdatePromotionStatement(connection, player)) {
statement.execute(); statement.execute();
} catch (SQLException e) { } catch (SQLException e) {
Logger.error( e.toString()); Logger.error(e.toString());
} }
} }
@ -197,7 +198,7 @@ public class CharacterRecord extends DataRecord {
WarehousePushThread.charDelta = 0; WarehousePushThread.charDelta = 0;
try (Connection localConnection = DataWarehouse.connectionPool.getConnection(); try (Connection localConnection = DbManager.getConnection();
PreparedStatement statement = localConnection.prepareStatement(queryString, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); // Make this an updatable result set as we'll reset the dirty flag as we go along PreparedStatement statement = localConnection.prepareStatement(queryString, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); // Make this an updatable result set as we'll reset the dirty flag as we go along
ResultSet rs = statement.executeQuery()) { ResultSet rs = statement.executeQuery()) {
@ -263,13 +264,13 @@ public class CharacterRecord extends DataRecord {
public void write() { public void write() {
try (Connection connection = DataWarehouse.connectionPool.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement statement = buildCharacterInsertStatement(connection, this.player)) { PreparedStatement statement = buildCharacterInsertStatement(connection, this.player)) {
statement.execute(); statement.execute();
} catch (SQLException e) { } catch (SQLException e) {
Logger.error( "Error writing character record " + e.toString()); Logger.error("Error writing character record " + e.toString());
} }
} }

3
src/engine/db/archive/CityRecord.java

@ -10,6 +10,7 @@
package engine.db.archive; package engine.db.archive;
import engine.Enum; import engine.Enum;
import engine.gameManager.DbManager;
import engine.objects.City; import engine.objects.City;
import engine.workthreads.WarehousePushThread; import engine.workthreads.WarehousePushThread;
@ -126,7 +127,7 @@ public class CityRecord extends DataRecord {
public void write() { public void write() {
try (Connection connection = DataWarehouse.connectionPool.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement statement = this.buildCityInsertStatement(connection)) { PreparedStatement statement = this.buildCityInsertStatement(connection)) {
statement.execute(); statement.execute();

37
src/engine/db/archive/DataWarehouse.java

@ -12,6 +12,7 @@ package engine.db.archive;
import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource; import com.zaxxer.hikari.HikariDataSource;
import engine.gameManager.ConfigManager; import engine.gameManager.ConfigManager;
import engine.gameManager.DbManager;
import engine.util.Hasher; import engine.util.Hasher;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
@ -27,14 +28,13 @@ public class DataWarehouse implements Runnable {
public static final Hasher hasher = new Hasher("Cthulhu Owns Joo"); public static final Hasher hasher = new Hasher("Cthulhu Owns Joo");
private static final LinkedBlockingQueue<DataRecord> recordQueue = new LinkedBlockingQueue<>(); private static final LinkedBlockingQueue<DataRecord> recordQueue = new LinkedBlockingQueue<>();
public static HikariDataSource connectionPool = null;
public static HikariDataSource remoteConnectionPool = null; public static HikariDataSource remoteConnectionPool = null;
public DataWarehouse() { public DataWarehouse() {
Logger.info("Configuring local Database Connection Pool..."); Logger.info("Configuring local Database Connection Pool...");
configureConnectionPool(); DbManager.configureConnectionPool();
// If WarehousePush is disabled // If WarehousePush is disabled
// then early exit // then early exit
@ -72,11 +72,7 @@ public class DataWarehouse implements Runnable {
String queryString; String queryString;
String hashString; String hashString;
try { connection = DbManager.getConnection();
connection = DataWarehouse.connectionPool.getConnection();
} catch (SQLException e) {
e.printStackTrace();
}
if (connection == null) { if (connection == null) {
Logger.error("Null connection when writing zone hash."); Logger.error("Null connection when writing zone hash.");
@ -140,11 +136,7 @@ public class DataWarehouse implements Runnable {
String queryString; String queryString;
ResultSet resultSet; ResultSet resultSet;
try { connection = DbManager.getConnection();
connection = DataWarehouse.connectionPool.getConnection();
} catch (SQLException e) {
e.printStackTrace();
}
if (connection == null) { if (connection == null) {
Logger.error("Null connection during char record lookup"); Logger.error("Null connection during char record lookup");
@ -282,27 +274,6 @@ public class DataWarehouse implements Runnable {
} }
} }
private static void configureConnectionPool() {
HikariConfig config = new HikariConfig();
config.setMaximumPoolSize(10);
config.setJdbcUrl("jdbc:mysql://" + ConfigManager.MB_DATABASE_ADDRESS.getValue() +
":" + ConfigManager.MB_DATABASE_PORT.getValue() + "/" +
ConfigManager.MB_DATABASE_NAME.getValue());
config.setUsername(ConfigManager.MB_DATABASE_USER.getValue());
config.setPassword( ConfigManager.MB_DATABASE_PASS.getValue());
config.addDataSourceProperty("characterEncoding", "utf8");
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
connectionPool = new HikariDataSource(config); // setup the connection pool
Logger.info("Local warehouse database connection configured");
}
private static void configureRemoteConnectionPool() { private static void configureRemoteConnectionPool() {
HikariConfig config = new HikariConfig(); HikariConfig config = new HikariConfig();

3
src/engine/db/archive/GuildRecord.java

@ -11,6 +11,7 @@ package engine.db.archive;
import engine.Enum; import engine.Enum;
import engine.Enum.RecordEventType; import engine.Enum.RecordEventType;
import engine.gameManager.DbManager;
import engine.objects.Guild; import engine.objects.Guild;
import engine.workthreads.WarehousePushThread; import engine.workthreads.WarehousePushThread;
@ -164,7 +165,7 @@ public class GuildRecord extends DataRecord {
public void write() { public void write() {
try (Connection connection = DataWarehouse.connectionPool.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement statement = this.buildGuildInsertStatement(connection)) { PreparedStatement statement = this.buildGuildInsertStatement(connection)) {
statement.execute(); statement.execute();

3
src/engine/db/archive/MineRecord.java

@ -10,6 +10,7 @@
package engine.db.archive; package engine.db.archive;
import engine.Enum; import engine.Enum;
import engine.gameManager.DbManager;
import engine.objects.AbstractCharacter; import engine.objects.AbstractCharacter;
import engine.objects.Mine; import engine.objects.Mine;
import engine.objects.PlayerCharacter; import engine.objects.PlayerCharacter;
@ -131,7 +132,7 @@ public class MineRecord extends DataRecord {
public void write() { public void write() {
try (Connection connection = DataWarehouse.connectionPool.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement statement = this.buildMineInsertStatement(connection)) { PreparedStatement statement = this.buildMineInsertStatement(connection)) {
statement.execute(); statement.execute();

9
src/engine/db/archive/PvpRecord.java

@ -9,6 +9,7 @@
package engine.db.archive; package engine.db.archive;
import engine.gameManager.DbManager;
import engine.gameManager.ZoneManager; import engine.gameManager.ZoneManager;
import engine.math.Vector3fImmutable; import engine.math.Vector3fImmutable;
import engine.objects.Guild; import engine.objects.Guild;
@ -90,7 +91,7 @@ public class PvpRecord extends DataRecord {
LinkedList<Integer> outList = new LinkedList<>(); LinkedList<Integer> outList = new LinkedList<>();
try (Connection connection = DataWarehouse.connectionPool.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement statement = buildHistoryStatement(connection, charUUID, historyType); PreparedStatement statement = buildHistoryStatement(connection, charUUID, historyType);
ResultSet rs = statement.executeQuery()) { ResultSet rs = statement.executeQuery()) {
@ -132,7 +133,7 @@ public class PvpRecord extends DataRecord {
outString = "[LUA_PVP() DATA WAREHOUSE]" + newLine; outString = "[LUA_PVP() DATA WAREHOUSE]" + newLine;
dividerString = "--------------------------------" + newLine; dividerString = "--------------------------------" + newLine;
try (Connection connection = DataWarehouse.connectionPool.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement statement = buildLuaHistoryQueryStatement(connection, charUUID); PreparedStatement statement = buildLuaHistoryQueryStatement(connection, charUUID);
ResultSet rs = statement.executeQuery()) { ResultSet rs = statement.executeQuery()) {
@ -293,13 +294,13 @@ public class PvpRecord extends DataRecord {
public void write() { public void write() {
try (Connection connection = DataWarehouse.connectionPool.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement statement = buildPvPInsertStatement(connection)) { PreparedStatement statement = buildPvPInsertStatement(connection)) {
statement.execute(); statement.execute();
} catch (SQLException e) { } catch (SQLException e) {
Logger.error( e.toString()); Logger.error(e.toString());
} }
// Warehouse record for this pvp event written if code path reaches here. // Warehouse record for this pvp event written if code path reaches here.

3
src/engine/db/archive/RealmRecord.java

@ -10,6 +10,7 @@
package engine.db.archive; package engine.db.archive;
import engine.Enum; import engine.Enum;
import engine.gameManager.DbManager;
import engine.objects.Realm; import engine.objects.Realm;
import engine.workthreads.WarehousePushThread; import engine.workthreads.WarehousePushThread;
@ -128,7 +129,7 @@ public class RealmRecord extends DataRecord {
public void write() { public void write() {
try (Connection connection = DataWarehouse.connectionPool.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement statement = this.buildRealmInsertStatement(connection)) { PreparedStatement statement = this.buildRealmInsertStatement(connection)) {
statement.execute(); statement.execute();

2
src/engine/db/handlers/dbHandlerBase.java

@ -34,7 +34,7 @@ public abstract class dbHandlerBase {
protected final void prepareCallable(final String sql) { protected final void prepareCallable(final String sql) {
try { try {
this.cs.set((CallableStatement) DbManager.getConn().prepareCall(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)); this.cs.set((CallableStatement) DbManager.getConnection().prepareCall(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY));
} catch (SQLException e) { } catch (SQLException e) {
Logger.error("DbManager.getConn", e); Logger.error("DbManager.getConn", e);
Logger.error("SQL Error number: " + e.getErrorCode()); Logger.error("SQL Error number: " + e.getErrorCode());

56
src/engine/gameManager/DbManager.java

@ -8,11 +8,12 @@
package engine.gameManager; package engine.gameManager;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import engine.Enum; import engine.Enum;
import engine.Enum.GameObjectType; import engine.Enum.GameObjectType;
import engine.db.handlers.*; import engine.db.handlers.*;
import engine.objects.*; import engine.objects.*;
import engine.pooling.ConnectionPool;
import engine.server.MBServerStatics; import engine.server.MBServerStatics;
import engine.util.Hasher; import engine.util.Hasher;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
@ -26,28 +27,14 @@ import java.util.concurrent.ConcurrentHashMap;
public enum DbManager { public enum DbManager {
DBMANAGER; DBMANAGER;
private static ConnectionPool connPool; private static HikariDataSource connectionPool = null;
public static Hasher hasher; public static Hasher hasher;
//Local Object Caching //Local Object Caching
private static final EnumMap<GameObjectType, ConcurrentHashMap<Integer, AbstractGameObject>> objectCache = new EnumMap<>(GameObjectType.class); private static final EnumMap<GameObjectType, ConcurrentHashMap<Integer, AbstractGameObject>> objectCache = new EnumMap<>(GameObjectType.class);
public static boolean configureDatabaseLayer() {
boolean worked = true;
try {
DbManager.connPool = new ConnectionPool();
DbManager.connPool.fill(10);
DBMANAGER.hasher = new Hasher();
} catch (Exception e ) {
e.printStackTrace();
worked = false;
}
return worked;
}
public static AbstractGameObject getObject(GameObjectType objectType, int objectUUID) { public static AbstractGameObject getObject(GameObjectType objectType, int objectUUID) {
AbstractGameObject outObject = null; AbstractGameObject outObject = null;
@ -87,9 +74,6 @@ public enum DbManager {
return outObject; return outObject;
} }
public static int getPoolSize(){
return connPool.getPoolSize();
}
public static boolean inCache(GameObjectType gameObjectType, int uuid) { public static boolean inCache(GameObjectType gameObjectType, int uuid) {
@ -227,7 +211,7 @@ public enum DbManager {
} }
public static PreparedStatement prepareStatement(String sql) throws SQLException { public static PreparedStatement prepareStatement(String sql) throws SQLException {
return getConn().prepareStatement(sql, 1); return getConnection().prepareStatement(sql, 1);
} }
// Omg refactor this out, somebody! // Omg refactor this out, somebody!
@ -259,15 +243,12 @@ public enum DbManager {
* @return the conn * @return the conn
*/ */
//XXX I think we have a severe resource leak here! No one is putting the connections back! //XXX I think we have a severe resource leak here! No one is putting the connections back!
public static Connection getConn() { public static Connection getConnection() {
Connection conn = DbManager.connPool.get();
try { try {
if (!conn.isClosed()) return DbManager.connectionPool.getConnection();
DbManager.connPool.put(conn);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error( e.toString()); throw new RuntimeException(e);
} }
return conn;
} }
public static final dbAccountHandler AccountQueries = new dbAccountHandler(); public static final dbAccountHandler AccountQueries = new dbAccountHandler();
@ -312,4 +293,25 @@ public enum DbManager {
public static final dbHeightMapHandler HeightMapQueries = new dbHeightMapHandler(); public static final dbHeightMapHandler HeightMapQueries = new dbHeightMapHandler();
public static final dbRunegateHandler RunegateQueries = new dbRunegateHandler(); public static final dbRunegateHandler RunegateQueries = new dbRunegateHandler();
public static void configureConnectionPool() {
HikariConfig config = new HikariConfig();
config.setMaximumPoolSize(Runtime.getRuntime().availableProcessors() * 2);
config.setJdbcUrl("jdbc:mysql://" + ConfigManager.MB_DATABASE_ADDRESS.getValue() +
":" + ConfigManager.MB_DATABASE_PORT.getValue() + "/" +
ConfigManager.MB_DATABASE_NAME.getValue());
config.setUsername(ConfigManager.MB_DATABASE_USER.getValue());
config.setPassword(ConfigManager.MB_DATABASE_PASS.getValue());
config.addDataSourceProperty("characterEncoding", "utf8");
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
connectionPool = new HikariDataSource(config); // setup the connection pool
Logger.info("Local warehouse database connection configured");
}
} }

3
src/engine/gameManager/SimulationManager.java

@ -10,7 +10,6 @@ package engine.gameManager;
import engine.Enum; import engine.Enum;
import engine.Enum.GameObjectType; import engine.Enum.GameObjectType;
import engine.db.archive.DataWarehouse;
import engine.objects.AbstractGameObject; import engine.objects.AbstractGameObject;
import engine.objects.City; import engine.objects.City;
import engine.objects.PlayerCharacter; import engine.objects.PlayerCharacter;
@ -58,7 +57,7 @@ public enum SimulationManager {
String popString = ""; String popString = "";
try (Connection connection = DataWarehouse.connectionPool.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement getPopString = connection.prepareStatement("CALL GET_POPULATION_STRING()");) { PreparedStatement getPopString = connection.prepareStatement("CALL GET_POPULATION_STRING()");) {
ResultSet rs = getPopString.executeQuery(); ResultSet rs = getPopString.executeQuery();

37
src/engine/server/login/LoginServer.java

@ -9,8 +9,6 @@
package engine.server.login; package engine.server.login;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import engine.Enum; import engine.Enum;
import engine.gameManager.*; import engine.gameManager.*;
import engine.job.JobScheduler; import engine.job.JobScheduler;
@ -52,7 +50,6 @@ public class LoginServer {
// Instance variables // Instance variables
private VersionInfoMsg versionInfoMessage; private VersionInfoMsg versionInfoMessage;
public static HikariDataSource connectionPool = null;
public static int population = 0; public static int population = 0;
public static boolean worldServerRunning = false; public static boolean worldServerRunning = false;
public static boolean loginServerRunning = false; public static boolean loginServerRunning = false;
@ -172,9 +169,6 @@ public class LoginServer {
this.versionInfoMessage = new VersionInfoMsg(ConfigManager.MB_MAJOR_VER.getValue(), this.versionInfoMessage = new VersionInfoMsg(ConfigManager.MB_MAJOR_VER.getValue(),
ConfigManager.MB_MINOR_VER.getValue()); ConfigManager.MB_MINOR_VER.getValue());
Logger.info("Initializing Database Pool");
initDatabasePool();
Logger.info("Initializing Database layer"); Logger.info("Initializing Database layer");
initDatabaseLayer(); initDatabaseLayer();
@ -229,12 +223,12 @@ public class LoginServer {
// Try starting a GOM <-> DB connection. // Try starting a GOM <-> DB connection.
try { try {
Logger.info("Configuring GameObjectManager to use Database: '" Logger.info("Configuring Magicbane to use Database: '"
+ ConfigManager.MB_DATABASE_NAME.getValue() + "' on " + ConfigManager.MB_DATABASE_NAME.getValue() + "' on "
+ ConfigManager.MB_DATABASE_ADDRESS.getValue() + ':' + ConfigManager.MB_DATABASE_ADDRESS.getValue() + ':'
+ ConfigManager.MB_DATABASE_PORT.getValue()); + ConfigManager.MB_DATABASE_PORT.getValue());
DbManager.configureDatabaseLayer(); DbManager.configureConnectionPool();
} catch (Exception e) { } catch (Exception e) {
Logger.error(e.getMessage()); Logger.error(e.getMessage());
@ -365,33 +359,12 @@ public class LoginServer {
} }
private void initDatabasePool() {
HikariConfig config = new HikariConfig();
config.setMaximumPoolSize(33); // (16 cores 1 spindle)
config.setJdbcUrl("jdbc:mysql://" + ConfigManager.MB_DATABASE_ADDRESS.getValue() +
":" + ConfigManager.MB_DATABASE_PORT.getValue() + "/" +
ConfigManager.MB_DATABASE_NAME.getValue());
config.setUsername(ConfigManager.MB_DATABASE_USER.getValue());
config.setPassword(ConfigManager.MB_DATABASE_PASS.getValue());
config.addDataSourceProperty("characterEncoding", "utf8");
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
connectionPool = new HikariDataSource(config); // setup the connection pool
Logger.info("local database connection configured");
}
public void invalidateCacheList() { public void invalidateCacheList() {
int objectUUID; int objectUUID;
String objectType; String objectType;
try (Connection connection = connectionPool.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement statement = connection.prepareStatement("SELECT * FROM `login_cachelist`"); PreparedStatement statement = connection.prepareStatement("SELECT * FROM `login_cachelist`");
ResultSet rs = statement.executeQuery()) { ResultSet rs = statement.executeQuery()) {
@ -424,7 +397,7 @@ public class LoginServer {
// clear the db table // clear the db table
try (Connection connection = connectionPool.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement statement = connection.prepareStatement("DELETE FROM `login_cachelist`")) { PreparedStatement statement = connection.prepareStatement("DELETE FROM `login_cachelist`")) {
statement.execute(); statement.execute();
@ -447,7 +420,7 @@ public class LoginServer {
// query data warehouse for unresolved bane with this character // query data warehouse for unresolved bane with this character
try (Connection connection = connectionPool.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement statement = buildQueryActiveBaneStatement(connection, playerCharacter); PreparedStatement statement = buildQueryActiveBaneStatement(connection, playerCharacter);
ResultSet rs = statement.executeQuery()) { ResultSet rs = statement.executeQuery()) {

2
src/engine/server/world/WorldServer.java

@ -471,7 +471,7 @@ public class WorldServer {
+ ConfigManager.MB_DATABASE_ADDRESS.getValue() + ':' + ConfigManager.MB_DATABASE_ADDRESS.getValue() + ':'
+ ConfigManager.MB_DATABASE_PORT.getValue()); + ConfigManager.MB_DATABASE_PORT.getValue());
DbManager.configureDatabaseLayer(); DbManager.configureConnectionPool();
} catch (Exception e) { } catch (Exception e) {
Logger.error(e.getMessage()); Logger.error(e.getMessage());

1
src/engine/workthreads/HourlyJobThread.java

@ -284,7 +284,6 @@ public class HourlyJobThread implements Runnable {
Logger.info(WorldServer.getUptimeString()); Logger.info(WorldServer.getUptimeString());
Logger.info(SimulationManager.getPopulationString()); Logger.info(SimulationManager.getPopulationString());
Logger.info(MessageDispatcher.getNetstatString()); Logger.info(MessageDispatcher.getNetstatString());
Logger.info("Connection Pool Size: " + DbManager.getPoolSize());
Logger.info(PurgeOprhans.recordsDeleted.toString() + "orphaned items deleted"); Logger.info(PurgeOprhans.recordsDeleted.toString() + "orphaned items deleted");
} }
} }

4
src/engine/workthreads/PurgeOprhans.java

@ -8,7 +8,7 @@
package engine.workthreads; package engine.workthreads;
import engine.db.archive.DataWarehouse; import engine.gameManager.DbManager;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.sql.Connection; import java.sql.Connection;
@ -46,7 +46,7 @@ public class PurgeOprhans implements Runnable {
// Member variable declaration // Member variable declaration
try ( try (
Connection connection = DataWarehouse.connectionPool.getConnection(); Connection connection = DbManager.getConnection();
PreparedStatement statement = connection.prepareStatement("SELECT * from `object` where `type` = 'item' AND `parent` IS NULL", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); PreparedStatement statement = connection.prepareStatement("SELECT * from `object` where `type` = 'item' AND `parent` IS NULL", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = statement.executeQuery()) { ResultSet rs = statement.executeQuery()) {

29
src/engine/workthreads/WarehousePushThread.java

@ -18,6 +18,7 @@ package engine.workthreads;
import engine.Enum; import engine.Enum;
import engine.db.archive.*; import engine.db.archive.*;
import engine.gameManager.ConfigManager; import engine.gameManager.ConfigManager;
import engine.gameManager.DbManager;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.sql.*; import java.sql.*;
@ -153,7 +154,7 @@ public class WarehousePushThread implements Runnable {
public static boolean pushMineRecords() { public static boolean pushMineRecords() {
try (Connection localConnection = DataWarehouse.connectionPool.getConnection(); try (Connection localConnection = DbManager.getConnection();
PreparedStatement statement = MineRecord.buildMineQueryStatement(localConnection); PreparedStatement statement = MineRecord.buildMineQueryStatement(localConnection);
ResultSet rs = statement.executeQuery()) { ResultSet rs = statement.executeQuery()) {
@ -164,7 +165,7 @@ public class WarehousePushThread implements Runnable {
return true; return true;
} catch (SQLException e) { } catch (SQLException e) {
Logger.error( "Error with local DB connection: " + e.toString()); Logger.error("Error with local DB connection: " + e.toString());
e.printStackTrace(); e.printStackTrace();
return false; return false;
} }
@ -172,7 +173,7 @@ public class WarehousePushThread implements Runnable {
public static boolean pushCharacterRecords() { public static boolean pushCharacterRecords() {
try (Connection localConnection = DataWarehouse.connectionPool.getConnection(); try (Connection localConnection = DbManager.getConnection();
PreparedStatement statement = CharacterRecord.buildCharacterQueryStatement(localConnection); PreparedStatement statement = CharacterRecord.buildCharacterQueryStatement(localConnection);
ResultSet rs = statement.executeQuery()) { ResultSet rs = statement.executeQuery()) {
@ -183,7 +184,7 @@ public class WarehousePushThread implements Runnable {
return true; return true;
} catch (SQLException e) { } catch (SQLException e) {
Logger.error( "Error with local DB connection: " + e.toString()); Logger.error("Error with local DB connection: " + e.toString());
e.printStackTrace(); e.printStackTrace();
return false; return false;
} }
@ -191,7 +192,7 @@ public class WarehousePushThread implements Runnable {
private static boolean pushGuildRecords() { private static boolean pushGuildRecords() {
try (Connection localConnection = DataWarehouse.connectionPool.getConnection(); try (Connection localConnection = DbManager.getConnection();
PreparedStatement statement = GuildRecord.buildGuildQueryStatement(localConnection); PreparedStatement statement = GuildRecord.buildGuildQueryStatement(localConnection);
ResultSet rs = statement.executeQuery()) { ResultSet rs = statement.executeQuery()) {
@ -238,7 +239,7 @@ public class WarehousePushThread implements Runnable {
private static boolean pushBaneRecords() { private static boolean pushBaneRecords() {
try (Connection localConnection = DataWarehouse.connectionPool.getConnection(); try (Connection localConnection = DbManager.getConnection();
PreparedStatement statement = BaneRecord.buildBaneQueryStatement(localConnection); PreparedStatement statement = BaneRecord.buildBaneQueryStatement(localConnection);
ResultSet rs = statement.executeQuery()) { ResultSet rs = statement.executeQuery()) {
@ -271,7 +272,7 @@ public class WarehousePushThread implements Runnable {
private static boolean pushCityRecords() { private static boolean pushCityRecords() {
try (Connection localConnection = DataWarehouse.connectionPool.getConnection(); try (Connection localConnection = DbManager.getConnection();
PreparedStatement statement = CityRecord.buildCityQueryStatement(localConnection); PreparedStatement statement = CityRecord.buildCityQueryStatement(localConnection);
ResultSet rs = statement.executeQuery()) { ResultSet rs = statement.executeQuery()) {
@ -282,7 +283,7 @@ public class WarehousePushThread implements Runnable {
return true; return true;
} catch (SQLException e) { } catch (SQLException e) {
Logger.error( "Error with local DB connection: " + e.toString()); Logger.error("Error with local DB connection: " + e.toString());
e.printStackTrace(); e.printStackTrace();
return false; return false;
} }
@ -290,7 +291,7 @@ public class WarehousePushThread implements Runnable {
private static boolean pushPvpRecords() { private static boolean pushPvpRecords() {
try (Connection localConnection = DataWarehouse.connectionPool.getConnection(); try (Connection localConnection = DbManager.getConnection();
PreparedStatement statement = PvpRecord.buildPvpQueryStatement(localConnection); PreparedStatement statement = PvpRecord.buildPvpQueryStatement(localConnection);
ResultSet rs = statement.executeQuery()) { ResultSet rs = statement.executeQuery()) {
@ -323,7 +324,7 @@ public class WarehousePushThread implements Runnable {
private static boolean pushRealmRecords() { private static boolean pushRealmRecords() {
try (Connection localConnection = DataWarehouse.connectionPool.getConnection(); try (Connection localConnection = DbManager.getConnection();
PreparedStatement statement = RealmRecord.buildRealmQueryStatement(localConnection); PreparedStatement statement = RealmRecord.buildRealmQueryStatement(localConnection);
ResultSet rs = statement.executeQuery()) { ResultSet rs = statement.executeQuery()) {
@ -335,7 +336,7 @@ public class WarehousePushThread implements Runnable {
return true; return true;
} catch (SQLException e) { } catch (SQLException e) {
Logger.error( "Error with local DB connection: " + e.toString()); Logger.error("Error with local DB connection: " + e.toString());
e.printStackTrace(); e.printStackTrace();
return false; return false;
} }
@ -392,7 +393,7 @@ public class WarehousePushThread implements Runnable {
queryString = "SELECT * FROM `warehouse_index`"; queryString = "SELECT * FROM `warehouse_index`";
try (Connection localConnection = DataWarehouse.connectionPool.getConnection(); try (Connection localConnection = DbManager.getConnection();
CallableStatement statement = localConnection.prepareCall(queryString); CallableStatement statement = localConnection.prepareCall(queryString);
ResultSet rs = statement.executeQuery()) { ResultSet rs = statement.executeQuery()) {
@ -417,14 +418,14 @@ public class WarehousePushThread implements Runnable {
private static boolean updateWarehouseIndex() { private static boolean updateWarehouseIndex() {
try (Connection connection = DataWarehouse.connectionPool.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement statement = WarehousePushThread.buildIndexUpdateStatement(connection)) { PreparedStatement statement = WarehousePushThread.buildIndexUpdateStatement(connection)) {
statement.execute(); statement.execute();
return true; return true;
} catch (SQLException e) { } catch (SQLException e) {
Logger.error( e.toString()); Logger.error(e.toString());
return false; return false;
} }
} }

Loading…
Cancel
Save