This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 68c4d2227e5 Remove PacketPayload.close() (#25866)
68c4d2227e5 is described below
commit 68c4d2227e55a2716a0c0678056b89cf4175861e
Author: Liang Zhang <[email protected]>
AuthorDate: Wed May 24 09:57:29 2023 +0800
Remove PacketPayload.close() (#25866)
---
.../db/protocol/payload/PacketPayload.java | 2 +-
.../protocol/mysql/payload/MySQLPacketPayload.java | 5 -
.../mysql/payload/MySQLPacketPayloadTest.java | 170 +++++----------------
.../payload/PostgreSQLPacketPayload.java | 13 --
.../payload/PostgreSQLPacketPayloadTest.java | 1 -
infra/util/pom.xml | 2 +-
.../frontend/command/CommandExecutorTask.java | 28 +++-
.../netty/FrontendChannelInboundHandler.java | 8 +-
8 files changed, 69 insertions(+), 160 deletions(-)
diff --git
a/db-protocol/core/src/main/java/org/apache/shardingsphere/db/protocol/payload/PacketPayload.java
b/db-protocol/core/src/main/java/org/apache/shardingsphere/db/protocol/payload/PacketPayload.java
index be22a9f48ca..f8ed1d63f76 100644
---
a/db-protocol/core/src/main/java/org/apache/shardingsphere/db/protocol/payload/PacketPayload.java
+++
b/db-protocol/core/src/main/java/org/apache/shardingsphere/db/protocol/payload/PacketPayload.java
@@ -24,7 +24,7 @@ import java.nio.charset.Charset;
/**
* Packet payload.
*/
-public interface PacketPayload extends AutoCloseable {
+public interface PacketPayload {
/**
* Get byte buf.
diff --git
a/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/payload/MySQLPacketPayload.java
b/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/payload/MySQLPacketPayload.java
index 781f8d48707..68fff63c06b 100644
---
a/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/payload/MySQLPacketPayload.java
+++
b/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/payload/MySQLPacketPayload.java
@@ -406,9 +406,4 @@ public final class MySQLPacketPayload implements
PacketPayload {
public void writeReserved(final int length) {
byteBuf.writeZero(length);
}
-
- @Override
- public void close() {
- byteBuf.release();
- }
}
diff --git
a/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/payload/MySQLPacketPayloadTest.java
b/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/payload/MySQLPacketPayloadTest.java
index fe461922f2c..15d5b8ca10a 100644
---
a/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/payload/MySQLPacketPayloadTest.java
+++
b/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/payload/MySQLPacketPayloadTest.java
@@ -40,176 +40,132 @@ class MySQLPacketPayloadTest {
@Test
void assertReadInt1() {
when(byteBuf.readUnsignedByte()).thenReturn((short) 1);
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- assertThat(actual.readInt1(), is(1));
- }
+ assertThat(new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).readInt1(), is(1));
}
@Test
void assertWriteInt1() {
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- actual.writeInt1(1);
- }
+ new MySQLPacketPayload(byteBuf, StandardCharsets.UTF_8).writeInt1(1);
verify(byteBuf).writeByte(1);
}
@Test
void assertReadInt2() {
when(byteBuf.readUnsignedShortLE()).thenReturn(1);
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- assertThat(actual.readInt2(), is(1));
- }
+ assertThat(new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).readInt2(), is(1));
}
@Test
void assertWriteInt2() {
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- actual.writeInt2(1);
- }
+ new MySQLPacketPayload(byteBuf, StandardCharsets.UTF_8).writeInt2(1);
verify(byteBuf).writeShortLE(1);
}
@Test
void assertReadInt3() {
when(byteBuf.readUnsignedMediumLE()).thenReturn(1);
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- assertThat(actual.readInt3(), is(1));
- }
+ assertThat(new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).readInt3(), is(1));
}
@Test
void assertWriteInt3() {
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- actual.writeInt3(1);
- }
+ new MySQLPacketPayload(byteBuf, StandardCharsets.UTF_8).writeInt3(1);
verify(byteBuf).writeMediumLE(1);
}
@Test
void assertReadInt4() {
when(byteBuf.readIntLE()).thenReturn(1);
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- assertThat(actual.readInt4(), is(1));
- }
+ assertThat(new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).readInt4(), is(1));
}
@Test
void assertWriteInt4() {
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- actual.writeInt4(1);
- }
+ new MySQLPacketPayload(byteBuf, StandardCharsets.UTF_8).writeInt4(1);
verify(byteBuf).writeIntLE(1);
}
@Test
void assertReadInt6() {
when(byteBuf.readByte()).thenReturn((byte) 0x01, (byte) 0x00);
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- assertThat(actual.readInt6(), is(1L));
- }
+ assertThat(new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).readInt6(), is(1L));
when(byteBuf.readByte()).thenReturn((byte) 0x00, (byte) 0x00, (byte)
0x00, (byte) 0x00, (byte) 0x00, (byte) 0x80);
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- assertThat(actual.readInt6(), is(0x800000000000L));
- }
+ assertThat(new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).readInt6(), is(0x800000000000L));
}
@Test
void assertWriteInt6() {
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- assertDoesNotThrow(() -> actual.writeInt6(1L));
- }
+ assertDoesNotThrow(() -> new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).writeInt6(1L));
}
@Test
void assertReadInt8() {
when(byteBuf.readLongLE()).thenReturn(1L);
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- assertThat(actual.readInt8(), is(1L));
- }
+ assertThat(new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).readInt8(), is(1L));
}
@Test
void assertWriteInt8() {
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- actual.writeInt8(1L);
- }
+ new MySQLPacketPayload(byteBuf, StandardCharsets.UTF_8).writeInt8(1L);
verify(byteBuf).writeLongLE(1L);
}
@Test
void assertReadIntLenencWithOneByte() {
when(byteBuf.readUnsignedByte()).thenReturn((short) 1);
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- assertThat(actual.readIntLenenc(), is(1L));
- }
+ assertThat(new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).readIntLenenc(), is(1L));
}
@Test
void assertReadIntLenencWithZero() {
when(byteBuf.readUnsignedByte()).thenReturn((short) 0xfb);
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- assertThat(actual.readIntLenenc(), is(0L));
- }
+ assertThat(new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).readIntLenenc(), is(0L));
}
@Test
void assertReadIntLenencWithTwoBytes() {
when(byteBuf.readUnsignedByte()).thenReturn((short) 0xfc);
when(byteBuf.readUnsignedShortLE()).thenReturn(100);
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- assertThat(actual.readIntLenenc(), is(100L));
- }
+ assertThat(new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).readIntLenenc(), is(100L));
}
@Test
void assertReadIntLenencWithThreeBytes() {
when(byteBuf.readUnsignedByte()).thenReturn((short) 0xfd);
when(byteBuf.readUnsignedMediumLE()).thenReturn(99999);
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- assertThat(actual.readIntLenenc(), is(99999L));
- }
+ assertThat(new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).readIntLenenc(), is(99999L));
}
@Test
void assertReadIntLenencWithFourBytes() {
when(byteBuf.readUnsignedByte()).thenReturn((short) 0xff);
when(byteBuf.readLongLE()).thenReturn(Long.MAX_VALUE);
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- assertThat(actual.readIntLenenc(), is(Long.MAX_VALUE));
- }
+ assertThat(new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).readIntLenenc(), is(Long.MAX_VALUE));
}
@Test
void assertWriteIntLenencWithOneByte() {
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- actual.writeIntLenenc(1L);
- }
+ new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).writeIntLenenc(1L);
verify(byteBuf).writeByte(1);
}
@Test
void assertWriteIntLenencWithTwoBytes() {
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- actual.writeIntLenenc(Double.valueOf(Math.pow(2, 16)).longValue()
- 1);
- }
+ new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).writeIntLenenc(Double.valueOf(Math.pow(2,
16)).longValue() - 1);
verify(byteBuf).writeByte(0xfc);
verify(byteBuf).writeShortLE(Double.valueOf(Math.pow(2,
16)).intValue() - 1);
}
@Test
void assertWriteIntLenencWithThreeBytes() {
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- actual.writeIntLenenc(Double.valueOf(Math.pow(2, 24)).longValue()
- 1);
- }
+ new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).writeIntLenenc(Double.valueOf(Math.pow(2,
24)).longValue() - 1);
verify(byteBuf).writeByte(0xfd);
verify(byteBuf).writeMediumLE(Double.valueOf(Math.pow(2,
24)).intValue() - 1);
}
@Test
void assertWriteIntLenencWithFourBytes() {
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- actual.writeIntLenenc(Double.valueOf(Math.pow(2, 25)).longValue()
- 1);
- }
+ new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).writeIntLenenc(Double.valueOf(Math.pow(2,
25)).longValue() - 1);
verify(byteBuf).writeByte(0xfe);
verify(byteBuf).writeLongLE(Double.valueOf(Math.pow(2, 25)).intValue()
- 1);
}
@@ -217,120 +173,90 @@ class MySQLPacketPayloadTest {
@Test
void assertReadStringLenenc() {
when(byteBuf.readUnsignedByte()).thenReturn((short) 0);
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- assertThat(actual.readStringLenenc(), is(""));
- }
+ assertThat(new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).readStringLenenc(), is(""));
}
@Test
void assertReadStringLenencByBytes() {
when(byteBuf.readUnsignedByte()).thenReturn((short) 0);
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- assertThat(actual.readStringLenencByBytes(), is(new byte[]{}));
- }
+ assertThat(new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).readStringLenencByBytes(), is(new byte[]{}));
}
@Test
void assertWriteStringLenencWithEmpty() {
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- actual.writeStringLenenc("");
- }
+ new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).writeStringLenenc("");
verify(byteBuf).writeByte(0);
}
@Test
void assertWriteBytesLenenc() {
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- actual.writeBytesLenenc("value".getBytes());
- }
+ new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).writeBytesLenenc("value".getBytes());
verify(byteBuf).writeByte(5);
verify(byteBuf).writeBytes("value".getBytes());
}
@Test
void assertWriteBytesLenencWithEmpty() {
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- actual.writeBytesLenenc("".getBytes());
- }
+ new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).writeBytesLenenc("".getBytes());
verify(byteBuf).writeByte(0);
}
@Test
void assertWriteStringLenenc() {
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- actual.writeStringLenenc("value");
- }
+ new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).writeStringLenenc("value");
verify(byteBuf).writeByte(5);
verify(byteBuf).writeBytes("value".getBytes());
}
@Test
void assertReadStringFix() {
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- assertThat(actual.readStringFix(0), is(""));
- }
+ assertThat(new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).readStringFix(0), is(""));
}
@Test
void assertReadStringFixByBytes() {
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- assertThat(actual.readStringFixByBytes(0), is(new byte[]{}));
- }
+ assertThat(new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).readStringFixByBytes(0), is(new byte[]{}));
}
@Test
void assertWriteStringFix() {
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- actual.writeStringFix("value");
- }
+ new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).writeStringFix("value");
verify(byteBuf).writeBytes("value".getBytes());
}
@Test
void assertWriteBytes() {
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- actual.writeBytes("value".getBytes());
- }
+ new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).writeBytes("value".getBytes());
verify(byteBuf).writeBytes("value".getBytes());
}
@Test
void assertReadStringVar() {
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- assertThat(actual.readStringVar(), is(""));
- }
+ assertThat(new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).readStringVar(), is(""));
}
@Test
void assertWriteStringVar() {
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- assertDoesNotThrow(() -> actual.writeStringVar(""));
- }
+ assertDoesNotThrow(() -> new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).writeStringVar(""));
}
@Test
void assertReadStringNul() {
when(byteBuf.bytesBefore((byte) 0)).thenReturn(0);
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- assertThat(actual.readStringNul(), is(""));
- }
+ assertThat(new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).readStringNul(), is(""));
verify(byteBuf).skipBytes(1);
}
@Test
void assertReadStringNulByBytes() {
when(byteBuf.bytesBefore((byte) 0)).thenReturn(0);
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- assertThat(actual.readStringNulByBytes(), is(new byte[]{}));
- }
+ assertThat(new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).readStringNulByBytes(), is(new byte[]{}));
verify(byteBuf).skipBytes(1);
}
@Test
void assertWriteStringNul() {
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- actual.writeStringNul("value");
- }
+ new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).writeStringNul("value");
verify(byteBuf).writeBytes("value".getBytes());
verify(byteBuf).writeByte(0);
}
@@ -338,38 +264,24 @@ class MySQLPacketPayloadTest {
@Test
void assertReadStringEOF() {
when(byteBuf.readableBytes()).thenReturn(0);
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- assertThat(actual.readStringEOF(), is(""));
- }
+ assertThat(new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).readStringEOF(), is(""));
}
@Test
void assertWriteStringEOF() {
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- actual.writeStringEOF("value");
- }
+ new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).writeStringEOF("value");
verify(byteBuf).writeBytes("value".getBytes());
}
@Test
void assertSkipReserved() {
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- actual.skipReserved(10);
- }
+ new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).skipReserved(10);
verify(byteBuf).skipBytes(10);
}
@Test
void assertWriteReserved() {
- try (MySQLPacketPayload actual = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8)) {
- actual.writeReserved(10);
- }
+ new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).writeReserved(10);
verify(byteBuf).writeZero(10);
}
-
- @Test
- void assertClose() {
- new MySQLPacketPayload(byteBuf, StandardCharsets.UTF_8).close();
- verify(byteBuf).release();
- }
}
diff --git
a/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/payload/PostgreSQLPacketPayload.java
b/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/payload/PostgreSQLPacketPayload.java
index 958a30ad2aa..6030532da4a 100644
---
a/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/payload/PostgreSQLPacketPayload.java
+++
b/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/payload/PostgreSQLPacketPayload.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.db.protocol.postgresql.payload;
import io.netty.buffer.ByteBuf;
-import io.netty.buffer.CompositeByteBuf;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.db.protocol.payload.PacketPayload;
@@ -176,16 +175,4 @@ public final class PostgreSQLPacketPayload implements
PacketPayload {
public boolean hasCompletePacket() {
return byteBuf.readableBytes() >= 5 && byteBuf.readableBytes() - 1 >=
byteBuf.getInt(byteBuf.readerIndex() + 1);
}
-
- @Override
- public void close() {
- if (byteBuf instanceof CompositeByteBuf) {
- int remainBytes = byteBuf.readableBytes();
- if (remainBytes > 0) {
- byteBuf.skipBytes(remainBytes);
- }
- ((CompositeByteBuf) byteBuf).discardReadComponents();
- }
- byteBuf.release();
- }
}
diff --git
a/db-protocol/postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/payload/PostgreSQLPacketPayloadTest.java
b/db-protocol/postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/payload/PostgreSQLPacketPayloadTest.java
index d48715c6d3f..a96a0fc4b3a 100644
---
a/db-protocol/postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/payload/PostgreSQLPacketPayloadTest.java
+++
b/db-protocol/postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/payload/PostgreSQLPacketPayloadTest.java
@@ -53,6 +53,5 @@ class PostgreSQLPacketPayloadTest {
assertThat(payload.bytesBeforeZero(), is(expectedString.length()));
assertThat(payload.readStringNul(), is(expectedString));
assertThat(payload.getByteBuf(), is(byteBuf));
- payload.close();
}
}
diff --git a/infra/util/pom.xml b/infra/util/pom.xml
index f0a6e9281ff..4f6a6d7b8de 100644
--- a/infra/util/pom.xml
+++ b/infra/util/pom.xml
@@ -38,7 +38,7 @@
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
</dependency>
-
+
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
diff --git
a/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTask.java
b/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTask.java
index e8cb7f26156..2531fe81f75 100644
---
a/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTask.java
+++
b/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTask.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.proxy.frontend.command;
import io.netty.buffer.ByteBuf;
+import io.netty.buffer.CompositeByteBuf;
import io.netty.channel.ChannelHandlerContext;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -70,11 +71,12 @@ public final class CommandExecutorTask implements Runnable {
public void run() {
boolean isNeedFlush = false;
boolean sqlShowEnabled =
ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getProps().getValue(ConfigurationPropertyKey.SQL_SHOW);
- try (PacketPayload payload =
databaseProtocolFrontendEngine.getCodecEngine().createPacketPayload((ByteBuf)
message, context.channel().attr(CommonConstants.CHARSET_ATTRIBUTE_KEY).get())) {
+ try {
if (sqlShowEnabled) {
fillLogMDC();
}
- isNeedFlush = executeCommand(context, payload);
+ isNeedFlush = executeCommand(context,
+
databaseProtocolFrontendEngine.getCodecEngine().createPacketPayload((ByteBuf)
message, context.channel().attr(CommonConstants.CHARSET_ATTRIBUTE_KEY).get()));
// CHECKSTYLE:OFF
} catch (final Exception ex) {
// CHECKSTYLE:ON
@@ -99,9 +101,18 @@ public final class CommandExecutorTask implements Runnable {
if (sqlShowEnabled) {
clearLogMDC();
}
+ if (message instanceof CompositeByteBuf) {
+ releaseCompositeByteBuf((CompositeByteBuf) message);
+ }
+ ((ByteBuf) message).release();
}
}
+ private void fillLogMDC() {
+ MDC.put(LogMDCConstants.DATABASE_KEY,
connectionSession.getDatabaseName());
+ MDC.put(LogMDCConstants.USER_KEY,
connectionSession.getGrantee().toString());
+ }
+
private boolean executeCommand(final ChannelHandlerContext context, final
PacketPayload payload) throws SQLException {
CommandExecuteEngine commandExecuteEngine =
databaseProtocolFrontendEngine.getCommandExecuteEngine();
CommandPacketType type =
commandExecuteEngine.getCommandPacketType(payload);
@@ -151,12 +162,15 @@ public final class CommandExecutorTask implements
Runnable {
processException(ex);
}
- private void fillLogMDC() {
- MDC.put(LogMDCConstants.DATABASE_KEY,
connectionSession.getDatabaseName());
- MDC.put(LogMDCConstants.USER_KEY,
connectionSession.getGrantee().toString());
- }
-
private void clearLogMDC() {
MDC.clear();
}
+
+ private void releaseCompositeByteBuf(final CompositeByteBuf
compositeByteBuf) {
+ int remainBytes = compositeByteBuf.readableBytes();
+ if (remainBytes > 0) {
+ compositeByteBuf.skipBytes(remainBytes);
+ }
+ compositeByteBuf.discardReadComponents();
+ }
}
diff --git
a/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandler.java
b/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandler.java
index 69b2f92b2b4..81631f43a4d 100644
---
a/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandler.java
+++
b/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandler.java
@@ -23,7 +23,6 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.db.protocol.constant.CommonConstants;
-import org.apache.shardingsphere.db.protocol.payload.PacketPayload;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.executor.sql.process.ProcessEngine;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
@@ -77,8 +76,9 @@ public final class FrontendChannelInboundHandler extends
ChannelInboundHandlerAd
}
private boolean authenticate(final ChannelHandlerContext context, final
ByteBuf message) {
- try (PacketPayload payload =
databaseProtocolFrontendEngine.getCodecEngine().createPacketPayload(message,
context.channel().attr(CommonConstants.CHARSET_ATTRIBUTE_KEY).get())) {
- AuthenticationResult authResult =
databaseProtocolFrontendEngine.getAuthenticationEngine().authenticate(context,
payload);
+ try {
+ AuthenticationResult authResult =
databaseProtocolFrontendEngine.getAuthenticationEngine().authenticate(context,
+
databaseProtocolFrontendEngine.getCodecEngine().createPacketPayload(message,
context.channel().attr(CommonConstants.CHARSET_ATTRIBUTE_KEY).get()));
if (authResult.isFinished()) {
connectionSession.setGrantee(new
Grantee(authResult.getUsername(), authResult.getHostname()));
connectionSession.setCurrentDatabase(authResult.getDatabase());
@@ -95,6 +95,8 @@ public final class FrontendChannelInboundHandler extends
ChannelInboundHandlerAd
}
context.writeAndFlush(databaseProtocolFrontendEngine.getCommandExecuteEngine().getErrorPacket(ex));
context.close();
+ } finally {
+ message.release();
}
return false;
}