changeset 1094:7026f72f9bfc

MySql - bugfixes
author Devel 2
date Mon, 11 May 2020 13:51:50 +0200
parents f48d0f6748e6
children d729a8ca2552
files stress-tester/src/main/java/com/passus/st/client/DbMetric.java stress-tester/src/main/java/com/passus/st/client/mysql/MySqlFlowHandler.java stress-tester/src/main/java/com/passus/st/client/mysql/MySqlFlowHandlerDataDecoder.java stress-tester/src/main/java/com/passus/st/client/mysql/MySqlFlowHandlerDataEncoder.java stress-tester/src/main/java/com/passus/st/client/mysql/filter/MySqlFilter.java stress-tester/src/main/java/com/passus/st/client/mysql/filter/MySqlLoginFilter.java
diffstat 6 files changed, 43 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/DbMetric.java	Mon May 11 12:28:21 2020 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/DbMetric.java	Mon May 11 13:51:50 2020 +0200
@@ -11,9 +11,12 @@
 
     private HashMap<String, MutableInt> queryTypeCount = new HashMap<>();
 
+    private int recordsNum = 0;
+
     public DbMetric(String name) {
         super(name);
         attrs.put("queryTypeCount", queryTypeCount);
+        attrs.put("recordsNum", recordsNum);
     }
 
     public abstract String extractStatementType(String query);
@@ -29,14 +32,20 @@
         }
     }
 
+    public void incRecordsNum() {
+        recordsNum++;
+    }
+
     @Override
     public void update(Metric metric) {
         DbMetric dbMetric = (DbMetric) metric;
         Metric.updateCountMap(queryTypeCount, dbMetric.queryTypeCount);
+        recordsNum += dbMetric.recordsNum;
     }
 
     @Override
     public void reset() {
         queryTypeCount.clear();
+        recordsNum = 0;
     }
 }
--- a/stress-tester/src/main/java/com/passus/st/client/mysql/MySqlFlowHandler.java	Mon May 11 12:28:21 2020 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/mysql/MySqlFlowHandler.java	Mon May 11 13:51:50 2020 +0200
@@ -11,6 +11,7 @@
 
 import java.util.List;
 
+import static com.passus.net.mysql.MySqlPacketTypes.ROW_RESPONSE;
 import static com.passus.st.Protocols.NETFLOW;
 
 public final class MySqlFlowHandler extends AbstractFlowHandler<MySqlMetric, MySqlPacket, List<MySqlPacket>> implements TimeAware {
@@ -99,6 +100,16 @@
                     disconnectAndBlock(flowContext);
                 }
             }
+        } else {
+            for (MySqlPacket resp : resps) {
+                if (resp.getPacketType() == ROW_RESPONSE) {
+                    if (collectMetrics) {
+                        synchronized (metric) {
+                            metric.incRecordsNum();
+                        }
+                    }
+                }
+            }
         }
     }
 
--- a/stress-tester/src/main/java/com/passus/st/client/mysql/MySqlFlowHandlerDataDecoder.java	Mon May 11 12:28:21 2020 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/mysql/MySqlFlowHandlerDataDecoder.java	Mon May 11 13:51:50 2020 +0200
@@ -40,6 +40,11 @@
     }
 
     @Override
