Skip to content

Commit 9878051

Browse files
committed
Fix tile-saving errors after reloading bluemap with sql storage
1 parent 60a8f5f commit 9878051

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/lowres/LowresLayer.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ private LowresTile createTile(Vector2i tilePos) {
8484
private void saveTile(Vector2i tilePos, @Nullable LowresTile tile, RemovalCause removalCause) {
8585
if (tile == null) return;
8686

87+
// check if storage is closed
88+
if (mapStorage.getStorage().isClosed()){
89+
Logger.global.logDebug("Tried to save tile " + tilePos + " (lod: " + lod + ") but storage is already closed.");
90+
return;
91+
}
92+
8793
// save the tile
8894
try (OutputStream out = mapStorage.write(lod, tilePos)) {
8995
tile.save(out);

BlueMapCore/src/main/java/de/bluecolored/bluemap/core/storage/Storage.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ public TileStorage tileStorage(final String mapId, final int lod) {
5959
return new TileStorage(mapId, lod);
6060
}
6161

62+
public abstract boolean isClosed();
63+
6264
public class MapStorage {
6365

6466
private final String mapId;
@@ -79,6 +81,10 @@ public void delete(int lod, Vector2i tile) throws IOException {
7981
deleteMapTile(mapId, lod, tile);
8082
}
8183

84+
public Storage getStorage() {
85+
return Storage.this;
86+
}
87+
8288
}
8389

8490
public class TileStorage {
@@ -103,6 +109,10 @@ public void delete(Vector2i tile) throws IOException {
103109
deleteMapTile(mapId, lod, tile);
104110
}
105111

112+
public Storage getStorage() {
113+
return Storage.this;
114+
}
115+
106116
}
107117

108118
}

BlueMapCore/src/main/java/de/bluecolored/bluemap/core/storage/file/FileStorage.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ public FileStorage(Path root, Compression compression) {
5757
@Override
5858
public void initialize() {}
5959

60+
@Override
61+
public boolean isClosed() {
62+
return false;
63+
}
64+
6065
@Override
6166
public void close() throws IOException {}
6267

BlueMapCore/src/main/java/de/bluecolored/bluemap/core/storage/sql/SQLStorage.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ public class SQLStorage extends Storage {
6161
.executor(BlueMap.THREAD_POOL)
6262
.build(this::loadMapTileCompressionFK);
6363

64+
private volatile boolean closed;
65+
6466
public SQLStorage(SQLStorageSettings config) throws MalformedURLException, SQLDriverException {
67+
this.closed = false;
68+
6569
try {
6670
if (config.getDriverClass().isPresent()) {
6771
if (config.getDriverJar().isPresent()) {
@@ -478,8 +482,14 @@ public void initialize() throws IOException {
478482
}
479483
}
480484

485+
@Override
486+
public boolean isClosed() {
487+
return closed;
488+
}
489+
481490
@Override
482491
public void close() throws IOException {
492+
this.closed = true;
483493
if (dataSource instanceof AutoCloseable) {
484494
try {
485495
((AutoCloseable) dataSource).close();

0 commit comments

Comments
 (0)