diff --git a/DynmapCore/src/main/java/org/dynmap/MapManager.java b/DynmapCore/src/main/java/org/dynmap/MapManager.java index 533f0040..d9260097 100644 --- a/DynmapCore/src/main/java/org/dynmap/MapManager.java +++ b/DynmapCore/src/main/java/org/dynmap/MapManager.java @@ -311,32 +311,6 @@ public class MapManager { rendertype = RENDERTYPE_FULLRENDER; } this.resume = resume; - - final CountDownLatch latch = new CountDownLatch(1); - - if (resume) { // if resume render - final MapStorage ms = world.getMapStorage(); - ms.enumMapBaseTiles(world, map, new MapStorageBaseTileEnumCB() { - @Override - public void tileFound(MapStorageTile tile, MapType.ImageEncoding enc) { - String tileId = String.format("%s_%s_%d_%d", tile.world.getName(), tile.map.getName(), tile.x, tile.y); - //sender.sendMessage("Tile found: " + tileId); - storedTileIds.add(tileId); - } - }, new MapStorageTileSearchEndCB() { - @Override - public void searchEnded() { - latch.countDown(); - } - }); - - try { - latch.await(10, TimeUnit.SECONDS); - } catch (InterruptedException e) { - e.printStackTrace(); - sender.sendMessage(e.toString()); - } - } } /* Full world, all maps render, with optional render radius */ @@ -528,6 +502,27 @@ public class MapManager { } return; } + // If doing resume, load existing tile IDs here (constructor was stupid, and caused timeouts for non-trivial maps - need to check PRs better.... + if (resume) { // if resume render + sendMessage(String.format("Scanning map to find existing tiles for resume...")); + final MapStorage ms = world.getMapStorage(); + ms.enumMapBaseTiles(world, map, new MapStorageBaseTileEnumCB() { + @Override + public void tileFound(MapStorageTile tile, MapType.ImageEncoding enc) { + String tileId = String.format("%s_%s_%d_%d", tile.world.getName(), tile.map.getName(), tile.x, tile.y); + //sender.sendMessage("Tile found: " + tileId); + storedTileIds.add(tileId); + } + }, new MapStorageTileSearchEndCB() { + @Override + public void searchEnded() { + + } + }); + sendMessage(String.format("Scan complete - starting render")); + resume = false; // Only due on first run + } + if(tile0 == null) { /* Not single tile render */ if (saverestorepending && world.isLoaded() && (savependingperiod > 0) && ((lastPendingSaveTS + (1000 *savependingperiod)) < System.currentTimeMillis())) { savePending(this.world, true); // Save the pending data for the given world diff --git a/DynmapCore/src/main/java/org/dynmap/storage/mssql/MicrosoftSQLMapStorage.java b/DynmapCore/src/main/java/org/dynmap/storage/mssql/MicrosoftSQLMapStorage.java index f37ec4f8..15be1fcd 100644 --- a/DynmapCore/src/main/java/org/dynmap/storage/mssql/MicrosoftSQLMapStorage.java +++ b/DynmapCore/src/main/java/org/dynmap/storage/mssql/MicrosoftSQLMapStorage.java @@ -673,11 +673,13 @@ public class MicrosoftSQLMapStorage extends MapStorage { try { c = getConnection(); boolean done = false; + int offset = 0; + int limit = 100; while (!done) { // Query tiles for given mapkey Statement stmt = c.createStatement(); - ResultSet rs = stmt.executeQuery("SELECT x,y,zoom,Format FROM " + tableTiles + " WHERE MapID=" + mapkey + " LIMIT 100;"); + ResultSet rs = stmt.executeQuery(String.format("SELECT x,y,zoom,Format FROM %s WHERE MapID=%d OFFSET %d LIMIT %d;", tableTiles, mapkey, offset, limit)); int cnt = 0; while (rs.next()) { StorageTile st = new StorageTile(world, map, rs.getInt("x"), rs.getInt("y"), rs.getInt("zoom"), var); @@ -691,7 +693,8 @@ public class MicrosoftSQLMapStorage extends MapStorage { } rs.close(); stmt.close(); - if (cnt < 100) done = true; + if (cnt < limit) done = true; + offset += cnt; } if(cbEnd != null) cbEnd.searchEnded(); diff --git a/DynmapCore/src/main/java/org/dynmap/storage/mysql/MySQLMapStorage.java b/DynmapCore/src/main/java/org/dynmap/storage/mysql/MySQLMapStorage.java index 84008484..b708b66e 100644 --- a/DynmapCore/src/main/java/org/dynmap/storage/mysql/MySQLMapStorage.java +++ b/DynmapCore/src/main/java/org/dynmap/storage/mysql/MySQLMapStorage.java @@ -793,10 +793,12 @@ public class MySQLMapStorage extends MapStorage { try { c = getConnection(); boolean done = false; + int limit = 100; + int offset = 0; while (!done) { // Query tiles for given mapkey Statement stmt = c.createStatement(); - ResultSet rs = stmt.executeQuery("SELECT x,y,zoom,Format FROM " + tableTiles + " WHERE MapID=" + mapkey + " LIMIT 100;"); + ResultSet rs = stmt.executeQuery(String.format("SELECT x,y,zoom,Format FROM %s WHERE MapID=%d OFFSET %d LIMIT %d;", tableTiles, mapkey, offset, limit)); int cnt = 0; while (rs.next()) { StorageTile st = new StorageTile(world, map, rs.getInt("x"), rs.getInt("y"), rs.getInt("zoom"), var); @@ -810,7 +812,8 @@ public class MySQLMapStorage extends MapStorage { } rs.close(); stmt.close(); - if (cnt < 100) done = true; + if (cnt < limit) done = true; + offset += cnt; } if(cbEnd != null) cbEnd.searchEnded(); diff --git a/DynmapCore/src/main/java/org/dynmap/storage/postgresql/PostgreSQLMapStorage.java b/DynmapCore/src/main/java/org/dynmap/storage/postgresql/PostgreSQLMapStorage.java index fbe75262..c45a20c0 100644 --- a/DynmapCore/src/main/java/org/dynmap/storage/postgresql/PostgreSQLMapStorage.java +++ b/DynmapCore/src/main/java/org/dynmap/storage/postgresql/PostgreSQLMapStorage.java @@ -699,11 +699,12 @@ public class PostgreSQLMapStorage extends MapStorage { try { c = getConnection(); boolean done = false; - + int offset = 0; + int limit = 100; while (!done) { // Query tiles for given mapkey Statement stmt = c.createStatement(); - ResultSet rs = stmt.executeQuery("SELECT x,y,zoom,Format FROM " + tableTiles + " WHERE MapID=" + mapkey + " LIMIT 100;"); + ResultSet rs = stmt.executeQuery(String.format("SELECT x,y,zoom,Format FROM %s WHERE MapID=%d OFFSET %d LIMIT %d;", tableTiles, mapKey, offset, limit)); int cnt = 0; while (rs.next()) { StorageTile st = new StorageTile(world, map, rs.getInt("x"), rs.getInt("y"), rs.getInt("zoom"), var); @@ -717,7 +718,8 @@ public class PostgreSQLMapStorage extends MapStorage { } rs.close(); stmt.close(); - if (cnt < 100) done = true; + if (cnt < limit) done = true; + offset += cnt; } if(cbEnd != null) cbEnd.searchEnded(); diff --git a/DynmapCore/src/main/java/org/dynmap/storage/sqllte/SQLiteMapStorage.java b/DynmapCore/src/main/java/org/dynmap/storage/sqllte/SQLiteMapStorage.java index 46cdbb25..52cb1cea 100644 --- a/DynmapCore/src/main/java/org/dynmap/storage/sqllte/SQLiteMapStorage.java +++ b/DynmapCore/src/main/java/org/dynmap/storage/sqllte/SQLiteMapStorage.java @@ -640,12 +640,14 @@ public class SQLiteMapStorage extends MapStorage { return; } try { - c = getConnection(); boolean done = false; + int offset = 0; + int limit = 100; while (!done) { + c = getConnection(); // Do inside loop - single threaded sqlite will have issues otherwise.... // Query tiles for given mapkey Statement stmt = c.createStatement(); - ResultSet rs = doExecuteQuery(stmt, "SELECT x,y,zoom,Format FROM Tiles WHERE MapID=" + mapkey + " LIMIT 100;"); + ResultSet rs = doExecuteQuery(stmt, String.format("SELECT x,y,zoom,Format FROM Tiles WHERE MapID=%d OFFSET %d LIMIT %d", mapkey, offset, limit)); int cnt = 0; while (rs.next()) { StorageTile st = new StorageTile(world, map, rs.getInt("x"), rs.getInt("y"), rs.getInt("zoom"), var); @@ -659,7 +661,10 @@ public class SQLiteMapStorage extends MapStorage { } rs.close(); stmt.close(); - if (cnt < 100) done = true; + if (cnt < limit) done = true; + offset += cnt; + releaseConnection(c, err); + c = null; } if(cbEnd != null) cbEnd.searchEnded(); @@ -1055,4 +1060,11 @@ public class SQLiteMapStorage extends MapStorage { } } } + + public void logSQLException(String opmsg, SQLException x) { + // Ignore interrupted + if (x.getMessage().equals("Interrupted")) return; + + super.logSQLException(opmsg, x); + } }