Add more orderly storage shutdown

This commit is contained in:
Mike Primm 2022-07-24 13:09:52 -05:00
parent e68f628131
commit ab54919956
6 changed files with 210 additions and 20 deletions

View File

@ -1113,7 +1113,9 @@ public class DynmapCore implements DynmapCommonAPI {
mapManager.stopRendering(); mapManager.stopRendering();
mapManager = null; mapManager = null;
} }
if (defaultStorage != null) {
defaultStorage.shutdownStorage();
}
playerfacemgr = null; playerfacemgr = null;
/* Clean up registered listeners */ /* Clean up registered listeners */
listenerManager.cleanup(); listenerManager.cleanup();

View File

@ -26,13 +26,18 @@ public abstract class MapStorage {
private static HashMap<String, Integer> filelocks = new HashMap<String, Integer>(); private static HashMap<String, Integer> filelocks = new HashMap<String, Integer>();
private static final Integer WRITELOCK = (-1); private static final Integer WRITELOCK = (-1);
protected File baseStandaloneDir; protected File baseStandaloneDir;
protected boolean isShutdown;
protected long serverID; protected long serverID;
protected MapStorage() { protected MapStorage() {
this.serverID = 0; this.serverID = 0;
this.isShutdown = false;
} }
public void shutdownStorage() {
this.isShutdown = true;
}
// Proper modulo - versus the bogus Java behavior of negative modulo for negative numerators // Proper modulo - versus the bogus Java behavior of negative modulo for negative numerators
protected static final int modulo(int x, int y) { protected static final int modulo(int x, int y) {
return ((x % y) + y) % y; return ((x % y) + y) % y;
@ -475,6 +480,7 @@ public abstract class MapStorage {
} }
public void logSQLException(String opmsg, SQLException x) { public void logSQLException(String opmsg, SQLException x) {
if (isShutdown) return;
Log.severe("SQLException: " + opmsg); Log.severe("SQLException: " + opmsg);
Log.severe(" ErrorCode: " + x.getErrorCode() + ", SQLState=" + x.getSQLState()); Log.severe(" ErrorCode: " + x.getErrorCode() + ", SQLState=" + x.getSQLState());
Log.severe(" Message: " + x.getMessage()); Log.severe(" Message: " + x.getMessage());
@ -485,4 +491,11 @@ public abstract class MapStorage {
cause = cause.getCause(); cause = cause.getCause();
} }
} }
public static class StorageShutdownException extends Exception {
private static final long serialVersionUID = 8961471920726795043L;
public StorageShutdownException() {}
}
} }

View File

