This is an automated email from the ASF dual-hosted git repository.
totalo 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 dd9190e Fixes #16333. (#16336)
dd9190e is described below
commit dd9190e8bc0911db297ebd666ca921a072725800
Author: Raigor <[email protected]>
AuthorDate: Thu Mar 24 22:55:29 2022 +0800
Fixes #16333. (#16336)
---
.../frontend/command/CommandExecutorTask.java | 13 +++++++++
.../proxy/frontend/constant/MDCConstants.java | 32 ++++++++++++++++++++++
2 files changed, 45 insertions(+)
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTask.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTask.java
index 1a4f331..a3a6185 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTask.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTask.java
@@ -31,8 +31,10 @@ import
org.apache.shardingsphere.proxy.backend.exception.BackendConnectionExcept
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import
org.apache.shardingsphere.proxy.frontend.command.executor.CommandExecutor;
import
org.apache.shardingsphere.proxy.frontend.command.executor.QueryCommandExecutor;
+import org.apache.shardingsphere.proxy.frontend.constant.MDCConstants;
import org.apache.shardingsphere.proxy.frontend.exception.ExpectedExceptions;
import
org.apache.shardingsphere.proxy.frontend.spi.DatabaseProtocolFrontendEngine;
+import org.slf4j.MDC;
import java.sql.SQLException;
import java.util.Collection;
@@ -65,6 +67,7 @@ public final class CommandExecutorTask implements Runnable {
public void run() {
boolean isNeedFlush = false;
try (PacketPayload payload =
databaseProtocolFrontendEngine.getCodecEngine().createPacketPayload((ByteBuf)
message, context.channel().attr(CommonConstants.CHARSET_ATTRIBUTE_KEY).get())) {
+ fillMDC();
connectionSession.getBackendConnection().prepareForTaskExecution();
isNeedFlush = executeCommand(context, payload);
// CHECKSTYLE:OFF
@@ -84,6 +87,7 @@ public final class CommandExecutorTask implements Runnable {
context.flush();
}
processClosedExceptions(exceptions);
+ clearMDC();
}
}
@@ -130,4 +134,13 @@ public final class CommandExecutorTask implements Runnable
{
}
processException(ex);
}
+
+ private void fillMDC() {
+ MDC.put(MDCConstants.SCHEMA_KEY, connectionSession.getSchemaName());
+ MDC.put(MDCConstants.USER_KEY,
connectionSession.getGrantee().toString());
+ }
+
+ private void clearMDC() {
+ MDC.clear();
+ }
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/constant/MDCConstants.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/constant/MDCConstants.java
new file mode 100644
index 0000000..7229428
--- /dev/null
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/constant/MDCConstants.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.proxy.frontend.constant;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+/**
+ * MDC constants.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class MDCConstants {
+
+ public static final String SCHEMA_KEY = "schema";
+
+ public static final String USER_KEY = "user";
+}