From dbd27b641e61a6ad60011ef48e732da6a000025d Mon Sep 17 00:00:00 2001 From: riking Date: Tue, 15 Oct 2013 18:32:54 -0700 Subject: [PATCH] Give periodic status messages to the console in conversion --- .../java/com/gmail/nossr50/database/DatabaseManager.java | 2 ++ .../gmail/nossr50/database/FlatfileDatabaseManager.java | 7 +++++++ .../com/gmail/nossr50/database/SQLDatabaseManager.java | 7 +++++++ .../nossr50/runnables/database/FormulaConversionTask.java | 8 ++++++++ 4 files changed, 24 insertions(+) diff --git a/src/main/java/com/gmail/nossr50/database/DatabaseManager.java b/src/main/java/com/gmail/nossr50/database/DatabaseManager.java index d918d2373..717f835c4 100644 --- a/src/main/java/com/gmail/nossr50/database/DatabaseManager.java +++ b/src/main/java/com/gmail/nossr50/database/DatabaseManager.java @@ -11,6 +11,8 @@ import com.gmail.nossr50.datatypes.player.PlayerProfile; public interface DatabaseManager { // One month in milliseconds public final long PURGE_TIME = 2630000000L * Config.getInstance().getOldUsersCutoff(); + // During convertUsers, how often to output a status + public final int progressInterval = 200; /** * Purge users with 0 power level from the database. diff --git a/src/main/java/com/gmail/nossr50/database/FlatfileDatabaseManager.java b/src/main/java/com/gmail/nossr50/database/FlatfileDatabaseManager.java index d1ff02192..041d95e18 100644 --- a/src/main/java/com/gmail/nossr50/database/FlatfileDatabaseManager.java +++ b/src/main/java/com/gmail/nossr50/database/FlatfileDatabaseManager.java @@ -411,6 +411,8 @@ public final class FlatfileDatabaseManager implements DatabaseManager { public void convertUsers(DatabaseManager destination) { BufferedReader in = null; String usersFilePath = mcMMO.getUsersFilePath(); + int convertedUsers = 0; + long startMillis = System.currentTimeMillis(); synchronized (fileWritingLock) { try { @@ -427,6 +429,11 @@ public final class FlatfileDatabaseManager implements DatabaseManager { catch (Exception e) { e.printStackTrace(); } + convertedUsers++; + if ((convertedUsers % DatabaseManager.progressInterval) == 0) { + // Can't use Bukkit.broadcastMessage because async + System.out.println(String.format("[mcMMO] Conversion progress: %d users at %.2f users/second", convertedUsers, convertedUsers / ((System.currentTimeMillis() - startMillis) / 1000D))); + } } } catch (Exception e) { diff --git a/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java b/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java index 1d68f049e..e7bf32182 100644 --- a/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java +++ b/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java @@ -447,6 +447,8 @@ public final class SQLDatabaseManager implements DatabaseManager { + "WHERE u.user = ?"); List usernames = getStoredUsers(); ResultSet result = null; + int convertedUsers = 0; + long startMillis = System.currentTimeMillis(); for (String playerName : usernames) { statement.setString(1, playerName); try { @@ -458,6 +460,11 @@ public final class SQLDatabaseManager implements DatabaseManager { catch (SQLException e) { // Ignore } + convertedUsers++; + if ((convertedUsers % DatabaseManager.progressInterval) == 0) { + // Can't use Bukkit.broadcastMessage because async + System.out.println(String.format("[mcMMO] Conversion progress: %d users at %.2f users/second", convertedUsers, convertedUsers / ((System.currentTimeMillis() - startMillis) / 1000D))); + } } } catch (SQLException e) { diff --git a/src/main/java/com/gmail/nossr50/runnables/database/FormulaConversionTask.java b/src/main/java/com/gmail/nossr50/runnables/database/FormulaConversionTask.java index 3da82c0b1..781e49b93 100644 --- a/src/main/java/com/gmail/nossr50/runnables/database/FormulaConversionTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/database/FormulaConversionTask.java @@ -5,6 +5,7 @@ import org.bukkit.scheduler.BukkitRunnable; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.experience.ExperienceConfig; +import com.gmail.nossr50.database.DatabaseManager; import com.gmail.nossr50.datatypes.experience.FormulaType; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.PlayerProfile; @@ -23,6 +24,8 @@ public class FormulaConversionTask extends BukkitRunnable { @Override public void run() { + int convertedUsers = 0; + long startMillis = System.currentTimeMillis(); for (String playerName : mcMMO.getDatabaseManager().getStoredUsers()) { McMMOPlayer mcMMOPlayer = UserManager.getPlayer(playerName, true); PlayerProfile profile; @@ -43,6 +46,11 @@ public class FormulaConversionTask extends BukkitRunnable { profile = mcMMOPlayer.getProfile(); editValues(profile); } + convertedUsers++; + if ((convertedUsers % DatabaseManager.progressInterval) == 0) { + // Can't use Bukkit.broadcastMessage because async + System.out.println(String.format("[mcMMO] Conversion progress: %d users at %.2f users/second", convertedUsers, convertedUsers / ((System.currentTimeMillis() - startMillis) / 1000D))); + } } mcMMO.getFormulaManager().setPreviousFormulaType(formulaType);