mirror of
https://github.com/actiontech/dble.git
synced 2026-05-06 14:30:54 -05:00
fix: front-end determines that the packet size cannot exceed the set value
This commit is contained in:
@@ -7,6 +7,7 @@ import com.actiontech.dble.backend.mysql.proto.handler.Impl.MySQLProtoHandlerImp
|
||||
import com.actiontech.dble.backend.mysql.proto.handler.ProtoHandler;
|
||||
import com.actiontech.dble.backend.mysql.proto.handler.ProtoHandlerResult;
|
||||
import com.actiontech.dble.config.ErrorCode;
|
||||
import com.actiontech.dble.config.model.SystemConfig;
|
||||
import com.actiontech.dble.net.connection.AbstractConnection;
|
||||
import com.actiontech.dble.net.mysql.ErrorPacket;
|
||||
import com.actiontech.dble.net.mysql.MySQLPacket;
|
||||
@@ -314,6 +315,10 @@ public abstract class AbstractService implements Service {
|
||||
if (data != null && !executeTask.isReuse()) {
|
||||
this.setPacketId(executeTask.getSequenceId());
|
||||
}
|
||||
if (data != null && data.length - MySQLPacket.PACKET_HEADER_SIZE >= SystemConfig.getInstance().getMaxPacketSize()) {
|
||||
throw new IllegalArgumentException("Packet for query is too large (" + data.length + " > " + SystemConfig.getInstance().getMaxPacketSize() + ").You can change maxPacketSize value in bootstrap.cnf.");
|
||||
}
|
||||
|
||||
if (isSupportCompress()) {
|
||||
final ConcurrentLinkedQueue<byte[]> decompressUnfinishedDataQueue = new ConcurrentLinkedQueue<>();
|
||||
List<byte[]> packs = CompressUtil.decompressMysqlPacket(data, decompressUnfinishedDataQueue);
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.actiontech.dble.route.parser.util.ParseUtil;
|
||||
import com.actiontech.dble.server.parser.ServerParse;
|
||||
import com.actiontech.dble.server.parser.ServerParseSelect;
|
||||
import com.actiontech.dble.server.response.*;
|
||||
import com.actiontech.dble.services.manager.response.SelectMaxAllowedPacket;
|
||||
import com.actiontech.dble.services.mysqlsharding.ShardingService;
|
||||
|
||||
|
||||
@@ -107,6 +108,9 @@ public final class SelectHandler {
|
||||
case ServerParseSelect.ROW_COUNT:
|
||||
SelectRowCount.response(service);
|
||||
break;
|
||||
case ServerParseSelect.MAX_ALLOWED_PACKET:
|
||||
SelectMaxAllowedPacket.execute(service);
|
||||
break;
|
||||
default:
|
||||
service.execute(stmt, ServerParse.SELECT);
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ public final class ServerParseSelect {
|
||||
public static final int SESSION_TRANSACTION_ISOLATION = 13;
|
||||
public static final int SESSION_TRANSACTION_READ_ONLY = 14;
|
||||
public static final int ROW_COUNT = 15;
|
||||
public static final int MAX_ALLOWED_PACKET = 16;
|
||||
|
||||
private static final char[] TRACE_STR = "TRACE".toCharArray();
|
||||
private static final char[] VERSION_COMMENT_STR = "VERSION_COMMENT".toCharArray();
|
||||
@@ -492,6 +493,9 @@ public final class ServerParseSelect {
|
||||
case 't':
|
||||
case 'T':
|
||||
return traceCheck(stmt, offset);
|
||||
case 'm':
|
||||
case 'M':
|
||||
return maxCheck(stmt, offset);
|
||||
default:
|
||||
return OTHER;
|
||||
}
|
||||
@@ -499,6 +503,17 @@ public final class ServerParseSelect {
|
||||
return OTHER;
|
||||
}
|
||||
|
||||
// select @@max_allowed_packet;
|
||||
private static int maxCheck(String stmt, int offset) {
|
||||
if (stmt.length() > offset + 17) {
|
||||
String suffix = stmt.substring(offset).toUpperCase();
|
||||
if (suffix.startsWith("MAX_ALLOWED_PACKET") && (stmt.length() == offset + 18 || ParseUtil.isEOF(stmt, offset + 18))) {
|
||||
return MAX_ALLOWED_PACKET;
|
||||
}
|
||||
}
|
||||
return OTHER;
|
||||
}
|
||||
|
||||
/**
|
||||
* SELECT DATABASE()
|
||||
*/
|
||||
|
||||
@@ -8,6 +8,7 @@ package com.actiontech.dble.server.response;
|
||||
import com.actiontech.dble.backend.mysql.PacketUtil;
|
||||
import com.actiontech.dble.backend.mysql.VersionUtil;
|
||||
import com.actiontech.dble.config.Fields;
|
||||
import com.actiontech.dble.config.model.SystemConfig;
|
||||
import com.actiontech.dble.net.mysql.*;
|
||||
import com.actiontech.dble.services.mysqlsharding.ShardingService;
|
||||
import com.google.common.base.Splitter;
|
||||
@@ -77,6 +78,10 @@ public final class SelectVariables {
|
||||
case "collation_connection":
|
||||
row.add(service.getCharset().getCollation() != null ? service.getCharset().getCollation().getBytes() : null);
|
||||
break;
|
||||
case "max_allowed_packet":
|
||||
case "@@max_allowed_packet":
|
||||
row.add(String.valueOf(SystemConfig.getInstance().getMaxPacketSize()).getBytes());
|
||||
break;
|
||||
default:
|
||||
String value = VARIABLES.get(s) == null ? "" : VARIABLES.get(s);
|
||||
row.add(value.getBytes());
|
||||
@@ -123,7 +128,6 @@ public final class SelectVariables {
|
||||
VARIABLES.put("@@interactive_timeout", "172800");
|
||||
VARIABLES.put("@@license", "GPL");
|
||||
VARIABLES.put("@@lower_case_table_names", "1");
|
||||
VARIABLES.put("@@max_allowed_packet", "16777216");
|
||||
VARIABLES.put("@@net_buffer_length", "16384");
|
||||
VARIABLES.put("@@net_write_timeout", "60");
|
||||
VARIABLES.put("@@query_cache_size", "0");
|
||||
@@ -144,7 +148,6 @@ public final class SelectVariables {
|
||||
VARIABLES.put("interactive_timeout", "172800");
|
||||
VARIABLES.put("license", "GPL");
|
||||
VARIABLES.put("lower_case_table_names", "1");
|
||||
VARIABLES.put("max_allowed_packet", "16777216");
|
||||
VARIABLES.put("net_buffer_length", "16384");
|
||||
VARIABLES.put("net_write_timeout", "60");
|
||||
VARIABLES.put("query_cache_size", "0");
|
||||
|
||||
+4
-3
@@ -7,8 +7,9 @@ package com.actiontech.dble.services.manager.response;
|
||||
|
||||
import com.actiontech.dble.backend.mysql.PacketUtil;
|
||||
import com.actiontech.dble.config.Fields;
|
||||
import com.actiontech.dble.config.model.SystemConfig;
|
||||
import com.actiontech.dble.net.mysql.*;
|
||||
import com.actiontech.dble.services.manager.ManagerService;
|
||||
import com.actiontech.dble.net.service.AbstractService;
|
||||
import com.actiontech.dble.util.LongUtil;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
@@ -34,7 +35,7 @@ public final class SelectMaxAllowedPacket {
|
||||
EOF.setPacketId(++packetId);
|
||||
}
|
||||
|
||||
public static void execute(ManagerService service) {
|
||||
public static void execute(AbstractService service) {
|
||||
ByteBuffer buffer = service.allocate();
|
||||
|
||||
// write header
|
||||
@@ -52,7 +53,7 @@ public final class SelectMaxAllowedPacket {
|
||||
byte packetId = EOF.getPacketId();
|
||||
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
|
||||
row.setPacketId(++packetId);
|
||||
row.add(LongUtil.toBytes(1048576));
|
||||
row.add(LongUtil.toBytes(SystemConfig.getInstance().getMaxPacketSize()));
|
||||
buffer = row.write(buffer, service, true);
|
||||
|
||||
// write last eof
|
||||
|
||||
Reference in New Issue
Block a user