@ -66,8 +66,9 @@ public class AWSS3MapStorage extends MapStorage {
@Override @Override
public boolean exists() { public boolean exists() {
boolean exists = false; boolean exists = false;
S3Client s3 = getConnection(); S3Client s3 = null;
try { try {
s3 = getConnection();
ListObjectsV2Request req = ListObjectsV2Request.builder().bucketName(bucketname).prefix(baseKey).maxKeys(1).build(); ListObjectsV2Request req = ListObjectsV2Request.builder().bucketName(bucketname).prefix(baseKey).maxKeys(1).build();
ListObjectsV2Response rslt = s3.listObjectsV2(req); ListObjectsV2Response rslt = s3.listObjectsV2(req);
if ((rslt != null) && (rslt.getKeyCount() > 0)) if ((rslt != null) && (rslt.getKeyCount() > 0))
@ -76,6 +77,8 @@ public class AWSS3MapStorage extends MapStorage {
if (!x.getCode().equals("SignatureDoesNotMatch")) { // S3 behavior when no object match.... if (!x.getCode().equals("SignatureDoesNotMatch")) { // S3 behavior when no object match....
Log.severe("AWS Exception", x); Log.severe("AWS Exception", x);
} }
} catch (StorageShutdownException x) {
} finally { } finally {
releaseConnection(s3); releaseConnection(s3);
} }
@ -89,8 +92,9 @@ public class AWSS3MapStorage extends MapStorage {
@Override @Override
public TileRead read() { public TileRead read() {
S3Client s3 = getConnection(); S3Client s3 = null;
try { try {
s3 = getConnection();
GetObjectRequest req = GetObjectRequest.builder().bucketName(bucketname).key(baseKey).build(); GetObjectRequest req = GetObjectRequest.builder().bucketName(bucketname).key(baseKey).build();
ResponseBytes<GetObjectResponse> obj = s3.getObjectAsBytes(req); ResponseBytes<GetObjectResponse> obj = s3.getObjectAsBytes(req);
if (obj != null) { if (obj != null) {
@ -114,6 +118,7 @@ public class AWSS3MapStorage extends MapStorage {
return null; // Nominal case if it doesn't exist return null; // Nominal case if it doesn't exist
} catch (S3Exception x) { } catch (S3Exception x) {
Log.severe("AWS Exception", x); Log.severe("AWS Exception", x);
} catch (StorageShutdownException x) {
} finally { } finally {
releaseConnection(s3); releaseConnection(s3);
} }
@ -123,8 +128,9 @@ public class AWSS3MapStorage extends MapStorage {
@Override @Override
public boolean write(long hash, BufferOutputStream encImage, long timestamp) { public boolean write(long hash, BufferOutputStream encImage, long timestamp) {
boolean done = false; boolean done = false;
S3Client s3 = getConnection(); S3Client s3 = null;
try { try {
s3 = getConnection();
if (encImage == null) { // Delete? if (encImage == null) { // Delete?
DeleteObjectRequest req = DeleteObjectRequest.builder().bucketName(bucketname).key(baseKey).build(); DeleteObjectRequest req = DeleteObjectRequest.builder().bucketName(bucketname).key(baseKey).build();
s3.deleteObject(req); s3.deleteObject(req);
@ -137,6 +143,7 @@ public class AWSS3MapStorage extends MapStorage {
done = true; done = true;
} catch (S3Exception x) { } catch (S3Exception x) {
Log.severe("AWS Exception", x); Log.severe("AWS Exception", x);
} catch (StorageShutdownException x) {
} finally { } finally {
releaseConnection(s3); releaseConnection(s3);
} }
@ -249,12 +256,13 @@ public class AWSS3MapStorage extends MapStorage {
} }
// Now creste the access client for the S3 service // Now creste the access client for the S3 service
Log.info("Using AWS S3 storage: web site at S3 bucket " + bucketname + " in region " + region); Log.info("Using AWS S3 storage: web site at S3 bucket " + bucketname + " in region " + region);
S3Client s3 = getConnection(); S3Client s3 = null;
if (s3 == null) {
Log.severe("Error creating S3 access client");
return false;
}
try { try {
s3 = getConnection();
if (s3 == null) {
Log.severe("Error creating S3 access client");
return false;
}
// Make sure bucket exists (do list) // Make sure bucket exists (do list)
ListObjectsV2Request listreq = ListObjectsV2Request.builder() ListObjectsV2Request listreq = ListObjectsV2Request.builder()
.bucketName(bucketname) .bucketName(bucketname)
@ -270,6 +278,8 @@ public class AWSS3MapStorage extends MapStorage {
} catch (S3Exception s3x) { } catch (S3Exception s3x) {
Log.severe("AWS Exception", s3x); Log.severe("AWS Exception", s3x);
return false; return false;
} catch (StorageShutdownException x) {
return false;
} finally { } finally {
releaseConnection(s3); releaseConnection(s3);
} }
@ -334,8 +344,9 @@ public class AWSS3MapStorage extends MapStorage {
String basekey = prefix + "tiles/" + world.getName() + "/" + map.getPrefix() + var.variantSuffix + "/"; String basekey = prefix + "tiles/" + world.getName() + "/" + map.getPrefix() + var.variantSuffix + "/";
ListObjectsV2Request req = ListObjectsV2Request.builder().bucketName(bucketname).prefix(basekey).maxKeys(1000).build(); ListObjectsV2Request req = ListObjectsV2Request.builder().bucketName(bucketname).prefix(basekey).maxKeys(1000).build();
boolean done = false; boolean done = false;
S3Client s3 = getConnection(); S3Client s3 = null;
try { try {
s3 = getConnection();
while (!done) { while (!done) {
ListObjectsV2Response result = s3.listObjectsV2(req); ListObjectsV2Response result = s3.listObjectsV2(req);
List<S3Object> objects = result.getContents(); List<S3Object> objects = result.getContents();
@ -395,6 +406,7 @@ public class AWSS3MapStorage extends MapStorage {
Log.severe("AWS Exception", x); Log.severe("AWS Exception", x);
Log.severe("req=" + req); Log.severe("req=" + req);
} }
} catch (StorageShutdownException x) {
} finally { } finally {
releaseConnection(s3); releaseConnection(s3);
} }
@ -442,8 +454,9 @@ public class AWSS3MapStorage extends MapStorage {
private void processPurgeMapTiles(DynmapWorld world, MapType map, ImageVariant var) { private void processPurgeMapTiles(DynmapWorld world, MapType map, ImageVariant var) {
String basekey = prefix + "tiles/" + world.getName() + "/" + map.getPrefix() + var.variantSuffix + "/"; String basekey = prefix + "tiles/" + world.getName() + "/" + map.getPrefix() + var.variantSuffix + "/";
ListObjectsV2Request req = ListObjectsV2Request.builder().bucketName(bucketname).prefix(basekey).delimiter("").maxKeys(1000).encodingType("url").requestPayer("requester").build(); ListObjectsV2Request req = ListObjectsV2Request.builder().bucketName(bucketname).prefix(basekey).delimiter("").maxKeys(1000).encodingType("url").requestPayer("requester").build();
S3Client s3 = getConnection(); S3Client s3 = null;
try { try {
s3 = getConnection();
boolean done = false; boolean done = false;
while (!done) { while (!done) {
ListObjectsV2Response result = s3.listObjectsV2(req); ListObjectsV2Response result = s3.listObjectsV2(req);
@ -466,6 +479,7 @@ public class AWSS3MapStorage extends MapStorage {
Log.severe("AWS Exception", x); Log.severe("AWS Exception", x);
Log.severe("req=" + req); Log.severe("req=" + req);
} }
} catch (StorageShutdownException x) {
} finally { } finally {
releaseConnection(s3); releaseConnection(s3);
} }
@ -494,8 +508,9 @@ public class AWSS3MapStorage extends MapStorage {
BufferOutputStream encImage) { BufferOutputStream encImage) {
boolean done = false; boolean done = false;
String baseKey = prefix + "tiles/faces/" + facetype.id + "/" + playername + ".png"; String baseKey = prefix + "tiles/faces/" + facetype.id + "/" + playername + ".png";
S3Client s3 = getConnection(); S3Client s3 = null;
try { try {
s3 = getConnection();
if (encImage == null) { // Delete? if (encImage == null) { // Delete?
DeleteObjectRequest delreq = DeleteObjectRequest.builder().bucketName(bucketname).key(baseKey).build(); DeleteObjectRequest delreq = DeleteObjectRequest.builder().bucketName(bucketname).key(baseKey).build();
s3.deleteObject(delreq); s3.deleteObject(delreq);
@ -507,6 +522,7 @@ public class AWSS3MapStorage extends MapStorage {
done = true; done = true;
} catch (S3Exception x) { } catch (S3Exception x) {
Log.severe("AWS Exception", x); Log.severe("AWS Exception", x);
} catch (StorageShutdownException x) {
} finally { } finally {
releaseConnection(s3); releaseConnection(s3);
} }
@ -523,8 +539,9 @@ public class AWSS3MapStorage extends MapStorage {
public boolean hasPlayerFaceImage(String playername, FaceType facetype) { public boolean hasPlayerFaceImage(String playername, FaceType facetype) {
String baseKey = prefix + "tiles/faces/" + facetype.id + "/" + playername + ".png"; String baseKey = prefix + "tiles/faces/" + facetype.id + "/" + playername + ".png";
boolean exists = false; boolean exists = false;
S3Client s3 = getConnection(); S3Client s3 = null;
try { try {
s3 = getConnection();
ListObjectsV2Request req = ListObjectsV2Request.builder().bucketName(bucketname).prefix(baseKey).maxKeys(1).build(); ListObjectsV2Request req = ListObjectsV2Request.builder().bucketName(bucketname).prefix(baseKey).maxKeys(1).build();
ListObjectsV2Response rslt = s3.listObjectsV2(req); ListObjectsV2Response rslt = s3.listObjectsV2(req);
if ((rslt != null) && (rslt.getKeyCount() > 0)) if ((rslt != null) && (rslt.getKeyCount() > 0))
@ -533,6 +550,7 @@ public class AWSS3MapStorage extends MapStorage {
if (!x.getCode().equals("SignatureDoesNotMatch")) { // S3 behavior when no object match.... if (!x.getCode().equals("SignatureDoesNotMatch")) { // S3 behavior when no object match....
Log.severe("AWS Exception", x); Log.severe("AWS Exception", x);
} }
} catch (StorageShutdownException x) {
} finally { } finally {
releaseConnection(s3); releaseConnection(s3);
} }
@ -543,8 +561,9 @@ public class AWSS3MapStorage extends MapStorage {
public boolean setMarkerImage(String markerid, BufferOutputStream encImage) { public boolean setMarkerImage(String markerid, BufferOutputStream encImage) {
boolean done = false; boolean done = false;
String baseKey = prefix + "tiles/_markers_/" + markerid + ".png"; String baseKey = prefix + "tiles/_markers_/" + markerid + ".png";
S3Client s3 = getConnection(); S3Client s3 = null;
try { try {
s3 = getConnection();
if (encImage == null) { // Delete? if (encImage == null) { // Delete?
DeleteObjectRequest delreq = DeleteObjectRequest.builder().bucketName(bucketname).key(baseKey).build(); DeleteObjectRequest delreq = DeleteObjectRequest.builder().bucketName(bucketname).key(baseKey).build();
s3.deleteObject(delreq); s3.deleteObject(delreq);
@ -556,6 +575,7 @@ public class AWSS3MapStorage extends MapStorage {
done = true; done = true;
} catch (S3Exception x) { } catch (S3Exception x) {
Log.severe("AWS Exception", x); Log.severe("AWS Exception", x);
} catch (StorageShutdownException x) {
} finally { } finally {
releaseConnection(s3); releaseConnection(s3);
} }
@ -571,8 +591,9 @@ public class AWSS3MapStorage extends MapStorage {
public boolean setMarkerFile(String world, String content) { public boolean setMarkerFile(String world, String content) {
boolean done = false; boolean done = false;
String baseKey = prefix + "tiles/_markers_/marker_" + world + ".json"; String baseKey = prefix + "tiles/_markers_/marker_" + world + ".json";
S3Client s3 = getConnection(); S3Client s3 = null;
try { try {
s3 = getConnection();
if (content == null) { // Delete? if (content == null) { // Delete?
DeleteObjectRequest delreq = DeleteObjectRequest.builder().bucketName(bucketname).key(baseKey).build(); DeleteObjectRequest delreq = DeleteObjectRequest.builder().bucketName(bucketname).key(baseKey).build();
s3.deleteObject(delreq); s3.deleteObject(delreq);
@ -584,6 +605,7 @@ public class AWSS3MapStorage extends MapStorage {
done = true; done = true;
} catch (S3Exception x) { } catch (S3Exception x) {
Log.severe("AWS Exception", x); Log.severe("AWS Exception", x);
} catch (StorageShutdownException x) {
} finally { } finally {
releaseConnection(s3); releaseConnection(s3);
} }
@ -668,8 +690,9 @@ public class AWSS3MapStorage extends MapStorage {
boolean done = false; boolean done = false;
String baseKey = prefix + fileid; String baseKey = prefix + fileid;
S3Client s3 = getConnection(); S3Client s3 = null;
try { try {
s3 = getConnection();
byte[] cacheval = standalone_cache.get(fileid); byte[] cacheval = standalone_cache.get(fileid);
if (content == null) { // Delete? if (content == null) { // Delete?
@ -716,14 +739,16 @@ public class AWSS3MapStorage extends MapStorage {
done = true; done = true;
} catch (S3Exception x) { } catch (S3Exception x) {
Log.severe("AWS Exception", x); Log.severe("AWS Exception", x);
} catch (StorageShutdownException x) {
} finally { } finally {
releaseConnection(s3); releaseConnection(s3);
} }
return done; return done;
} }
private S3Client getConnection() throws S3Exception { private S3Client getConnection() throws S3Exception, StorageShutdownException {
S3Client c = null; S3Client c = null;
if (isShutdown) throw new StorageShutdownException();
synchronized (cpool) { synchronized (cpool) {
while (c == null) { while (c == null) {
for (int i = 0; i < cpool.length; i++) { // See if available connection for (int i = 0; i < cpool.length; i++) { // See if available connection

View File

@ -85,6 +85,8 @@ public class MySQLMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Tile exists error", x); logSQLException("Tile exists error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -110,6 +112,8 @@ public class MySQLMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Tile matches hash error", x); logSQLException("Tile matches hash error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -140,6 +144,8 @@ public class MySQLMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Tile read error", x); logSQLException("Tile read error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -196,6 +202,8 @@ public class MySQLMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Tile write error", x); logSQLException("Tile write error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -382,6 +390,8 @@ public class MySQLMapStorage extends MapStorage {
stmt.close(); stmt.close();
} catch (SQLException x) { } catch (SQLException x) {
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
if (c != null) { releaseConnection(c, err); } if (c != null) { releaseConnection(c, err); }
} }
@ -421,6 +431,8 @@ public class MySQLMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Error loading map table", x); logSQLException("Error loading map table", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
c = null; c = null;
@ -460,6 +472,8 @@ public class MySQLMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Error updating Maps table", x); logSQLException("Error updating Maps table", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -492,6 +506,9 @@ public class MySQLMapStorage extends MapStorage {
logSQLException("Error creating tables", x); logSQLException("Error creating tables", x);
err = true; err = true;
return false; return false;
} catch (StorageShutdownException x) {
err = true;
return false;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
c = null; c = null;
@ -509,6 +526,9 @@ public class MySQLMapStorage extends MapStorage {
logSQLException("Error updating tables to version=2", x); logSQLException("Error updating tables to version=2", x);
err = true; err = true;
return false; return false;
} catch (StorageShutdownException x) {
err = true;
return false;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
c = null; c = null;
@ -527,6 +547,9 @@ public class MySQLMapStorage extends MapStorage {
logSQLException("Error updating tables to version=3", x); logSQLException("Error updating tables to version=3", x);
err = true; err = true;
return false; return false;
} catch (StorageShutdownException x) {
err = true;
return false;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
c = null; c = null;
@ -545,6 +568,9 @@ public class MySQLMapStorage extends MapStorage {
logSQLException("Error updating tables to version=4", x); logSQLException("Error updating tables to version=4", x);
err = true; err = true;
return false; return false;
} catch (StorageShutdownException x) {
err = true;
return false;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
c = null; c = null;
@ -579,6 +605,9 @@ public class MySQLMapStorage extends MapStorage {
logSQLException("Error updating tables to version=5", x); logSQLException("Error updating tables to version=5", x);
err = true; err = true;
return false; return false;
} catch (StorageShutdownException x) {
err = true;
return false;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
c = null; c = null;
@ -595,6 +624,9 @@ public class MySQLMapStorage extends MapStorage {
logSQLException("Error updating tables to version=5", x); logSQLException("Error updating tables to version=5", x);
err = true; err = true;
return false; return false;
} catch (StorageShutdownException x) {
err = true;
return false;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
c = null; c = null;
@ -607,8 +639,9 @@ public class MySQLMapStorage extends MapStorage {
return true; return true;
} }
private Connection getConnection() throws SQLException { private Connection getConnection() throws SQLException, StorageShutdownException {
Connection c = null; Connection c = null;
if (isShutdown) { throw new StorageShutdownException(); }
synchronized (cpool) { synchronized (cpool) {
while (c == null) { while (c == null) {
for (int i = 0; i < cpool.length; i++) { // See if available connection for (int i = 0; i < cpool.length; i++) { // See if available connection
@ -778,6 +811,8 @@ public class MySQLMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Tile enum error", x); logSQLException("Tile enum error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -816,6 +851,8 @@ public class MySQLMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Tile purge error", x); logSQLException("Tile purge error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -855,6 +892,8 @@ public class MySQLMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Face write error", x); logSQLException("Face write error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -882,6 +921,8 @@ public class MySQLMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Face reqd error", x); logSQLException("Face reqd error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -907,6 +948,8 @@ public class MySQLMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Face exists error", x); logSQLException("Face exists error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -954,6 +997,8 @@ public class MySQLMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Marker write error", x); logSQLException("Marker write error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
if (rs != null) { try { rs.close(); } catch (SQLException sx) {} } if (rs != null) { try { rs.close(); } catch (SQLException sx) {} }
if (stmt != null) { try { stmt.close(); } catch (SQLException sx) {} } if (stmt != null) { try { stmt.close(); } catch (SQLException sx) {} }
@ -981,6 +1026,8 @@ public class MySQLMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Marker read error", x); logSQLException("Marker read error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -1027,6 +1074,8 @@ public class MySQLMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Marker file write error", x); logSQLException("Marker file write error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
if (rs != null) { try { rs.close(); } catch (SQLException sx) {} } if (rs != null) { try { rs.close(); } catch (SQLException sx) {} }
if (stmt != null) { try { stmt.close(); } catch (SQLException sx) {} } if (stmt != null) { try { stmt.close(); } catch (SQLException sx) {} }
@ -1054,6 +1103,8 @@ public class MySQLMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Marker file read error", x); logSQLException("Marker file read error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -1110,6 +1161,8 @@ public class MySQLMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Standalone file read error", x); logSQLException("Standalone file read error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -1160,6 +1213,8 @@ public class MySQLMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Standalone file write error", x); logSQLException("Standalone file write error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
if (rs != null) { try { rs.close(); } catch (SQLException sx) {} } if (rs != null) { try { rs.close(); } catch (SQLException sx) {} }
if (stmt != null) { try { stmt.close(); } catch (SQLException sx) {} } if (stmt != null) { try { stmt.close(); } catch (SQLException sx) {} }

View File

@ -87,6 +87,8 @@ public class PostgreSQLMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Tile exists error", x); logSQLException("Tile exists error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -112,6 +114,8 @@ public class PostgreSQLMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Tile matches hash error", x); logSQLException("Tile matches hash error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -141,6 +145,8 @@ public class PostgreSQLMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Tile read error", x); logSQLException("Tile read error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -197,6 +203,8 @@ public class PostgreSQLMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Tile write error", x); logSQLException("Tile write error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -366,6 +374,8 @@ public class PostgreSQLMapStorage extends MapStorage {
stmt.close(); stmt.close();
} catch (SQLException x) { } catch (SQLException x) {
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
if (c != null) { releaseConnection(c, err); } if (c != null) { releaseConnection(c, err); }
} }
@ -403,6 +413,8 @@ public class PostgreSQLMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Error loading map table", x); logSQLException("Error loading map table", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
c = null; c = null;
@ -442,6 +454,8 @@ public class PostgreSQLMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Error updating Maps table", x); logSQLException("Error updating Maps table", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -474,6 +488,9 @@ public class PostgreSQLMapStorage extends MapStorage {
logSQLException("Error creating tables", x); logSQLException("Error creating tables", x);
err = true; err = true;
return false; return false;
} catch (StorageShutdownException x) {
err = true;
return false;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
c = null; c = null;
@ -491,6 +508,9 @@ public class PostgreSQLMapStorage extends MapStorage {
logSQLException("Error upgrading tables to version=2", x); logSQLException("Error upgrading tables to version=2", x);
err = true; err = true;
return false; return false;
} catch (StorageShutdownException x) {
err = true;
return false;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
c = null; c = null;
@ -509,6 +529,9 @@ public class PostgreSQLMapStorage extends MapStorage {
logSQLException("Error upgrading tables to version=3", x); logSQLException("Error upgrading tables to version=3", x);
err = true; err = true;
return false; return false;
} catch (StorageShutdownException x) {
err = true;
return false;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
c = null; c = null;
@ -525,6 +548,9 @@ public class PostgreSQLMapStorage extends MapStorage {
logSQLException("Error upgrading tables to version=4", x); logSQLException("Error upgrading tables to version=4", x);
err = true; err = true;
return false; return false;
} catch (StorageShutdownException x) {
err = true;
return false;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
c = null; c = null;
@ -537,8 +563,9 @@ public class PostgreSQLMapStorage extends MapStorage {
return true; return true;
} }
private Connection getConnection() throws SQLException { private Connection getConnection() throws SQLException, StorageShutdownException {
Connection c = null; Connection c = null;
if (isShutdown) throw new StorageShutdownException();
synchronized (cpool) { synchronized (cpool) {
while (c == null) { while (c == null) {
for (int i = 0; i < cpool.length; i++) { // See if available connection for (int i = 0; i < cpool.length; i++) { // See if available connection
@ -690,6 +717,8 @@ public class PostgreSQLMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Tile enum error", x); logSQLException("Tile enum error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -744,6 +773,8 @@ public class PostgreSQLMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Tile purge error", x); logSQLException("Tile purge error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -783,6 +814,8 @@ public class PostgreSQLMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Face write error", x); logSQLException("Face write error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -810,6 +843,8 @@ public class PostgreSQLMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Face read error", x); logSQLException("Face read error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -835,6 +870,8 @@ public class PostgreSQLMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Face exists error", x); logSQLException("Face exists error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -882,6 +919,8 @@ public class PostgreSQLMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Marker write error", x); logSQLException("Marker write error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
if (rs != null) { try { rs.close(); } catch (SQLException sx) {} } if (rs != null) { try { rs.close(); } catch (SQLException sx) {} }
if (stmt != null) { try { stmt.close(); } catch (SQLException sx) {} } if (stmt != null) { try { stmt.close(); } catch (SQLException sx) {} }
@ -909,6 +948,8 @@ public class PostgreSQLMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Marker read error", x); logSQLException("Marker read error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -955,6 +996,8 @@ public class PostgreSQLMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Marker file write error", x); logSQLException("Marker file write error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
if (rs != null) { try { rs.close(); } catch (SQLException sx) {} } if (rs != null) { try { rs.close(); } catch (SQLException sx) {} }
if (stmt != null) { try { stmt.close(); } catch (SQLException sx) {} } if (stmt != null) { try { stmt.close(); } catch (SQLException sx) {} }
@ -982,6 +1025,8 @@ public class PostgreSQLMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Marker file read error", x); logSQLException("Marker file read error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -1038,6 +1083,8 @@ public class PostgreSQLMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Standalone file read error", x); logSQLException("Standalone file read error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -1088,6 +1135,8 @@ public class PostgreSQLMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Standalone file write error", x); logSQLException("Standalone file write error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
if (rs != null) { try { rs.close(); } catch (SQLException sx) {} } if (rs != null) { try { rs.close(); } catch (SQLException sx) {} }
if (stmt != null) { try { stmt.close(); } catch (SQLException sx) {} } if (stmt != null) { try { stmt.close(); } catch (SQLException sx) {} }

View File

@ -70,6 +70,8 @@ public class SQLiteMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Tile exists error", x); logSQLException("Tile exists error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -96,6 +98,8 @@ public class SQLiteMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Tile matches hash error", x); logSQLException("Tile matches hash error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -132,6 +136,8 @@ public class SQLiteMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Tile read error", x); logSQLException("Tile read error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -191,6 +197,8 @@ public class SQLiteMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Tile write error", x); logSQLException("Tile write error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -269,6 +277,7 @@ public class SQLiteMapStorage extends MapStorage {
@Override @Override
public boolean init(DynmapCore core) { public boolean init(DynmapCore core) {
if (!super.init(core)) { if (!super.init(core)) {
isShutdown = true;
return false; return false;
} }
File dbfile = core.getFile(core.configuration.getString("storage/dbfile", "dynmap.db")); File dbfile = core.getFile(core.configuration.getString("storage/dbfile", "dynmap.db"));
@ -281,6 +290,7 @@ public class SQLiteMapStorage extends MapStorage {
return initializeTables(); return initializeTables();
} catch (ClassNotFoundException cnfx) { } catch (ClassNotFoundException cnfx) {
Log.severe("SQLite-JDBC classes not found - sqlite data source not usable"); Log.severe("SQLite-JDBC classes not found - sqlite data source not usable");
isShutdown = true;
return false; return false;
} }
} }
@ -301,6 +311,8 @@ public class SQLiteMapStorage extends MapStorage {
stmt.close(); stmt.close();
} catch (SQLException x) { } catch (SQLException x) {
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
if (c != null) { releaseConnection(c, err); } if (c != null) { releaseConnection(c, err); }
} }
@ -339,6 +351,8 @@ public class SQLiteMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Error loading map table", x); logSQLException("Error loading map table", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
c = null; c = null;
@ -378,6 +392,8 @@ public class SQLiteMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Error updating Maps table", x); logSQLException("Error updating Maps table", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -410,6 +426,9 @@ public class SQLiteMapStorage extends MapStorage {
logSQLException("Error creating tables", x); logSQLException("Error creating tables", x);
err = true; err = true;
return false; return false;
} catch (StorageShutdownException x) {
err = true;
return false;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
c = null; c = null;
@ -428,6 +447,9 @@ public class SQLiteMapStorage extends MapStorage {
logSQLException("Error updating tables to version=2", x); logSQLException("Error updating tables to version=2", x);
err = true; err = true;
return false; return false;
} catch (StorageShutdownException x) {
err = true;
return false;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
c = null; c = null;
@ -445,6 +467,9 @@ public class SQLiteMapStorage extends MapStorage {
logSQLException("Error updating tables to version=3", x); logSQLException("Error updating tables to version=3", x);
err = true; err = true;
return false; return false;
} catch (StorageShutdownException x) {
err = true;
return false;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
c = null; c = null;
@ -457,8 +482,11 @@ public class SQLiteMapStorage extends MapStorage {
return true; return true;
} }
private Connection getConnection() throws SQLException { private Connection getConnection() throws SQLException, StorageShutdownException {
Connection c = null; Connection c = null;
if (isShutdown) {
throw new StorageShutdownException();
}
synchronized (cpool) { synchronized (cpool) {
while (c == null) { while (c == null) {
for (int i = 0; i < cpool.length; i++) { // See if available connection for (int i = 0; i < cpool.length; i++) { // See if available connection
@ -633,6 +661,8 @@ public class SQLiteMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Tile enum error", x); logSQLException("Tile enum error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -670,6 +700,8 @@ public class SQLiteMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Tile purge error", x); logSQLException("Tile purge error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -712,6 +744,8 @@ public class SQLiteMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Face write error", x); logSQLException("Face write error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -746,6 +780,8 @@ public class SQLiteMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Face read error", x); logSQLException("Face read error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -772,6 +808,8 @@ public class SQLiteMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Face exists error", x); logSQLException("Face exists error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -823,6 +861,8 @@ public class SQLiteMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Marker write error", x); logSQLException("Marker write error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
if (rs != null) { try { rs.close(); } catch (SQLException sx) {} } if (rs != null) { try { rs.close(); } catch (SQLException sx) {} }
if (stmt != null) { try { stmt.close(); } catch (SQLException sx) {} } if (stmt != null) { try { stmt.close(); } catch (SQLException sx) {} }
@ -857,6 +897,8 @@ public class SQLiteMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Marker read error", x); logSQLException("Marker read error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }
@ -904,6 +946,8 @@ public class SQLiteMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Marker file write error", x); logSQLException("Marker file write error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
if (rs != null) { try { rs.close(); } catch (SQLException sx) {} } if (rs != null) { try { rs.close(); } catch (SQLException sx) {} }
if (stmt != null) { try { stmt.close(); } catch (SQLException sx) {} } if (stmt != null) { try { stmt.close(); } catch (SQLException sx) {} }
@ -932,6 +976,8 @@ public class SQLiteMapStorage extends MapStorage {
} catch (SQLException x) { } catch (SQLException x) {
logSQLException("Marker file read error", x); logSQLException("Marker file read error", x);
err = true; err = true;
} catch (StorageShutdownException x) {
err = true;
} finally { } finally {
releaseConnection(c, err); releaseConnection(c, err);
} }