Revert "Ensuring every task will be committed"

This reverts commit bfb69c31


Former-commit-id: 464758a976b214770751046a362d527a91c775a4
This commit is contained in:
sandtechnology committed 2020-04-02 09:45:51 +08:00
1 parent 337462b55b
commit 5f57fd5041
2 files changed
+10 -26

No files matched your search

@@ -42,8 +42,6 @@ public class DatabaseManager {
private final Queue<DatabaseTask> sqlQueue = new LinkedBlockingQueue<>();
private DatabaseTask lastFailedTask=null;
@NotNull
private final Database database;
@@ -91,7 +89,6 @@ public class DatabaseManager {
* Internal method, runTasks in queue.
*/
private void runTask() {
DatabaseTask databaseTask=null;
try {
Connection connection=this.database.getConnection();
//start our commit
@@ -104,19 +101,13 @@ public class DatabaseManager {
}
Timer timer = new Timer(true);
if(lastFailedTask!=null){
Util.debugLog("Executing the SQL task which failed last time: " + lastFailedTask);
lastFailedTask.run(connection);
lastFailedTask=null;
}else {
databaseTask = sqlQueue.poll();
if (databaseTask == null) {
break;
}
Util.debugLog("Executing the SQL task: " + databaseTask);
databaseTask.run(connection);
DatabaseTask task = sqlQueue.poll();
if (task == null) {
break;
}
Util.debugLog("Executing the SQL task: " + task);
task.run(connection);
long tookTime = timer.endTimer();
if (tookTime > 500) {
warningSender.sendWarn(
@@ -129,7 +120,6 @@ public class DatabaseManager {
connection.close();
} catch (SQLException sqle) {
plugin.getSentryErrorReporter().ignoreThrow();
lastFailedTask=databaseTask;
this.plugin
.getLogger()
.log(Level.WARNING, "Database connection may lost, we are trying reconnecting, if this message appear too many times, you should check your database file(sqlite) and internet connection(mysql).", sqle);
@@ -154,13 +144,7 @@ public class DatabaseManager {
if (useQueue) {
sqlQueue.offer(task);
} else {
try {
task.run();
} catch (SQLException e) {
e.printStackTrace();
//retry
add(task);
}
task.run();
}
}
@@ -21,7 +21,7 @@ public class DatabaseTask {
this.task = task;
}
public void run() throws SQLException {
public void run() {
try (PreparedStatement ps = database.getConnection().prepareStatement(statement)) {
task.edit(ps);
ps.execute();
@@ -30,7 +30,7 @@ public class DatabaseTask {
task.onFailed(e);
}
}
public void run(@NonNull Connection connection) throws SQLException {
public void run(@NonNull Connection connection) {
try (PreparedStatement ps = connection.prepareStatement(statement);) {
task.edit(ps);
ps.execute();
@@ -46,8 +46,8 @@ public class DatabaseTask {
default void onSuccess() {
}
default void onFailed(SQLException e) throws SQLException {
throw e;
default void onFailed(SQLException e) {
e.printStackTrace();
}
}