mirror of
https://github.com/BlueMap-Minecraft/BlueMap.git
synced 2024-11-25 12:05:13 +01:00
Fix some issues with the new sql-storage implementations
This commit is contained in:
parent
f18f7a9a16
commit
240ca6c00e
@ -54,7 +54,7 @@
|
||||
@Getter
|
||||
public class SQLConfig extends StorageConfig {
|
||||
|
||||
private static final Pattern URL_DIALECT_PATTERN = Pattern.compile("jdbc:([^:]*)://.*");
|
||||
private static final Pattern URL_DIALECT_PATTERN = Pattern.compile("jdbc:([^:]*):.*");
|
||||
|
||||
private String connectionUrl = "jdbc:mysql://localhost/bluemap?permitMysqlScheme";
|
||||
private Map<String, String> connectionProperties = new HashMap<>();
|
||||
@ -102,7 +102,12 @@ public Dialect getDialect() throws ConfigurationException {
|
||||
// default from connection-url
|
||||
if (key == null) {
|
||||
Matcher matcher = URL_DIALECT_PATTERN.matcher(connectionUrl);
|
||||
if (!matcher.find()) return Dialect.MYSQL;
|
||||
if (!matcher.find()) {
|
||||
throw new ConfigurationException("""
|
||||
Failed to parse the provided connection-url!
|
||||
Please check your 'connection-url' setting in your configuration and make sure it is in the correct format.
|
||||
""".strip());
|
||||
}
|
||||
key = Key.bluemap(matcher.group(1)).getFormatted();
|
||||
}
|
||||
|
||||
|
@ -136,7 +136,7 @@ public void delete(DoublePredicate onProgress) throws IOException {
|
||||
deleted = sql.purgeMapTiles(mapId, 1000);
|
||||
totalDeleted += deleted;
|
||||
|
||||
if (onProgress.test((double) totalDeleted / tileCount))
|
||||
if (!onProgress.test((double) totalDeleted / tileCount))
|
||||
return;
|
||||
|
||||
} while (deleted > 0 && totalDeleted < tileCount);
|
||||
|
@ -36,7 +36,6 @@
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@SuppressWarnings("SqlSourceToSinkFlow")
|
||||
@RequiredArgsConstructor
|
||||
@ -45,9 +44,9 @@ public abstract class AbstractCommandSet implements CommandSet {
|
||||
private final Database db;
|
||||
|
||||
final LoadingCache<String, Integer> mapKeys = Caffeine.newBuilder()
|
||||
.build(this::mapKey);
|
||||
.build(this::findOrCreateMapKey);
|
||||
final LoadingCache<Compression, Integer> compressionKeys = Caffeine.newBuilder()
|
||||
.build(this::compressionKey);
|
||||
.build(this::findOrCreateCompressionKey);
|
||||
|
||||
@Language("sql")
|
||||
public abstract String createMapTableStatement();
|
||||
@ -83,8 +82,8 @@ public int writeMapTile(
|
||||
String mapId, int lod, int x, int z, Compression compression,
|
||||
byte[] bytes
|
||||
) throws IOException {
|
||||
int mapKey = Objects.requireNonNull(mapKeys.get(mapId));
|
||||
int compressionKey = Objects.requireNonNull(compressionKeys.get(compression));
|
||||
int mapKey = mapKey(mapId);
|
||||
int compressionKey = compressionKey(compression);
|
||||
return db.run(connection -> {
|
||||
return executeUpdate(connection,
|
||||
writeMapTileStatement(),
|
||||
@ -201,7 +200,7 @@ public TilePosition[] listMapTiles(String mapId, int lod, Compression compressio
|
||||
|
||||
@Override
|
||||
public int writeMapMeta(String mapId, String itemName, byte[] bytes) throws IOException {
|
||||
int mapKey = Objects.requireNonNull(mapKeys.get(mapId));
|
||||
int mapKey = mapKey(mapId);
|
||||
return db.run(connection -> {
|
||||
return executeUpdate(connection,
|
||||
writeMapMetaStatement(),
|
||||
@ -265,6 +264,7 @@ public boolean hasMapMeta(String mapId, String itemName) throws IOException {
|
||||
|
||||
@Override
|
||||
public void purgeMap(String mapId) throws IOException {
|
||||
synchronized (mapKeys) {
|
||||
db.run(connection -> {
|
||||
|
||||
executeUpdate(connection,
|
||||
@ -283,6 +283,9 @@ public void purgeMap(String mapId) throws IOException {
|
||||
);
|
||||
|
||||
});
|
||||
|
||||
mapKeys.invalidate(mapId);
|
||||
}
|
||||
}
|
||||
|
||||
@Language("sql")
|
||||
@ -324,7 +327,14 @@ public String[] listMapIds(int start, int count) throws IOException {
|
||||
@Language("sql")
|
||||
public abstract String createMapKeyStatement();
|
||||
|
||||
public int mapKey(String mapId) throws IOException {
|
||||
public int mapKey(String mapId) {
|
||||
synchronized (mapKeys) {
|
||||
//noinspection DataFlowIssue
|
||||
return mapKeys.get(mapId);
|
||||
}
|
||||
}
|
||||
|
||||
public int findOrCreateMapKey(String mapId) throws IOException {
|
||||
return db.run(connection -> {
|
||||
ResultSet result = executeQuery(connection,
|
||||
findMapKeyStatement(),
|
||||
@ -353,7 +363,14 @@ public int mapKey(String mapId) throws IOException {
|
||||
@Language("sql")
|
||||
public abstract String createCompressionKeyStatement();
|
||||
|
||||
public int compressionKey(Compression compression) throws IOException {
|
||||
public int compressionKey(Compression compression) {
|
||||
synchronized (compressionKeys) {
|
||||
//noinspection DataFlowIssue
|
||||
return compressionKeys.get(compression);
|
||||
}
|
||||
}
|
||||
|
||||
public int findOrCreateCompressionKey(Compression compression) throws IOException {
|
||||
return db.run(connection -> {
|
||||
ResultSet result = executeQuery(connection,
|
||||
findCompressionKeyStatement(),
|
||||
|
@ -38,7 +38,7 @@ public SqliteCommandSet(Database db) {
|
||||
public String createMapTableStatement() {
|
||||
return """
|
||||
CREATE TABLE IF NOT EXISTS `bluemap_map` (
|
||||
`id` INTEGER UNSIGNED PRIMARY KEY AUTOINCREMENT,
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
`map_id` TEXT UNIQUE NOT NULL
|
||||
) STRICT
|
||||
""";
|
||||
@ -49,7 +49,7 @@ public String createMapTableStatement() {
|
||||
public String createCompressionTableStatement() {
|
||||
return """
|
||||
CREATE TABLE IF NOT EXISTS `bluemap_map_tile_compression` (
|
||||
`id` INTEGER UNSIGNED PRIMARY KEY AUTOINCREMENT,
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
`compression` TEXT UNIQUE NOT NULL
|
||||
) STRICT
|
||||
""";
|
||||
@ -60,7 +60,7 @@ public String createCompressionTableStatement() {
|
||||
public String createMapMetaTableStatement() {
|
||||
return """
|
||||
CREATE TABLE IF NOT EXISTS `bluemap_map_meta` (
|
||||
`map` INTEGER UNSIGNED NOT NULL,
|
||||
`map` INTEGER NOT NULL,
|
||||
`key` TEXT NOT NULL,
|
||||
`value` BLOB NOT NULL,
|
||||
PRIMARY KEY (`map`, `key`),
|
||||
@ -78,11 +78,11 @@ FOREIGN KEY (`map`)
|
||||
public String createMapTileTableStatement() {
|
||||
return """
|
||||
CREATE TABLE IF NOT EXISTS `bluemap_map_tile` (
|
||||
`map` INTEGER UNSIGNED NOT NULL,
|
||||
`lod` INTEGER UNSIGNED NOT NULL,
|
||||
`map` INTEGER NOT NULL,
|
||||
`lod` INTEGER NOT NULL,
|
||||
`x` INTEGER NOT NULL,
|
||||
`z` INTEGER NOT NULL,
|
||||
`compression` INTEGER UNSIGNED NOT NULL,
|
||||
`compression` INTEGER NOT NULL,
|
||||
`data` BLOB NOT NULL,
|
||||
PRIMARY KEY (`map`, `lod`, `x`, `z`),
|
||||
CONSTRAINT `fk_bluemap_map_tile_map`
|
||||
@ -104,7 +104,7 @@ FOREIGN KEY (`compression`)
|
||||
public String fixLegacyCompressionIdsStatement() {
|
||||
return """
|
||||
UPDATE `bluemap_map_tile_compression`
|
||||
SET `compression` = CONCAT('bluemap:', `compression`)
|
||||
SET `compression` = 'bluemap:' || `compression`
|
||||
WHERE NOT `compression` LIKE '%:%'
|
||||
""";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user