Skip to content

Commit

Permalink
Merge pull request MyCATApache#2222 from codelaw1/1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
junwen12221 authored Jun 13, 2019
2 parents 46b6018 + e11d296 commit 0ed942f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/main/java/io/mycat/memory/unsafe/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package io.mycat.memory.unsafe;

import io.mycat.MycatServer;
import io.mycat.memory.unsafe.utils.BytesTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -61,6 +62,7 @@ public final class Platform {
public static final boolean littleEndian = ByteOrder.nativeOrder()
.equals(ByteOrder.LITTLE_ENDIAN);

public static final long sqlTimeout = MycatServer.getInstance().getConfig().getSystem().getSqlExecuteTimeout() * 1000L;
static {
boolean _unaligned;
// use reflection to access unaligned field
Expand Down Expand Up @@ -293,12 +295,19 @@ public static void copyMemory(
} else {
srcOffset += length;
dstOffset += length;
while (length > 0) {
while (length > 0) { // if backend db run time out ,this will be endless loop
long size = Math.min(length, UNSAFE_COPY_THRESHOLD);
long lbegin = System.currentTimeMillis();
srcOffset -= size;
dstOffset -= size;
_UNSAFE.copyMemory(src, srcOffset, dst, dstOffset, size);
length -= size;
long l = System.currentTimeMillis() - lbegin;
if(l > sqlTimeout) { // when sql run timeout,break the loop
logger.error("copyMemory timeout.loop(seconds):" + String.valueOf(l / 1000));

break;
}
}

}
Expand Down

0 comments on commit 0ed942f

Please sign in to comment.