Skip to content

Commit 7f7de03

Browse files
committed
Fixed MysqlDataTruncation error when logging large bundles (fixes #799)
1 parent ec96019 commit 7f7de03

3 files changed

Lines changed: 52 additions & 2 deletions

File tree

src/main/java/net/coreprotect/database/Database.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,11 @@ private static void createMySQLTableStructures(String prefix, Statement statemen
365365

366366
// Container
367367
index = ", INDEX(wid,x,z,time), INDEX(user,time), INDEX(type,time)";
368-
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "container(rowid int NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid), time int, user int, wid int, x int, y int, z int, type int, data int, amount int, metadata blob, action tinyint, rolled_back tinyint" + index + ") ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4");
368+
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "container(rowid int NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid), time int, user int, wid int, x int, y int, z int, type int, data int, amount int, metadata mediumblob, action tinyint, rolled_back tinyint" + index + ") ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4");
369369

370370
// Item
371371
index = ", INDEX(wid,x,z,time), INDEX(user,time), INDEX(type,time)";
372-
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "item(rowid int NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid), time int, user int, wid int, x int, y int, z int, type int, data blob, amount int, action tinyint, rolled_back tinyint" + index + ") ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4");
372+
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "item(rowid int NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid), time int, user int, wid int, x int, y int, z int, type int, data mediumblob, amount int, action tinyint, rolled_back tinyint" + index + ") ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4");
373373

374374
// Database lock
375375
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "database_lock(rowid int NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid),status tinyint,time int) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4");

src/main/java/net/coreprotect/patch/script/__2_24_0.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ protected static boolean patch(Statement statement) {
2121
e.printStackTrace();
2222
return false;
2323
}
24+
25+
if (!updateItemMetadataColumns(statement)) {
26+
return false;
27+
}
2428
}
2529
}
2630
catch (Exception e) {
@@ -31,4 +35,26 @@ protected static boolean patch(Statement statement) {
3135
return true;
3236
}
3337

38+
protected static boolean updateItemMetadataColumns(Statement statement) {
39+
if (Config.getGlobal().MYSQL) {
40+
return modifyColumn(statement, ConfigHandler.prefix + "container", "ALTER TABLE " + ConfigHandler.prefix + "container MODIFY metadata MEDIUMBLOB") &&
41+
modifyColumn(statement, ConfigHandler.prefix + "item", "ALTER TABLE " + ConfigHandler.prefix + "item MODIFY data MEDIUMBLOB");
42+
}
43+
44+
return true;
45+
}
46+
47+
private static boolean modifyColumn(Statement statement, String table, String query) {
48+
try {
49+
statement.executeUpdate(query);
50+
return true;
51+
}
52+
catch (Exception e) {
53+
Chat.console(Phrase.build(Phrase.PATCH_SKIP_UPDATE, table, Selector.FIRST, Selector.FIRST));
54+
e.printStackTrace();
55+
}
56+
57+
return false;
58+
}
59+
3460
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package net.coreprotect.patch.script;
2+
3+
import java.sql.Statement;
4+
5+
import net.coreprotect.patch.Patch;
6+
7+
public class __2_24_1 {
8+
9+
protected static boolean patch(Statement statement) {
10+
try {
11+
Integer[] last_version = Patch.getDatabaseVersion(statement.getConnection(), true);
12+
if (last_version[0] == 2 && last_version[1] == 24 && last_version[2] == 0) {
13+
return __2_24_0.updateItemMetadataColumns(statement);
14+
}
15+
}
16+
catch (Exception e) {
17+
e.printStackTrace();
18+
return false;
19+
}
20+
21+
return true;
22+
}
23+
24+
}

0 commit comments

Comments
 (0)