From 0e4490576ae0c67dd2b61b92d5755e39f063499d Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sat, 20 May 2023 09:39:23 -0400 Subject: [PATCH] Game uses hikaricp for all connection pooling. Connection count set dynamically. --- src/engine/db/archive/BaneRecord.java | 37 +++++------ src/engine/db/archive/CharacterRecord.java | 19 +++--- src/engine/db/archive/CityRecord.java | 5 +- src/engine/db/archive/DataWarehouse.java | 37 ++--------- src/engine/db/archive/GuildRecord.java | 15 ++--- src/engine/db/archive/MineRecord.java | 3 +- src/engine/db/archive/PvpRecord.java | 31 ++++----- src/engine/db/archive/RealmRecord.java | 3 +- src/engine/db/handlers/dbHandlerBase.java | 2 +- src/engine/gameManager/DbManager.java | 56 +++++++++-------- src/engine/gameManager/SimulationManager.java | 3 +- src/engine/server/login/LoginServer.java | 39 ++---------- src/engine/server/world/WorldServer.java | 2 +- src/engine/workthreads/HourlyJobThread.java | 1 - src/engine/workthreads/PurgeOprhans.java | 4 +- .../workthreads/WarehousePushThread.java | 63 ++++++++++--------- 16 files changed, 136 insertions(+), 184 deletions(-) diff --git a/src/engine/db/archive/BaneRecord.java b/src/engine/db/archive/BaneRecord.java index 51209f06..27f6507f 100644 --- a/src/engine/db/archive/BaneRecord.java +++ b/src/engine/db/archive/BaneRecord.java @@ -10,6 +10,7 @@ package engine.db.archive; import engine.Enum; +import engine.gameManager.DbManager; import engine.objects.Bane; import engine.objects.City; import engine.workthreads.WarehousePushThread; @@ -134,9 +135,9 @@ public class BaneRecord extends DataRecord { DateTime outDateTime = null; - try (Connection connection = DataWarehouse.connectionPool.getConnection(); - PreparedStatement statement = buildDateTimeQueryStatement(connection, city); - ResultSet rs = statement.executeQuery()) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement statement = buildDateTimeQueryStatement(connection, city); + ResultSet rs = statement.executeQuery()) { while (rs.next()) { @@ -145,7 +146,7 @@ public class BaneRecord extends DataRecord { } } catch (SQLException e) { - Logger.error( e.toString()); + Logger.error(e.toString()); } return outDateTime; @@ -166,13 +167,13 @@ public class BaneRecord extends DataRecord { if (bane == null) return; - try (Connection connection = DataWarehouse.connectionPool.getConnection(); - PreparedStatement statement = buildUpdateLiveDateStatement(connection, bane, dateTime)) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement statement = buildUpdateLiveDateStatement(connection, bane, dateTime)) { statement.execute(); } catch (SQLException e) { - Logger.error( e.toString()); + Logger.error(e.toString()); } } @@ -203,8 +204,8 @@ public class BaneRecord extends DataRecord { public static void updateResolution(Bane bane, RecordEventType eventType) { - try (Connection connection = DataWarehouse.connectionPool.getConnection(); - PreparedStatement statement = buildUpdateResolutionStatement(connection, bane, eventType)) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement statement = buildUpdateResolutionStatement(connection, bane, eventType)) { statement.execute(); @@ -223,9 +224,9 @@ public class BaneRecord extends DataRecord { dividerString = "--------------------------------" + newLine; queryString = "CALL `baneHistory`()"; - try (Connection connection = DataWarehouse.connectionPool.getConnection(); - PreparedStatement statement = connection.prepareCall(queryString); - ResultSet rs = statement.executeQuery()) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement statement = connection.prepareCall(queryString); + ResultSet rs = statement.executeQuery()) { while (rs.next()) { @@ -253,9 +254,9 @@ public class BaneRecord extends DataRecord { WarehousePushThread.baneDelta = 0; - try (Connection localConnection = DataWarehouse.connectionPool.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 - ResultSet rs = statement.executeQuery()) { + 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 + ResultSet rs = statement.executeQuery()) { while (rs.next()) { @@ -338,13 +339,13 @@ public class BaneRecord extends DataRecord { public void write() { - try (Connection connection = DataWarehouse.connectionPool.getConnection(); - PreparedStatement statement = buildBaneInsertStatement(connection)) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement statement = buildBaneInsertStatement(connection)) { statement.execute(); } catch (SQLException e) { - Logger.error( e.toString()); + Logger.error(e.toString()); } } diff --git a/src/engine/db/archive/CharacterRecord.java b/src/engine/db/archive/CharacterRecord.java index b1c6e3b5..157c6d71 100644 --- a/src/engine/db/archive/CharacterRecord.java +++ b/src/engine/db/archive/CharacterRecord.java @@ -10,6 +10,7 @@ package engine.db.archive; import engine.Enum; +import engine.gameManager.DbManager; import engine.objects.Guild; import engine.objects.PlayerCharacter; import engine.workthreads.WarehousePushThread; @@ -109,13 +110,13 @@ public class CharacterRecord extends DataRecord { public static void advanceKillCounter(PlayerCharacter player) { - try (Connection connection = DataWarehouse.connectionPool.getConnection(); + try (Connection connection = DbManager.getConnection(); PreparedStatement statement = buildKillCounterStatement(connection, player)) { statement.execute(); } 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) { - try (Connection connection = DataWarehouse.connectionPool.getConnection(); + try (Connection connection = DbManager.getConnection(); PreparedStatement statement = buildDeathCounterStatement(connection, player)) { statement.execute(); } 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) { - try (Connection connection = DataWarehouse.connectionPool.getConnection(); + try (Connection connection = DbManager.getConnection(); PreparedStatement statement = buildUpdatePromotionStatement(connection, player)) { statement.execute(); } catch (SQLException e) { - Logger.error( e.toString()); + Logger.error(e.toString()); } } @@ -197,7 +198,7 @@ public class CharacterRecord extends DataRecord { 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 ResultSet rs = statement.executeQuery()) { @@ -263,13 +264,13 @@ public class CharacterRecord extends DataRecord { public void write() { - try (Connection connection = DataWarehouse.connectionPool.getConnection(); + try (Connection connection = DbManager.getConnection(); PreparedStatement statement = buildCharacterInsertStatement(connection, this.player)) { statement.execute(); } catch (SQLException e) { - Logger.error( "Error writing character record " + e.toString()); + Logger.error("Error writing character record " + e.toString()); } } diff --git a/src/engine/db/archive/CityRecord.java b/src/engine/db/archive/CityRecord.java index 50b123e0..785cf405 100644 --- a/src/engine/db/archive/CityRecord.java +++ b/src/engine/db/archive/CityRecord.java @@ -10,6 +10,7 @@ package engine.db.archive; import engine.Enum; +import engine.gameManager.DbManager; import engine.objects.City; import engine.workthreads.WarehousePushThread; @@ -126,8 +127,8 @@ public class CityRecord extends DataRecord { public void write() { - try (Connection connection = DataWarehouse.connectionPool.getConnection(); - PreparedStatement statement = this.buildCityInsertStatement(connection)) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement statement = this.buildCityInsertStatement(connection)) { statement.execute(); diff --git a/src/engine/db/archive/DataWarehouse.java b/src/engine/db/archive/DataWarehouse.java index 5483e18b..9236a38c 100644 --- a/src/engine/db/archive/DataWarehouse.java +++ b/src/engine/db/archive/DataWarehouse.java @@ -12,6 +12,7 @@ package engine.db.archive; import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; import engine.gameManager.ConfigManager; +import engine.gameManager.DbManager; import engine.util.Hasher; import org.pmw.tinylog.Logger; @@ -27,14 +28,13 @@ public class DataWarehouse implements Runnable { public static final Hasher hasher = new Hasher("Cthulhu Owns Joo"); private static final LinkedBlockingQueue recordQueue = new LinkedBlockingQueue<>(); - public static HikariDataSource connectionPool = null; public static HikariDataSource remoteConnectionPool = null; public DataWarehouse() { Logger.info("Configuring local Database Connection Pool..."); - configureConnectionPool(); + DbManager.configureConnectionPool(); // If WarehousePush is disabled // then early exit @@ -72,11 +72,7 @@ public class DataWarehouse implements Runnable { String queryString; String hashString; - try { - connection = DataWarehouse.connectionPool.getConnection(); - } catch (SQLException e) { - e.printStackTrace(); - } + connection = DbManager.getConnection(); if (connection == null) { Logger.error("Null connection when writing zone hash."); @@ -140,11 +136,7 @@ public class DataWarehouse implements Runnable { String queryString; ResultSet resultSet; - try { - connection = DataWarehouse.connectionPool.getConnection(); - } catch (SQLException e) { - e.printStackTrace(); - } + connection = DbManager.getConnection(); if (connection == null) { 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() { HikariConfig config = new HikariConfig(); diff --git a/src/engine/db/archive/GuildRecord.java b/src/engine/db/archive/GuildRecord.java index c68a3cb3..ec141cea 100644 --- a/src/engine/db/archive/GuildRecord.java +++ b/src/engine/db/archive/GuildRecord.java @@ -11,6 +11,7 @@ package engine.db.archive; import engine.Enum; import engine.Enum.RecordEventType; +import engine.gameManager.DbManager; import engine.objects.Guild; import engine.workthreads.WarehousePushThread; @@ -164,16 +165,16 @@ public class GuildRecord extends DataRecord { public void write() { - try (Connection connection = DataWarehouse.connectionPool.getConnection(); - PreparedStatement statement = this.buildGuildInsertStatement(connection)) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement statement = this.buildGuildInsertStatement(connection)) { - statement.execute(); + statement.execute(); - } catch (SQLException e) { - e.printStackTrace(); - } + } catch (SQLException e) { + e.printStackTrace(); + } - } + } private PreparedStatement buildGuildInsertStatement(Connection connection) throws SQLException { diff --git a/src/engine/db/archive/MineRecord.java b/src/engine/db/archive/MineRecord.java index 69621ba8..dbc236c0 100644 --- a/src/engine/db/archive/MineRecord.java +++ b/src/engine/db/archive/MineRecord.java @@ -10,6 +10,7 @@ package engine.db.archive; import engine.Enum; +import engine.gameManager.DbManager; import engine.objects.AbstractCharacter; import engine.objects.Mine; import engine.objects.PlayerCharacter; @@ -131,7 +132,7 @@ public class MineRecord extends DataRecord { public void write() { - try (Connection connection = DataWarehouse.connectionPool.getConnection(); + try (Connection connection = DbManager.getConnection(); PreparedStatement statement = this.buildMineInsertStatement(connection)) { statement.execute(); diff --git a/src/engine/db/archive/PvpRecord.java b/src/engine/db/archive/PvpRecord.java index a3199127..56734977 100644 --- a/src/engine/db/archive/PvpRecord.java +++ b/src/engine/db/archive/PvpRecord.java @@ -9,6 +9,7 @@ package engine.db.archive; +import engine.gameManager.DbManager; import engine.gameManager.ZoneManager; import engine.math.Vector3fImmutable; import engine.objects.Guild; @@ -90,19 +91,19 @@ public class PvpRecord extends DataRecord { LinkedList outList = new LinkedList<>(); - try (Connection connection = DataWarehouse.connectionPool.getConnection(); - PreparedStatement statement = buildHistoryStatement(connection, charUUID, historyType); - ResultSet rs = statement.executeQuery()) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement statement = buildHistoryStatement(connection, charUUID, historyType); + ResultSet rs = statement.executeQuery()) { while (rs.next()) { switch (historyType) { - case KILLS: - outList.add((int) DataWarehouse.hasher.decrypt(rs.getString("victim_id"))[0]); - break; - case DEATHS: - outList.add((int) DataWarehouse.hasher.decrypt(rs.getString("char_id"))[0]); - break; + case KILLS: + outList.add((int) DataWarehouse.hasher.decrypt(rs.getString("victim_id"))[0]); + break; + case DEATHS: + outList.add((int) DataWarehouse.hasher.decrypt(rs.getString("char_id"))[0]); + break; } } } catch (SQLException e) { @@ -132,9 +133,9 @@ public class PvpRecord extends DataRecord { outString = "[LUA_PVP() DATA WAREHOUSE]" + newLine; dividerString = "--------------------------------" + newLine; - try (Connection connection = DataWarehouse.connectionPool.getConnection(); - PreparedStatement statement = buildLuaHistoryQueryStatement(connection, charUUID); - ResultSet rs = statement.executeQuery()) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement statement = buildLuaHistoryQueryStatement(connection, charUUID); + ResultSet rs = statement.executeQuery()) { while (rs.next()) { @@ -293,13 +294,13 @@ public class PvpRecord extends DataRecord { public void write() { - try (Connection connection = DataWarehouse.connectionPool.getConnection(); - PreparedStatement statement = buildPvPInsertStatement(connection)) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement statement = buildPvPInsertStatement(connection)) { statement.execute(); } catch (SQLException e) { - Logger.error( e.toString()); + Logger.error(e.toString()); } // Warehouse record for this pvp event written if code path reaches here. diff --git a/src/engine/db/archive/RealmRecord.java b/src/engine/db/archive/RealmRecord.java index 556eebe2..957858e5 100644 --- a/src/engine/db/archive/RealmRecord.java +++ b/src/engine/db/archive/RealmRecord.java @@ -10,6 +10,7 @@ package engine.db.archive; import engine.Enum; +import engine.gameManager.DbManager; import engine.objects.Realm; import engine.workthreads.WarehousePushThread; @@ -128,7 +129,7 @@ public class RealmRecord extends DataRecord { public void write() { - try (Connection connection = DataWarehouse.connectionPool.getConnection(); + try (Connection connection = DbManager.getConnection(); PreparedStatement statement = this.buildRealmInsertStatement(connection)) { statement.execute(); diff --git a/src/engine/db/handlers/dbHandlerBase.java b/src/engine/db/handlers/dbHandlerBase.java index 2531d854..726d9494 100644 --- a/src/engine/db/handlers/dbHandlerBase.java +++ b/src/engine/db/handlers/dbHandlerBase.java @@ -34,7 +34,7 @@ public abstract class dbHandlerBase { protected final void prepareCallable(final String sql) { 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) { Logger.error("DbManager.getConn", e); Logger.error("SQL Error number: " + e.getErrorCode()); diff --git a/src/engine/gameManager/DbManager.java b/src/engine/gameManager/DbManager.java index c89099e2..d0778236 100644 --- a/src/engine/gameManager/DbManager.java +++ b/src/engine/gameManager/DbManager.java @@ -8,11 +8,12 @@ package engine.gameManager; +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.HikariDataSource; import engine.Enum; import engine.Enum.GameObjectType; import engine.db.handlers.*; import engine.objects.*; -import engine.pooling.ConnectionPool; import engine.server.MBServerStatics; import engine.util.Hasher; import org.pmw.tinylog.Logger; @@ -26,28 +27,14 @@ import java.util.concurrent.ConcurrentHashMap; public enum DbManager { DBMANAGER; - private static ConnectionPool connPool; + private static HikariDataSource connectionPool = null; + public static Hasher hasher; //Local Object Caching private static final EnumMap> 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) { AbstractGameObject outObject = null; @@ -87,9 +74,6 @@ public enum DbManager { return outObject; } - public static int getPoolSize(){ - return connPool.getPoolSize(); - } public static boolean inCache(GameObjectType gameObjectType, int uuid) { @@ -227,7 +211,7 @@ public enum DbManager { } public static PreparedStatement prepareStatement(String sql) throws SQLException { - return getConn().prepareStatement(sql, 1); + return getConnection().prepareStatement(sql, 1); } // Omg refactor this out, somebody! @@ -259,15 +243,12 @@ public enum DbManager { * @return the conn */ //XXX I think we have a severe resource leak here! No one is putting the connections back! - public static Connection getConn() { - Connection conn = DbManager.connPool.get(); + public static Connection getConnection() { try { - if (!conn.isClosed()) - DbManager.connPool.put(conn); + return DbManager.connectionPool.getConnection(); } catch (SQLException e) { - Logger.error( e.toString()); + throw new RuntimeException(e); } - return conn; } public static final dbAccountHandler AccountQueries = new dbAccountHandler(); @@ -312,4 +293,25 @@ public enum DbManager { public static final dbHeightMapHandler HeightMapQueries = new dbHeightMapHandler(); 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"); + } } diff --git a/src/engine/gameManager/SimulationManager.java b/src/engine/gameManager/SimulationManager.java index 478369e2..9cff43a1 100644 --- a/src/engine/gameManager/SimulationManager.java +++ b/src/engine/gameManager/SimulationManager.java @@ -10,7 +10,6 @@ package engine.gameManager; import engine.Enum; import engine.Enum.GameObjectType; -import engine.db.archive.DataWarehouse; import engine.objects.AbstractGameObject; import engine.objects.City; import engine.objects.PlayerCharacter; @@ -58,7 +57,7 @@ public enum SimulationManager { String popString = ""; - try (Connection connection = DataWarehouse.connectionPool.getConnection(); + try (Connection connection = DbManager.getConnection(); PreparedStatement getPopString = connection.prepareStatement("CALL GET_POPULATION_STRING()");) { ResultSet rs = getPopString.executeQuery(); diff --git a/src/engine/server/login/LoginServer.java b/src/engine/server/login/LoginServer.java index 2933e51d..dfa35aa9 100644 --- a/src/engine/server/login/LoginServer.java +++ b/src/engine/server/login/LoginServer.java @@ -9,8 +9,6 @@ package engine.server.login; -import com.zaxxer.hikari.HikariConfig; -import com.zaxxer.hikari.HikariDataSource; import engine.Enum; import engine.gameManager.*; import engine.job.JobScheduler; @@ -52,7 +50,6 @@ public class LoginServer { // Instance variables private VersionInfoMsg versionInfoMessage; - public static HikariDataSource connectionPool = null; public static int population = 0; public static boolean worldServerRunning = false; public static boolean loginServerRunning = false; @@ -172,9 +169,6 @@ public class LoginServer { this.versionInfoMessage = new VersionInfoMsg(ConfigManager.MB_MAJOR_VER.getValue(), ConfigManager.MB_MINOR_VER.getValue()); - Logger.info("Initializing Database Pool"); - initDatabasePool(); - Logger.info("Initializing Database layer"); initDatabaseLayer(); @@ -229,12 +223,12 @@ public class LoginServer { // Try starting a GOM <-> DB connection. try { - Logger.info("Configuring GameObjectManager to use Database: '" + Logger.info("Configuring Magicbane to use Database: '" + ConfigManager.MB_DATABASE_NAME.getValue() + "' on " + ConfigManager.MB_DATABASE_ADDRESS.getValue() + ':' + ConfigManager.MB_DATABASE_PORT.getValue()); - DbManager.configureDatabaseLayer(); + DbManager.configureConnectionPool(); } catch (Exception e) { 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() { int objectUUID; String objectType; - try (Connection connection = connectionPool.getConnection(); + try (Connection connection = DbManager.getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM `login_cachelist`"); ResultSet rs = statement.executeQuery()) { @@ -400,7 +373,7 @@ public class LoginServer { objectUUID = rs.getInt("UID"); objectType = rs.getString("type"); - Logger.info("INVALIDATED : " + objectType + " UUID: " + objectUUID); + Logger.info("INVALIDATED : " + objectType + " UUID: " + objectUUID); switch (objectType) { @@ -424,7 +397,7 @@ public class LoginServer { // clear the db table - try (Connection connection = connectionPool.getConnection(); + try (Connection connection = DbManager.getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM `login_cachelist`")) { statement.execute(); @@ -447,7 +420,7 @@ public class LoginServer { // query data warehouse for unresolved bane with this character - try (Connection connection = connectionPool.getConnection(); + try (Connection connection = DbManager.getConnection(); PreparedStatement statement = buildQueryActiveBaneStatement(connection, playerCharacter); ResultSet rs = statement.executeQuery()) { diff --git a/src/engine/server/world/WorldServer.java b/src/engine/server/world/WorldServer.java index 3aa843d2..98658e53 100644 --- a/src/engine/server/world/WorldServer.java +++ b/src/engine/server/world/WorldServer.java @@ -471,7 +471,7 @@ public class WorldServer { + ConfigManager.MB_DATABASE_ADDRESS.getValue() + ':' + ConfigManager.MB_DATABASE_PORT.getValue()); - DbManager.configureDatabaseLayer(); + DbManager.configureConnectionPool(); } catch (Exception e) { Logger.error(e.getMessage()); diff --git a/src/engine/workthreads/HourlyJobThread.java b/src/engine/workthreads/HourlyJobThread.java index fe363244..dbf17e0c 100644 --- a/src/engine/workthreads/HourlyJobThread.java +++ b/src/engine/workthreads/HourlyJobThread.java @@ -284,7 +284,6 @@ public class HourlyJobThread implements Runnable { Logger.info(WorldServer.getUptimeString()); Logger.info(SimulationManager.getPopulationString()); Logger.info(MessageDispatcher.getNetstatString()); - Logger.info("Connection Pool Size: " + DbManager.getPoolSize()); Logger.info(PurgeOprhans.recordsDeleted.toString() + "orphaned items deleted"); } } diff --git a/src/engine/workthreads/PurgeOprhans.java b/src/engine/workthreads/PurgeOprhans.java index c75f4d69..dc33c17c 100644 --- a/src/engine/workthreads/PurgeOprhans.java +++ b/src/engine/workthreads/PurgeOprhans.java @@ -8,7 +8,7 @@ package engine.workthreads; -import engine.db.archive.DataWarehouse; +import engine.gameManager.DbManager; import org.pmw.tinylog.Logger; import java.sql.Connection; @@ -46,7 +46,7 @@ public class PurgeOprhans implements Runnable { // Member variable declaration 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); ResultSet rs = statement.executeQuery()) { diff --git a/src/engine/workthreads/WarehousePushThread.java b/src/engine/workthreads/WarehousePushThread.java index 39757da5..da920ecb 100644 --- a/src/engine/workthreads/WarehousePushThread.java +++ b/src/engine/workthreads/WarehousePushThread.java @@ -18,6 +18,7 @@ package engine.workthreads; import engine.Enum; import engine.db.archive.*; import engine.gameManager.ConfigManager; +import engine.gameManager.DbManager; import org.pmw.tinylog.Logger; import java.sql.*; @@ -153,9 +154,9 @@ public class WarehousePushThread implements Runnable { public static boolean pushMineRecords() { - try (Connection localConnection = DataWarehouse.connectionPool.getConnection(); - PreparedStatement statement = MineRecord.buildMineQueryStatement(localConnection); - ResultSet rs = statement.executeQuery()) { + try (Connection localConnection = DbManager.getConnection(); + PreparedStatement statement = MineRecord.buildMineQueryStatement(localConnection); + ResultSet rs = statement.executeQuery()) { while (rs.next()) { pushMineRecord(rs); @@ -164,7 +165,7 @@ public class WarehousePushThread implements Runnable { return true; } catch (SQLException e) { - Logger.error( "Error with local DB connection: " + e.toString()); + Logger.error("Error with local DB connection: " + e.toString()); e.printStackTrace(); return false; } @@ -172,9 +173,9 @@ public class WarehousePushThread implements Runnable { public static boolean pushCharacterRecords() { - try (Connection localConnection = DataWarehouse.connectionPool.getConnection(); - PreparedStatement statement = CharacterRecord.buildCharacterQueryStatement(localConnection); - ResultSet rs = statement.executeQuery()) { + try (Connection localConnection = DbManager.getConnection(); + PreparedStatement statement = CharacterRecord.buildCharacterQueryStatement(localConnection); + ResultSet rs = statement.executeQuery()) { while (rs.next()) { pushCharacterRecord(rs); @@ -183,7 +184,7 @@ public class WarehousePushThread implements Runnable { return true; } catch (SQLException e) { - Logger.error( "Error with local DB connection: " + e.toString()); + Logger.error("Error with local DB connection: " + e.toString()); e.printStackTrace(); return false; } @@ -191,9 +192,9 @@ public class WarehousePushThread implements Runnable { private static boolean pushGuildRecords() { - try (Connection localConnection = DataWarehouse.connectionPool.getConnection(); - PreparedStatement statement = GuildRecord.buildGuildQueryStatement(localConnection); - ResultSet rs = statement.executeQuery()) { + try (Connection localConnection = DbManager.getConnection(); + PreparedStatement statement = GuildRecord.buildGuildQueryStatement(localConnection); + ResultSet rs = statement.executeQuery()) { while (rs.next()) { pushGuildRecord(rs); @@ -238,9 +239,9 @@ public class WarehousePushThread implements Runnable { private static boolean pushBaneRecords() { - try (Connection localConnection = DataWarehouse.connectionPool.getConnection(); - PreparedStatement statement = BaneRecord.buildBaneQueryStatement(localConnection); - ResultSet rs = statement.executeQuery()) { + try (Connection localConnection = DbManager.getConnection(); + PreparedStatement statement = BaneRecord.buildBaneQueryStatement(localConnection); + ResultSet rs = statement.executeQuery()) { while (rs.next()) { pushBaneRecord(rs); @@ -271,9 +272,9 @@ public class WarehousePushThread implements Runnable { private static boolean pushCityRecords() { - try (Connection localConnection = DataWarehouse.connectionPool.getConnection(); - PreparedStatement statement = CityRecord.buildCityQueryStatement(localConnection); - ResultSet rs = statement.executeQuery()) { + try (Connection localConnection = DbManager.getConnection(); + PreparedStatement statement = CityRecord.buildCityQueryStatement(localConnection); + ResultSet rs = statement.executeQuery()) { while (rs.next()) { pushCityRecord(rs); @@ -282,7 +283,7 @@ public class WarehousePushThread implements Runnable { return true; } catch (SQLException e) { - Logger.error( "Error with local DB connection: " + e.toString()); + Logger.error("Error with local DB connection: " + e.toString()); e.printStackTrace(); return false; } @@ -290,9 +291,9 @@ public class WarehousePushThread implements Runnable { private static boolean pushPvpRecords() { - try (Connection localConnection = DataWarehouse.connectionPool.getConnection(); - PreparedStatement statement = PvpRecord.buildPvpQueryStatement(localConnection); - ResultSet rs = statement.executeQuery()) { + try (Connection localConnection = DbManager.getConnection(); + PreparedStatement statement = PvpRecord.buildPvpQueryStatement(localConnection); + ResultSet rs = statement.executeQuery()) { while (rs.next()) { @@ -323,9 +324,9 @@ public class WarehousePushThread implements Runnable { private static boolean pushRealmRecords() { - try (Connection localConnection = DataWarehouse.connectionPool.getConnection(); - PreparedStatement statement = RealmRecord.buildRealmQueryStatement(localConnection); - ResultSet rs = statement.executeQuery()) { + try (Connection localConnection = DbManager.getConnection(); + PreparedStatement statement = RealmRecord.buildRealmQueryStatement(localConnection); + ResultSet rs = statement.executeQuery()) { while (rs.next()) { @@ -335,7 +336,7 @@ public class WarehousePushThread implements Runnable { return true; } catch (SQLException e) { - Logger.error( "Error with local DB connection: " + e.toString()); + Logger.error("Error with local DB connection: " + e.toString()); e.printStackTrace(); return false; } @@ -392,9 +393,9 @@ public class WarehousePushThread implements Runnable { queryString = "SELECT * FROM `warehouse_index`"; - try (Connection localConnection = DataWarehouse.connectionPool.getConnection(); - CallableStatement statement = localConnection.prepareCall(queryString); - ResultSet rs = statement.executeQuery()) { + try (Connection localConnection = DbManager.getConnection(); + CallableStatement statement = localConnection.prepareCall(queryString); + ResultSet rs = statement.executeQuery()) { while (rs.next()) { charIndex = rs.getInt("charIndex"); @@ -417,14 +418,14 @@ public class WarehousePushThread implements Runnable { private static boolean updateWarehouseIndex() { - try (Connection connection = DataWarehouse.connectionPool.getConnection(); - PreparedStatement statement = WarehousePushThread.buildIndexUpdateStatement(connection)) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement statement = WarehousePushThread.buildIndexUpdateStatement(connection)) { statement.execute(); return true; } catch (SQLException e) { - Logger.error( e.toString()); + Logger.error(e.toString()); return false; } }