mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 13:16:45 +01:00
Fix database lock error
This commit is contained in:
parent
f8b1fcffa1
commit
2ec0b55482
@ -108,24 +108,37 @@ public class SQLManager implements AbstractDB {
|
||||
this.plotTasks = new ConcurrentHashMap<>();
|
||||
this.playerTasks = new ConcurrentHashMap<>();
|
||||
this.clusterTasks = new ConcurrentHashMap<>();
|
||||
this.prefix = p;
|
||||
this.SET_OWNER = "UPDATE `" + this.prefix + "plot` SET `owner` = ? WHERE `plot_id_x` = ? AND `plot_id_z` = ? AND `world` = ?";
|
||||
this.GET_ALL_PLOTS = "SELECT `id`, `plot_id_x`, `plot_id_z`, `world` FROM `" + this.prefix + "plot`";
|
||||
this.CREATE_PLOTS = "INSERT INTO `" + this.prefix + "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`, `timestamp`) values ";
|
||||
this.CREATE_SETTINGS = "INSERT INTO `" + this.prefix + "plot_settings` (`plot_plot_id`) values ";
|
||||
this.CREATE_TIERS = "INSERT INTO `" + this.prefix + "plot_%tier%` (`plot_plot_id`, `user_uuid`) values ";
|
||||
this.CREATE_PLOT = "INSERT INTO `" + this.prefix + "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`, `timestamp`) VALUES(?, ?, ?, ?, ?)";
|
||||
this.CREATE_CLUSTER =
|
||||
"INSERT INTO `" + this.prefix + "cluster`(`pos1_x`, `pos1_z`, `pos2_x`, `pos2_z`, `owner`, `world`) VALUES(?, ?, ?, ?, ?, ?)";
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
createTables();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
long last = System.currentTimeMillis();
|
||||
while (true) {
|
||||
if (SQLManager.this.closed) {
|
||||
break;
|
||||
}
|
||||
// schedule reconnect
|
||||
if (SQLManager.this.mySQL && System.currentTimeMillis() - last > 550000) {
|
||||
last = System.currentTimeMillis();
|
||||
boolean hasTask = !globalTasks.isEmpty() || !playerTasks.isEmpty() || !plotTasks.isEmpty() || !clusterTasks.isEmpty();
|
||||
if (hasTask) {
|
||||
try {
|
||||
close();
|
||||
SQLManager.this.closed = false;
|
||||
SQLManager.this.connection = database.forceConnection();
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
if (SQLManager.this.mySQL && System.currentTimeMillis() - last > 550000 || !connection.isValid(10000)) {
|
||||
last = System.currentTimeMillis();
|
||||
reconnect();
|
||||
}
|
||||
} catch (SQLException impossible) {
|
||||
impossible.printStackTrace();
|
||||
}
|
||||
if (!sendBatch()) {
|
||||
try {
|
||||
@ -140,22 +153,26 @@ public class SQLManager implements AbstractDB {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
this.prefix = p;
|
||||
// Set timout
|
||||
// setTimout();
|
||||
// Public final
|
||||
this.SET_OWNER = "UPDATE `" + this.prefix + "plot` SET `owner` = ? WHERE `plot_id_x` = ? AND `plot_id_z` = ? AND `world` = ?";
|
||||
this.GET_ALL_PLOTS = "SELECT `id`, `plot_id_x`, `plot_id_z`, `world` FROM `" + this.prefix + "plot`";
|
||||
this.CREATE_PLOTS = "INSERT INTO `" + this.prefix + "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`, `timestamp`) values ";
|
||||
this.CREATE_SETTINGS = "INSERT INTO `" + this.prefix + "plot_settings` (`plot_plot_id`) values ";
|
||||
this.CREATE_TIERS = "INSERT INTO `" + this.prefix + "plot_%tier%` (`plot_plot_id`, `user_uuid`) values ";
|
||||
this.CREATE_PLOT = "INSERT INTO `" + this.prefix + "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`, `timestamp`) VALUES(?, ?, ?, ?, ?)";
|
||||
this.CREATE_CLUSTER =
|
||||
"INSERT INTO `" + this.prefix + "cluster`(`pos1_x`, `pos1_z`, `pos2_x`, `pos2_z`, `owner`, `world`) VALUES(?, ?, ?, ?, ?, ?)";
|
||||
createTables();
|
||||
}
|
||||
|
||||
public void reconnect() {
|
||||
try {
|
||||
close();
|
||||
SQLManager.this.closed = false;
|
||||
SQLManager.this.connection = database.forceConnection();
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized Queue<Runnable> getGlobalTasks() {
|
||||
|
Loading…
Reference in New Issue
Block a user