+    public void clear(FlowContext flowContext) {
+        decoder.clear();
+    }
+
+    @Override
     public int decode(ByteBuff buffer, FlowContext flowContext) {
         int res = decoder.decode(buffer);
         if (decoder.state() == DataDecoder.STATE_FINISHED) {
--- a/stress-tester/src/main/java/com/passus/st/client/mysql/MySqlFlowHandlerDataEncoder.java	Mon May 11 12:28:21 2020 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/mysql/MySqlFlowHandlerDataEncoder.java	Mon May 11 13:51:50 2020 +0200
@@ -33,6 +33,7 @@
                 break;
             case MySqlPacketTypes.SHOW_FIELDS_COMMAND:
                 context.stage(STAGE_RESPONSE_SHOW_FIELDS);
+                break;
             default:
                 context.stage(STAGE_REQUEST);
         }
--- a/stress-tester/src/main/java/com/passus/st/client/mysql/filter/MySqlFilter.java	Mon May 11 12:28:21 2020 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/mysql/filter/MySqlFilter.java	Mon May 11 13:51:50 2020 +0200
@@ -4,29 +4,31 @@
 import com.passus.st.client.FlowContext;
 import com.passus.st.filter.FlowFilter;
 
+import java.util.List;
+
 public abstract class MySqlFilter implements FlowFilter {
 
     @Override
     public int filterInbound(Object req, Object resp, FlowContext context) {
-        if (req instanceof MySqlPacket || resp instanceof MySqlPacket) {
-            return filterInbound((MySqlPacket) req, (MySqlPacket) resp, context);
+        if (req instanceof MySqlPacket || resp instanceof List) {
+            return filterInbound((MySqlPacket) req, (List<MySqlPacket>) resp, context);
         }
         return DUNNO;
     }
 
-    public int filterInbound(MySqlPacket req, MySqlPacket resp, FlowContext context) {
+    public int filterInbound(MySqlPacket req, List<MySqlPacket> resp, FlowContext context) {
         return DUNNO;
     }
 
     @Override
     public int filterOutbound(Object req, Object resp, FlowContext context) {
-        if (req instanceof MySqlPacket || resp instanceof MySqlPacket) {
-            return filterOutbound((MySqlPacket) req, (MySqlPacket) resp, context);
+        if (req instanceof MySqlPacket || resp instanceof List) {
+            return filterOutbound((MySqlPacket) req, (List<MySqlPacket>) resp, context);
         }
         return DUNNO;
     }
 
-    public int filterOutbound(MySqlPacket req, MySqlPacket resp, FlowContext context) {
+    public int filterOutbound(MySqlPacket req, List<MySqlPacket> resp, FlowContext context) {
         return DUNNO;
     }
 
--- a/stress-tester/src/main/java/com/passus/st/client/mysql/filter/MySqlLoginFilter.java	Mon May 11 12:28:21 2020 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/mysql/filter/MySqlLoginFilter.java	Mon May 11 13:51:50 2020 +0200
@@ -17,6 +17,8 @@
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
+import java.util.List;
+
 import static com.passus.config.schema.ConfigurationSchemaBuilder.*;
 import static com.passus.net.mysql.MySqlUtils.passScramble411;
 import static com.passus.st.filter.CredentialsProviderNodeDefinition.providersNodeDef;
@@ -50,9 +52,12 @@
     }
 
     @Override
-    public int filterInbound(MySqlPacket req, MySqlPacket resp, FlowContext context) {
-        if (resp.getPacketType() == MySqlPacketTypes.GREETINGS) {
-            context.setParam("mysql.greeting", resp);
+    public int filterInbound(MySqlPacket req, List<MySqlPacket> resps, FlowContext context) {
+        if (resps.size() == 1) {
+            MySqlPacket resp = resps.get(0);
+            if (resp.getPacketType() == MySqlPacketTypes.GREETINGS) {
+                context.setParam("mysql.greeting", resp);
+            }
         }
 
         return DUNNO;
@@ -82,16 +87,13 @@
                     return;
             }
 
-/*            loginReq.setClientCapabilities(0x0000a207);
-            loginReq.setExtendedClientCapabilities(0x0000013e);*/
             loginReq.setUsername(credentials.getUser());
             loginReq.setAuthPlugin(authPlugin);
-            //loginReq.setAttributes(null);
         }
     }
 
     @Override
-    public int filterOutbound(MySqlPacket req, MySqlPacket resp, FlowContext context) {
+    public int filterOutbound(MySqlPacket req, List<MySqlPacket> resp, FlowContext context) {
         if (req.getPacketType() == MySqlPacketTypes.LOGIN_REQUEST) {
             MySqlServerGreetingResponse greeting = context.getParamValue("mysql.greeting");
             if (greeting != null) {