Problems caused by a database active-active
Which module is your feature request related to? ASMClass.java/addField(String fieldName)
Is your feature request related to a problem? java.lang.IllegalArgumentException: repeated interface: com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor
Describe the solution you'd like A clear and concise description of what you want to happen. modify ASMClass.java/addField method. eg: @Override public void addField(final String accessorTypeName) throws InstrumentException { try { String fieldName = FIELD_PREFIX + JavaAssistUtils.javaClassNameToVariableName(accessorTypeName); if(this.hasField(fieldName)){ logger.info("{} is already added."); return; }
final Class<?> accessorType = this.pluginContext.injectClass(this.classLoader, accessorTypeName);
final AccessorAnalyzer accessorAnalyzer = new AccessorAnalyzer();
final AccessorAnalyzer.AccessorDetails accessorDetails = accessorAnalyzer.analyze(accessorType);
final ASMFieldNodeAdapter fieldNode = this.classNode.addField(fieldName, accessorDetails.getFieldType());
this.classNode.addInterface(accessorTypeName);
this.classNode.addGetterMethod(accessorDetails.getGetter().getName(), fieldNode);
this.classNode.addSetterMethod(accessorDetails.getSetter().getName(), fieldNode);
setModified(true);
} catch (Exception e) {
throw new InstrumentException("Failed to add field with accessor [" + accessorTypeName + "]. Cause:" + e.getMessage(), e);
}
}
Describe alternatives you've considered Prevent repeated loading
Additional context Add any other context or screenshots about the feature request here.
when A extend B implement C ,and B implement C,jdkproxy use A interface and superclass interface,will cause error “java.lang.IllegalArgumentException: repeated interface: C”. eg mysql-jdbc-driver class LoadBalancingConnectionProxy.java 761. I revise AsmClass addField method,when A superclass is arleady implement C,not enhance A。But I don’t know what effect this will have,can you help me。
Phenomenon: When a Java application with the Pinpoint agent installed operates on a database using an older version of mysql-connector-java (≤ 5.1.37) and the connection string contains "loadbalance", intermittent errors occur: Caused by: java.lang.IllegalArgumentException: repeated interface: com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor, affecting database operations. (Adjusting the prepared.statement.cache.size parameter affects the frequency of these errors.)
Cause: The Pinpoint agent's mysql-jdbc plugin modifies PreparedStatement and its parent class StatementImpl via bytecode enhancement. Consequently, the enhanced classes implement interfaces from the mysql-jdbc plugin, including the shared DatabaseInfoAccessor interface. The LoadBalancingConnectionProxy class in mysql-connector-java collects all interfaces implemented by PreparedStatement and its parent classes, then generates a proxy object using Proxy.newProxyInstance. In older versions of mysql-connector-java, the collected interfaces are stored in a class array without deduplication and are directly passed as parameters to Proxy.newProxyInstance. This results in duplicate DatabaseInfoAccessor interfaces (one from PreparedStatement and one from StatementImpl), triggering the error. In contrast, newer versions of mysql-connector-java store the collected interfaces in a LinkedHashSet, which automatically removes duplicates before calling Proxy.newProxyInstance to create the proxy object.
Recommendation: Upgrade mysql-connector-java to version 5.1.38 or higher.
when A extend B implement C ,and B implement C,jdkproxy use A interface and superclass interface,will cause error “java.lang.IllegalArgumentException: repeated interface: C”. eg mysql-jdbc-driver class LoadBalancingConnectionProxy.java 761. I revise AsmClass addField method,when A superclass is arleady implement C,not enhance A。But I don’t know what effect this will have,can you help me。
you are right, A is PreparedStatement, B is StatementImpl, and C is DatabaseInfoAccessor.