Skip to content

Commit

Permalink
[CONJ-771] manage possible concurrent modification exception on conne…
Browse files Browse the repository at this point in the history
…ction force kill without needing synchronisation
  • Loading branch information
rusher committed Mar 18, 2020
1 parent 0aa3191 commit 3e6d64c
Showing 1 changed file with 32 additions and 29 deletions.
61 changes: 32 additions & 29 deletions src/main/java/org/mariadb/jdbc/internal/io/LruTraceCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.util.Collection;
import java.util.ConcurrentModificationException;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
Expand Down Expand Up @@ -90,40 +91,42 @@ protected boolean removeEldestEntry(Map.Entry<String, TraceObject> eldest) {
*
* @return trace cache value
*/
public synchronized String printStack() {
public String printStack() {
StringBuilder sb = new StringBuilder();
Map.Entry<String, TraceObject>[] arr = entrySet().toArray(new Map.Entry[0]);
for (Map.Entry<String, TraceObject> entry : arr) {
TraceObject traceObj = entry.getValue();
String key = entry.getKey();
String indicator = "";
boolean finished = false;
while (!finished) {
try {
Map.Entry<String, TraceObject>[] arr = entrySet().toArray(new Map.Entry[0]);
for (Map.Entry<String, TraceObject> entry : arr) {
TraceObject traceObj = entry.getValue();
String key = entry.getKey();
String indicator = "";

switch (traceObj.getIndicatorFlag()) {
case TraceObject.NOT_COMPRESSED:
break;
switch (traceObj.getIndicatorFlag()) {
case TraceObject.COMPRESSED_PROTOCOL_NOT_COMPRESSED_PACKET:
indicator = " (compressed protocol - packet not compressed)";
break;
case TraceObject.COMPRESSED_PROTOCOL_COMPRESSED_PACKET:
indicator = " (compressed protocol - packet compressed)";
break;
default:
break;
}
sb.append("\nthread:").append(traceObj.getThreadId());
if (traceObj.isSend()) {
sb.append(" send at -exchange:");
} else {
sb.append(" read at -exchange:");
}

case TraceObject.COMPRESSED_PROTOCOL_NOT_COMPRESSED_PACKET:
indicator = " (compressed protocol - packet not compressed)";
break;

case TraceObject.COMPRESSED_PROTOCOL_COMPRESSED_PACKET:
indicator = " (compressed protocol - packet compressed)";
break;

default:
break;
}
sb.append("\nthread:").append(traceObj.getThreadId());
if (traceObj.isSend()) {
sb.append(" send at -exchange:");
} else {
sb.append(" read at -exchange:");
sb.append(key).append(indicator).append(Utils.hexdump(traceObj.getBuf()));
}
finished = true;
} catch (ConcurrentModificationException cc) {
// eat
}

sb.append(key).append(indicator).append(Utils.hexdump(traceObj.getBuf()));

traceObj.remove();
}

this.clear();
return sb.toString();
}
Expand Down

0 comments on commit 3e6d64c

Please sign in to comment.