diff --git a/client/src/main/java/com/alibaba/otter/canal/client/CanalConnectors.java b/client/src/main/java/com/alibaba/otter/canal/client/CanalConnectors.java
index d64bd491..391b21dc 100644
--- a/client/src/main/java/com/alibaba/otter/canal/client/CanalConnectors.java
+++ b/client/src/main/java/com/alibaba/otter/canal/client/CanalConnectors.java
@@ -44,8 +44,10 @@ public class CanalConnectors {
*/
public static CanalConnector newClusterConnector(List extends SocketAddress> addresses, String destination,
String username, String password) {
- ClusterCanalConnector canalConnector = new ClusterCanalConnector(username, password, destination,
- new SimpleNodeAccessStrategy(addresses));
+ ClusterCanalConnector canalConnector = new ClusterCanalConnector(username,
+ password,
+ destination,
+ new SimpleNodeAccessStrategy(addresses));
canalConnector.setSoTimeout(30 * 1000);
return canalConnector;
}
@@ -61,13 +63,10 @@ public class CanalConnectors {
*/
public static CanalConnector newClusterConnector(String zkServers, String destination, String username,
String password) {
- ClusterCanalConnector canalConnector = new ClusterCanalConnector(
- username,
- password,
- destination,
- new ClusterNodeAccessStrategy(
- destination,
- ZkClientx.getZkClient(zkServers)));
+ ClusterCanalConnector canalConnector = new ClusterCanalConnector(username,
+ password,
+ destination,
+ new ClusterNodeAccessStrategy(destination, ZkClientx.getZkClient(zkServers)));
canalConnector.setSoTimeout(30 * 1000);
return canalConnector;
}
diff --git a/client/src/main/java/com/alibaba/otter/canal/client/impl/SimpleCanalConnector.java b/client/src/main/java/com/alibaba/otter/canal/client/impl/SimpleCanalConnector.java
index 7993669d..a432e668 100644
--- a/client/src/main/java/com/alibaba/otter/canal/client/impl/SimpleCanalConnector.java
+++ b/client/src/main/java/com/alibaba/otter/canal/client/impl/SimpleCanalConnector.java
@@ -102,7 +102,7 @@ public class SimpleCanalConnector implements CanalConnector {
rollback();
}
}
-
+
connected = true;
}
@@ -411,7 +411,6 @@ public class SimpleCanalConnector implements CanalConnector {
}
}
-
private void waitClientRunning() {
try {
if (zkClientx != null) {
diff --git a/codeformat.xml b/codeformat.xml
new file mode 100644
index 00000000..01b28b5b
--- /dev/null
+++ b/codeformat.xml
@@ -0,0 +1,291 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/codetemplates.xml b/codetemplates.xml
new file mode 100644
index 00000000..20ee0fc1
--- /dev/null
+++ b/codetemplates.xml
@@ -0,0 +1,27 @@
+${filecomment}
+${package_declaration}
+${typecomment}
+${type_declaration}
+
+
+
+// ${todo} Auto-generated catch block
+${exception_var}.printStackTrace();// ${todo} Auto-generated method stub
+${body_statement}${body_statement}
+// ${todo} Auto-generated constructor stubreturn ${field};${field} = ${param};
diff --git a/common/src/main/java/com/alibaba/otter/canal/common/utils/AddressUtils.java b/common/src/main/java/com/alibaba/otter/canal/common/utils/AddressUtils.java
index d3ee1137..14d1831a 100644
--- a/common/src/main/java/com/alibaba/otter/canal/common/utils/AddressUtils.java
+++ b/common/src/main/java/com/alibaba/otter/canal/common/utils/AddressUtils.java
@@ -38,7 +38,8 @@ public class AddressUtils {
private static boolean isValidHostAddress(InetAddress address) {
if (address == null || address.isLoopbackAddress()) return false;
String name = address.getHostAddress();
- return (name != null && !EMPTY_IP.equals(name) && !LOCALHOST_IP.equals(name) && IP_PATTERN.matcher(name).matches());
+ return (name != null && !EMPTY_IP.equals(name) && !LOCALHOST_IP.equals(name) && IP_PATTERN.matcher(name)
+ .matches());
}
public static String getHostIp() {
diff --git a/common/src/main/java/com/alibaba/otter/canal/common/zookeeper/ZkClientx.java b/common/src/main/java/com/alibaba/otter/canal/common/zookeeper/ZkClientx.java
index 74bde300..76255bd1 100644
--- a/common/src/main/java/com/alibaba/otter/canal/common/zookeeper/ZkClientx.java
+++ b/common/src/main/java/com/alibaba/otter/canal/common/zookeeper/ZkClientx.java
@@ -1,6 +1,5 @@
package com.alibaba.otter.canal.common.zookeeper;
-import com.google.common.collect.MigrateMap;
import java.util.Map;
import org.I0Itec.zkclient.IZkConnection;
@@ -13,7 +12,7 @@ import org.I0Itec.zkclient.serialize.ZkSerializer;
import org.apache.zookeeper.CreateMode;
import com.google.common.base.Function;
-import com.google.common.collect.MapMaker;
+import com.google.common.collect.MigrateMap;
/**
* 使用自定义的ZooKeeperx for zk connection
@@ -24,14 +23,12 @@ import com.google.common.collect.MapMaker;
public class ZkClientx extends ZkClient {
// 对于zkclient进行一次缓存,避免一个jvm内部使用多个zk connection
- private static Map clients = MigrateMap.makeComputingMap(new Function()
- {
+ private static Map clients = MigrateMap.makeComputingMap(new Function() {
- public ZkClientx apply(String servers)
- {
- return new ZkClientx(servers);
- }
- });
+ public ZkClientx apply(String servers) {
+ return new ZkClientx(servers);
+ }
+ });
public static ZkClientx getZkClient(String servers) {
return clients.get(servers);
@@ -65,10 +62,12 @@ public class ZkClientx extends ZkClient {
* Create a persistent Sequential node.
*
* @param path
- * @param createParents if true all parent dirs are created as well and no {@link ZkNodeExistsException} is thrown
- * in case the path already exists
- * @throws ZkInterruptedException if operation was interrupted, or a required reconnection got interrupted
- * @throws IllegalArgumentException if called from anything except the ZooKeeper event thread
+ * @param createParents if true all parent dirs are created as well and no
+ * {@link ZkNodeExistsException} is thrown in case the path already exists
+ * @throws ZkInterruptedException if operation was interrupted, or a
+ * required reconnection got interrupted
+ * @throws IllegalArgumentException if called from anything except the
+ * ZooKeeper event thread
* @throws ZkException if any ZooKeeper exception occurred
* @throws RuntimeException if any other exception occurs
*/
@@ -92,10 +91,12 @@ public class ZkClientx extends ZkClient {
*
* @param path
* @param data
- * @param createParents if true all parent dirs are created as well and no {@link ZkNodeExistsException} is thrown
- * in case the path already exists
- * @throws ZkInterruptedException if operation was interrupted, or a required reconnection got interrupted
- * @throws IllegalArgumentException if called from anything except the ZooKeeper event thread
+ * @param createParents if true all parent dirs are created as well and no
+ * {@link ZkNodeExistsException} is thrown in case the path already exists
+ * @throws ZkInterruptedException if operation was interrupted, or a
+ * required reconnection got interrupted
+ * @throws IllegalArgumentException if called from anything except the
+ * ZooKeeper event thread
* @throws ZkException if any ZooKeeper exception occurred
* @throws RuntimeException if any other exception occurs
*/
@@ -121,10 +122,12 @@ public class ZkClientx extends ZkClient {
*
* @param path
* @param data
- * @param createParents if true all parent dirs are created as well and no {@link ZkNodeExistsException} is thrown
- * in case the path already exists
- * @throws ZkInterruptedException if operation was interrupted, or a required reconnection got interrupted
- * @throws IllegalArgumentException if called from anything except the ZooKeeper event thread
+ * @param createParents if true all parent dirs are created as well and no
+ * {@link ZkNodeExistsException} is thrown in case the path already exists
+ * @throws ZkInterruptedException if operation was interrupted, or a
+ * required reconnection got interrupted
+ * @throws IllegalArgumentException if called from anything except the
+ * ZooKeeper event thread
* @throws ZkException if any ZooKeeper exception occurred
* @throws RuntimeException if any other exception occurs
*/
diff --git a/common/src/main/java/com/alibaba/otter/canal/common/zookeeper/ZooKeeperx.java b/common/src/main/java/com/alibaba/otter/canal/common/zookeeper/ZooKeeperx.java
index 7eec37b3..a3b68dae 100644
--- a/common/src/main/java/com/alibaba/otter/canal/common/zookeeper/ZooKeeperx.java
+++ b/common/src/main/java/com/alibaba/otter/canal/common/zookeeper/ZooKeeperx.java
@@ -15,8 +15,8 @@ import org.apache.zookeeper.ClientCnxn;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.Watcher;
-import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.ZooDefs.Ids;
+import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.ZooKeeper.States;
import org.apache.zookeeper.client.ConnectStringParser;
import org.apache.zookeeper.client.HostProvider;
@@ -39,7 +39,7 @@ public class ZooKeeperx implements IZkConnection {
private static final Field clientCnxnField = ReflectionUtils.findField(ZooKeeper.class, "cnxn");
private static final Field hostProviderField = ReflectionUtils.findField(ClientCnxn.class, "hostProvider");
private static final Field serverAddressesField = ReflectionUtils.findField(StaticHostProvider.class,
- "serverAddresses");
+ "serverAddresses");
private static final int DEFAULT_SESSION_TIMEOUT = 90000;
private ZooKeeper _zk = null;
@@ -159,9 +159,8 @@ public class ZooKeeperx implements IZkConnection {
// 强制获取zk中的地址信息
ClientCnxn cnxn = (ClientCnxn) ReflectionUtils.getField(clientCnxnField, zk);
HostProvider hostProvider = (HostProvider) ReflectionUtils.getField(hostProviderField, cnxn);
- List serverAddrs = (List) ReflectionUtils.getField(
- serverAddressesField,
- hostProvider);
+ List serverAddrs = (List) ReflectionUtils.getField(serverAddressesField,
+ hostProvider);
// 添加第二组集群列表
serverAddrs.addAll(new ConnectStringParser(cluster).getServerAddresses());
}
diff --git a/common/src/main/java/com/alibaba/otter/canal/common/zookeeper/ZookeeperPathUtils.java b/common/src/main/java/com/alibaba/otter/canal/common/zookeeper/ZookeeperPathUtils.java
index 967e0f29..578e2951 100644
--- a/common/src/main/java/com/alibaba/otter/canal/common/zookeeper/ZookeeperPathUtils.java
+++ b/common/src/main/java/com/alibaba/otter/canal/common/zookeeper/ZookeeperPathUtils.java
@@ -120,8 +120,10 @@ public class ZookeeperPathUtils {
}
public static String getBatchMarkWithIdPath(String destinationName, short clientId, Long batchId) {
- return MessageFormat.format(DESTINATION_CLIENTID_BATCH_MARK_WITH_ID_PATH, destinationName,
- String.valueOf(clientId), getBatchMarkNode(batchId));
+ return MessageFormat.format(DESTINATION_CLIENTID_BATCH_MARK_WITH_ID_PATH,
+ destinationName,
+ String.valueOf(clientId),
+ getBatchMarkNode(batchId));
}
public static String getCursorPath(String destination, short clientId) {
diff --git a/common/src/main/java/com/alibaba/otter/canal/common/zookeeper/running/ServerRunningMonitors.java b/common/src/main/java/com/alibaba/otter/canal/common/zookeeper/running/ServerRunningMonitors.java
index 30569ebb..3df588e9 100644
--- a/common/src/main/java/com/alibaba/otter/canal/common/zookeeper/running/ServerRunningMonitors.java
+++ b/common/src/main/java/com/alibaba/otter/canal/common/zookeeper/running/ServerRunningMonitors.java
@@ -11,7 +11,8 @@ import java.util.Map;
public class ServerRunningMonitors {
private static ServerRunningData serverData;
- private static Map runningMonitors; //
+ private static Map runningMonitors; //
public static ServerRunningData getServerData() {
return serverData;
diff --git a/common/src/main/java/com/google/common/collect/MigrateMap.java b/common/src/main/java/com/google/common/collect/MigrateMap.java
index 0f22901b..ab5bedb3 100644
--- a/common/src/main/java/com/google/common/collect/MigrateMap.java
+++ b/common/src/main/java/com/google/common/collect/MigrateMap.java
@@ -1,17 +1,17 @@
package com.google.common.collect;
-import com.google.common.base.Function;
import java.util.concurrent.ConcurrentMap;
-public class MigrateMap
-{
- public static ConcurrentMap makeComputingMap(MapMaker maker, Function super K, ? extends V> computingFunction)
- {
+import com.google.common.base.Function;
+
+public class MigrateMap {
+
+ public static ConcurrentMap makeComputingMap(MapMaker maker,
+ Function super K, ? extends V> computingFunction) {
return maker.makeComputingMap(computingFunction);
}
- public static ConcurrentMap makeComputingMap(Function super K, ? extends V> computingFunction)
- {
+ public static ConcurrentMap makeComputingMap(Function super K, ? extends V> computingFunction) {
return new MapMaker().makeComputingMap(computingFunction);
}
}
diff --git a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/CharsetConversion.java b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/CharsetConversion.java
index b9f3dade..a4f07ac6 100644
--- a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/CharsetConversion.java
+++ b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/CharsetConversion.java
@@ -6,24 +6,24 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
- * An utility class implements MySQL/Java charsets conversion. you can see com.mysql.jdbc.CharsetMapping.
+ * An utility class implements MySQL/Java charsets conversion. you can see
+ * com.mysql.jdbc.CharsetMapping.
*
* @author Changyuan.lh
*/
-public final class CharsetConversion
-{
+public final class CharsetConversion {
+
static final Log logger = LogFactory.getLog(CharsetConversion.class);
- static final class Entry
- {
+ static final class Entry {
+
protected final int charsetId;
protected final String mysqlCharset;
protected final String mysqlCollation;
protected final String javaCharset;
Entry(final int id, String mysqlCharset, // NL
- String mysqlCollation, String javaCharset)
- {
+ String mysqlCollation, String javaCharset){
this.charsetId = id;
this.mysqlCharset = mysqlCharset;
this.mysqlCollation = mysqlCollation;
@@ -34,38 +34,31 @@ public final class CharsetConversion
// Character set data used in lookups. The array will be sparse.
static final Entry[] entries = new Entry[0xff];
- static Entry getEntry(final int id)
- {
- if (id >= 0 && id < entries.length)
- {
+ static Entry getEntry(final int id) {
+ if (id >= 0 && id < entries.length) {
return entries[id];
- }
- else
- {
+ } else {
throw new IllegalArgumentException("Invalid charset id: " + id);
}
}
// Loads character set information.
- static void putEntry(final int charsetId, String mysqlCharset,
- String mysqlCollation, String javaCharset)
- {
+ static void putEntry(final int charsetId, String mysqlCharset, String mysqlCollation, String javaCharset) {
entries[charsetId] = new Entry(charsetId, mysqlCharset, // NL
- mysqlCollation, javaCharset);
+ mysqlCollation,
+ javaCharset);
}
// Loads character set information.
@Deprecated
- static void putEntry(final int charsetId, String mysqlCharset,
- String mysqlCollation)
- {
+ static void putEntry(final int charsetId, String mysqlCharset, String mysqlCollation) {
entries[charsetId] = new Entry(charsetId, mysqlCharset, // NL
- mysqlCollation, /* Unknown java charset */null);
+ mysqlCollation, /* Unknown java charset */
+ null);
}
// Load character set data statically.
- static
- {
+ static {
putEntry(1, "big5", "big5_chinese_ci", "Big5");
putEntry(2, "latin2", "latin2_czech_cs", "ISO8859_2");
putEntry(3, "dec8", "dec8_swedish_ci", "ISO8859_1");
@@ -135,7 +128,7 @@ public final class CharsetConversion
putEntry(69, "dec8", "dec8_bin", "US-ASCII");
putEntry(70, "greek", "greek_bin", "ISO8859_7");
putEntry(71, "hebrew", "hebrew_bin", "ISO8859_8");
- putEntry(72, "hp8", "hp8_bin" , "US-ASCII");
+ putEntry(72, "hp8", "hp8_bin", "US-ASCII");
putEntry(73, "keybcs2", "keybcs2_bin", "Cp895");
putEntry(74, "koi8r", "koi8r_bin", "KOI8_R");
putEntry(75, "koi8u", "koi8u_bin", "KOI8_U");
@@ -274,16 +267,12 @@ public final class CharsetConversion
/**
* Return defined charset name for mysql.
*/
- public static String getCharset(final int id)
- {
+ public static String getCharset(final int id) {
Entry entry = getEntry(id);
- if (entry != null)
- {
+ if (entry != null) {
return entry.mysqlCharset;
- }
- else
- {
+ } else {
logger.warn("Unexpect mysql charset: " + id);
return null;
}
@@ -292,16 +281,12 @@ public final class CharsetConversion
/**
* Return defined collaction name for mysql.
*/
- public static String getCollation(final int id)
- {
+ public static String getCollation(final int id) {
Entry entry = getEntry(id);
- if (entry != null)
- {
+ if (entry != null) {
return entry.mysqlCollation;
- }
- else
- {
+ } else {
logger.warn("Unexpect mysql charset: " + id);
return null;
}
@@ -310,55 +295,41 @@ public final class CharsetConversion
/**
* Return converted charset name for java.
*/
- public static String getJavaCharset(final int id)
- {
+ public static String getJavaCharset(final int id) {
Entry entry = getEntry(id);
- if (entry != null)
- {
- if (entry.javaCharset != null)
- {
+ if (entry != null) {
+ if (entry.javaCharset != null) {
return entry.javaCharset;
- }
- else
- {
- logger.warn("Unknown java charset for: id = " + id
- + ", name = " + entry.mysqlCharset + ", coll = "
- + entry.mysqlCollation);
+ } else {
+ logger.warn("Unknown java charset for: id = " + id + ", name = " + entry.mysqlCharset + ", coll = "
+ + entry.mysqlCollation);
return null;
}
- }
- else
- {
+ } else {
logger.warn("Unexpect mysql charset: " + id);
return null;
}
}
- public static void main(String[] args)
- {
- for (int i = 0; i < entries.length; i++)
- {
+ public static void main(String[] args) {
+ for (int i = 0; i < entries.length; i++) {
Entry entry = entries[i];
System.out.print(i);
System.out.print(',');
System.out.print(' ');
- if (entry != null)
- {
+ if (entry != null) {
System.out.print(entry.mysqlCharset);
System.out.print(',');
System.out.print(' ');
System.out.print(entry.javaCharset);
- if (entry.javaCharset != null)
- {
+ if (entry.javaCharset != null) {
System.out.print(',');
System.out.print(' ');
System.out.print(Charset.forName(entry.javaCharset).name());
}
- }
- else
- {
+ } else {
System.out.print("null");
}
System.out.println();
diff --git a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/DirectLogFetcher.java b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/DirectLogFetcher.java
index 70f763a8..caec32fa 100644
--- a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/DirectLogFetcher.java
+++ b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/DirectLogFetcher.java
@@ -21,16 +21,13 @@ import org.apache.commons.logging.LogFactory;
* DirectLogFetcher fetcher = new DirectLogFetcher();
* fetcher.open(conn, file, 0, 13);
*
- * while (fetcher.fetch())
- * {
+ * while (fetcher.fetch()) {
* LogEvent event;
- * do
- * {
+ * do {
* event = decoder.decode(fetcher, context);
*
* // process log event.
- * }
- * while (event != null);
+ * } while (event != null);
* }
* // connection closed.
*
@@ -38,97 +35,79 @@ import org.apache.commons.logging.LogFactory;
* @author Changyuan.lh
* @version 1.0
*/
-public final class DirectLogFetcher extends LogFetcher
-{
- protected static final Log logger = LogFactory.getLog(DirectLogFetcher.class);
+public final class DirectLogFetcher extends LogFetcher {
+
+ protected static final Log logger = LogFactory.getLog(DirectLogFetcher.class);
/** Command to dump binlog */
- public static final byte COM_BINLOG_DUMP = 18;
+ public static final byte COM_BINLOG_DUMP = 18;
/** Packet header sizes */
- public static final int NET_HEADER_SIZE = 4;
- public static final int SQLSTATE_LENGTH = 5;
+ public static final int NET_HEADER_SIZE = 4;
+ public static final int SQLSTATE_LENGTH = 5;
/** Packet offsets */
- public static final int PACKET_LEN_OFFSET = 0;
- public static final int PACKET_SEQ_OFFSET = 3;
+ public static final int PACKET_LEN_OFFSET = 0;
+ public static final int PACKET_SEQ_OFFSET = 3;
/** Maximum packet length */
- public static final int MAX_PACKET_LENGTH = (256 * 256 * 256 - 1);
+ public static final int MAX_PACKET_LENGTH = (256 * 256 * 256 - 1);
/** BINLOG_DUMP options */
- public static final int BINLOG_DUMP_NON_BLOCK = 1;
+ public static final int BINLOG_DUMP_NON_BLOCK = 1;
public static final int BINLOG_SEND_ANNOTATE_ROWS_EVENT = 2;
private Connection conn;
private OutputStream mysqlOutput;
private InputStream mysqlInput;
- public DirectLogFetcher()
- {
+ public DirectLogFetcher(){
super(DEFAULT_INITIAL_CAPACITY, DEFAULT_GROWTH_FACTOR);
}
- public DirectLogFetcher(final int initialCapacity)
- {
+ public DirectLogFetcher(final int initialCapacity){
super(initialCapacity, DEFAULT_GROWTH_FACTOR);
}
- public DirectLogFetcher(final int initialCapacity, final float growthFactor)
- {
+ public DirectLogFetcher(final int initialCapacity, final float growthFactor){
super(initialCapacity, growthFactor);
}
- private static final Object unwrapConnection(Object conn, Class> connClazz)
- throws IOException
- {
- while (!connClazz.isInstance(conn))
- {
- try
- {
+ private static final Object unwrapConnection(Object conn, Class> connClazz) throws IOException {
+ while (!connClazz.isInstance(conn)) {
+ try {
Class> connProxy = Class.forName("org.springframework.jdbc.datasource.ConnectionProxy");
- if (connProxy.isInstance(conn))
- {
+ if (connProxy.isInstance(conn)) {
conn = invokeMethod(conn, connProxy, "getTargetConnection");
continue;
}
- }
- catch (ClassNotFoundException e)
- {
- // org.springframework.jdbc.datasource.ConnectionProxy not found.
+ } catch (ClassNotFoundException e) {
+ // org.springframework.jdbc.datasource.ConnectionProxy not
+ // found.
}
- try
- {
+ try {
Class> connProxy = Class.forName("org.apache.commons.dbcp.DelegatingConnection");
- if (connProxy.isInstance(conn))
- {
+ if (connProxy.isInstance(conn)) {
conn = getDeclaredField(conn, connProxy, "_conn");
continue;
}
- }
- catch (ClassNotFoundException e)
- {
+ } catch (ClassNotFoundException e) {
// org.apache.commons.dbcp.DelegatingConnection not found.
}
- try
- {
- if (conn instanceof java.sql.Wrapper)
- {
+ try {
+ if (conn instanceof java.sql.Wrapper) {
Class> connIface = Class.forName("com.mysql.jdbc.Connection");
conn = ((java.sql.Wrapper) conn).unwrap(connIface);
continue;
}
- }
- catch (ClassNotFoundException e)
- {
+ } catch (ClassNotFoundException e) {
// com.mysql.jdbc.Connection not found.
- }
- catch (SQLException e)
- {
- logger.warn("Unwrap " + conn.getClass().getName() + " to "
- + connClazz.getName() + " failed: " + e.getMessage(), e);
+ } catch (SQLException e) {
+ logger.warn("Unwrap " + conn.getClass().getName() + " to " + connClazz.getName() + " failed: "
+ + e.getMessage(),
+ e);
}
return null;
@@ -136,127 +115,85 @@ public final class DirectLogFetcher extends LogFetcher
return conn;
}
- private static final Object invokeMethod(Object obj, Class> objClazz,
- String name)
- {
- try
- {
+ private static final Object invokeMethod(Object obj, Class> objClazz, String name) {
+ try {
Method method = objClazz.getMethod(name, (Class>[]) null);
return method.invoke(obj, (Object[]) null);
- }
- catch (NoSuchMethodException e)
- {
- throw new IllegalArgumentException("No such method: \'" + name
- + "\' @ " + objClazz.getName(), e);
- }
- catch (IllegalAccessException e)
- {
- throw new IllegalArgumentException("Cannot invoke method: \'"
- + name + "\' @ " + objClazz.getName(), e);
- }
- catch (InvocationTargetException e)
- {
- throw new IllegalArgumentException("Invoke method failed: \'"
- + name + "\' @ " + objClazz.getName(),
- e.getTargetException());
+ } catch (NoSuchMethodException e) {
+ throw new IllegalArgumentException("No such method: \'" + name + "\' @ " + objClazz.getName(), e);
+ } catch (IllegalAccessException e) {
+ throw new IllegalArgumentException("Cannot invoke method: \'" + name + "\' @ " + objClazz.getName(), e);
+ } catch (InvocationTargetException e) {
+ throw new IllegalArgumentException("Invoke method failed: \'" + name + "\' @ " + objClazz.getName(),
+ e.getTargetException());
}
}
- private static final Object getDeclaredField(Object obj, Class> objClazz,
- String name)
- {
- try
- {
+ private static final Object getDeclaredField(Object obj, Class> objClazz, String name) {
+ try {
Field field = objClazz.getDeclaredField(name);
field.setAccessible(true);
return field.get(obj);
- }
- catch (NoSuchFieldException e)
- {
- throw new IllegalArgumentException("No such field: \'" + name
- + "\' @ " + objClazz.getName(), e);
- }
- catch (IllegalAccessException e)
- {
- throw new IllegalArgumentException("Cannot get field: \'" + name
- + "\' @ " + objClazz.getName(), e);
+ } catch (NoSuchFieldException e) {
+ throw new IllegalArgumentException("No such field: \'" + name + "\' @ " + objClazz.getName(), e);
+ } catch (IllegalAccessException e) {
+ throw new IllegalArgumentException("Cannot get field: \'" + name + "\' @ " + objClazz.getName(), e);
}
}
/**
* Connect MySQL master to fetch binlog.
*/
- public void open(Connection conn, String fileName, final int serverId)
- throws IOException
- {
+ public void open(Connection conn, String fileName, final int serverId) throws IOException {
open(conn, fileName, BIN_LOG_HEADER_SIZE, serverId, false);
}
/**
* Connect MySQL master to fetch binlog.
*/
- public void open(Connection conn, String fileName, final int serverId,
- boolean nonBlocking) throws IOException
- {
+ public void open(Connection conn, String fileName, final int serverId, boolean nonBlocking) throws IOException {
open(conn, fileName, BIN_LOG_HEADER_SIZE, serverId, nonBlocking);
}
/**
* Connect MySQL master to fetch binlog.
*/
- public void open(Connection conn, String fileName, final long filePosition,
- final int serverId) throws IOException
- {
+ public void open(Connection conn, String fileName, final long filePosition, final int serverId) throws IOException {
open(conn, fileName, filePosition, serverId, false);
}
/**
* Connect MySQL master to fetch binlog.
*/
- public void open(Connection conn, String fileName, long filePosition,
- final int serverId, boolean nonBlocking) throws IOException
- {
- try
- {
+ public void open(Connection conn, String fileName, long filePosition, final int serverId, boolean nonBlocking)
+ throws IOException {
+ try {
this.conn = conn;
Class> connClazz = Class.forName("com.mysql.jdbc.ConnectionImpl");
Object unwrapConn = unwrapConnection(conn, connClazz);
- if (unwrapConn == null)
- {
- throw new IOException("Unable to unwrap "
- + conn.getClass().getName()
- + " to com.mysql.jdbc.ConnectionImpl");
+ if (unwrapConn == null) {
+ throw new IOException("Unable to unwrap " + conn.getClass().getName()
+ + " to com.mysql.jdbc.ConnectionImpl");
}
// Get underlying IO streams for network communications.
Object connIo = getDeclaredField(unwrapConn, connClazz, "io");
- if (connIo == null)
- {
- throw new IOException("Get null field:"
- + conn.getClass().getName() + "#io");
+ if (connIo == null) {
+ throw new IOException("Get null field:" + conn.getClass().getName() + "#io");
}
- mysqlOutput = (OutputStream) getDeclaredField(connIo,
- connIo.getClass(), "mysqlOutput");
- mysqlInput = (InputStream) getDeclaredField(connIo,
- connIo.getClass(), "mysqlInput");
+ mysqlOutput = (OutputStream) getDeclaredField(connIo, connIo.getClass(), "mysqlOutput");
+ mysqlInput = (InputStream) getDeclaredField(connIo, connIo.getClass(), "mysqlInput");
- if (filePosition == 0)
- filePosition = BIN_LOG_HEADER_SIZE;
+ if (filePosition == 0) filePosition = BIN_LOG_HEADER_SIZE;
sendBinlogDump(fileName, filePosition, serverId, nonBlocking);
position = 0;
- }
- catch (IOException e)
- {
+ } catch (IOException e) {
close(); /* Do cleanup */
- logger.error("Error on COM_BINLOG_DUMP: file = " + fileName
- + ", position = " + filePosition);
+ logger.error("Error on COM_BINLOG_DUMP: file = " + fileName + ", position = " + filePosition);
throw e;
- }
- catch (ClassNotFoundException e)
- {
+ } catch (ClassNotFoundException e) {
close(); /* Do cleanup */
- throw new IOException(
- "Unable to load com.mysql.jdbc.ConnectionImpl", e);
+ throw new IOException("Unable to load com.mysql.jdbc.ConnectionImpl", e);
}
}
@@ -265,8 +202,7 @@ public final class DirectLogFetcher extends LogFetcher
*
* @param b the byte to put in the buffer
*/
- protected final void putByte(byte b)
- {
+ protected final void putByte(byte b) {
ensureCapacity(position + 1);
buffer[position++] = b;
@@ -277,8 +213,7 @@ public final class DirectLogFetcher extends LogFetcher
*
* @param i16 the integer to put in the buffer
*/
- protected final void putInt16(int i16)
- {
+ protected final void putInt16(int i16) {
ensureCapacity(position + 2);
byte[] buf = buffer;
@@ -291,8 +226,7 @@ public final class DirectLogFetcher extends LogFetcher
*
* @param i32 the integer to put in the buffer
*/
- protected final void putInt32(long i32)
- {
+ protected final void putInt32(long i32) {
ensureCapacity(position + 4);
byte[] buf = buffer;
@@ -307,8 +241,7 @@ public final class DirectLogFetcher extends LogFetcher
*
* @param s the value to put in the buffer
*/
- protected final void putString(String s)
- {
+ protected final void putString(String s) {
ensureCapacity(position + (s.length() * 2) + 1);
System.arraycopy(s.getBytes(), 0, buffer, position, s.length());
@@ -316,10 +249,8 @@ public final class DirectLogFetcher extends LogFetcher
buffer[position++] = 0;
}
- protected final void sendBinlogDump(String fileName,
- final long filePosition, final int serverId, boolean nonBlocking)
- throws IOException
- {
+ protected final void sendBinlogDump(String fileName, final long filePosition, final int serverId,
+ boolean nonBlocking) throws IOException {
position = NET_HEADER_SIZE;
putByte(COM_BINLOG_DUMP);
@@ -327,7 +258,7 @@ public final class DirectLogFetcher extends LogFetcher
int binlog_flags = nonBlocking ? BINLOG_DUMP_NON_BLOCK : 0;
binlog_flags |= BINLOG_SEND_ANNOTATE_ROWS_EVENT;
putInt16(binlog_flags); // binlog_flags
- putInt32(serverId); // slave's server-id
+ putInt32(serverId); // slave's server-id
putString(fileName);
final byte[] buf = buffer;
@@ -345,13 +276,10 @@ public final class DirectLogFetcher extends LogFetcher
*
* @see com.taobao.tddl.dbsync.binlog.LogFetcher#fetch()
*/
- public boolean fetch() throws IOException
- {
- try
- {
+ public boolean fetch() throws IOException {
+ try {
// Fetching packet header from input.
- if (!fetch0(0, NET_HEADER_SIZE))
- {
+ if (!fetch0(0, NET_HEADER_SIZE)) {
logger.warn("Reached end of input stream while fetching header");
return false;
}
@@ -359,61 +287,48 @@ public final class DirectLogFetcher extends LogFetcher
// Fetching the first packet(may a multi-packet).
int netlen = getUint24(PACKET_LEN_OFFSET);
int netnum = getUint8(PACKET_SEQ_OFFSET);
- if (!fetch0(NET_HEADER_SIZE, netlen))
- {
- logger.warn("Reached end of input stream: packet #" + netnum
- + ", len = " + netlen);
+ if (!fetch0(NET_HEADER_SIZE, netlen)) {
+ logger.warn("Reached end of input stream: packet #" + netnum + ", len = " + netlen);
return false;
}
// Detecting error code.
final int mark = getUint8(NET_HEADER_SIZE);
- if (mark != 0)
- {
+ if (mark != 0) {
if (mark == 255) // error from master
{
- // Indicates an error, for example trying to fetch from wrong
+ // Indicates an error, for example trying to fetch from
+ // wrong
// binlog position.
position = NET_HEADER_SIZE + 1;
final int errno = getInt16();
String sqlstate = forward(1).getFixString(SQLSTATE_LENGTH);
String errmsg = getFixString(limit - position);
- throw new IOException("Received error packet:"
- + " errno = " + errno + ", sqlstate = " + sqlstate
- + " errmsg = " + errmsg);
- }
- else if (mark == 254)
- {
+ throw new IOException("Received error packet:" + " errno = " + errno + ", sqlstate = " + sqlstate
+ + " errmsg = " + errmsg);
+ } else if (mark == 254) {
// Indicates end of stream. It's not clear when this would
// be sent.
- logger.warn("Received EOF packet from server, apparent"
- + " master disconnected.");
+ logger.warn("Received EOF packet from server, apparent" + " master disconnected.");
return false;
- }
- else
- {
+ } else {
// Should not happen.
- throw new IOException("Unexpected response " + mark
- + " while fetching binlog: packet #" + netnum
- + ", len = " + netlen);
+ throw new IOException("Unexpected response " + mark + " while fetching binlog: packet #" + netnum
+ + ", len = " + netlen);
}
}
// The first packet is a multi-packet, concatenate the packets.
- while (netlen == MAX_PACKET_LENGTH)
- {
- if (!fetch0(0, NET_HEADER_SIZE))
- {
+ while (netlen == MAX_PACKET_LENGTH) {
+ if (!fetch0(0, NET_HEADER_SIZE)) {
logger.warn("Reached end of input stream while fetching header");
return false;
}
netlen = getUint24(PACKET_LEN_OFFSET);
netnum = getUint8(PACKET_SEQ_OFFSET);
- if (!fetch0(limit, netlen))
- {
- logger.warn("Reached end of input stream: packet #"
- + netnum + ", len = " + netlen);
+ if (!fetch0(limit, netlen)) {
+ logger.warn("Reached end of input stream: packet #" + netnum + ", len = " + netlen);
return false;
}
}
@@ -423,43 +338,32 @@ public final class DirectLogFetcher extends LogFetcher
position = origin;
limit -= origin;
return true;
- }
- catch (SocketTimeoutException e)
- {
+ } catch (SocketTimeoutException e) {
close(); /* Do cleanup */
logger.error("Socket timeout expired, closing connection", e);
throw e;
- }
- catch (InterruptedIOException e)
- {
+ } catch (InterruptedIOException e) {
close(); /* Do cleanup */
logger.warn("I/O interrupted while reading from client socket", e);
throw e;
- }
- catch (IOException e)
- {
+ } catch (IOException e) {
close(); /* Do cleanup */
logger.error("I/O error while reading from client socket", e);
throw e;
}
}
- private final boolean fetch0(final int off, final int len)
- throws IOException
- {
+ private final boolean fetch0(final int off, final int len) throws IOException {
ensureCapacity(off + len);
- for (int count, n = 0; n < len; n += count)
- {
- if (0 > (count = mysqlInput.read(buffer, off + n, len - n)))
- {
+ for (int count, n = 0; n < len; n += count) {
+ if (0 > (count = mysqlInput.read(buffer, off + n, len - n))) {
// Reached end of input stream
return false;
}
}
- if (limit < off + len)
- limit = off + len;
+ if (limit < off + len) limit = off + len;
return true;
}
@@ -468,19 +372,14 @@ public final class DirectLogFetcher extends LogFetcher
*
* @see com.taobao.tddl.dbsync.binlog.LogFetcher#close()
*/
- public void close() throws IOException
- {
- try
- {
- if (conn != null)
- conn.close();
+ public void close() throws IOException {
+ try {
+ if (conn != null) conn.close();
conn = null;
mysqlInput = null;
mysqlOutput = null;
- }
- catch (SQLException e)
- {
+ } catch (SQLException e) {
logger.warn("Unable to close connection", e);
}
}
diff --git a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/LogBuffer.java b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/LogBuffer.java
index d975777f..6bae7d1a 100644
--- a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/LogBuffer.java
+++ b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/LogBuffer.java
@@ -14,22 +14,18 @@ import java.util.BitSet;
* @author Changyuan.lh
* @version 1.0
*/
-public class LogBuffer
-{
+public class LogBuffer {
+
protected byte[] buffer;
protected int origin, limit;
protected int position;
- protected LogBuffer()
- {
+ protected LogBuffer(){
}
- public LogBuffer(byte[] buffer, final int origin, final int limit)
- {
- if (origin + limit > buffer.length)
- throw new IllegalArgumentException("capacity excceed: "
- + (origin + limit));
+ public LogBuffer(byte[] buffer, final int origin, final int limit){
+ if (origin + limit > buffer.length) throw new IllegalArgumentException("capacity excceed: " + (origin + limit));
this.buffer = buffer;
this.origin = origin;
@@ -40,10 +36,8 @@ public class LogBuffer
/**
* Return n bytes in this buffer.
*/
- public final LogBuffer duplicate(final int pos, final int len)
- {
- if (pos + len > limit)
- throw new IllegalArgumentException("limit excceed: " + (pos + len));
+ public final LogBuffer duplicate(final int pos, final int len) {
+ if (pos + len > limit) throw new IllegalArgumentException("limit excceed: " + (pos + len));
// XXX: Do momery copy avoid buffer modified.
final int off = origin + pos;
@@ -54,11 +48,9 @@ public class LogBuffer
/**
* Return next n bytes in this buffer.
*/
- public final LogBuffer duplicate(final int len)
- {
- if (position + len > origin + limit)
- throw new IllegalArgumentException("limit excceed: "
- + (position + len - origin));
+ public final LogBuffer duplicate(final int len) {
+ if (position + len > origin + limit) throw new IllegalArgumentException("limit excceed: "
+ + (position + len - origin));
// XXX: Do momery copy avoid buffer modified.
final int end = position + len;
@@ -71,8 +63,7 @@ public class LogBuffer
/**
* Return next n bytes in this buffer.
*/
- public final LogBuffer duplicate()
- {
+ public final LogBuffer duplicate() {
// XXX: Do momery copy avoid buffer modified.
byte[] buf = Arrays.copyOfRange(buffer, origin, origin + limit);
return new LogBuffer(buf, 0, limit);
@@ -83,8 +74,7 @@ public class LogBuffer
*
* @return The capacity of this buffer
*/
- public final int capacity()
- {
+ public final int capacity() {
return buffer.length;
}
@@ -93,8 +83,7 @@ public class LogBuffer
*
* @return The position of this buffer
*/
- public final int position()
- {
+ public final int position() {
return position - origin;
}
@@ -103,17 +92,13 @@ public class LogBuffer
* new position then it is discarded.
*
* @param newPosition The new position value; must be non-negative and no
- * larger than the current limit
- *
+ * larger than the current limit
* @return This buffer
- *
* @throws IllegalArgumentException If the preconditions on
- * newPosition do not hold
+ * newPosition do not hold
*/
- public final LogBuffer position(final int newPosition)
- {
- if (newPosition > limit || newPosition < 0)
- throw new IllegalArgumentException("limit excceed: " + newPosition);
+ public final LogBuffer position(final int newPosition) {
+ if (newPosition > limit || newPosition < 0) throw new IllegalArgumentException("limit excceed: " + newPosition);
this.position = origin + newPosition;
return this;
@@ -123,14 +108,11 @@ public class LogBuffer
* Forwards this buffer's position.
*
* @param len The forward distance
- *
* @return This buffer
*/
- public final LogBuffer forward(final int len)
- {
- if (position + len > origin + limit)
- throw new IllegalArgumentException("limit excceed: "
- + (position + len - origin));
+ public final LogBuffer forward(final int len) {
+ if (position + len > origin + limit) throw new IllegalArgumentException("limit excceed: "
+ + (position + len - origin));
this.position += len;
return this;
@@ -140,27 +122,20 @@ public class LogBuffer
* Consume this buffer, moving origin and position.
*
* @param len The consume distance
- *
* @return This buffer
*/
- public final LogBuffer consume(final int len)
- {
- if (limit > len)
- {
+ public final LogBuffer consume(final int len) {
+ if (limit > len) {
limit -= len;
origin += len;
position = origin;
return this;
- }
- else if (limit == len)
- {
+ } else if (limit == len) {
limit = 0;
origin = 0;
position = 0;
return this;
- }
- else
- {
+ } else {
/* Should not happen. */
throw new IllegalArgumentException("limit excceed: " + len);
}
@@ -171,8 +146,7 @@ public class LogBuffer
*
* @return This buffer
*/
- public final LogBuffer rewind()
- {
+ public final LogBuffer rewind() {
position = origin;
return this;
}
@@ -182,8 +156,7 @@ public class LogBuffer
*
* @return The limit of this buffer
*/
- public final int limit()
- {
+ public final int limit() {
return limit;
}
@@ -193,18 +166,14 @@ public class LogBuffer
* the new limit then it is discarded.
*
* @param newLimit The new limit value; must be non-negative and no larger
- * than this buffer's capacity
- *
+ * than this buffer's capacity
* @return This buffer
- *
- * @throws IllegalArgumentException If the preconditions on
- * newLimit do not hold
+ * @throws IllegalArgumentException If the preconditions on newLimit
+ * do not hold
*/
- public final LogBuffer limit(int newLimit)
- {
- if (origin + newLimit > buffer.length || newLimit < 0)
- throw new IllegalArgumentException("capacity excceed: "
- + (origin + newLimit));
+ public final LogBuffer limit(int newLimit) {
+ if (origin + newLimit > buffer.length || newLimit < 0) throw new IllegalArgumentException("capacity excceed: "
+ + (origin + newLimit));
limit = newLimit;
return this;
@@ -216,8 +185,7 @@ public class LogBuffer
*
* @return The number of elements remaining in this buffer
*/
- public final int remaining()
- {
+ public final int remaining() {
return limit + origin - position;
}
@@ -226,20 +194,17 @@ public class LogBuffer
* limit.
*
* @return true if, and only if, there is at least one element
- * remaining in this buffer
+ * remaining in this buffer
*/
- public final boolean hasRemaining()
- {
+ public final boolean hasRemaining() {
return position < limit + origin;
}
/**
* Return 8-bit signed int from buffer.
*/
- public final int getInt8(final int pos)
- {
- if (pos >= limit || pos < 0)
- throw new IllegalArgumentException("limit excceed: " + pos);
+ public final int getInt8(final int pos) {
+ if (pos >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: " + pos);
return buffer[origin + pos];
}
@@ -247,11 +212,8 @@ public class LogBuffer
/**
* Return next 8-bit signed int from buffer.
*/
- public final int getInt8()
- {
- if (position >= origin + limit)
- throw new IllegalArgumentException("limit excceed: "
- + (position - origin));
+ public final int getInt8() {
+ if (position >= origin + limit) throw new IllegalArgumentException("limit excceed: " + (position - origin));
return buffer[position++];
}
@@ -259,10 +221,8 @@ public class LogBuffer
/**
* Return 8-bit unsigned int from buffer.
*/
- public final int getUint8(final int pos)
- {
- if (pos >= limit || pos < 0)
- throw new IllegalArgumentException("limit excceed: " + pos);
+ public final int getUint8(final int pos) {
+ if (pos >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: " + pos);
return 0xff & buffer[origin + pos];
}
@@ -270,11 +230,8 @@ public class LogBuffer
/**
* Return next 8-bit unsigned int from buffer.
*/
- public final int getUint8()
- {
- if (position >= origin + limit)
- throw new IllegalArgumentException("limit excceed: "
- + (position - origin));
+ public final int getUint8() {
+ if (position >= origin + limit) throw new IllegalArgumentException("limit excceed: " + (position - origin));
return 0xff & buffer[position++];
}
@@ -284,13 +241,11 @@ public class LogBuffer
*
* @see mysql-5.1.60/include/my_global.h - sint2korr
*/
- public final int getInt16(final int pos)
- {
+ public final int getInt16(final int pos) {
final int position = origin + pos;
- if (pos + 1 >= limit || pos < 0)
- throw new IllegalArgumentException("limit excceed: "
- + (pos < 0 ? pos : (pos + 1)));
+ if (pos + 1 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
+ + (pos < 0 ? pos : (pos + 1)));
byte[] buf = buffer;
return (0xff & buf[position]) | ((buf[position + 1]) << 8);
@@ -301,28 +256,24 @@ public class LogBuffer
*
* @see mysql-5.1.60/include/my_global.h - sint2korr
*/
- public final int getInt16()
- {
- if (position + 1 >= origin + limit)
- throw new IllegalArgumentException("limit excceed: "
- + (position - origin + 1));
+ public final int getInt16() {
+ if (position + 1 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
+ + (position - origin + 1));
byte[] buf = buffer;
return (0xff & buf[position++]) | ((buf[position++]) << 8);
}
-
+
/**
* Return 16-bit unsigned int from buffer. (little-endian)
*
* @see mysql-5.1.60/include/my_global.h - uint2korr
*/
- public final int getUint16(final int pos)
- {
+ public final int getUint16(final int pos) {
final int position = origin + pos;
- if (pos + 1 >= limit || pos < 0)
- throw new IllegalArgumentException("limit excceed: "
- + (pos < 0 ? pos : (pos + 1)));
+ if (pos + 1 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
+ + (pos < 0 ? pos : (pos + 1)));
byte[] buf = buffer;
return (0xff & buf[position]) | ((0xff & buf[position + 1]) << 8);
@@ -333,28 +284,24 @@ public class LogBuffer
*
* @see mysql-5.1.60/include/my_global.h - uint2korr
*/
- public final int getUint16()
- {
- if (position + 1 >= origin + limit)
- throw new IllegalArgumentException("limit excceed: "
- + (position - origin + 1));
+ public final int getUint16() {
+ if (position + 1 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
+ + (position - origin + 1));
byte[] buf = buffer;
return (0xff & buf[position++]) | ((0xff & buf[position++]) << 8);
}
-
+
/**
* Return 16-bit signed int from buffer. (big-endian)
*
* @see mysql-5.6.10/include/myisampack.h - mi_sint2korr
*/
- public final int getBeInt16(final int pos)
- {
+ public final int getBeInt16(final int pos) {
final int position = origin + pos;
- if (pos + 1 >= limit || pos < 0)
- throw new IllegalArgumentException("limit excceed: "
- + (pos < 0 ? pos : (pos + 1)));
+ if (pos + 1 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
+ + (pos < 0 ? pos : (pos + 1)));
byte[] buf = buffer;
return (0xff & buf[position + 1]) | ((buf[position]) << 8);
@@ -365,11 +312,9 @@ public class LogBuffer
*
* @see mysql-5.1.60/include/my_global.h - mi_sint2korr
*/
- public final int getBeInt16()
- {
- if (position + 1 >= origin + limit)
- throw new IllegalArgumentException("limit excceed: "
- + (position - origin + 1));
+ public final int getBeInt16() {
+ if (position + 1 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
+ + (position - origin + 1));
byte[] buf = buffer;
return (buf[position++] << 8) | (0xff & buf[position++]);
@@ -380,13 +325,11 @@ public class LogBuffer
*
* @see mysql-5.6.10/include/myisampack.h - mi_usint2korr
*/
- public final int getBeUint16(final int pos)
- {
+ public final int getBeUint16(final int pos) {
final int position = origin + pos;
- if (pos + 1 >= limit || pos < 0)
- throw new IllegalArgumentException("limit excceed: "
- + (pos < 0 ? pos : (pos + 1)));
+ if (pos + 1 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
+ + (pos < 0 ? pos : (pos + 1)));
byte[] buf = buffer;
return (0xff & buf[position + 1]) | ((0xff & buf[position]) << 8);
@@ -397,32 +340,27 @@ public class LogBuffer
*
* @see mysql-5.6.10/include/myisampack.h - mi_usint2korr
*/
- public final int getBeUint16()
- {
- if (position + 1 >= origin + limit)
- throw new IllegalArgumentException("limit excceed: "
- + (position - origin + 1));
+ public final int getBeUint16() {
+ if (position + 1 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
+ + (position - origin + 1));
byte[] buf = buffer;
return ((0xff & buf[position++]) << 8) | (0xff & buf[position++]);
}
-
+
/**
* Return 24-bit signed int from buffer. (little-endian)
*
* @see mysql-5.1.60/include/my_global.h - sint3korr
*/
- public final int getInt24(final int pos)
- {
+ public final int getInt24(final int pos) {
final int position = origin + pos;
- if (pos + 2 >= limit || pos < 0)
- throw new IllegalArgumentException("limit excceed: "
- + (pos < 0 ? pos : (pos + 2)));
+ if (pos + 2 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
+ + (pos < 0 ? pos : (pos + 2)));
byte[] buf = buffer;
- return (0xff & buf[position]) | ((0xff & buf[position + 1]) << 8)
- | ((buf[position + 2]) << 16);
+ return (0xff & buf[position]) | ((0xff & buf[position + 1]) << 8) | ((buf[position + 2]) << 16);
}
/**
@@ -430,33 +368,27 @@ public class LogBuffer
*
* @see mysql-5.1.60/include/my_global.h - sint3korr
*/
- public final int getInt24()
- {
- if (position + 2 >= origin + limit)
- throw new IllegalArgumentException("limit excceed: "
- + (position - origin + 2));
+ public final int getInt24() {
+ if (position + 2 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
+ + (position - origin + 2));
byte[] buf = buffer;
- return (0xff & buf[position++]) | ((0xff & buf[position++]) << 8)
- | ((buf[position++]) << 16);
+ return (0xff & buf[position++]) | ((0xff & buf[position++]) << 8) | ((buf[position++]) << 16);
}
-
+
/**
* Return 24-bit signed int from buffer. (big-endian)
*
* @see mysql-5.6.10/include/myisampack.h - mi_usint3korr
*/
- public final int getBeInt24(final int pos)
- {
+ public final int getBeInt24(final int pos) {
final int position = origin + pos;
- if (pos + 2 >= limit || pos < 0)
- throw new IllegalArgumentException("limit excceed: "
- + (pos < 0 ? pos : (pos + 2)));
+ if (pos + 2 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
+ + (pos < 0 ? pos : (pos + 2)));
byte[] buf = buffer;
- return (0xff & buf[position + 2]) | ((0xff & buf[position + 1]) << 8)
- | ((buf[position]) << 16);
+ return (0xff & buf[position + 2]) | ((0xff & buf[position + 1]) << 8) | ((buf[position]) << 16);
}
/**
@@ -464,34 +396,27 @@ public class LogBuffer
*
* @see mysql-5.6.10/include/myisampack.h - mi_usint3korr
*/
- public final int getBeInt24()
- {
- if (position + 2 >= origin + limit)
- throw new IllegalArgumentException("limit excceed: "
- + (position - origin + 2));
+ public final int getBeInt24() {
+ if (position + 2 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
+ + (position - origin + 2));
byte[] buf = buffer;
- return ((buf[position++]) << 16) | ((0xff & buf[position++]) << 8)
- | (0xff & buf[position++]);
+ return ((buf[position++]) << 16) | ((0xff & buf[position++]) << 8) | (0xff & buf[position++]);
}
-
/**
* Return 24-bit unsigned int from buffer. (little-endian)
*
* @see mysql-5.1.60/include/my_global.h - uint3korr
*/
- public final int getUint24(final int pos)
- {
+ public final int getUint24(final int pos) {
final int position = origin + pos;
- if (pos + 2 >= limit || pos < 0)
- throw new IllegalArgumentException("limit excceed: "
- + (pos < 0 ? pos : (pos + 2)));
+ if (pos + 2 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
+ + (pos < 0 ? pos : (pos + 2)));
byte[] buf = buffer;
- return (0xff & buf[position]) | ((0xff & buf[position + 1]) << 8)
- | ((0xff & buf[position + 2]) << 16);
+ return (0xff & buf[position]) | ((0xff & buf[position + 1]) << 8) | ((0xff & buf[position + 2]) << 16);
}
/**
@@ -499,33 +424,27 @@ public class LogBuffer
*
* @see mysql-5.1.60/include/my_global.h - uint3korr
*/
- public final int getUint24()
- {
- if (position + 2 >= origin + limit)
- throw new IllegalArgumentException("limit excceed: "
- + (position - origin + 2));
+ public final int getUint24() {
+ if (position + 2 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
+ + (position - origin + 2));
byte[] buf = buffer;
- return (0xff & buf[position++]) | ((0xff & buf[position++]) << 8)
- | ((0xff & buf[position++]) << 16);
+ return (0xff & buf[position++]) | ((0xff & buf[position++]) << 8) | ((0xff & buf[position++]) << 16);
}
-
+
/**
* Return 24-bit unsigned int from buffer. (big-endian)
*
* @see mysql-5.6.10/include/myisampack.h - mi_usint3korr
*/
- public final int getBeUint24(final int pos)
- {
+ public final int getBeUint24(final int pos) {
final int position = origin + pos;
- if (pos + 2 >= limit || pos < 0)
- throw new IllegalArgumentException("limit excceed: "
- + (pos < 0 ? pos : (pos + 2)));
+ if (pos + 2 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
+ + (pos < 0 ? pos : (pos + 2)));
byte[] buf = buffer;
- return (0xff & buf[position + 2]) | ((0xff & buf[position + 1]) << 8)
- | ((0xff & buf[position]) << 16);
+ return (0xff & buf[position + 2]) | ((0xff & buf[position + 1]) << 8) | ((0xff & buf[position]) << 16);
}
/**
@@ -533,15 +452,12 @@ public class LogBuffer
*
* @see mysql-5.6.10/include/myisampack.h - mi_usint3korr
*/
- public final int getBeUint24()
- {
- if (position + 2 >= origin + limit)
- throw new IllegalArgumentException("limit excceed: "
- + (position - origin + 2));
+ public final int getBeUint24() {
+ if (position + 2 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
+ + (position - origin + 2));
byte[] buf = buffer;
- return ((0xff & buf[position++]) << 16) | ((0xff & buf[position++]) << 8)
- | (0xff & buf[position++]);
+ return ((0xff & buf[position++]) << 16) | ((0xff & buf[position++]) << 8) | (0xff & buf[position++]);
}
/**
@@ -549,37 +465,31 @@ public class LogBuffer
*
* @see mysql-5.1.60/include/my_global.h - sint4korr
*/
- public final int getInt32(final int pos)
- {
+ public final int getInt32(final int pos) {
final int position = origin + pos;
- if (pos + 3 >= limit || pos < 0)
- throw new IllegalArgumentException("limit excceed: "
- + (pos < 0 ? pos : (pos + 3)));
+ if (pos + 3 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
+ + (pos < 0 ? pos : (pos + 3)));
byte[] buf = buffer;
- return (0xff & buf[position]) | ((0xff & buf[position + 1]) << 8)
- | ((0xff & buf[position + 2]) << 16)
- | ((buf[position + 3]) << 24);
+ return (0xff & buf[position]) | ((0xff & buf[position + 1]) << 8) | ((0xff & buf[position + 2]) << 16)
+ | ((buf[position + 3]) << 24);
}
-
+
/**
* Return 32-bit signed int from buffer. (big-endian)
*
* @see mysql-5.6.10/include/myisampack.h - mi_sint4korr
*/
- public final int getBeInt32(final int pos)
- {
+ public final int getBeInt32(final int pos) {
final int position = origin + pos;
- if (pos + 3 >= limit || pos < 0)
- throw new IllegalArgumentException("limit excceed: "
- + (pos < 0 ? pos : (pos + 3)));
+ if (pos + 3 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
+ + (pos < 0 ? pos : (pos + 3)));
byte[] buf = buffer;
- return (0xff & buf[position + 3]) | ((0xff & buf[position + 2]) << 8)
- | ((0xff & buf[position + 1]) << 16)
- | ((buf[position]) << 24);
+ return (0xff & buf[position + 3]) | ((0xff & buf[position + 2]) << 8) | ((0xff & buf[position + 1]) << 16)
+ | ((buf[position]) << 24);
}
/**
@@ -587,15 +497,13 @@ public class LogBuffer
*
* @see mysql-5.1.60/include/my_global.h - sint4korr
*/
- public final int getInt32()
- {
- if (position + 3 >= origin + limit)
- throw new IllegalArgumentException("limit excceed: "
- + (position - origin + 3));
+ public final int getInt32() {
+ if (position + 3 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
+ + (position - origin + 3));
byte[] buf = buffer;
- return (0xff & buf[position++]) | ((0xff & buf[position++]) << 8)
- | ((0xff & buf[position++]) << 16) | ((buf[position++]) << 24);
+ return (0xff & buf[position++]) | ((0xff & buf[position++]) << 8) | ((0xff & buf[position++]) << 16)
+ | ((buf[position++]) << 24);
}
/**
@@ -603,35 +511,29 @@ public class LogBuffer
*
* @see mysql-5.6.10/include/myisampack.h - mi_sint4korr
*/
- public final int getBeInt32()
- {
- if (position + 3 >= origin + limit)
- throw new IllegalArgumentException("limit excceed: "
- + (position - origin + 3));
+ public final int getBeInt32() {
+ if (position + 3 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
+ + (position - origin + 3));
byte[] buf = buffer;
return ((buf[position++]) << 24) | ((0xff & buf[position++]) << 16) | ((0xff & buf[position++]) << 8)
| (0xff & buf[position++]);
}
-
+
/**
* Return 32-bit unsigned int from buffer. (little-endian)
*
* @see mysql-5.1.60/include/my_global.h - uint4korr
*/
- public final long getUint32(final int pos)
- {
+ public final long getUint32(final int pos) {
final int position = origin + pos;
- if (pos + 3 >= limit || pos < 0)
- throw new IllegalArgumentException("limit excceed: "
- + (pos < 0 ? pos : (pos + 3)));
+ if (pos + 3 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
+ + (pos < 0 ? pos : (pos + 3)));
byte[] buf = buffer;
- return ((long) (0xff & buf[position]))
- | ((long) (0xff & buf[position + 1]) << 8)
- | ((long) (0xff & buf[position + 2]) << 16)
- | ((long) (0xff & buf[position + 3]) << 24);
+ return ((long) (0xff & buf[position])) | ((long) (0xff & buf[position + 1]) << 8)
+ | ((long) (0xff & buf[position + 2]) << 16) | ((long) (0xff & buf[position + 3]) << 24);
}
/**
@@ -639,114 +541,88 @@ public class LogBuffer
*
* @see mysql-5.6.10/include/myisampack.h - mi_usint4korr
*/
- public final long getBeUint32(final int pos)
- {
+ public final long getBeUint32(final int pos) {
final int position = origin + pos;
- if (pos + 3 >= limit || pos < 0)
- throw new IllegalArgumentException("limit excceed: "
- + (pos < 0 ? pos : (pos + 3)));
+ if (pos + 3 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
+ + (pos < 0 ? pos : (pos + 3)));
byte[] buf = buffer;
- return ((long) (0xff & buf[position + 3]))
- | ((long) (0xff & buf[position + 2]) << 8)
- | ((long) (0xff & buf[position + 1]) << 16)
- | ((long) (0xff & buf[position]) << 24);
+ return ((long) (0xff & buf[position + 3])) | ((long) (0xff & buf[position + 2]) << 8)
+ | ((long) (0xff & buf[position + 1]) << 16) | ((long) (0xff & buf[position]) << 24);
}
-
/**
* Return next 32-bit unsigned int from buffer. (little-endian)
*
* @see mysql-5.1.60/include/my_global.h - uint4korr
*/
- public final long getUint32()
- {
- if (position + 3 >= origin + limit)
- throw new IllegalArgumentException("limit excceed: "
- + (position - origin + 3));
+ public final long getUint32() {
+ if (position + 3 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
+ + (position - origin + 3));
byte[] buf = buffer;
- return ((long) (0xff & buf[position++]))
- | ((long) (0xff & buf[position++]) << 8)
- | ((long) (0xff & buf[position++]) << 16)
- | ((long) (0xff & buf[position++]) << 24);
+ return ((long) (0xff & buf[position++])) | ((long) (0xff & buf[position++]) << 8)
+ | ((long) (0xff & buf[position++]) << 16) | ((long) (0xff & buf[position++]) << 24);
}
-
+
/**
* Return next 32-bit unsigned int from buffer. (big-endian)
*
* @see mysql-5.6.10/include/myisampack.h - mi_uint4korr
*/
- public final long getBeUint32()
- {
- if (position + 3 >= origin + limit)
- throw new IllegalArgumentException("limit excceed: "
- + (position - origin + 3));
+ public final long getBeUint32() {
+ if (position + 3 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
+ + (position - origin + 3));
byte[] buf = buffer;
- return ((long) (0xff & buf[position++]) << 24)
- | ((long) (0xff & buf[position++]) << 16)
- | ((long) (0xff & buf[position++]) << 8)
- | ((long) (0xff & buf[position++]));
+ return ((long) (0xff & buf[position++]) << 24) | ((long) (0xff & buf[position++]) << 16)
+ | ((long) (0xff & buf[position++]) << 8) | ((long) (0xff & buf[position++]));
}
-
+
/**
* Return 40-bit unsigned int from buffer. (little-endian)
*/
- public final long getUlong40(final int pos)
- {
+ public final long getUlong40(final int pos) {
final int position = origin + pos;
- if (pos + 4 >= limit || pos < 0)
- throw new IllegalArgumentException("limit excceed: "
- + (pos < 0 ? pos : (pos + 4)));
+ if (pos + 4 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
+ + (pos < 0 ? pos : (pos + 4)));
byte[] buf = buffer;
- return ((long) (0xff & buf[position]))
- | ((long) (0xff & buf[position + 1]) << 8)
- | ((long) (0xff & buf[position + 2]) << 16)
- | ((long) (0xff & buf[position + 3]) << 24)
- | ((long) (0xff & buf[position + 4]) << 32);
+ return ((long) (0xff & buf[position])) | ((long) (0xff & buf[position + 1]) << 8)
+ | ((long) (0xff & buf[position + 2]) << 16) | ((long) (0xff & buf[position + 3]) << 24)
+ | ((long) (0xff & buf[position + 4]) << 32);
}
/**
* Return next 40-bit unsigned int from buffer. (little-endian)
*/
- public final long getUlong40()
- {
- if (position + 4 >= origin + limit)
- throw new IllegalArgumentException("limit excceed: "
- + (position - origin + 4));
+ public final long getUlong40() {
+ if (position + 4 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
+ + (position - origin + 4));
byte[] buf = buffer;
- return ((long) (0xff & buf[position++]))
- | ((long) (0xff & buf[position++]) << 8)
- | ((long) (0xff & buf[position++]) << 16)
- | ((long) (0xff & buf[position++]) << 24)
- | ((long) (0xff & buf[position++]) << 32);
+ return ((long) (0xff & buf[position++])) | ((long) (0xff & buf[position++]) << 8)
+ | ((long) (0xff & buf[position++]) << 16) | ((long) (0xff & buf[position++]) << 24)
+ | ((long) (0xff & buf[position++]) << 32);
}
-
/**
* Return 40-bit unsigned int from buffer. (big-endian)
*
* @see mysql-5.6.10/include/myisampack.h - mi_uint5korr
*/
- public final long getBeUlong40(final int pos)
- {
+ public final long getBeUlong40(final int pos) {
final int position = origin + pos;
- if (pos + 4 >= limit || pos < 0)
- throw new IllegalArgumentException("limit excceed: "
- + (pos < 0 ? pos : (pos + 4)));
+ if (pos + 4 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
+ + (pos < 0 ? pos : (pos + 4)));
byte[] buf = buffer;
- return ((long) (0xff & buf[position + 4]))
- | ((long) (0xff & buf[position + 3]) << 8)
- | ((long) (0xff & buf[position + 2]) << 16)
- | ((long) (0xff & buf[position + 1]) << 24)
- | ((long) (0xff & buf[position]) << 32);
+ return ((long) (0xff & buf[position + 4])) | ((long) (0xff & buf[position + 3]) << 8)
+ | ((long) (0xff & buf[position + 2]) << 16) | ((long) (0xff & buf[position + 1]) << 24)
+ | ((long) (0xff & buf[position]) << 32);
}
/**
@@ -754,18 +630,14 @@ public class LogBuffer
*
* @see mysql-5.6.10/include/myisampack.h - mi_uint5korr
*/
- public final long getBeUlong40()
- {
- if (position + 4 >= origin + limit)
- throw new IllegalArgumentException("limit excceed: "
- + (position - origin + 4));
+ public final long getBeUlong40() {
+ if (position + 4 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
+ + (position - origin + 4));
byte[] buf = buffer;
- return ((long) (0xff & buf[position++]) << 32)
- | ((long) (0xff & buf[position++]) << 24)
- | ((long) (0xff & buf[position++]) << 16)
- | ((long) (0xff & buf[position++]) << 8)
- | ((long) (0xff & buf[position++]));
+ return ((long) (0xff & buf[position++]) << 32) | ((long) (0xff & buf[position++]) << 24)
+ | ((long) (0xff & buf[position++]) << 16) | ((long) (0xff & buf[position++]) << 8)
+ | ((long) (0xff & buf[position++]));
}
/**
@@ -773,43 +645,33 @@ public class LogBuffer
*
* @see mysql-5.1.60/include/my_global.h - sint6korr
*/
- public final long getLong48(final int pos)
- {
+ public final long getLong48(final int pos) {
final int position = origin + pos;
- if (pos + 5 >= limit || pos < 0)
- throw new IllegalArgumentException("limit excceed: "
- + (pos < 0 ? pos : (pos + 5)));
+ if (pos + 5 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
+ + (pos < 0 ? pos : (pos + 5)));
byte[] buf = buffer;
- return ((long) (0xff & buf[position]))
- | ((long) (0xff & buf[position + 1]) << 8)
- | ((long) (0xff & buf[position + 2]) << 16)
- | ((long) (0xff & buf[position + 3]) << 24)
- | ((long) (0xff & buf[position + 4]) << 32)
- | ((long) (buf[position + 5]) << 40);
+ return ((long) (0xff & buf[position])) | ((long) (0xff & buf[position + 1]) << 8)
+ | ((long) (0xff & buf[position + 2]) << 16) | ((long) (0xff & buf[position + 3]) << 24)
+ | ((long) (0xff & buf[position + 4]) << 32) | ((long) (buf[position + 5]) << 40);
}
-
+
/**
* Return 48-bit signed long from buffer. (big-endian)
*
* @see mysql-5.6.10/include/myisampack.h - mi_sint6korr
*/
- public final long getBeLong48(final int pos)
- {
+ public final long getBeLong48(final int pos) {
final int position = origin + pos;
- if (pos + 5 >= limit || pos < 0)
- throw new IllegalArgumentException("limit excceed: "
- + (pos < 0 ? pos : (pos + 5)));
+ if (pos + 5 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
+ + (pos < 0 ? pos : (pos + 5)));
byte[] buf = buffer;
- return ((long) (0xff & buf[position + 5]))
- | ((long) (0xff & buf[position + 4]) << 8)
- | ((long) (0xff & buf[position + 3]) << 16)
- | ((long) (0xff & buf[position + 2]) << 24)
- | ((long) (0xff & buf[position + 1]) << 32)
- | ((long) (buf[position]) << 40);
+ return ((long) (0xff & buf[position + 5])) | ((long) (0xff & buf[position + 4]) << 8)
+ | ((long) (0xff & buf[position + 3]) << 16) | ((long) (0xff & buf[position + 2]) << 24)
+ | ((long) (0xff & buf[position + 1]) << 32) | ((long) (buf[position]) << 40);
}
/**
@@ -817,39 +679,29 @@ public class LogBuffer
*
* @see mysql-5.1.60/include/my_global.h - sint6korr
*/
- public final long getLong48()
- {
- if (position + 5 >= origin + limit)
- throw new IllegalArgumentException("limit excceed: "
- + (position - origin + 5));
+ public final long getLong48() {
+ if (position + 5 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
+ + (position - origin + 5));
byte[] buf = buffer;
- return ((long) (0xff & buf[position++]))
- | ((long) (0xff & buf[position++]) << 8)
- | ((long) (0xff & buf[position++]) << 16)
- | ((long) (0xff & buf[position++]) << 24)
- | ((long) (0xff & buf[position++]) << 32)
- | ((long) (buf[position++]) << 40);
+ return ((long) (0xff & buf[position++])) | ((long) (0xff & buf[position++]) << 8)
+ | ((long) (0xff & buf[position++]) << 16) | ((long) (0xff & buf[position++]) << 24)
+ | ((long) (0xff & buf[position++]) << 32) | ((long) (buf[position++]) << 40);
}
-
+
/**
* Return next 48-bit signed long from buffer. (Big-endian)
*
* @see mysql-5.6.10/include/myisampack.h - mi_sint6korr
*/
- public final long getBeLong48()
- {
- if (position + 5 >= origin + limit)
- throw new IllegalArgumentException("limit excceed: "
- + (position - origin + 5));
+ public final long getBeLong48() {
+ if (position + 5 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
+ + (position - origin + 5));
byte[] buf = buffer;
- return ((long) (buf[position++]) << 40)
- | ((long) (0xff & buf[position++]) << 32)
- | ((long) (0xff & buf[position++]) << 24)
- | ((long) (0xff & buf[position++]) << 16)
- | ((long) (0xff & buf[position++]) << 8)
- | ((long) (0xff & buf[position++]));
+ return ((long) (buf[position++]) << 40) | ((long) (0xff & buf[position++]) << 32)
+ | ((long) (0xff & buf[position++]) << 24) | ((long) (0xff & buf[position++]) << 16)
+ | ((long) (0xff & buf[position++]) << 8) | ((long) (0xff & buf[position++]));
}
/**
@@ -857,43 +709,33 @@ public class LogBuffer
*
* @see mysql-5.1.60/include/my_global.h - uint6korr
*/
- public final long getUlong48(final int pos)
- {
+ public final long getUlong48(final int pos) {
final int position = origin + pos;
- if (pos + 5 >= limit || pos < 0)
- throw new IllegalArgumentException("limit excceed: "
- + (pos < 0 ? pos : (pos + 5)));
+ if (pos + 5 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
+ + (pos < 0 ? pos : (pos + 5)));
byte[] buf = buffer;
- return ((long) (0xff & buf[position]))
- | ((long) (0xff & buf[position + 1]) << 8)
- | ((long) (0xff & buf[position + 2]) << 16)
- | ((long) (0xff & buf[position + 3]) << 24)
- | ((long) (0xff & buf[position + 4]) << 32)
- | ((long) (0xff & buf[position + 5]) << 40);
+ return ((long) (0xff & buf[position])) | ((long) (0xff & buf[position + 1]) << 8)
+ | ((long) (0xff & buf[position + 2]) << 16) | ((long) (0xff & buf[position + 3]) << 24)
+ | ((long) (0xff & buf[position + 4]) << 32) | ((long) (0xff & buf[position + 5]) << 40);
}
-
+
/**
* Return 48-bit unsigned long from buffer. (big-endian)
*
* @see mysql-5.6.10/include/myisampack.h - mi_uint6korr
*/
- public final long getBeUlong48(final int pos)
- {
+ public final long getBeUlong48(final int pos) {
final int position = origin + pos;
- if (pos + 5 >= limit || pos < 0)
- throw new IllegalArgumentException("limit excceed: "
- + (pos < 0 ? pos : (pos + 5)));
+ if (pos + 5 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
+ + (pos < 0 ? pos : (pos + 5)));
byte[] buf = buffer;
- return ((long) (0xff & buf[position + 5]))
- | ((long) (0xff & buf[position + 4]) << 8)
- | ((long) (0xff & buf[position + 3]) << 16)
- | ((long) (0xff & buf[position + 2]) << 24)
- | ((long) (0xff & buf[position + 1]) << 32)
- | ((long) (0xff & buf[position]) << 40);
+ return ((long) (0xff & buf[position + 5])) | ((long) (0xff & buf[position + 4]) << 8)
+ | ((long) (0xff & buf[position + 3]) << 16) | ((long) (0xff & buf[position + 2]) << 24)
+ | ((long) (0xff & buf[position + 1]) << 32) | ((long) (0xff & buf[position]) << 40);
}
/**
@@ -901,123 +743,89 @@ public class LogBuffer
*
* @see mysql-5.1.60/include/my_global.h - uint6korr
*/
- public final long getUlong48()
- {
- if (position + 5 >= origin + limit)
- throw new IllegalArgumentException("limit excceed: "
- + (position - origin + 5));
+ public final long getUlong48() {
+ if (position + 5 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
+ + (position - origin + 5));
byte[] buf = buffer;
- return ((long) (0xff & buf[position++]))
- | ((long) (0xff & buf[position++]) << 8)
- | ((long) (0xff & buf[position++]) << 16)
- | ((long) (0xff & buf[position++]) << 24)
- | ((long) (0xff & buf[position++]) << 32)
- | ((long) (0xff & buf[position++]) << 40);
+ return ((long) (0xff & buf[position++])) | ((long) (0xff & buf[position++]) << 8)
+ | ((long) (0xff & buf[position++]) << 16) | ((long) (0xff & buf[position++]) << 24)
+ | ((long) (0xff & buf[position++]) << 32) | ((long) (0xff & buf[position++]) << 40);
}
-
+
/**
* Return next 48-bit unsigned long from buffer. (big-endian)
*
* @see mysql-5.6.10/include/myisampack.h - mi_uint6korr
*/
- public final long getBeUlong48()
- {
- if (position + 5 >= origin + limit)
- throw new IllegalArgumentException("limit excceed: "
- + (position - origin + 5));
+ public final long getBeUlong48() {
+ if (position + 5 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
+ + (position - origin + 5));
byte[] buf = buffer;
- return ((long) (0xff & buf[position++]) << 40)
- | ((long) (0xff & buf[position++]) << 32)
- | ((long) (0xff & buf[position++]) << 24)
- | ((long) (0xff & buf[position++]) << 16)
- | ((long) (0xff & buf[position++]) << 8)
- | ((long) (0xff & buf[position++]));
+ return ((long) (0xff & buf[position++]) << 40) | ((long) (0xff & buf[position++]) << 32)
+ | ((long) (0xff & buf[position++]) << 24) | ((long) (0xff & buf[position++]) << 16)
+ | ((long) (0xff & buf[position++]) << 8) | ((long) (0xff & buf[position++]));
}
-
+
/**
* Return 56-bit unsigned int from buffer. (little-endian)
- *
*/
- public final long getUlong56(final int pos)
- {
+ public final long getUlong56(final int pos) {
final int position = origin + pos;
- if (pos + 6 >= limit || pos < 0)
- throw new IllegalArgumentException("limit excceed: "
- + (pos < 0 ? pos : (pos + 6)));
+ if (pos + 6 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
+ + (pos < 0 ? pos : (pos + 6)));
byte[] buf = buffer;
- return ((long) (0xff & buf[position]))
- | ((long) (0xff & buf[position + 1]) << 8)
- | ((long) (0xff & buf[position + 2]) << 16)
- | ((long) (0xff & buf[position + 3]) << 24)
- | ((long) (0xff & buf[position + 4]) << 32)
- | ((long) (0xff & buf[position + 5]) << 40)
- | ((long) (0xff & buf[position + 6]) << 48);
+ return ((long) (0xff & buf[position])) | ((long) (0xff & buf[position + 1]) << 8)
+ | ((long) (0xff & buf[position + 2]) << 16) | ((long) (0xff & buf[position + 3]) << 24)
+ | ((long) (0xff & buf[position + 4]) << 32) | ((long) (0xff & buf[position + 5]) << 40)
+ | ((long) (0xff & buf[position + 6]) << 48);
}
/**
* Return next 56-bit unsigned int from buffer. (little-endian)
- *
*/
- public final long getUlong56()
- {
- if (position + 6 >= origin + limit)
- throw new IllegalArgumentException("limit excceed: "
- + (position - origin + 6));
+ public final long getUlong56() {
+ if (position + 6 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
+ + (position - origin + 6));
byte[] buf = buffer;
- return ((long) (0xff & buf[position++]) )
- | ((long) (0xff & buf[position++]) << 8)
- | ((long) (0xff & buf[position++]) << 16)
- | ((long) (0xff & buf[position++]) << 24)
- | ((long) (0xff & buf[position++]) << 32)
- | ((long) (0xff & buf[position++]) << 40)
- | ((long) (0xff & buf[position++]) << 48);
+ return ((long) (0xff & buf[position++])) | ((long) (0xff & buf[position++]) << 8)
+ | ((long) (0xff & buf[position++]) << 16) | ((long) (0xff & buf[position++]) << 24)
+ | ((long) (0xff & buf[position++]) << 32) | ((long) (0xff & buf[position++]) << 40)
+ | ((long) (0xff & buf[position++]) << 48);
}
-
+
/**
* Return 56-bit unsigned int from buffer. (big-endian)
- *
*/
- public final long getBeUlong56(final int pos)
- {
+ public final long getBeUlong56(final int pos) {
final int position = origin + pos;
- if (pos + 6 >= limit || pos < 0)
- throw new IllegalArgumentException("limit excceed: "
- + (pos < 0 ? pos : (pos + 6)));
+ if (pos + 6 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
+ + (pos < 0 ? pos : (pos + 6)));
byte[] buf = buffer;
- return ((long) (0xff & buf[position + 6]))
- | ((long) (0xff & buf[position + 5]) << 8)
- | ((long) (0xff & buf[position + 4]) << 16)
- | ((long) (0xff & buf[position + 3]) << 24)
- | ((long) (0xff & buf[position + 2]) << 32)
- | ((long) (0xff & buf[position + 1]) << 40)
- | ((long) (0xff & buf[position]) << 48);
+ return ((long) (0xff & buf[position + 6])) | ((long) (0xff & buf[position + 5]) << 8)
+ | ((long) (0xff & buf[position + 4]) << 16) | ((long) (0xff & buf[position + 3]) << 24)
+ | ((long) (0xff & buf[position + 2]) << 32) | ((long) (0xff & buf[position + 1]) << 40)
+ | ((long) (0xff & buf[position]) << 48);
}
/**
* Return next 56-bit unsigned int from buffer. (big-endian)
- *
*/
- public final long getBeUlong56()
- {
- if (position + 6 >= origin + limit)
- throw new IllegalArgumentException("limit excceed: "
- + (position - origin + 6));
+ public final long getBeUlong56() {
+ if (position + 6 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
+ + (position - origin + 6));
byte[] buf = buffer;
- return ((long) (0xff & buf[position++]) << 48)
- | ((long) (0xff & buf[position++]) << 40)
- | ((long) (0xff & buf[position++]) << 32)
- | ((long) (0xff & buf[position++]) << 24)
- | ((long) (0xff & buf[position++]) << 16)
- | ((long) (0xff & buf[position++]) << 8)
- | ((long) (0xff & buf[position++]));
+ return ((long) (0xff & buf[position++]) << 48) | ((long) (0xff & buf[position++]) << 40)
+ | ((long) (0xff & buf[position++]) << 32) | ((long) (0xff & buf[position++]) << 24)
+ | ((long) (0xff & buf[position++]) << 16) | ((long) (0xff & buf[position++]) << 8)
+ | ((long) (0xff & buf[position++]));
}
/**
@@ -1025,47 +833,35 @@ public class LogBuffer
*
* @see mysql-5.1.60/include/my_global.h - sint8korr
*/
- public final long getLong64(final int pos)
- {
+ public final long getLong64(final int pos) {
final int position = origin + pos;
- if (pos + 7 >= limit || pos < 0)
- throw new IllegalArgumentException("limit excceed: "
- + (pos < 0 ? pos : (pos + 7)));
+ if (pos + 7 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
+ + (pos < 0 ? pos : (pos + 7)));
byte[] buf = buffer;
- return ((long) (0xff & buf[position]))
- | ((long) (0xff & buf[position + 1]) << 8)
- | ((long) (0xff & buf[position + 2]) << 16)
- | ((long) (0xff & buf[position + 3]) << 24)
- | ((long) (0xff & buf[position + 4]) << 32)
- | ((long) (0xff & buf[position + 5]) << 40)
- | ((long) (0xff & buf[position + 6]) << 48)
- | ((long) (buf[position + 7]) << 56);
+ return ((long) (0xff & buf[position])) | ((long) (0xff & buf[position + 1]) << 8)
+ | ((long) (0xff & buf[position + 2]) << 16) | ((long) (0xff & buf[position + 3]) << 24)
+ | ((long) (0xff & buf[position + 4]) << 32) | ((long) (0xff & buf[position + 5]) << 40)
+ | ((long) (0xff & buf[position + 6]) << 48) | ((long) (buf[position + 7]) << 56);
}
-
+
/**
* Return 64-bit signed long from buffer. (big-endian)
*
* @see mysql-5.6.10/include/myisampack.h - mi_sint8korr
*/
- public final long getBeLong64(final int pos)
- {
+ public final long getBeLong64(final int pos) {
final int position = origin + pos;
- if (pos + 7 >= limit || pos < 0)
- throw new IllegalArgumentException("limit excceed: "
- + (pos < 0 ? pos : (pos + 7)));
+ if (pos + 7 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
+ + (pos < 0 ? pos : (pos + 7)));
byte[] buf = buffer;
- return ((long) (0xff & buf[position + 7]))
- | ((long) (0xff & buf[position + 6]) << 8)
- | ((long) (0xff & buf[position + 5]) << 16)
- | ((long) (0xff & buf[position + 4]) << 24)
- | ((long) (0xff & buf[position + 3]) << 32)
- | ((long) (0xff & buf[position + 2]) << 40)
- | ((long) (0xff & buf[position + 1]) << 48)
- | ((long) (buf[position]) << 56);
+ return ((long) (0xff & buf[position + 7])) | ((long) (0xff & buf[position + 6]) << 8)
+ | ((long) (0xff & buf[position + 5]) << 16) | ((long) (0xff & buf[position + 4]) << 24)
+ | ((long) (0xff & buf[position + 3]) << 32) | ((long) (0xff & buf[position + 2]) << 40)
+ | ((long) (0xff & buf[position + 1]) << 48) | ((long) (buf[position]) << 56);
}
/**
@@ -1073,73 +869,56 @@ public class LogBuffer
*
* @see mysql-5.1.60/include/my_global.h - sint8korr
*/
- public final long getLong64()
- {
- if (position + 7 >= origin + limit)
- throw new IllegalArgumentException("limit excceed: "
- + (position - origin + 7));
+ public final long getLong64() {
+ if (position + 7 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
+ + (position - origin + 7));
byte[] buf = buffer;
- return ((long) (0xff & buf[position++]))
- | ((long) (0xff & buf[position++]) << 8)
- | ((long) (0xff & buf[position++]) << 16)
- | ((long) (0xff & buf[position++]) << 24)
- | ((long) (0xff & buf[position++]) << 32)
- | ((long) (0xff & buf[position++]) << 40)
- | ((long) (0xff & buf[position++]) << 48)
- | ((long) (buf[position++]) << 56);
+ return ((long) (0xff & buf[position++])) | ((long) (0xff & buf[position++]) << 8)
+ | ((long) (0xff & buf[position++]) << 16) | ((long) (0xff & buf[position++]) << 24)
+ | ((long) (0xff & buf[position++]) << 32) | ((long) (0xff & buf[position++]) << 40)
+ | ((long) (0xff & buf[position++]) << 48) | ((long) (buf[position++]) << 56);
}
-
+
/**
* Return next 64-bit signed long from buffer. (big-endian)
*
* @see mysql-5.6.10/include/myisampack.h - mi_sint8korr
*/
- public final long getBeLong64()
- {
- if (position + 7 >= origin + limit)
- throw new IllegalArgumentException("limit excceed: "
- + (position - origin + 7));
+ public final long getBeLong64() {
+ if (position + 7 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
+ + (position - origin + 7));
byte[] buf = buffer;
- return ((long) (buf[position++]) << 56)
- | ((long) (0xff & buf[position++]) << 48)
- | ((long) (0xff & buf[position++]) << 40)
- | ((long) (0xff & buf[position++]) << 32)
- | ((long) (0xff & buf[position++]) << 24)
- | ((long) (0xff & buf[position++]) << 16)
- | ((long) (0xff & buf[position++]) << 8)
- | ((long) (0xff & buf[position++]));
+ return ((long) (buf[position++]) << 56) | ((long) (0xff & buf[position++]) << 48)
+ | ((long) (0xff & buf[position++]) << 40) | ((long) (0xff & buf[position++]) << 32)
+ | ((long) (0xff & buf[position++]) << 24) | ((long) (0xff & buf[position++]) << 16)
+ | ((long) (0xff & buf[position++]) << 8) | ((long) (0xff & buf[position++]));
}
/* The max ulonglong - 0x ff ff ff ff ff ff ff ff */
- public static final BigInteger BIGINT_MAX_VALUE = new BigInteger(
- "18446744073709551615");
+ public static final BigInteger BIGINT_MAX_VALUE = new BigInteger("18446744073709551615");
/**
* Return 64-bit unsigned long from buffer. (little-endian)
*
* @see mysql-5.1.60/include/my_global.h - uint8korr
*/
- public final BigInteger getUlong64(final int pos)
- {
+ public final BigInteger getUlong64(final int pos) {
final long long64 = getLong64(pos);
- return (long64 >= 0) ? BigInteger.valueOf(long64)
- : BIGINT_MAX_VALUE.add(BigInteger.valueOf(1 + long64));
+ return (long64 >= 0) ? BigInteger.valueOf(long64) : BIGINT_MAX_VALUE.add(BigInteger.valueOf(1 + long64));
}
-
+
/**
* Return 64-bit unsigned long from buffer. (big-endian)
*
* @see mysql-5.6.10/include/myisampack.h - mi_uint8korr
*/
- public final BigInteger getBeUlong64(final int pos)
- {
+ public final BigInteger getBeUlong64(final int pos) {
final long long64 = getBeLong64(pos);
- return (long64 >= 0) ? BigInteger.valueOf(long64)
- : BIGINT_MAX_VALUE.add(BigInteger.valueOf(1 + long64));
+ return (long64 >= 0) ? BigInteger.valueOf(long64) : BIGINT_MAX_VALUE.add(BigInteger.valueOf(1 + long64));
}
/**
@@ -1147,25 +926,21 @@ public class LogBuffer
*
* @see mysql-5.1.60/include/my_global.h - uint8korr
*/
- public final BigInteger getUlong64()
- {
+ public final BigInteger getUlong64() {
final long long64 = getLong64();
- return (long64 >= 0) ? BigInteger.valueOf(long64)
- : BIGINT_MAX_VALUE.add(BigInteger.valueOf(1 + long64));
+ return (long64 >= 0) ? BigInteger.valueOf(long64) : BIGINT_MAX_VALUE.add(BigInteger.valueOf(1 + long64));
}
-
+
/**
* Return next 64-bit unsigned long from buffer. (big-endian)
*
* @see mysql-5.6.10/include/myisampack.h - mi_uint8korr
*/
- public final BigInteger getBeUlong64()
- {
+ public final BigInteger getBeUlong64() {
final long long64 = getBeLong64();
- return (long64 >= 0) ? BigInteger.valueOf(long64)
- : BIGINT_MAX_VALUE.add(BigInteger.valueOf(1 + long64));
+ return (long64 >= 0) ? BigInteger.valueOf(long64) : BIGINT_MAX_VALUE.add(BigInteger.valueOf(1 + long64));
}
/**
@@ -1173,8 +948,7 @@ public class LogBuffer
*
* @see mysql-5.1.60/include/my_global.h - float4get
*/
- public final float getFloat32(final int pos)
- {
+ public final float getFloat32(final int pos) {
return Float.intBitsToFloat(getInt32(pos));
}
@@ -1183,8 +957,7 @@ public class LogBuffer
*
* @see mysql-5.1.60/include/my_global.h - float4get
*/
- public final float getFloat32()
- {
+ public final float getFloat32() {
return Float.intBitsToFloat(getInt32());
}
@@ -1193,8 +966,7 @@ public class LogBuffer
*
* @see mysql-5.1.60/include/my_global.h - float8get
*/
- public final double getDouble64(final int pos)
- {
+ public final double getDouble64(final int pos) {
return Double.longBitsToDouble(getLong64(pos));
}
@@ -1203,20 +975,17 @@ public class LogBuffer
*
* @see mysql-5.1.60/include/my_global.h - float8get
*/
- public final double getDouble64()
- {
+ public final double getDouble64() {
return Double.longBitsToDouble(getLong64());
}
public static final long NULL_LENGTH = ((long) ~0);
/**
- * Return packed number from buffer. (little-endian)
- *
- * A Packed Integer has the capacity of storing up to 8-byte integers, while
- * small integers still can use 1, 3, or 4 bytes. The value of the first
- * byte determines how to read the number, according to the following table.
- *
+ * Return packed number from buffer. (little-endian) A Packed Integer has
+ * the capacity of storing up to 8-byte integers, while small integers still
+ * can use 1, 3, or 4 bytes. The value of the first byte determines how to
+ * read the number, according to the following table.
*
* - 0-250 The first byte is the number (in the range 0-250). No
* additional bytes are used.
@@ -1226,26 +995,22 @@ public class LogBuffer
* - 254 Eight more bytes are used. The number is in the range
* 0xffffff-0xffffffffffffffff.
*
- *
* That representation allows a first byte value of 251 to represent the SQL
* NULL value.
*/
- public final long getPackedLong(final int pos)
- {
+ public final long getPackedLong(final int pos) {
final int lead = getUint8(pos);
- if (lead < 251)
- return lead;
+ if (lead < 251) return lead;
- switch (lead)
- {
- case 251:
- return NULL_LENGTH;
- case 252:
- return getUint16(pos + 1);
- case 253:
- return getUint24(pos + 1);
- default: /* Must be 254 when here */
- return getUint32(pos + 1);
+ switch (lead) {
+ case 251:
+ return NULL_LENGTH;
+ case 252:
+ return getUint16(pos + 1);
+ case 253:
+ return getUint24(pos + 1);
+ default: /* Must be 254 when here */
+ return getUint32(pos + 1);
}
}
@@ -1254,24 +1019,21 @@ public class LogBuffer
*
* @see LogBuffer#getPackedLong(int)
*/
- public final long getPackedLong()
- {
+ public final long getPackedLong() {
final int lead = getUint8();
- if (lead < 251)
- return lead;
+ if (lead < 251) return lead;
- switch (lead)
- {
- case 251:
- return NULL_LENGTH;
- case 252:
- return getUint16();
- case 253:
- return getUint24();
- default: /* Must be 254 when here */
- final long value = getUint32();
- position += 4; /* ignore other */
- return value;
+ switch (lead) {
+ case 251:
+ return NULL_LENGTH;
+ case 252:
+ return getUint16();
+ case 253:
+ return getUint24();
+ default: /* Must be 254 when here */
+ final long value = getUint32();
+ position += 4; /* ignore other */
+ return value;
}
}
@@ -1281,28 +1043,23 @@ public class LogBuffer
/**
* Return fix length string from buffer.
*/
- public final String getFixString(final int pos, final int len)
- {
+ public final String getFixString(final int pos, final int len) {
return getFixString(pos, len, ISO_8859_1);
}
/**
* Return next fix length string from buffer.
*/
- public final String getFixString(final int len)
- {
+ public final String getFixString(final int len) {
return getFixString(len, ISO_8859_1);
}
/**
* Return fix length string from buffer.
*/
- public final String getFixString(final int pos, final int len,
- String charsetName)
- {
- if (pos + len > limit || pos < 0)
- throw new IllegalArgumentException("limit excceed: "
- + (pos < 0 ? pos : (pos + len)));
+ public final String getFixString(final int pos, final int len, String charsetName) {
+ if (pos + len > limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
+ + (pos < 0 ? pos : (pos + len)));
final int from = origin + pos;
final int end = from + len;
@@ -1311,25 +1068,19 @@ public class LogBuffer
for (; (found < end) && buf[found] != '\0'; found++)
/* empty loop */;
- try
- {
+ try {
return new String(buf, from, found - from, charsetName);
- }
- catch (UnsupportedEncodingException e)
- {
- throw new IllegalArgumentException("Unsupported encoding: "
- + charsetName, e);
+ } catch (UnsupportedEncodingException e) {
+ throw new IllegalArgumentException("Unsupported encoding: " + charsetName, e);
}
}
/**
* Return next fix length string from buffer.
*/
- public final String getFixString(final int len, String charsetName)
- {
- if (position + len > origin + limit)
- throw new IllegalArgumentException("limit excceed: "
- + (position + len - origin));
+ public final String getFixString(final int len, String charsetName) {
+ if (position + len > origin + limit) throw new IllegalArgumentException("limit excceed: "
+ + (position + len - origin));
final int from = position;
final int end = from + len;
@@ -1338,132 +1089,96 @@ public class LogBuffer
for (; (found < end) && buf[found] != '\0'; found++)
/* empty loop */;
- try
- {
+ try {
String string = new String(buf, from, found - from, charsetName);
position += len;
return string;
- }
- catch (UnsupportedEncodingException e)
- {
- throw new IllegalArgumentException("Unsupported encoding: "
- + charsetName, e);
+ } catch (UnsupportedEncodingException e) {
+ throw new IllegalArgumentException("Unsupported encoding: " + charsetName, e);
}
}
/**
- * Return fix-length string from buffer without null-terminate checking.
- *
- * Fix bug #17 {@link https://github.com/AlibabaTech/canal/issues/17 }
+ * Return fix-length string from buffer without null-terminate checking. Fix
+ * bug #17 {@link https://github.com/AlibabaTech/canal/issues/17 }
*/
- public final String getFullString(final int pos, final int len,
- String charsetName)
- {
- if (pos + len > limit || pos < 0)
- throw new IllegalArgumentException("limit excceed: "
- + (pos < 0 ? pos : (pos + len)));
+ public final String getFullString(final int pos, final int len, String charsetName) {
+ if (pos + len > limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
+ + (pos < 0 ? pos : (pos + len)));
- try
- {
+ try {
return new String(buffer, origin + pos, len, charsetName);
- }
- catch (UnsupportedEncodingException e)
- {
- throw new IllegalArgumentException("Unsupported encoding: "
- + charsetName, e);
+ } catch (UnsupportedEncodingException e) {
+ throw new IllegalArgumentException("Unsupported encoding: " + charsetName, e);
}
}
/**
* Return next fix-length string from buffer without null-terminate
- * checking.
- *
- * Fix bug #17 {@link https://github.com/AlibabaTech/canal/issues/17 }
+ * checking. Fix bug #17 {@link https
+ * ://github.com/AlibabaTech/canal/issues/17 }
*/
- public final String getFullString(final int len, String charsetName)
- {
- if (position + len > origin + limit)
- throw new IllegalArgumentException("limit excceed: "
- + (position + len - origin));
+ public final String getFullString(final int len, String charsetName) {
+ if (position + len > origin + limit) throw new IllegalArgumentException("limit excceed: "
+ + (position + len - origin));
- try
- {
+ try {
String string = new String(buffer, position, len, charsetName);
position += len;
return string;
- }
- catch (UnsupportedEncodingException e)
- {
- throw new IllegalArgumentException("Unsupported encoding: "
- + charsetName, e);
+ } catch (UnsupportedEncodingException e) {
+ throw new IllegalArgumentException("Unsupported encoding: " + charsetName, e);
}
}
/**
* Return dynamic length string from buffer.
*/
- public final String getString(final int pos)
- {
+ public final String getString(final int pos) {
return getString(pos, ISO_8859_1);
}
/**
* Return next dynamic length string from buffer.
*/
- public final String getString()
- {
+ public final String getString() {
return getString(ISO_8859_1);
}
/**
* Return dynamic length string from buffer.
*/
- public final String getString(final int pos, String charsetName)
- {
- if (pos >= limit || pos < 0)
- throw new IllegalArgumentException("limit excceed: " + pos);
+ public final String getString(final int pos, String charsetName) {
+ if (pos >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: " + pos);
byte[] buf = buffer;
final int len = (0xff & buf[origin + pos]);
- if (pos + len + 1 > limit)
- throw new IllegalArgumentException("limit excceed: "
- + (pos + len + 1));
+ if (pos + len + 1 > limit) throw new IllegalArgumentException("limit excceed: " + (pos + len + 1));
- try
- {
+ try {
return new String(buf, origin + pos + 1, len, charsetName);
- }
- catch (UnsupportedEncodingException e)
- {
- throw new IllegalArgumentException("Unsupported encoding: "
- + charsetName, e);
+ } catch (UnsupportedEncodingException e) {
+ throw new IllegalArgumentException("Unsupported encoding: " + charsetName, e);
}
}
/**
* Return next dynamic length string from buffer.
*/
- public final String getString(String charsetName)
- {
- if (position >= origin + limit)
- throw new IllegalArgumentException("limit excceed: " + position);
+ public final String getString(String charsetName) {
+ if (position >= origin + limit) throw new IllegalArgumentException("limit excceed: " + position);
byte[] buf = buffer;
final int len = (0xff & buf[position]);
- if (position + len + 1 > origin + limit)
- throw new IllegalArgumentException("limit excceed: "
- + (position + len + 1 - origin));
+ if (position + len + 1 > origin + limit) throw new IllegalArgumentException("limit excceed: "
+ + (position + len + 1 - origin));
- try
- {
+ try {
String string = new String(buf, position + 1, len, charsetName);
position += len + 1;
return string;
- }
- catch (UnsupportedEncodingException e)
- {
- throw new IllegalArgumentException("Unsupported encoding: "
- + charsetName, e);
+ } catch (UnsupportedEncodingException e) {
+ throw new IllegalArgumentException("Unsupported encoding: " + charsetName, e);
}
}
@@ -1472,8 +1187,7 @@ public class LogBuffer
*
* @see mysql-5.1.60/include/myisampack.h - mi_sint2korr
*/
- private static final int getInt16BE(byte[] buffer, final int pos)
- {
+ private static final int getInt16BE(byte[] buffer, final int pos) {
return ((buffer[pos]) << 8) | (0xff & buffer[pos + 1]);
}
@@ -1482,10 +1196,8 @@ public class LogBuffer
*
* @see mysql-5.1.60/include/myisampack.h - mi_sint3korr
*/
- private static final int getInt24BE(byte[] buffer, final int pos)
- {
- return (buffer[pos] << 16) | ((0xff & buffer[pos + 1]) << 8)
- | (0xff & buffer[pos + 2]);
+ private static final int getInt24BE(byte[] buffer, final int pos) {
+ return (buffer[pos] << 16) | ((0xff & buffer[pos + 1]) << 8) | (0xff & buffer[pos + 2]);
}
/**
@@ -1493,10 +1205,9 @@ public class LogBuffer
*
* @see mysql-5.1.60/include/myisampack.h - mi_sint4korr
*/
- private static final int getInt32BE(byte[] buffer, final int pos)
- {
- return (buffer[pos] << 24) | ((0xff & buffer[pos + 1]) << 16)
- | ((0xff & buffer[pos + 2]) << 8) | (0xff & buffer[pos + 3]);
+ private static final int getInt32BE(byte[] buffer, final int pos) {
+ return (buffer[pos] << 24) | ((0xff & buffer[pos + 1]) << 16) | ((0xff & buffer[pos + 2]) << 8)
+ | (0xff & buffer[pos + 3]);
}
/* decimal representation */
@@ -1504,8 +1215,7 @@ public class LogBuffer
public static final int DIG_BASE = 1000000000;
public static final int DIG_MAX = DIG_BASE - 1;
public static final int dig2bytes[] = { 0, 1, 1, 2, 2, 3, 3, 4, 4, 4 };
- public static final int powers10[] = { 1, 10, 100, 1000, 10000, 100000,
- 1000000, 10000000, 100000000, 1000000000 };
+ public static final int powers10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 };
public static final int DIG_PER_INT32 = 9;
public static final int SIZE_OF_INT32 = 4;
@@ -1515,9 +1225,7 @@ public class LogBuffer
*
* @see mysql-5.1.60/strings/decimal.c - bin2decimal()
*/
- public final BigDecimal getDecimal(final int pos, final int precision,
- final int scale)
- {
+ public final BigDecimal getDecimal(final int pos, final int precision, final int scale) {
final int intg = precision - scale;
final int frac = scale;
final int intg0 = intg / DIG_PER_INT32;
@@ -1525,15 +1233,15 @@ public class LogBuffer
final int intg0x = intg - intg0 * DIG_PER_INT32;
final int frac0x = frac - frac0 * DIG_PER_INT32;
- final int binSize = intg0 * SIZE_OF_INT32 + dig2bytes[intg0x] + frac0
- * SIZE_OF_INT32 + dig2bytes[frac0x];
- if (pos + binSize > limit || pos < 0)
- {
- throw new IllegalArgumentException("limit excceed: "
- + (pos < 0 ? pos : (pos + binSize)));
+ final int binSize = intg0 * SIZE_OF_INT32 + dig2bytes[intg0x] + frac0 * SIZE_OF_INT32 + dig2bytes[frac0x];
+ if (pos + binSize > limit || pos < 0) {
+ throw new IllegalArgumentException("limit excceed: " + (pos < 0 ? pos : (pos + binSize)));
}
return getDecimal0(origin + pos, intg, frac, // NL
- intg0, frac0, intg0x, frac0x);
+ intg0,
+ frac0,
+ intg0x,
+ frac0x);
}
/**
@@ -1541,8 +1249,7 @@ public class LogBuffer
*
* @see mysql-5.1.60/strings/decimal.c - bin2decimal()
*/
- public final BigDecimal getDecimal(final int precision, final int scale)
- {
+ public final BigDecimal getDecimal(final int precision, final int scale) {
final int intg = precision - scale;
final int frac = scale;
final int intg0 = intg / DIG_PER_INT32;
@@ -1550,16 +1257,16 @@ public class LogBuffer
final int intg0x = intg - intg0 * DIG_PER_INT32;
final int frac0x = frac - frac0 * DIG_PER_INT32;
- final int binSize = intg0 * SIZE_OF_INT32 + dig2bytes[intg0x] + frac0
- * SIZE_OF_INT32 + dig2bytes[frac0x];
- if (position + binSize > origin + limit)
- {
- throw new IllegalArgumentException("limit excceed: "
- + (position + binSize - origin));
+ final int binSize = intg0 * SIZE_OF_INT32 + dig2bytes[intg0x] + frac0 * SIZE_OF_INT32 + dig2bytes[frac0x];
+ if (position + binSize > origin + limit) {
+ throw new IllegalArgumentException("limit excceed: " + (position + binSize - origin));
}
BigDecimal decimal = getDecimal0(position, intg, frac, // NL
- intg0, frac0, intg0x, frac0x);
+ intg0,
+ frac0,
+ intg0x,
+ frac0x);
position += binSize;
return decimal;
}
@@ -1589,150 +1296,28 @@ public class LogBuffer
* @see mysql-5.1.60/strings/decimal.c - bin2decimal()
* @see mysql-5.1.60/strings/decimal.c - decimal2string()
*/
- private final BigDecimal getDecimal0(final int begin, final int intg,
- final int frac, final int intg0, final int frac0, final int intg0x,
- final int frac0x)
- {
+ private final BigDecimal getDecimal0(final int begin, final int intg, final int frac, final int intg0,
+ final int frac0, final int intg0x, final int frac0x) {
final int mask = ((buffer[begin] & 0x80) == 0x80) ? 0 : -1;
int from = begin;
/* max string length */
final int len = ((mask != 0) ? 1 : 0) + ((intg != 0) ? intg : 1) // NL
- + ((frac != 0) ? 1 : 0) + frac;
+ + ((frac != 0) ? 1 : 0) + frac;
char[] buf = new char[len];
int pos = 0;
if (mask != 0) /* decimal sign */
- buf[pos++] = ('-');
+ buf[pos++] = ('-');
final byte[] d_copy = buffer;
d_copy[begin] ^= 0x80; /* clear sign */
int mark = pos;
- if (intg0x != 0)
- {
+ if (intg0x != 0) {
final int i = dig2bytes[intg0x];
int x = 0;
- switch (i)
- {
- case 1:
- x = d_copy[from] /* one byte */;
- break;
- case 2:
- x = getInt16BE(d_copy, from);
- break;
- case 3:
- x = getInt24BE(d_copy, from);
- break;
- case 4:
- x = getInt32BE(d_copy, from);
- break;
- }
- from += i;
- x ^= mask;
- if (x < 0 || x >= powers10[intg0x + 1])
- {
- throw new IllegalArgumentException("bad format, x exceed: " + x
- + ", " + powers10[intg0x + 1]);
- }
- if (x != 0 /* !digit || x != 0 */)
- {
- for (int j = intg0x; j > 0; j--)
- {
- final int divisor = powers10[j - 1];
- final int y = x / divisor;
- if (mark < pos || y != 0)
- {
- buf[pos++] = ((char) ('0' + y));
- }
- x -= y * divisor;
- }
- }
- }
-
- for (final int stop = from + intg0 * SIZE_OF_INT32; from < stop; from += SIZE_OF_INT32)
- {
- int x = getInt32BE(d_copy, from);
- x ^= mask;
- if (x < 0 || x > DIG_MAX)
- {
- throw new IllegalArgumentException("bad format, x exceed: " + x
- + ", " + DIG_MAX);
- }
- if (x != 0)
- {
- if (mark < pos)
- {
- for (int i = DIG_PER_DEC1; i > 0; i--)
- {
- final int divisor = powers10[i - 1];
- final int y = x / divisor;
- buf[pos++] = ((char) ('0' + y));
- x -= y * divisor;
- }
- }
- else
- {
- for (int i = DIG_PER_DEC1; i > 0; i--)
- {
- final int divisor = powers10[i - 1];
- final int y = x / divisor;
- if (mark < pos || y != 0)
- {
- buf[pos++] = ((char) ('0' + y));
- }
- x -= y * divisor;
- }
- }
- }
- else if (mark < pos)
- {
- for (int i = DIG_PER_DEC1; i > 0; i--)
- buf[pos++] = ('0');
- }
- }
-
- if (mark == pos)
- /* fix 0.0 problem, only '.' may cause BigDecimal parsing exception. */
- buf[pos++] = ('0');
-
- if (frac > 0)
- {
- buf[pos++] = ('.');
- mark = pos;
-
- for (final int stop = from + frac0 * SIZE_OF_INT32; from < stop; from += SIZE_OF_INT32)
- {
- int x = getInt32BE(d_copy, from);
- x ^= mask;
- if (x < 0 || x > DIG_MAX)
- {
- throw new IllegalArgumentException("bad format, x exceed: "
- + x + ", " + DIG_MAX);
- }
- if (x != 0)
- {
- for (int i = DIG_PER_DEC1; i > 0; i--)
- {
- final int divisor = powers10[i - 1];
- final int y = x / divisor;
- buf[pos++] = ((char) ('0' + y));
- x -= y * divisor;
- }
- }
- else
- {
- for (int i = DIG_PER_DEC1; i > 0; i--)
- buf[pos++] = ('0');
- }
- }
-
- if (frac0x != 0)
- {
- final int i = dig2bytes[frac0x];
- int x = 0;
- switch (i)
- {
+ switch (i) {
case 1:
x = d_copy[from] /* one byte */;
break;
@@ -1745,19 +1330,106 @@ public class LogBuffer
case 4:
x = getInt32BE(d_copy, from);
break;
+ }
+ from += i;
+ x ^= mask;
+ if (x < 0 || x >= powers10[intg0x + 1]) {
+ throw new IllegalArgumentException("bad format, x exceed: " + x + ", " + powers10[intg0x + 1]);
+ }
+ if (x != 0 /* !digit || x != 0 */) {
+ for (int j = intg0x; j > 0; j--) {
+ final int divisor = powers10[j - 1];
+ final int y = x / divisor;
+ if (mark < pos || y != 0) {
+ buf[pos++] = ((char) ('0' + y));
+ }
+ x -= y * divisor;
+ }
+ }
+ }
+
+ for (final int stop = from + intg0 * SIZE_OF_INT32; from < stop; from += SIZE_OF_INT32) {
+ int x = getInt32BE(d_copy, from);
+ x ^= mask;
+ if (x < 0 || x > DIG_MAX) {
+ throw new IllegalArgumentException("bad format, x exceed: " + x + ", " + DIG_MAX);
+ }
+ if (x != 0) {
+ if (mark < pos) {
+ for (int i = DIG_PER_DEC1; i > 0; i--) {
+ final int divisor = powers10[i - 1];
+ final int y = x / divisor;
+ buf[pos++] = ((char) ('0' + y));
+ x -= y * divisor;
+ }
+ } else {
+ for (int i = DIG_PER_DEC1; i > 0; i--) {
+ final int divisor = powers10[i - 1];
+ final int y = x / divisor;
+ if (mark < pos || y != 0) {
+ buf[pos++] = ((char) ('0' + y));
+ }
+ x -= y * divisor;
+ }
+ }
+ } else if (mark < pos) {
+ for (int i = DIG_PER_DEC1; i > 0; i--)
+ buf[pos++] = ('0');
+ }
+ }
+
+ if (mark == pos)
+ /* fix 0.0 problem, only '.' may cause BigDecimal parsing exception. */
+ buf[pos++] = ('0');
+
+ if (frac > 0) {
+ buf[pos++] = ('.');
+ mark = pos;
+
+ for (final int stop = from + frac0 * SIZE_OF_INT32; from < stop; from += SIZE_OF_INT32) {
+ int x = getInt32BE(d_copy, from);
+ x ^= mask;
+ if (x < 0 || x > DIG_MAX) {
+ throw new IllegalArgumentException("bad format, x exceed: " + x + ", " + DIG_MAX);
+ }
+ if (x != 0) {
+ for (int i = DIG_PER_DEC1; i > 0; i--) {
+ final int divisor = powers10[i - 1];
+ final int y = x / divisor;
+ buf[pos++] = ((char) ('0' + y));
+ x -= y * divisor;
+ }
+ } else {
+ for (int i = DIG_PER_DEC1; i > 0; i--)
+ buf[pos++] = ('0');
+ }
+ }
+
+ if (frac0x != 0) {
+ final int i = dig2bytes[frac0x];
+ int x = 0;
+ switch (i) {
+ case 1:
+ x = d_copy[from] /* one byte */;
+ break;
+ case 2:
+ x = getInt16BE(d_copy, from);
+ break;
+ case 3:
+ x = getInt24BE(d_copy, from);
+ break;
+ case 4:
+ x = getInt32BE(d_copy, from);
+ break;
}
x ^= mask;
- if (x != 0)
- {
+ if (x != 0) {
final int dig = DIG_PER_DEC1 - frac0x;
x *= powers10[dig];
- if (x < 0 || x > DIG_MAX)
- {
- throw new IllegalArgumentException(
- "bad format, x exceed: " + x + ", " + DIG_MAX);
+ if (x < 0 || x > DIG_MAX) {
+ throw new IllegalArgumentException("bad format, x exceed: " + x + ", " + DIG_MAX);
}
- for (int j = DIG_PER_DEC1; j > dig; j--)
- {
+ for (int j = DIG_PER_DEC1; j > dig; j--) {
final int divisor = powers10[j - 1];
final int y = x / divisor;
buf[pos++] = ((char) ('0' + y));
@@ -1767,8 +1439,8 @@ public class LogBuffer
}
if (mark == pos)
- /* make number more friendly */
- buf[pos++] = ('0');
+ /* make number more friendly */
+ buf[pos++] = ('0');
}
d_copy[begin] ^= 0x80; /* restore sign */
@@ -1781,11 +1453,9 @@ public class LogBuffer
*
* @param len The length of MY_BITMAP in bits.
*/
- public final void fillBitmap(BitSet bitmap, final int pos, final int len)
- {
- if (pos + ((len + 7) / 8) > limit || pos < 0)
- throw new IllegalArgumentException("limit excceed: "
- + (pos + (len + 7) / 8));
+ public final void fillBitmap(BitSet bitmap, final int pos, final int len) {
+ if (pos + ((len + 7) / 8) > limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
+ + (pos + (len + 7) / 8));
fillBitmap0(bitmap, origin + pos, len);
}
@@ -1795,11 +1465,10 @@ public class LogBuffer
*
* @param len The length of MY_BITMAP in bits.
*/
- public final void fillBitmap(BitSet bitmap, final int len)
- {
- if (position + ((len + 7) / 8) > origin + limit)
- throw new IllegalArgumentException("limit excceed: "
- + (position + ((len + 7) / 8) - origin));
+ public final void fillBitmap(BitSet bitmap, final int len) {
+ if (position + ((len + 7) / 8) > origin + limit) throw new IllegalArgumentException("limit excceed: "
+ + (position
+ + ((len + 7) / 8) - origin));
position = fillBitmap0(bitmap, position, len);
}
@@ -1809,31 +1478,20 @@ public class LogBuffer
*
* @param len The length of MY_BITMAP in bits.
*/
- private final int fillBitmap0(BitSet bitmap, int pos, final int len)
- {
+ private final int fillBitmap0(BitSet bitmap, int pos, final int len) {
final byte[] buf = buffer;
- for (int bit = 0; bit < len; bit += 8)
- {
+ for (int bit = 0; bit < len; bit += 8) {
int flag = ((int) buf[pos++]) & 0xff;
- if (flag == 0)
- continue;
- if ((flag & 0x01) != 0)
- bitmap.set(bit);
- if ((flag & 0x02) != 0)
- bitmap.set(bit + 1);
- if ((flag & 0x04) != 0)
- bitmap.set(bit + 2);
- if ((flag & 0x08) != 0)
- bitmap.set(bit + 3);
- if ((flag & 0x10) != 0)
- bitmap.set(bit + 4);
- if ((flag & 0x20) != 0)
- bitmap.set(bit + 5);
- if ((flag & 0x40) != 0)
- bitmap.set(bit + 6);
- if ((flag & 0x80) != 0)
- bitmap.set(bit + 7);
+ if (flag == 0) continue;
+ if ((flag & 0x01) != 0) bitmap.set(bit);
+ if ((flag & 0x02) != 0) bitmap.set(bit + 1);
+ if ((flag & 0x04) != 0) bitmap.set(bit + 2);
+ if ((flag & 0x08) != 0) bitmap.set(bit + 3);
+ if ((flag & 0x10) != 0) bitmap.set(bit + 4);
+ if ((flag & 0x20) != 0) bitmap.set(bit + 5);
+ if ((flag & 0x40) != 0) bitmap.set(bit + 6);
+ if ((flag & 0x80) != 0) bitmap.set(bit + 7);
}
return pos;
}
@@ -1843,8 +1501,7 @@ public class LogBuffer
*
* @param len The length of MY_BITMAP in bits.
*/
- public final BitSet getBitmap(final int pos, final int len)
- {
+ public final BitSet getBitmap(final int pos, final int len) {
BitSet bitmap = new BitSet(len);
fillBitmap(bitmap, pos, len);
return bitmap;
@@ -1855,8 +1512,7 @@ public class LogBuffer
*
* @param len The length of MY_BITMAP in bits.
*/
- public final BitSet getBitmap(final int len)
- {
+ public final BitSet getBitmap(final int len) {
BitSet bitmap = new BitSet(len);
fillBitmap(bitmap, len);
return bitmap;
@@ -1865,11 +1521,8 @@ public class LogBuffer
/**
* Fill n bytes into output stream.
*/
- public final void fillOutput(OutputStream out, final int pos, final int len)
- throws IOException
- {
- if (pos + len > limit || pos < 0)
- throw new IllegalArgumentException("limit excceed: " + (pos + len));
+ public final void fillOutput(OutputStream out, final int pos, final int len) throws IOException {
+ if (pos + len > limit || pos < 0) throw new IllegalArgumentException("limit excceed: " + (pos + len));
out.write(buffer, origin + pos, len);
}
@@ -1877,12 +1530,9 @@ public class LogBuffer
/**
* Fill next n bytes into output stream.
*/
- public final void fillOutput(OutputStream out, final int len)
- throws IOException
- {
- if (position + len > origin + limit)
- throw new IllegalArgumentException("limit excceed: "
- + (position + len - origin));
+ public final void fillOutput(OutputStream out, final int len) throws IOException {
+ if (position + len > origin + limit) throw new IllegalArgumentException("limit excceed: "
+ + (position + len - origin));
out.write(buffer, position, len);
position += len;
@@ -1891,11 +1541,8 @@ public class LogBuffer
/**
* Fill n bytes in this buffer.
*/
- public final void fillBytes(final int pos, byte[] dest, final int destPos,
- final int len)
- {
- if (pos + len > limit || pos < 0)
- throw new IllegalArgumentException("limit excceed: " + (pos + len));
+ public final void fillBytes(final int pos, byte[] dest, final int destPos, final int len) {
+ if (pos + len > limit || pos < 0) throw new IllegalArgumentException("limit excceed: " + (pos + len));
System.arraycopy(buffer, origin + pos, dest, destPos, len);
}
@@ -1903,11 +1550,9 @@ public class LogBuffer
/**
* Fill next n bytes in this buffer.
*/
- public final void fillBytes(byte[] dest, final int destPos, final int len)
- {
- if (position + len > origin + limit)
- throw new IllegalArgumentException("limit excceed: "
- + (position + len - origin));
+ public final void fillBytes(byte[] dest, final int destPos, final int len) {
+ if (position + len > origin + limit) throw new IllegalArgumentException("limit excceed: "
+ + (position + len - origin));
System.arraycopy(buffer, position, dest, destPos, len);
position += len;
@@ -1916,8 +1561,7 @@ public class LogBuffer
/**
* Return n-byte data from buffer.
*/
- public final byte[] getData(final int pos, final int len)
- {
+ public final byte[] getData(final int pos, final int len) {
byte[] buf = new byte[len];
fillBytes(pos, buf, 0, len);
return buf;
@@ -1926,8 +1570,7 @@ public class LogBuffer
/**
* Return next n-byte data from buffer.
*/
- public final byte[] getData(final int len)
- {
+ public final byte[] getData(final int len) {
byte[] buf = new byte[len];
fillBytes(buf, 0, len);
return buf;
@@ -1936,18 +1579,15 @@ public class LogBuffer
/**
* Return all remaining data from buffer.
*/
- public final byte[] getData()
- {
+ public final byte[] getData() {
return getData(0, limit);
}
/**
* Return full hexdump from position.
*/
- public final String hexdump(final int pos)
- {
- if ((limit - pos) > 0)
- {
+ public final String hexdump(final int pos) {
+ if ((limit - pos) > 0) {
final int begin = origin + pos;
final int end = origin + limit;
@@ -1955,8 +1595,7 @@ public class LogBuffer
StringBuilder dump = new StringBuilder();
dump.append(Integer.toHexString(buf[begin] >> 4));
dump.append(Integer.toHexString(buf[begin] & 0xf));
- for (int i = begin + 1; i < end; i++)
- {
+ for (int i = begin + 1; i < end; i++) {
dump.append("_");
dump.append(Integer.toHexString(buf[i] >> 4));
dump.append(Integer.toHexString(buf[i] & 0xf));
@@ -1970,10 +1609,8 @@ public class LogBuffer
/**
* Return hexdump from position, for len bytes.
*/
- public final String hexdump(final int pos, final int len)
- {
- if ((limit - pos) > 0)
- {
+ public final String hexdump(final int pos, final int len) {
+ if ((limit - pos) > 0) {
final int begin = origin + pos;
final int end = Math.min(begin + len, origin + limit);
@@ -1981,8 +1618,7 @@ public class LogBuffer
StringBuilder dump = new StringBuilder();
dump.append(Integer.toHexString(buf[begin] >> 4));
dump.append(Integer.toHexString(buf[begin] & 0xf));
- for (int i = begin + 1; i < end; i++)
- {
+ for (int i = begin + 1; i < end; i++) {
dump.append("_");
dump.append(Integer.toHexString(buf[i] >> 4));
dump.append(Integer.toHexString(buf[i] & 0xf));
diff --git a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/LogContext.java b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/LogContext.java
index 0a1f04e2..cac8c691 100644
--- a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/LogContext.java
+++ b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/LogContext.java
@@ -7,69 +7,56 @@ import com.taobao.tddl.dbsync.binlog.event.FormatDescriptionLogEvent;
import com.taobao.tddl.dbsync.binlog.event.TableMapLogEvent;
/**
- * TODO: Document Me!!
- *
- * NOTE: Log context will NOT write multi-threaded.
+ * TODO: Document Me!! NOTE: Log context will NOT write multi-threaded.
*
* @author Changyuan.lh
* @version 1.0
*/
-public final class LogContext
-{
+public final class LogContext {
+
private final Map mapOfTable = new HashMap();
private FormatDescriptionLogEvent formatDescription;
private LogPosition logPosition;
- public LogContext()
- {
+ public LogContext(){
this.formatDescription = FormatDescriptionLogEvent.FORMAT_DESCRIPTION_EVENT_5_x;
}
- public LogContext(FormatDescriptionLogEvent descriptionEvent)
- {
+ public LogContext(FormatDescriptionLogEvent descriptionEvent){
this.formatDescription = descriptionEvent;
}
- public final LogPosition getLogPosition()
- {
+ public final LogPosition getLogPosition() {
return logPosition;
}
- public final void setLogPosition(LogPosition logPosition)
- {
+ public final void setLogPosition(LogPosition logPosition) {
this.logPosition = logPosition;
}
- public final FormatDescriptionLogEvent getFormatDescription()
- {
+ public final FormatDescriptionLogEvent getFormatDescription() {
return formatDescription;
}
- public final void setFormatDescription(
- FormatDescriptionLogEvent formatDescription)
- {
+ public final void setFormatDescription(FormatDescriptionLogEvent formatDescription) {
this.formatDescription = formatDescription;
}
- public final void putTable(TableMapLogEvent mapEvent)
- {
+ public final void putTable(TableMapLogEvent mapEvent) {
mapOfTable.put(Long.valueOf(mapEvent.getTableId()), mapEvent);
}
- public final TableMapLogEvent getTable(final long tableId)
- {
+ public final TableMapLogEvent getTable(final long tableId) {
return mapOfTable.get(Long.valueOf(tableId));
}
- public final void clearAllTables()
- {
+ public final void clearAllTables() {
mapOfTable.clear();
}
- public void reset()
- {
+ public void reset() {
formatDescription = FormatDescriptionLogEvent.FORMAT_DESCRIPTION_EVENT_5_x;
mapOfTable.clear();
diff --git a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/LogDecoder.java b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/LogDecoder.java
index be86cc8a..95a57424 100644
--- a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/LogDecoder.java
+++ b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/LogDecoder.java
@@ -61,28 +61,24 @@ import com.taobao.tddl.dbsync.binlog.event.mariadb.MariaGtidLogEvent;
* @author Changyuan.lh
* @version 1.0
*/
-public final class LogDecoder
-{
+public final class LogDecoder {
+
protected static final Log logger = LogFactory.getLog(LogDecoder.class);
protected final BitSet handleSet = new BitSet(LogEvent.ENUM_END_EVENT);
- public LogDecoder()
- {
+ public LogDecoder(){
}
- public LogDecoder(final int fromIndex, final int toIndex)
- {
+ public LogDecoder(final int fromIndex, final int toIndex){
handleSet.set(fromIndex, toIndex);
}
- public final void handle(final int fromIndex, final int toIndex)
- {
+ public final void handle(final int fromIndex, final int toIndex) {
handleSet.set(fromIndex, toIndex);
}
- public final void handle(final int flagIndex)
- {
+ public final void handle(final int flagIndex) {
handleSet.set(flagIndex);
}
@@ -90,48 +86,32 @@ public final class LogDecoder
* Decoding an event from binary-log buffer.
*
* @return UknownLogEvent if event type is unknown or skipped,
- * null if buffer is not including a full event.
+ * null if buffer is not including a full event.
*/
- public LogEvent decode(LogBuffer buffer, LogContext context)
- throws IOException
- {
+ public LogEvent decode(LogBuffer buffer, LogContext context) throws IOException {
final int limit = buffer.limit();
- if (limit >= FormatDescriptionLogEvent.LOG_EVENT_HEADER_LEN)
- {
- LogHeader header = new LogHeader(buffer,
- context.getFormatDescription());
+ if (limit >= FormatDescriptionLogEvent.LOG_EVENT_HEADER_LEN) {
+ LogHeader header = new LogHeader(buffer, context.getFormatDescription());
final int len = header.getEventLen();
- if (limit >= len)
- {
+ if (limit >= len) {
LogEvent event;
/* Checking binary-log's header */
- if (handleSet.get(header.getType()))
- {
+ if (handleSet.get(header.getType())) {
buffer.limit(len);
- try
- {
+ try {
/* Decoding binary-log to event */
event = decode(buffer, header, context);
- }
- catch (IOException e)
- {
- if (logger.isWarnEnabled())
- logger.warn("Decoding "
- + LogEvent.getTypeName(header.getType())
- + " failed from: "
- + context.getLogPosition(), e);
+ } catch (IOException e) {
+ if (logger.isWarnEnabled()) logger.warn("Decoding " + LogEvent.getTypeName(header.getType())
+ + " failed from: " + context.getLogPosition(), e);
throw e;
- }
- finally
- {
+ } finally {
buffer.limit(limit); /* Restore limit */
}
- }
- else
- {
+ } else {
/* Ignore unsupported binary-log. */
event = new UnknownLogEvent(header);
}
@@ -152,338 +132,275 @@ public final class LogDecoder
*
* @return UknownLogEvent if event type is unknown or skipped.
*/
- public static LogEvent decode(LogBuffer buffer, LogHeader header,
- LogContext context) throws IOException
- {
+ public static LogEvent decode(LogBuffer buffer, LogHeader header, LogContext context) throws IOException {
FormatDescriptionLogEvent descriptionEvent = context.getFormatDescription();
LogPosition logPosition = context.getLogPosition();
-
+
int checksumAlg = LogEvent.BINLOG_CHECKSUM_ALG_UNDEF;
if (header.getType() != LogEvent.FORMAT_DESCRIPTION_EVENT) {
checksumAlg = descriptionEvent.header.getChecksumAlg();
- }else {
+ } else {
// 如果是format事件自己,也需要处理checksum
checksumAlg = header.getChecksumAlg();
}
-
+
if (checksumAlg != LogEvent.BINLOG_CHECKSUM_ALG_OFF && checksumAlg != LogEvent.BINLOG_CHECKSUM_ALG_UNDEF) {
// remove checksum bytes
buffer.limit(header.getEventLen() - LogEvent.BINLOG_CHECKSUM_LEN);
}
-
- switch (header.getType())
- {
- case LogEvent.QUERY_EVENT:
- {
- QueryLogEvent event = new QueryLogEvent(header, buffer,
- descriptionEvent);
+
+ switch (header.getType()) {
+ case LogEvent.QUERY_EVENT: {
+ QueryLogEvent event = new QueryLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
- case LogEvent.XID_EVENT:
- {
- XidLogEvent event = new XidLogEvent(header, buffer,
- descriptionEvent);
+ case LogEvent.XID_EVENT: {
+ XidLogEvent event = new XidLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
- case LogEvent.TABLE_MAP_EVENT:
- {
- TableMapLogEvent mapEvent = new TableMapLogEvent(header,
- buffer, descriptionEvent);
+ case LogEvent.TABLE_MAP_EVENT: {
+ TableMapLogEvent mapEvent = new TableMapLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
context.putTable(mapEvent);
return mapEvent;
}
- case LogEvent.WRITE_ROWS_EVENT_V1:
- {
- RowsLogEvent event = new WriteRowsLogEvent(header, buffer,
- descriptionEvent);
- /* updating position in context */
- logPosition.position = header.getLogPos();
- event.fillTable(context);
- return event;
- }
- case LogEvent.UPDATE_ROWS_EVENT_V1:
- {
- RowsLogEvent event = new UpdateRowsLogEvent(header, buffer,
- descriptionEvent);
- /* updating position in context */
- logPosition.position = header.getLogPos();
- event.fillTable(context);
- return event;
- }
- case LogEvent.DELETE_ROWS_EVENT_V1:
- {
- RowsLogEvent event = new DeleteRowsLogEvent(header, buffer,
- descriptionEvent);
- /* updating position in context */
- logPosition.position = header.getLogPos();
- event.fillTable(context);
- return event;
- }
- case LogEvent.ROTATE_EVENT:
- {
- RotateLogEvent event = new RotateLogEvent(header, buffer,
- descriptionEvent);
- /* updating position in context */
- logPosition = new LogPosition(event.getFilename(),
- event.getPosition());
- context.setLogPosition(logPosition);
- return event;
- }
- case LogEvent.LOAD_EVENT:
- case LogEvent.NEW_LOAD_EVENT:
- {
- LoadLogEvent event = new LoadLogEvent(header, buffer,
- descriptionEvent);
- /* updating position in context */
- logPosition.position = header.getLogPos();
- return event;
- }
- case LogEvent.SLAVE_EVENT: /* can never happen (unused event) */
- {
- if (logger.isWarnEnabled())
- logger.warn("Skipping unsupported SLAVE_EVENT from: "
- + context.getLogPosition());
- break;
- }
- case LogEvent.CREATE_FILE_EVENT:
- {
- CreateFileLogEvent event = new CreateFileLogEvent(header,
- buffer, descriptionEvent);
- /* updating position in context */
- logPosition.position = header.getLogPos();
- return event;
- }
- case LogEvent.APPEND_BLOCK_EVENT:
- {
- AppendBlockLogEvent event = new AppendBlockLogEvent(header,
- buffer, descriptionEvent);
- /* updating position in context */
- logPosition.position = header.getLogPos();
- return event;
- }
- case LogEvent.DELETE_FILE_EVENT:
- {
- DeleteFileLogEvent event = new DeleteFileLogEvent(header,
- buffer, descriptionEvent);
- /* updating position in context */
- logPosition.position = header.getLogPos();
- return event;
- }
- case LogEvent.EXEC_LOAD_EVENT:
- {
- ExecuteLoadLogEvent event = new ExecuteLoadLogEvent(header,
- buffer, descriptionEvent);
- /* updating position in context */
- logPosition.position = header.getLogPos();
- return event;
- }
- case LogEvent.START_EVENT_V3:
- {
- /* This is sent only by MySQL <=4.x */
- StartLogEventV3 event = new StartLogEventV3(header, buffer,
- descriptionEvent);
- /* updating position in context */
- logPosition.position = header.getLogPos();
- return event;
- }
- case LogEvent.STOP_EVENT:
- {
- StopLogEvent event = new StopLogEvent(header, buffer,
- descriptionEvent);
- /* updating position in context */
- logPosition.position = header.getLogPos();
- return event;
- }
- case LogEvent.INTVAR_EVENT:
- {
- IntvarLogEvent event = new IntvarLogEvent(header, buffer,
- descriptionEvent);
- /* updating position in context */
- logPosition.position = header.getLogPos();
- return event;
- }
- case LogEvent.RAND_EVENT:
- {
- RandLogEvent event = new RandLogEvent(header, buffer,
- descriptionEvent);
- /* updating position in context */
- logPosition.position = header.getLogPos();
- return event;
- }
- case LogEvent.USER_VAR_EVENT:
- {
- UserVarLogEvent event = new UserVarLogEvent(header, buffer,
- descriptionEvent);
- /* updating position in context */
- logPosition.position = header.getLogPos();
- return event;
- }
- case LogEvent.FORMAT_DESCRIPTION_EVENT:
- {
- descriptionEvent = new FormatDescriptionLogEvent(header,
- buffer, descriptionEvent);
- context.setFormatDescription(descriptionEvent);
- return descriptionEvent;
- }
- case LogEvent.PRE_GA_WRITE_ROWS_EVENT:
- {
- if (logger.isWarnEnabled())
- logger.warn("Skipping unsupported PRE_GA_WRITE_ROWS_EVENT from: "
- + context.getLogPosition());
- // ev = new Write_rows_log_event_old(buf, event_len,
- // description_event);
- break;
- }
- case LogEvent.PRE_GA_UPDATE_ROWS_EVENT:
- {
- if (logger.isWarnEnabled())
- logger.warn("Skipping unsupported PRE_GA_UPDATE_ROWS_EVENT from: "
- + context.getLogPosition());
- // ev = new Update_rows_log_event_old(buf, event_len,
- // description_event);
- break;
- }
- case LogEvent.PRE_GA_DELETE_ROWS_EVENT:
- {
- if (logger.isWarnEnabled())
- logger.warn("Skipping unsupported PRE_GA_DELETE_ROWS_EVENT from: "
- + context.getLogPosition());
- // ev = new Delete_rows_log_event_old(buf, event_len,
- // description_event);
- break;
- }
- case LogEvent.BEGIN_LOAD_QUERY_EVENT:
- {
- BeginLoadQueryLogEvent event = new BeginLoadQueryLogEvent(
- header, buffer, descriptionEvent);
- /* updating position in context */
- logPosition.position = header.getLogPos();
- return event;
- }
- case LogEvent.EXECUTE_LOAD_QUERY_EVENT:
- {
- ExecuteLoadQueryLogEvent event = new ExecuteLoadQueryLogEvent(
- header, buffer, descriptionEvent);
- /* updating position in context */
- logPosition.position = header.getLogPos();
- return event;
- }
- case LogEvent.INCIDENT_EVENT:
- {
- IncidentLogEvent event = new IncidentLogEvent(header, buffer,
- descriptionEvent);
- /* updating position in context */
- logPosition.position = header.getLogPos();
- return event;
- }
- case LogEvent.HEARTBEAT_LOG_EVENT:
- {
- HeartbeatLogEvent event = new HeartbeatLogEvent(header, buffer,
- descriptionEvent);
- /* updating position in context */
- logPosition.position = header.getLogPos();
- return event;
- }
- case LogEvent.IGNORABLE_LOG_EVENT:
- {
- IgnorableLogEvent event = new IgnorableLogEvent(header, buffer, descriptionEvent);
- /* updating position in context */
- logPosition.position = header.getLogPos();
- return event;
- }
- case LogEvent.ROWS_QUERY_LOG_EVENT:
- {
- RowsQueryLogEvent event = new RowsQueryLogEvent(header, buffer, descriptionEvent);
- /* updating position in context */
- logPosition.position = header.getLogPos();
- return event;
- }
- case LogEvent.WRITE_ROWS_EVENT: {
+ case LogEvent.WRITE_ROWS_EVENT_V1: {
RowsLogEvent event = new WriteRowsLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
event.fillTable(context);
return event;
}
- case LogEvent.UPDATE_ROWS_EVENT: {
+ case LogEvent.UPDATE_ROWS_EVENT_V1: {
RowsLogEvent event = new UpdateRowsLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
event.fillTable(context);
return event;
}
- case LogEvent.DELETE_ROWS_EVENT: {
+ case LogEvent.DELETE_ROWS_EVENT_V1: {
RowsLogEvent event = new DeleteRowsLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
event.fillTable(context);
return event;
}
- case LogEvent.GTID_LOG_EVENT:
- case LogEvent.ANONYMOUS_GTID_LOG_EVENT:
+ case LogEvent.ROTATE_EVENT: {
+ RotateLogEvent event = new RotateLogEvent(header, buffer, descriptionEvent);
+ /* updating position in context */
+ logPosition = new LogPosition(event.getFilename(), event.getPosition());
+ context.setLogPosition(logPosition);
+ return event;
+ }
+ case LogEvent.LOAD_EVENT:
+ case LogEvent.NEW_LOAD_EVENT: {
+ LoadLogEvent event = new LoadLogEvent(header, buffer, descriptionEvent);
+ /* updating position in context */
+ logPosition.position = header.getLogPos();
+ return event;
+ }
+ case LogEvent.SLAVE_EVENT: /* can never happen (unused event) */
{
+ if (logger.isWarnEnabled()) logger.warn("Skipping unsupported SLAVE_EVENT from: "
+ + context.getLogPosition());
+ break;
+ }
+ case LogEvent.CREATE_FILE_EVENT: {
+ CreateFileLogEvent event = new CreateFileLogEvent(header, buffer, descriptionEvent);
+ /* updating position in context */
+ logPosition.position = header.getLogPos();
+ return event;
+ }
+ case LogEvent.APPEND_BLOCK_EVENT: {
+ AppendBlockLogEvent event = new AppendBlockLogEvent(header, buffer, descriptionEvent);
+ /* updating position in context */
+ logPosition.position = header.getLogPos();
+ return event;
+ }
+ case LogEvent.DELETE_FILE_EVENT: {
+ DeleteFileLogEvent event = new DeleteFileLogEvent(header, buffer, descriptionEvent);
+ /* updating position in context */
+ logPosition.position = header.getLogPos();
+ return event;
+ }
+ case LogEvent.EXEC_LOAD_EVENT: {
+ ExecuteLoadLogEvent event = new ExecuteLoadLogEvent(header, buffer, descriptionEvent);
+ /* updating position in context */
+ logPosition.position = header.getLogPos();
+ return event;
+ }
+ case LogEvent.START_EVENT_V3: {
+ /* This is sent only by MySQL <=4.x */
+ StartLogEventV3 event = new StartLogEventV3(header, buffer, descriptionEvent);
+ /* updating position in context */
+ logPosition.position = header.getLogPos();
+ return event;
+ }
+ case LogEvent.STOP_EVENT: {
+ StopLogEvent event = new StopLogEvent(header, buffer, descriptionEvent);
+ /* updating position in context */
+ logPosition.position = header.getLogPos();
+ return event;
+ }
+ case LogEvent.INTVAR_EVENT: {
+ IntvarLogEvent event = new IntvarLogEvent(header, buffer, descriptionEvent);
+ /* updating position in context */
+ logPosition.position = header.getLogPos();
+ return event;
+ }
+ case LogEvent.RAND_EVENT: {
+ RandLogEvent event = new RandLogEvent(header, buffer, descriptionEvent);
+ /* updating position in context */
+ logPosition.position = header.getLogPos();
+ return event;
+ }
+ case LogEvent.USER_VAR_EVENT: {
+ UserVarLogEvent event = new UserVarLogEvent(header, buffer, descriptionEvent);
+ /* updating position in context */
+ logPosition.position = header.getLogPos();
+ return event;
+ }
+ case LogEvent.FORMAT_DESCRIPTION_EVENT: {
+ descriptionEvent = new FormatDescriptionLogEvent(header, buffer, descriptionEvent);
+ context.setFormatDescription(descriptionEvent);
+ return descriptionEvent;
+ }
+ case LogEvent.PRE_GA_WRITE_ROWS_EVENT: {
+ if (logger.isWarnEnabled()) logger.warn("Skipping unsupported PRE_GA_WRITE_ROWS_EVENT from: "
+ + context.getLogPosition());
+ // ev = new Write_rows_log_event_old(buf, event_len,
+ // description_event);
+ break;
+ }
+ case LogEvent.PRE_GA_UPDATE_ROWS_EVENT: {
+ if (logger.isWarnEnabled()) logger.warn("Skipping unsupported PRE_GA_UPDATE_ROWS_EVENT from: "
+ + context.getLogPosition());
+ // ev = new Update_rows_log_event_old(buf, event_len,
+ // description_event);
+ break;
+ }
+ case LogEvent.PRE_GA_DELETE_ROWS_EVENT: {
+ if (logger.isWarnEnabled()) logger.warn("Skipping unsupported PRE_GA_DELETE_ROWS_EVENT from: "
+ + context.getLogPosition());
+ // ev = new Delete_rows_log_event_old(buf, event_len,
+ // description_event);
+ break;
+ }
+ case LogEvent.BEGIN_LOAD_QUERY_EVENT: {
+ BeginLoadQueryLogEvent event = new BeginLoadQueryLogEvent(header, buffer, descriptionEvent);
+ /* updating position in context */
+ logPosition.position = header.getLogPos();
+ return event;
+ }
+ case LogEvent.EXECUTE_LOAD_QUERY_EVENT: {
+ ExecuteLoadQueryLogEvent event = new ExecuteLoadQueryLogEvent(header, buffer, descriptionEvent);
+ /* updating position in context */
+ logPosition.position = header.getLogPos();
+ return event;
+ }
+ case LogEvent.INCIDENT_EVENT: {
+ IncidentLogEvent event = new IncidentLogEvent(header, buffer, descriptionEvent);
+ /* updating position in context */
+ logPosition.position = header.getLogPos();
+ return event;
+ }
+ case LogEvent.HEARTBEAT_LOG_EVENT: {
+ HeartbeatLogEvent event = new HeartbeatLogEvent(header, buffer, descriptionEvent);
+ /* updating position in context */
+ logPosition.position = header.getLogPos();
+ return event;
+ }
+ case LogEvent.IGNORABLE_LOG_EVENT: {
+ IgnorableLogEvent event = new IgnorableLogEvent(header, buffer, descriptionEvent);
+ /* updating position in context */
+ logPosition.position = header.getLogPos();
+ return event;
+ }
+ case LogEvent.ROWS_QUERY_LOG_EVENT: {
+ RowsQueryLogEvent event = new RowsQueryLogEvent(header, buffer, descriptionEvent);
+ /* updating position in context */
+ logPosition.position = header.getLogPos();
+ return event;
+ }
+ case LogEvent.WRITE_ROWS_EVENT: {
+ RowsLogEvent event = new WriteRowsLogEvent(header, buffer, descriptionEvent);
+ /* updating position in context */
+ logPosition.position = header.getLogPos();
+ event.fillTable(context);
+ return event;
+ }
+ case LogEvent.UPDATE_ROWS_EVENT: {
+ RowsLogEvent event = new UpdateRowsLogEvent(header, buffer, descriptionEvent);
+ /* updating position in context */
+ logPosition.position = header.getLogPos();
+ event.fillTable(context);
+ return event;
+ }
+ case LogEvent.DELETE_ROWS_EVENT: {
+ RowsLogEvent event = new DeleteRowsLogEvent(header, buffer, descriptionEvent);
+ /* updating position in context */
+ logPosition.position = header.getLogPos();
+ event.fillTable(context);
+ return event;
+ }
+ case LogEvent.GTID_LOG_EVENT:
+ case LogEvent.ANONYMOUS_GTID_LOG_EVENT: {
GtidLogEvent event = new GtidLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
- case LogEvent.PREVIOUS_GTIDS_LOG_EVENT:
- {
+ case LogEvent.PREVIOUS_GTIDS_LOG_EVENT: {
PreviousGtidsLogEvent event = new PreviousGtidsLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
- case LogEvent.ANNOTATE_ROWS_EVENT:
- {
- AnnotateRowsEvent event = new AnnotateRowsEvent(header, buffer, descriptionEvent);
- /* updating position in context */
- logPosition.position = header.getLogPos();
- return event;
- }
- case LogEvent.BINLOG_CHECKPOINT_EVENT:
- {
- BinlogCheckPointLogEvent event = new BinlogCheckPointLogEvent(header, buffer, descriptionEvent);
- /* updating position in context */
- logPosition.position = header.getLogPos();
- return event;
- }
- case LogEvent.GTID_EVENT:
- {
- MariaGtidLogEvent event = new MariaGtidLogEvent(header, buffer, descriptionEvent);
- /* updating position in context */
- logPosition.position = header.getLogPos();
- return event;
- }
- case LogEvent.GTID_LIST_EVENT:
- {
- MariaGtidListLogEvent event = new MariaGtidListLogEvent(header, buffer, descriptionEvent);
- /* updating position in context */
- logPosition.position = header.getLogPos();
- return event;
- }
- default:
- /*
- Create an object of Ignorable_log_event for unrecognized sub-class.
- So that SLAVE SQL THREAD will only update the position and continue.
- */
- if((buffer.getUint16(LogEvent.FLAGS_OFFSET) & LogEvent.LOG_EVENT_IGNORABLE_F) > 0){
- IgnorableLogEvent event = new IgnorableLogEvent(header, buffer, descriptionEvent);
+ case LogEvent.ANNOTATE_ROWS_EVENT: {
+ AnnotateRowsEvent event = new AnnotateRowsEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
- }else {
- if (logger.isWarnEnabled())
- logger.warn("Skipping unrecognized binlog event "
- + LogEvent.getTypeName(header.getType()) + " from: "
- + context.getLogPosition());
}
+ case LogEvent.BINLOG_CHECKPOINT_EVENT: {
+ BinlogCheckPointLogEvent event = new BinlogCheckPointLogEvent(header, buffer, descriptionEvent);
+ /* updating position in context */
+ logPosition.position = header.getLogPos();
+ return event;
+ }
+ case LogEvent.GTID_EVENT: {
+ MariaGtidLogEvent event = new MariaGtidLogEvent(header, buffer, descriptionEvent);
+ /* updating position in context */
+ logPosition.position = header.getLogPos();
+ return event;
+ }
+ case LogEvent.GTID_LIST_EVENT: {
+ MariaGtidListLogEvent event = new MariaGtidListLogEvent(header, buffer, descriptionEvent);
+ /* updating position in context */
+ logPosition.position = header.getLogPos();
+ return event;
+ }
+ default:
+ /*
+ * Create an object of Ignorable_log_event for unrecognized
+ * sub-class. So that SLAVE SQL THREAD will only update the
+ * position and continue.
+ */
+ if ((buffer.getUint16(LogEvent.FLAGS_OFFSET) & LogEvent.LOG_EVENT_IGNORABLE_F) > 0) {
+ IgnorableLogEvent event = new IgnorableLogEvent(header, buffer, descriptionEvent);
+ /* updating position in context */
+ logPosition.position = header.getLogPos();
+ return event;
+ } else {
+ if (logger.isWarnEnabled()) logger.warn("Skipping unrecognized binlog event "
+ + LogEvent.getTypeName(header.getType()) + " from: "
+ + context.getLogPosition());
+ }
}
/* updating position in context */
diff --git a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/LogEvent.java b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/LogEvent.java
index 7f9c3a8f..dc460dea 100644
--- a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/LogEvent.java
+++ b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/LogEvent.java
@@ -7,239 +7,218 @@ import com.taobao.tddl.dbsync.binlog.event.LogHeader;
/**
* Binary log event definitions. This includes generic code common to all types
- * of log events, as well as specific code for each type of log event.
- *
- * - All numbers, whether they are 16-, 24-, 32-, or 64-bit numbers, are stored
- * in little endian, i.e., the least significant byte first, unless otherwise
- * specified.
- *
- * representation of unsigned integers, called Packed Integer. A Packed Integer
- * has the capacity of storing up to 8-byte integers, while small integers still
- * can use 1, 3, or 4 bytes. The value of the first byte determines how to read
- * the number, according to the following table:
- *
+ * of log events, as well as specific code for each type of log event. - All
+ * numbers, whether they are 16-, 24-, 32-, or 64-bit numbers, are stored in
+ * little endian, i.e., the least significant byte first, unless otherwise
+ * specified. representation of unsigned integers, called Packed Integer. A
+ * Packed Integer has the capacity of storing up to 8-byte integers, while small
+ * integers still can use 1, 3, or 4 bytes. The value of the first byte
+ * determines how to read the number, according to the following table:
*
* Format of Packed Integer
- *
*
* | First byte |
* Format |
*
- *
*
* | 0-250 |
* The first byte is the number (in the range 0-250), and no more bytes are
* used. |
*
- *
*
* | 252 |
* Two more bytes are used. The number is in the range 251-0xffff. |
*
- *
*
* | 253 |
* Three more bytes are used. The number is in the range 0xffff-0xffffff. |
*
- *
*
* | 254 |
* Eight more bytes are used. The number is in the range
* 0xffffff-0xffffffffffffffff. |
*
- *
*
- *
* - Strings are stored in various formats. The format of each string is
* documented separately.
*
* @see mysql-5.1.60/sql/log_event.h
- *
* @author Changyuan.lh
* @version 1.0
*/
-public abstract class LogEvent
-{
+public abstract class LogEvent {
+
/*
- * 3 is MySQL 4.x; 4 is MySQL 5.0.0.
- * Compared to version 3, version 4 has:
- * - a different Start_log_event, which includes info about the binary log
+ * 3 is MySQL 4.x; 4 is MySQL 5.0.0. Compared to version 3, version 4 has: -
+ * a different Start_log_event, which includes info about the binary log
* (sizes of headers); this info is included for better compatibility if the
- * master's MySQL version is different from the slave's.
- * - all events have a unique ID (the triplet (server_id, timestamp at server
- * start, other) to be sure an event is not executed more than once in a
- * multimaster setup, example:
- * M1
- * / \
- * v v
- * M2 M3
- * \ /
- * v v
- * S
- * if a query is run on M1, it will arrive twice on S, so we need that S
- * remembers the last unique ID it has processed, to compare and know if the
- * event should be skipped or not. Example of ID: we already have the server id
- * (4 bytes), plus:
+ * master's MySQL version is different from the slave's. - all events have a
+ * unique ID (the triplet (server_id, timestamp at server start, other) to
+ * be sure an event is not executed more than once in a multimaster setup,
+ * example: M1 / \ v v M2 M3 \ / v v S if a query is run on M1, it will
+ * arrive twice on S, so we need that S remembers the last unique ID it has
+ * processed, to compare and know if the event should be skipped or not.
+ * Example of ID: we already have the server id (4 bytes), plus:
* timestamp_when_the_master_started (4 bytes), a counter (a sequence number
* which increments every time we write an event to the binlog) (3 bytes).
* Q: how do we handle when the counter is overflowed and restarts from 0 ?
- *
* - Query and Load (Create or Execute) events may have a more precise
- * timestamp (with microseconds), number of matched/affected/warnings rows
- * and fields of session variables: SQL_MODE,
- * FOREIGN_KEY_CHECKS, UNIQUE_CHECKS, SQL_AUTO_IS_NULL, the collations and
- * charsets, the PASSWORD() version (old/new/...).
+ * timestamp (with microseconds), number of matched/affected/warnings rows
+ * and fields of session variables: SQL_MODE, FOREIGN_KEY_CHECKS,
+ * UNIQUE_CHECKS, SQL_AUTO_IS_NULL, the collations and charsets, the
+ * PASSWORD() version (old/new/...).
*/
- public static final int BINLOG_VERSION = 4;
+ public static final int BINLOG_VERSION = 4;
/* Default 5.0 server version */
- public static final String SERVER_VERSION = "5.0";
+ public static final String SERVER_VERSION = "5.0";
/**
* Event header offsets; these point to places inside the fixed header.
*/
- public static final int EVENT_TYPE_OFFSET = 4;
- public static final int SERVER_ID_OFFSET = 5;
- public static final int EVENT_LEN_OFFSET = 9;
- public static final int LOG_POS_OFFSET = 13;
- public static final int FLAGS_OFFSET = 17;
+ public static final int EVENT_TYPE_OFFSET = 4;
+ public static final int SERVER_ID_OFFSET = 5;
+ public static final int EVENT_LEN_OFFSET = 9;
+ public static final int LOG_POS_OFFSET = 13;
+ public static final int FLAGS_OFFSET = 17;
/* event-specific post-header sizes */
// where 3.23, 4.x and 5.0 agree
- public static final int QUERY_HEADER_MINIMAL_LEN = (4 + 4 + 1 + 2);
+ public static final int QUERY_HEADER_MINIMAL_LEN = (4 + 4 + 1 + 2);
// where 5.0 differs: 2 for len of N-bytes vars.
- public static final int QUERY_HEADER_LEN = (QUERY_HEADER_MINIMAL_LEN + 2);
+ public static final int QUERY_HEADER_LEN = (QUERY_HEADER_MINIMAL_LEN + 2);
/* Enumeration type for the different types of log events. */
- public static final int UNKNOWN_EVENT = 0;
- public static final int START_EVENT_V3 = 1;
- public static final int QUERY_EVENT = 2;
- public static final int STOP_EVENT = 3;
- public static final int ROTATE_EVENT = 4;
- public static final int INTVAR_EVENT = 5;
- public static final int LOAD_EVENT = 6;
- public static final int SLAVE_EVENT = 7;
- public static final int CREATE_FILE_EVENT = 8;
- public static final int APPEND_BLOCK_EVENT = 9;
- public static final int EXEC_LOAD_EVENT = 10;
- public static final int DELETE_FILE_EVENT = 11;
+ public static final int UNKNOWN_EVENT = 0;
+ public static final int START_EVENT_V3 = 1;
+ public static final int QUERY_EVENT = 2;
+ public static final int STOP_EVENT = 3;
+ public static final int ROTATE_EVENT = 4;
+ public static final int INTVAR_EVENT = 5;
+ public static final int LOAD_EVENT = 6;
+ public static final int SLAVE_EVENT = 7;
+ public static final int CREATE_FILE_EVENT = 8;
+ public static final int APPEND_BLOCK_EVENT = 9;
+ public static final int EXEC_LOAD_EVENT = 10;
+ public static final int DELETE_FILE_EVENT = 11;
/**
* NEW_LOAD_EVENT is like LOAD_EVENT except that it has a longer sql_ex,
* allowing multibyte TERMINATED BY etc; both types share the same class
* (Load_log_event)
*/
- public static final int NEW_LOAD_EVENT = 12;
- public static final int RAND_EVENT = 13;
- public static final int USER_VAR_EVENT = 14;
- public static final int FORMAT_DESCRIPTION_EVENT = 15;
- public static final int XID_EVENT = 16;
- public static final int BEGIN_LOAD_QUERY_EVENT = 17;
- public static final int EXECUTE_LOAD_QUERY_EVENT = 18;
+ public static final int NEW_LOAD_EVENT = 12;
+ public static final int RAND_EVENT = 13;
+ public static final int USER_VAR_EVENT = 14;
+ public static final int FORMAT_DESCRIPTION_EVENT = 15;
+ public static final int XID_EVENT = 16;
+ public static final int BEGIN_LOAD_QUERY_EVENT = 17;
+ public static final int EXECUTE_LOAD_QUERY_EVENT = 18;
- public static final int TABLE_MAP_EVENT = 19;
+ public static final int TABLE_MAP_EVENT = 19;
/**
* These event numbers were used for 5.1.0 to 5.1.15 and are therefore
* obsolete.
*/
- public static final int PRE_GA_WRITE_ROWS_EVENT = 20;
- public static final int PRE_GA_UPDATE_ROWS_EVENT = 21;
- public static final int PRE_GA_DELETE_ROWS_EVENT = 22;
+ public static final int PRE_GA_WRITE_ROWS_EVENT = 20;
+ public static final int PRE_GA_UPDATE_ROWS_EVENT = 21;
+ public static final int PRE_GA_DELETE_ROWS_EVENT = 22;
/**
* These event numbers are used from 5.1.16 and forward
*/
- public static final int WRITE_ROWS_EVENT_V1 = 23;
- public static final int UPDATE_ROWS_EVENT_V1 = 24;
- public static final int DELETE_ROWS_EVENT_V1 = 25;
+ public static final int WRITE_ROWS_EVENT_V1 = 23;
+ public static final int UPDATE_ROWS_EVENT_V1 = 24;
+ public static final int DELETE_ROWS_EVENT_V1 = 25;
/**
* Something out of the ordinary happened on the master
*/
- public static final int INCIDENT_EVENT = 26;
+ public static final int INCIDENT_EVENT = 26;
/**
- * Heartbeat event to be send by master at its idle time to ensure master's online status to slave
+ * Heartbeat event to be send by master at its idle time to ensure master's
+ * online status to slave
*/
- public static final int HEARTBEAT_LOG_EVENT = 27;
+ public static final int HEARTBEAT_LOG_EVENT = 27;
/**
- * In some situations, it is necessary to send over ignorable data to the slave: data that a slave can handle in
- * case there is code for handling it, but which can be ignored if it is not recognized.
+ * In some situations, it is necessary to send over ignorable data to the
+ * slave: data that a slave can handle in case there is code for handling
+ * it, but which can be ignored if it is not recognized.
*/
- public static final int IGNORABLE_LOG_EVENT = 28;
- public static final int ROWS_QUERY_LOG_EVENT = 29;
+ public static final int IGNORABLE_LOG_EVENT = 28;
+ public static final int ROWS_QUERY_LOG_EVENT = 29;
/** Version 2 of the Row events */
- public static final int WRITE_ROWS_EVENT = 30;
- public static final int UPDATE_ROWS_EVENT = 31;
- public static final int DELETE_ROWS_EVENT = 32;
+ public static final int WRITE_ROWS_EVENT = 30;
+ public static final int UPDATE_ROWS_EVENT = 31;
+ public static final int DELETE_ROWS_EVENT = 32;
- public static final int GTID_LOG_EVENT = 33;
- public static final int ANONYMOUS_GTID_LOG_EVENT = 34;
+ public static final int GTID_LOG_EVENT = 33;
+ public static final int ANONYMOUS_GTID_LOG_EVENT = 34;
+
+ public static final int PREVIOUS_GTIDS_LOG_EVENT = 35;
- public static final int PREVIOUS_GTIDS_LOG_EVENT = 35;
-
// mariaDb 5.5.34
/* New MySQL/Sun events are to be added right above this comment */
- public static final int MYSQL_EVENTS_END = 36;
+ public static final int MYSQL_EVENTS_END = 36;
- public static final int MARIA_EVENTS_BEGIN = 160;
+ public static final int MARIA_EVENTS_BEGIN = 160;
/* New Maria event numbers start from here */
- public static final int ANNOTATE_ROWS_EVENT = 160;
+ public static final int ANNOTATE_ROWS_EVENT = 160;
/*
- Binlog checkpoint event. Used for XA crash recovery on the master, not used
- in replication.
- A binlog checkpoint event specifies a binlog file such that XA crash
- recovery can start from that file - and it is guaranteed to find all XIDs
- that are prepared in storage engines but not yet committed.
+ * Binlog checkpoint event. Used for XA crash recovery on the master, not
+ * used in replication. A binlog checkpoint event specifies a binlog file
+ * such that XA crash recovery can start from that file - and it is
+ * guaranteed to find all XIDs that are prepared in storage engines but not
+ * yet committed.
*/
- public static final int BINLOG_CHECKPOINT_EVENT = 161;
+ public static final int BINLOG_CHECKPOINT_EVENT = 161;
/*
- Gtid event. For global transaction ID, used to start a new event group,
- instead of the old BEGIN query event, and also to mark stand-alone
- events.
+ * Gtid event. For global transaction ID, used to start a new event group,
+ * instead of the old BEGIN query event, and also to mark stand-alone
+ * events.
*/
- public static final int GTID_EVENT = 162;
+ public static final int GTID_EVENT = 162;
/*
- Gtid list event. Logged at the start of every binlog, to record the
- current replication state. This consists of the last GTID seen for
- each replication domain.
+ * Gtid list event. Logged at the start of every binlog, to record the
+ * current replication state. This consists of the last GTID seen for each
+ * replication domain.
*/
- public static final int GTID_LIST_EVENT = 163;
+ public static final int GTID_LIST_EVENT = 163;
/** end marker */
- public static final int ENUM_END_EVENT = 164;
+ public static final int ENUM_END_EVENT = 164;
/**
- 1 byte length, 1 byte format
- Length is total length in bytes, including 2 byte header
- Length values 0 and 1 are currently invalid and reserved.
- */
- public static final int EXTRA_ROW_INFO_LEN_OFFSET = 0;
- public static final int EXTRA_ROW_INFO_FORMAT_OFFSET = 1;
- public static final int EXTRA_ROW_INFO_HDR_BYTES = 2;
- public static final int EXTRA_ROW_INFO_MAX_PAYLOAD = (255 - EXTRA_ROW_INFO_HDR_BYTES);
-
+ * 1 byte length, 1 byte format Length is total length in bytes, including 2
+ * byte header Length values 0 and 1 are currently invalid and reserved.
+ */
+ public static final int EXTRA_ROW_INFO_LEN_OFFSET = 0;
+ public static final int EXTRA_ROW_INFO_FORMAT_OFFSET = 1;
+ public static final int EXTRA_ROW_INFO_HDR_BYTES = 2;
+ public static final int EXTRA_ROW_INFO_MAX_PAYLOAD = (255 - EXTRA_ROW_INFO_HDR_BYTES);
+
// Events are without checksum though its generator
- public static final int BINLOG_CHECKSUM_ALG_OFF = 0;
+ public static final int BINLOG_CHECKSUM_ALG_OFF = 0;
// is checksum-capable New Master (NM).
// CRC32 of zlib algorithm.
- public static final int BINLOG_CHECKSUM_ALG_CRC32 = 1;
+ public static final int BINLOG_CHECKSUM_ALG_CRC32 = 1;
// the cut line: valid alg range is [1, 0x7f].
- public static final int BINLOG_CHECKSUM_ALG_ENUM_END = 2;
+ public static final int BINLOG_CHECKSUM_ALG_ENUM_END = 2;
// special value to tag undetermined yet checksum
- public static final int BINLOG_CHECKSUM_ALG_UNDEF = 255;
+ public static final int BINLOG_CHECKSUM_ALG_UNDEF = 255;
// or events from checksum-unaware servers
- public static final int CHECKSUM_CRC32_SIGNATURE_LEN = 4;
- public static final int BINLOG_CHECKSUM_ALG_DESC_LEN = 1;
+ public static final int CHECKSUM_CRC32_SIGNATURE_LEN = 4;
+ public static final int BINLOG_CHECKSUM_ALG_DESC_LEN = 1;
/**
* defined statically while there is just one alg implemented
*/
- public static final int BINLOG_CHECKSUM_LEN = CHECKSUM_CRC32_SIGNATURE_LEN;
-
+ public static final int BINLOG_CHECKSUM_LEN = CHECKSUM_CRC32_SIGNATURE_LEN;
+
/* MySQL or old MariaDB slave with no announced capability. */
public static final int MARIA_SLAVE_CAPABILITY_UNKNOWN = 0;
@@ -258,124 +237,121 @@ public abstract class LogEvent
/* Our capability. */
public static final int MARIA_SLAVE_CAPABILITY_MINE = MARIA_SLAVE_CAPABILITY_GTID;
-
- /**
- For an event, 'e', carrying a type code, that a slave,
- 's', does not recognize, 's' will check 'e' for
- LOG_EVENT_IGNORABLE_F, and if the flag is set, then 'e'
- is ignored. Otherwise, 's' acknowledges that it has
- found an unknown event in the relay log.
- */
- public static final int LOG_EVENT_IGNORABLE_F = 0x80;
-
- /** enum_field_types */
- public static final int MYSQL_TYPE_DECIMAL = 0;
- public static final int MYSQL_TYPE_TINY = 1;
- public static final int MYSQL_TYPE_SHORT = 2;
- public static final int MYSQL_TYPE_LONG = 3;
- public static final int MYSQL_TYPE_FLOAT = 4;
- public static final int MYSQL_TYPE_DOUBLE = 5;
- public static final int MYSQL_TYPE_NULL = 6;
- public static final int MYSQL_TYPE_TIMESTAMP = 7;
- public static final int MYSQL_TYPE_LONGLONG = 8;
- public static final int MYSQL_TYPE_INT24 = 9;
- public static final int MYSQL_TYPE_DATE = 10;
- public static final int MYSQL_TYPE_TIME = 11;
- public static final int MYSQL_TYPE_DATETIME = 12;
- public static final int MYSQL_TYPE_YEAR = 13;
- public static final int MYSQL_TYPE_NEWDATE = 14;
- public static final int MYSQL_TYPE_VARCHAR = 15;
- public static final int MYSQL_TYPE_BIT = 16;
- public static final int MYSQL_TYPE_TIMESTAMP2 = 17;
- public static final int MYSQL_TYPE_DATETIME2 = 18;
- public static final int MYSQL_TYPE_TIME2 = 19;
- public static final int MYSQL_TYPE_NEWDECIMAL = 246;
- public static final int MYSQL_TYPE_ENUM = 247;
- public static final int MYSQL_TYPE_SET = 248;
- public static final int MYSQL_TYPE_TINY_BLOB = 249;
- public static final int MYSQL_TYPE_MEDIUM_BLOB = 250;
- public static final int MYSQL_TYPE_LONG_BLOB = 251;
- public static final int MYSQL_TYPE_BLOB = 252;
- public static final int MYSQL_TYPE_VAR_STRING = 253;
- public static final int MYSQL_TYPE_STRING = 254;
- public static final int MYSQL_TYPE_GEOMETRY = 255;
- public static String getTypeName(final int type)
- {
- switch (type)
- {
- case START_EVENT_V3:
- return "Start_v3";
- case STOP_EVENT:
- return "Stop";
- case QUERY_EVENT:
- return "Query";
- case ROTATE_EVENT:
- return "Rotate";
- case INTVAR_EVENT:
- return "Intvar";
- case LOAD_EVENT:
- return "Load";
- case NEW_LOAD_EVENT:
- return "New_load";
- case SLAVE_EVENT:
- return "Slave";
- case CREATE_FILE_EVENT:
- return "Create_file";
- case APPEND_BLOCK_EVENT:
- return "Append_block";
- case DELETE_FILE_EVENT:
- return "Delete_file";
- case EXEC_LOAD_EVENT:
- return "Exec_load";
- case RAND_EVENT:
- return "RAND";
- case XID_EVENT:
- return "Xid";
- case USER_VAR_EVENT:
- return "User var";
- case FORMAT_DESCRIPTION_EVENT:
- return "Format_desc";
- case TABLE_MAP_EVENT:
- return "Table_map";
- case PRE_GA_WRITE_ROWS_EVENT:
- return "Write_rows_event_old";
- case PRE_GA_UPDATE_ROWS_EVENT:
- return "Update_rows_event_old";
- case PRE_GA_DELETE_ROWS_EVENT:
- return "Delete_rows_event_old";
- case WRITE_ROWS_EVENT_V1:
- return "Write_rows_v1";
- case UPDATE_ROWS_EVENT_V1:
- return "Update_rows_v1";
- case DELETE_ROWS_EVENT_V1:
- return "Delete_rows_v1";
- case BEGIN_LOAD_QUERY_EVENT:
- return "Begin_load_query";
- case EXECUTE_LOAD_QUERY_EVENT:
- return "Execute_load_query";
- case INCIDENT_EVENT:
- return "Incident";
- case HEARTBEAT_LOG_EVENT:
- return "Heartbeat";
- case IGNORABLE_LOG_EVENT:
- return "Ignorable";
- case ROWS_QUERY_LOG_EVENT:
- return "Rows_query";
- case WRITE_ROWS_EVENT:
- return "Write_rows";
- case UPDATE_ROWS_EVENT:
- return "Update_rows";
- case DELETE_ROWS_EVENT:
- return "Delete_rows";
- case GTID_LOG_EVENT:
- return "Gtid";
- case ANONYMOUS_GTID_LOG_EVENT:
- return "Anonymous_Gtid";
- case PREVIOUS_GTIDS_LOG_EVENT:
- return "Previous_gtids";
- default:
- return "Unknown"; /* impossible */
+ /**
+ * For an event, 'e', carrying a type code, that a slave, 's', does not
+ * recognize, 's' will check 'e' for LOG_EVENT_IGNORABLE_F, and if the flag
+ * is set, then 'e' is ignored. Otherwise, 's' acknowledges that it has
+ * found an unknown event in the relay log.
+ */
+ public static final int LOG_EVENT_IGNORABLE_F = 0x80;
+
+ /** enum_field_types */
+ public static final int MYSQL_TYPE_DECIMAL = 0;
+ public static final int MYSQL_TYPE_TINY = 1;
+ public static final int MYSQL_TYPE_SHORT = 2;
+ public static final int MYSQL_TYPE_LONG = 3;
+ public static final int MYSQL_TYPE_FLOAT = 4;
+ public static final int MYSQL_TYPE_DOUBLE = 5;
+ public static final int MYSQL_TYPE_NULL = 6;
+ public static final int MYSQL_TYPE_TIMESTAMP = 7;
+ public static final int MYSQL_TYPE_LONGLONG = 8;
+ public static final int MYSQL_TYPE_INT24 = 9;
+ public static final int MYSQL_TYPE_DATE = 10;
+ public static final int MYSQL_TYPE_TIME = 11;
+ public static final int MYSQL_TYPE_DATETIME = 12;
+ public static final int MYSQL_TYPE_YEAR = 13;
+ public static final int MYSQL_TYPE_NEWDATE = 14;
+ public static final int MYSQL_TYPE_VARCHAR = 15;
+ public static final int MYSQL_TYPE_BIT = 16;
+ public static final int MYSQL_TYPE_TIMESTAMP2 = 17;
+ public static final int MYSQL_TYPE_DATETIME2 = 18;
+ public static final int MYSQL_TYPE_TIME2 = 19;
+ public static final int MYSQL_TYPE_NEWDECIMAL = 246;
+ public static final int MYSQL_TYPE_ENUM = 247;
+ public static final int MYSQL_TYPE_SET = 248;
+ public static final int MYSQL_TYPE_TINY_BLOB = 249;
+ public static final int MYSQL_TYPE_MEDIUM_BLOB = 250;
+ public static final int MYSQL_TYPE_LONG_BLOB = 251;
+ public static final int MYSQL_TYPE_BLOB = 252;
+ public static final int MYSQL_TYPE_VAR_STRING = 253;
+ public static final int MYSQL_TYPE_STRING = 254;
+ public static final int MYSQL_TYPE_GEOMETRY = 255;
+
+ public static String getTypeName(final int type) {
+ switch (type) {
+ case START_EVENT_V3:
+ return "Start_v3";
+ case STOP_EVENT:
+ return "Stop";
+ case QUERY_EVENT:
+ return "Query";
+ case ROTATE_EVENT:
+ return "Rotate";
+ case INTVAR_EVENT:
+ return "Intvar";
+ case LOAD_EVENT:
+ return "Load";
+ case NEW_LOAD_EVENT:
+ return "New_load";
+ case SLAVE_EVENT:
+ return "Slave";
+ case CREATE_FILE_EVENT:
+ return "Create_file";
+ case APPEND_BLOCK_EVENT:
+ return "Append_block";
+ case DELETE_FILE_EVENT:
+ return "Delete_file";
+ case EXEC_LOAD_EVENT:
+ return "Exec_load";
+ case RAND_EVENT:
+ return "RAND";
+ case XID_EVENT:
+ return "Xid";
+ case USER_VAR_EVENT:
+ return "User var";
+ case FORMAT_DESCRIPTION_EVENT:
+ return "Format_desc";
+ case TABLE_MAP_EVENT:
+ return "Table_map";
+ case PRE_GA_WRITE_ROWS_EVENT:
+ return "Write_rows_event_old";
+ case PRE_GA_UPDATE_ROWS_EVENT:
+ return "Update_rows_event_old";
+ case PRE_GA_DELETE_ROWS_EVENT:
+ return "Delete_rows_event_old";
+ case WRITE_ROWS_EVENT_V1:
+ return "Write_rows_v1";
+ case UPDATE_ROWS_EVENT_V1:
+ return "Update_rows_v1";
+ case DELETE_ROWS_EVENT_V1:
+ return "Delete_rows_v1";
+ case BEGIN_LOAD_QUERY_EVENT:
+ return "Begin_load_query";
+ case EXECUTE_LOAD_QUERY_EVENT:
+ return "Execute_load_query";
+ case INCIDENT_EVENT:
+ return "Incident";
+ case HEARTBEAT_LOG_EVENT:
+ return "Heartbeat";
+ case IGNORABLE_LOG_EVENT:
+ return "Ignorable";
+ case ROWS_QUERY_LOG_EVENT:
+ return "Rows_query";
+ case WRITE_ROWS_EVENT:
+ return "Write_rows";
+ case UPDATE_ROWS_EVENT:
+ return "Update_rows";
+ case DELETE_ROWS_EVENT:
+ return "Delete_rows";
+ case GTID_LOG_EVENT:
+ return "Gtid";
+ case ANONYMOUS_GTID_LOG_EVENT:
+ return "Anonymous_Gtid";
+ case PREVIOUS_GTIDS_LOG_EVENT:
+ return "Previous_gtids";
+ default:
+ return "Unknown"; /* impossible */
}
}
@@ -383,16 +359,14 @@ public abstract class LogEvent
protected final LogHeader header;
- protected LogEvent(LogHeader header)
- {
+ protected LogEvent(LogHeader header){
this.header = header;
}
/**
* Return event header.
*/
- public final LogHeader getHeader()
- {
+ public final LogHeader getHeader() {
return header;
}
@@ -400,16 +374,14 @@ public abstract class LogEvent
* The total size of this event, in bytes. In other words, this is the sum
* of the sizes of Common-Header, Post-Header, and Body.
*/
- public final int getEventLen()
- {
+ public final int getEventLen() {
return header.getEventLen();
}
/**
* Server ID of the server that created the event.
*/
- public final long getServerId()
- {
+ public final long getServerId() {
return header.getServerId();
}
@@ -420,18 +392,15 @@ public abstract class LogEvent
* file. In a relay log, this is the position of the next event in the
* master's binlog.
*/
- public final long getLogPos()
- {
+ public final long getLogPos() {
return header.getLogPos();
}
/**
* The time when the query started, in seconds since 1970.
*/
- public final long getWhen()
- {
+ public final long getWhen() {
return header.getWhen();
}
-
-
+
}
diff --git a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/LogFetcher.java b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/LogFetcher.java
index aca10a33..9558d862 100644
--- a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/LogFetcher.java
+++ b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/LogFetcher.java
@@ -29,8 +29,8 @@ import java.util.Arrays;
* @author Changyuan.lh
* @version 1.0
*/
-public abstract class LogFetcher extends LogBuffer implements Closeable
-{
+public abstract class LogFetcher extends LogBuffer implements Closeable {
+
/** Default initial capacity. */
public static final int DEFAULT_INITIAL_CAPACITY = 8192;
@@ -42,18 +42,15 @@ public abstract class LogFetcher extends LogBuffer implements Closeable
protected final float factor;
- public LogFetcher()
- {
+ public LogFetcher(){
this(DEFAULT_INITIAL_CAPACITY, DEFAULT_GROWTH_FACTOR);
}
- public LogFetcher(final int initialCapacity)
- {
+ public LogFetcher(final int initialCapacity){
this(initialCapacity, DEFAULT_GROWTH_FACTOR);
}
- public LogFetcher(final int initialCapacity, final float growthFactor)
- {
+ public LogFetcher(final int initialCapacity, final float growthFactor){
this.buffer = new byte[initialCapacity];
this.factor = growthFactor;
}
@@ -65,15 +62,12 @@ public abstract class LogFetcher extends LogBuffer implements Closeable
*
* @param minCapacity the desired minimum capacity
*/
- protected final void ensureCapacity(final int minCapacity)
- {
+ protected final void ensureCapacity(final int minCapacity) {
final int oldCapacity = buffer.length;
- if (minCapacity > oldCapacity)
- {
+ if (minCapacity > oldCapacity) {
int newCapacity = (int) (oldCapacity * factor);
- if (newCapacity < minCapacity)
- newCapacity = minCapacity;
+ if (newCapacity < minCapacity) newCapacity = minCapacity;
buffer = Arrays.copyOf(buffer, newCapacity);
}
diff --git a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/LogPosition.java b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/LogPosition.java
index 1661e22a..83dfc8db 100644
--- a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/LogPosition.java
+++ b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/LogPosition.java
@@ -6,8 +6,8 @@ package com.taobao.tddl.dbsync.binlog;
* @author Changyuan.lh
* @version 1.0
*/
-public class LogPosition implements Cloneable, Comparable
-{
+public class LogPosition implements Cloneable, Comparable {
+
/* binlog file's name */
protected String fileName;
@@ -19,8 +19,7 @@ public class LogPosition implements Cloneable, Comparable
*
* @param fileName file name for binlog files: mysql-bin.000001
*/
- public LogPosition(String fileName)
- {
+ public LogPosition(String fileName){
this.fileName = fileName;
this.position = 0L;
}
@@ -30,8 +29,7 @@ public class LogPosition implements Cloneable, Comparable
*
* @param fileName file name for binlog files: mysql-bin.000001
*/
- public LogPosition(String fileName, final long position)
- {
+ public LogPosition(String fileName, final long position){
this.fileName = fileName;
this.position = position;
}
@@ -39,31 +37,24 @@ public class LogPosition implements Cloneable, Comparable
/**
* Binlog position copy init.
*/
- public LogPosition(LogPosition source)
- {
+ public LogPosition(LogPosition source){
this.fileName = source.fileName;
this.position = source.position;
}
- public final String getFileName()
- {
+ public final String getFileName() {
return fileName;
}
- public final long getPosition()
- {
+ public final long getPosition() {
return position;
}
/* Clone binlog position without CloneNotSupportedException */
- public LogPosition clone()
- {
- try
- {
+ public LogPosition clone() {
+ try {
return (LogPosition) super.clone();
- }
- catch (CloneNotSupportedException e)
- {
+ } catch (CloneNotSupportedException e) {
// Never happend
return null;
}
@@ -72,12 +63,10 @@ public class LogPosition implements Cloneable, Comparable
/**
* Compares with the specified fileName and position.
*/
- public final int compareTo(String fileName, final long position)
- {
+ public final int compareTo(String fileName, final long position) {
final int val = this.fileName.compareTo(fileName);
- if (val == 0)
- {
+ if (val == 0) {
return (int) (this.position - position);
}
return val;
@@ -88,12 +77,10 @@ public class LogPosition implements Cloneable, Comparable
*
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
- public int compareTo(LogPosition o)
- {
+ public int compareTo(LogPosition o) {
final int val = fileName.compareTo(o.fileName);
- if (val == 0)
- {
+ if (val == 0) {
return (int) (position - o.position);
}
return val;
@@ -104,13 +91,10 @@ public class LogPosition implements Cloneable, Comparable
*
* @see java.lang.Object#equals(java.lang.Object)
*/
- public boolean equals(Object obj)
- {
- if (obj instanceof LogPosition)
- {
+ public boolean equals(Object obj) {
+ if (obj instanceof LogPosition) {
LogPosition pos = ((LogPosition) obj);
- return fileName.equals(pos.fileName)
- && (this.position == pos.position);
+ return fileName.equals(pos.fileName) && (this.position == pos.position);
}
return false;
}
@@ -120,8 +104,7 @@ public class LogPosition implements Cloneable, Comparable
*
* @see java.lang.Object#toString()
*/
- public String toString()
- {
+ public String toString() {
return fileName + ':' + position;
}
}
diff --git a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/AppendBlockLogEvent.java b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/AppendBlockLogEvent.java
index 4e459805..d0e7085d 100644
--- a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/AppendBlockLogEvent.java
+++ b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/AppendBlockLogEvent.java
@@ -9,8 +9,8 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* @author Changyuan.lh
* @version 1.0
*/
-public class AppendBlockLogEvent extends LogEvent
-{
+public class AppendBlockLogEvent extends LogEvent {
+
private final LogBuffer blockBuf;
private final int blockLen;
@@ -19,9 +19,7 @@ public class AppendBlockLogEvent extends LogEvent
/* AB = "Append Block" */
public static final int AB_FILE_ID_OFFSET = 0;
- public AppendBlockLogEvent(LogHeader header, LogBuffer buffer,
- FormatDescriptionLogEvent descriptionEvent)
- {
+ public AppendBlockLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){
super(header);
final int commonHeaderLen = descriptionEvent.commonHeaderLen;
@@ -36,18 +34,15 @@ public class AppendBlockLogEvent extends LogEvent
blockBuf = buffer.duplicate(blockLen);
}
- public final long getFileId()
- {
+ public final long getFileId() {
return fileId;
}
- public final LogBuffer getBuffer()
- {
+ public final LogBuffer getBuffer() {
return blockBuf;
}
- public final byte[] getData()
- {
+ public final byte[] getData() {
return blockBuf.getData();
}
}
diff --git a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/BeginLoadQueryLogEvent.java b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/BeginLoadQueryLogEvent.java
index df390862..35e461f2 100644
--- a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/BeginLoadQueryLogEvent.java
+++ b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/BeginLoadQueryLogEvent.java
@@ -10,11 +10,9 @@ import com.taobao.tddl.dbsync.binlog.LogBuffer;
* @author Changyuan.lh
* @version 1.0
*/
-public final class BeginLoadQueryLogEvent extends AppendBlockLogEvent
-{
- public BeginLoadQueryLogEvent(LogHeader header, LogBuffer buffer,
- FormatDescriptionLogEvent descriptionEvent)
- {
+public final class BeginLoadQueryLogEvent extends AppendBlockLogEvent {
+
+ public BeginLoadQueryLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){
super(header, buffer, descriptionEvent);
}
}
diff --git a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/CreateFileLogEvent.java b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/CreateFileLogEvent.java
index 3d5accba..ffd967a2 100644
--- a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/CreateFileLogEvent.java
+++ b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/CreateFileLogEvent.java
@@ -8,8 +8,8 @@ import com.taobao.tddl.dbsync.binlog.LogBuffer;
* @author Changyuan.lh
* @version 1.0
*/
-public final class CreateFileLogEvent extends LoadLogEvent
-{
+public final class CreateFileLogEvent extends LoadLogEvent {
+
protected LogBuffer blockBuf;
protected int blockLen;
protected long fileId;
@@ -20,9 +20,7 @@ public final class CreateFileLogEvent extends LoadLogEvent
public static final int CF_FILE_ID_OFFSET = 0;
public static final int CF_DATA_OFFSET = FormatDescriptionLogEvent.CREATE_FILE_HEADER_LEN;
- public CreateFileLogEvent(LogHeader header, LogBuffer buffer,
- FormatDescriptionLogEvent descriptionEvent)
- {
+ public CreateFileLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){
super(header, buffer, descriptionEvent);
final int headerLen = descriptionEvent.commonHeaderLen;
@@ -30,44 +28,37 @@ public final class CreateFileLogEvent extends LoadLogEvent
final int createFileHeaderLen = descriptionEvent.postHeaderLen[CREATE_FILE_EVENT - 1];
copyLogEvent(buffer,
- ((header.type == LOAD_EVENT) ? (loadHeaderLen + headerLen)
- : (headerLen + loadHeaderLen + createFileHeaderLen)),
- descriptionEvent);
+ ((header.type == LOAD_EVENT) ? (loadHeaderLen + headerLen) : (headerLen + loadHeaderLen + createFileHeaderLen)),
+ descriptionEvent);
- if (descriptionEvent.binlogVersion != 1)
- {
- fileId = buffer.getUint32(headerLen + loadHeaderLen
- + CF_FILE_ID_OFFSET);
+ if (descriptionEvent.binlogVersion != 1) {
+ fileId = buffer.getUint32(headerLen + loadHeaderLen + CF_FILE_ID_OFFSET);
/*
- Note that it's ok to use get_data_size() below, because it is computed
- with values we have already read from this event (because we called
- copy_log_event()); we are not using slave's format info to decode
- master's format, we are really using master's format info.
- Anyway, both formats should be identical (except the common_header_len)
- as these Load events are not changed between 4.0 and 5.0 (as logging of
- LOAD DATA INFILE does not use Load_log_event in 5.0).
- */
+ * Note that it's ok to use get_data_size() below, because it is
+ * computed with values we have already read from this event
+ * (because we called copy_log_event()); we are not using slave's
+ * format info to decode master's format, we are really using
+ * master's format info. Anyway, both formats should be identical
+ * (except the common_header_len) as these Load events are not
+ * changed between 4.0 and 5.0 (as logging of LOAD DATA INFILE does
+ * not use Load_log_event in 5.0).
+ */
blockLen = buffer.limit() - buffer.position();
blockBuf = buffer.duplicate(blockLen);
- }
- else
- {
+ } else {
initedFromOld = true;
}
}
- public final long getFileId()
- {
+ public final long getFileId() {
return fileId;
}
- public final LogBuffer getBuffer()
- {
+ public final LogBuffer getBuffer() {
return blockBuf;
}
- public final byte[] getData()
- {
+ public final byte[] getData() {
return blockBuf.getData();
}
}
diff --git a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/DeleteFileLogEvent.java b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/DeleteFileLogEvent.java
index 0fe3bae8..86a7ba5c 100644
--- a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/DeleteFileLogEvent.java
+++ b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/DeleteFileLogEvent.java
@@ -9,25 +9,22 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* @author Changyuan.lh
* @version 1.0
*/
-public final class DeleteFileLogEvent extends LogEvent
-{
+public final class DeleteFileLogEvent extends LogEvent {
+
private final long fileId;
/* DF = "Delete File" */
public static final int DF_FILE_ID_OFFSET = 0;
- public DeleteFileLogEvent(LogHeader header, LogBuffer buffer,
- FormatDescriptionLogEvent descriptionEvent)
- {
+ public DeleteFileLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){
super(header);
final int commonHeaderLen = descriptionEvent.commonHeaderLen;
buffer.position(commonHeaderLen + DF_FILE_ID_OFFSET);
- fileId = buffer.getUint32(); // DF_FILE_ID_OFFSET
+ fileId = buffer.getUint32(); // DF_FILE_ID_OFFSET
}
- public final long getFileId()
- {
+ public final long getFileId() {
return fileId;
}
}
diff --git a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/DeleteRowsLogEvent.java b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/DeleteRowsLogEvent.java
index 01983d27..4f06a97b 100644
--- a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/DeleteRowsLogEvent.java
+++ b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/DeleteRowsLogEvent.java
@@ -9,11 +9,9 @@ import com.taobao.tddl.dbsync.binlog.LogBuffer;
* @author Changyuan.lh
* @version 1.0
*/
-public final class DeleteRowsLogEvent extends RowsLogEvent
-{
- public DeleteRowsLogEvent(LogHeader header, LogBuffer buffer,
- FormatDescriptionLogEvent descriptionEvent)
- {
+public final class DeleteRowsLogEvent extends RowsLogEvent {
+
+ public DeleteRowsLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){
super(header, buffer, descriptionEvent);
}
}
diff --git a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/ExecuteLoadLogEvent.java b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/ExecuteLoadLogEvent.java
index 664b51a6..b4f36e61 100644
--- a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/ExecuteLoadLogEvent.java
+++ b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/ExecuteLoadLogEvent.java
@@ -9,25 +9,22 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
* @author Changyuan.lh
* @version 1.0
*/
-public final class ExecuteLoadLogEvent extends LogEvent
-{
+public final class ExecuteLoadLogEvent extends LogEvent {
+
private final long fileId;
/* EL = "Execute Load" */
public static final int EL_FILE_ID_OFFSET = 0;
- public ExecuteLoadLogEvent(LogHeader header, LogBuffer buffer,
- FormatDescriptionLogEvent descriptionEvent)
- {
+ public ExecuteLoadLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){
super(header);
final int commonHeaderLen = descriptionEvent.commonHeaderLen;
buffer.position(commonHeaderLen + EL_FILE_ID_OFFSET);
- fileId = buffer.getUint32(); // EL_FILE_ID_OFFSET
+ fileId = buffer.getUint32(); // EL_FILE_ID_OFFSET
}
- public final long getFileId()
- {
+ public final long getFileId() {
return fileId;
}
}
diff --git a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/ExecuteLoadQueryLogEvent.java b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/ExecuteLoadQueryLogEvent.java
index 6a9e0f7e..6b8481a4 100644
--- a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/ExecuteLoadQueryLogEvent.java
+++ b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/ExecuteLoadQueryLogEvent.java
@@ -8,7 +8,6 @@ import com.taobao.tddl.dbsync.binlog.LogBuffer;
* Event responsible for LOAD DATA execution, it similar to Query_log_event but
* before executing the query it substitutes original filename in LOAD DATA
* query with name of temporary file.
- *
*
* - 4 bytes. The ID of the file to load.
* - 4 bytes. The start position within the statement for filename
@@ -22,8 +21,8 @@ import com.taobao.tddl.dbsync.binlog.LogBuffer;
* @author Changyuan.lh
* @version 1.0
*/
-public final class ExecuteLoadQueryLogEvent extends QueryLogEvent
-{
+public final class ExecuteLoadQueryLogEvent extends QueryLogEvent {
+
/** file_id of temporary file */
private long fileId;
@@ -53,9 +52,8 @@ public final class ExecuteLoadQueryLogEvent extends QueryLogEvent
public static final int ELQ_FN_POS_END_OFFSET = ELQ_FILE_ID_OFFSET + 8;
public static final int ELQ_DUP_HANDLING_OFFSET = ELQ_FILE_ID_OFFSET + 12;
- public ExecuteLoadQueryLogEvent(LogHeader header, LogBuffer buffer,
- FormatDescriptionLogEvent descriptionEvent) throws IOException
- {
+ public ExecuteLoadQueryLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent)
+ throws IOException{
super(header, buffer, descriptionEvent);
buffer.position(descriptionEvent.commonHeaderLen + ELQ_FILE_ID_OFFSET);
@@ -66,36 +64,27 @@ public final class ExecuteLoadQueryLogEvent extends QueryLogEvent
dupHandling = buffer.getInt8(); // ELQ_DUP_HANDLING_OFFSET
final int len = query.length();
- if (fnPosStart > len || fnPosEnd > len
- || dupHandling > LOAD_DUP_REPLACE)
- {
- throw new IOException(String.format(
- "Invalid ExecuteLoadQueryLogEvent: fn_pos_start=%d, "
- + "fn_pos_end=%d, dup_handling=%d", fnPosStart,
- fnPosEnd, dupHandling));
+ if (fnPosStart > len || fnPosEnd > len || dupHandling > LOAD_DUP_REPLACE) {
+ throw new IOException(String.format("Invalid ExecuteLoadQueryLogEvent: fn_pos_start=%d, "
+ + "fn_pos_end=%d, dup_handling=%d", fnPosStart, fnPosEnd, dupHandling));
}
}
- public final int getFilenamePosStart()
- {
+ public final int getFilenamePosStart() {
return fnPosStart;
}
- public final int getFilenamePosEnd()
- {
+ public final int getFilenamePosEnd() {
return fnPosEnd;
}
- public final String getFilename()
- {
- if (query != null)
- return query.substring(fnPosStart, fnPosEnd).trim();
+ public final String getFilename() {
+ if (query != null) return query.substring(fnPosStart, fnPosEnd).trim();
return null;
}
- public final long getFileId()
- {
+ public final long getFileId() {
return fileId;
}
}
diff --git a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/FormatDescriptionLogEvent.java b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/FormatDescriptionLogEvent.java
index b2fe9352..67fee9f0 100644
--- a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/FormatDescriptionLogEvent.java
+++ b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/FormatDescriptionLogEvent.java
@@ -5,8 +5,8 @@ import java.io.IOException;
import com.taobao.tddl.dbsync.binlog.LogBuffer;
/**
- * For binlog version 4. This event is saved by threads which read it, as they need it for future use (to decode the
- * ordinary events).
+ * For binlog version 4. This event is saved by threads which read it, as they
+ * need it for future use (to decode the ordinary events).
*
* @see mysql-5.1.60/sql/log_event.cc - Format_description_log_event
* @author Changyuan.lh
@@ -15,23 +15,24 @@ import com.taobao.tddl.dbsync.binlog.LogBuffer;
public final class FormatDescriptionLogEvent extends StartLogEventV3 {
/**
- * The number of types we handle in Format_description_log_event (UNKNOWN_EVENT is not to be handled, it does not
- * exist in binlogs, it does not have a format).
+ * The number of types we handle in Format_description_log_event
+ * (UNKNOWN_EVENT is not to be handled, it does not exist in binlogs, it
+ * does not have a format).
*/
- public static final int LOG_EVENT_TYPES = (ENUM_END_EVENT - 1);
+ public static final int LOG_EVENT_TYPES = (ENUM_END_EVENT - 1);
- public static final int ST_COMMON_HEADER_LEN_OFFSET = (ST_SERVER_VER_OFFSET + ST_SERVER_VER_LEN + 4);
+ public static final int ST_COMMON_HEADER_LEN_OFFSET = (ST_SERVER_VER_OFFSET + ST_SERVER_VER_LEN + 4);
- public static final int OLD_HEADER_LEN = 13;
- public static final int LOG_EVENT_HEADER_LEN = 19;
- public static final int LOG_EVENT_MINIMAL_HEADER_LEN = 19;
+ public static final int OLD_HEADER_LEN = 13;
+ public static final int LOG_EVENT_HEADER_LEN = 19;
+ public static final int LOG_EVENT_MINIMAL_HEADER_LEN = 19;
/* event-specific post-header sizes */
- public static final int STOP_HEADER_LEN = 0;
- public static final int LOAD_HEADER_LEN = (4 + 4 + 4 + 1 + 1 + 4);
- public static final int SLAVE_HEADER_LEN = 0;
- public static final int START_V3_HEADER_LEN = (2 + ST_SERVER_VER_LEN + 4);
- public static final int ROTATE_HEADER_LEN = 8; // this
+ public static final int STOP_HEADER_LEN = 0;
+ public static final int LOAD_HEADER_LEN = (4 + 4 + 4 + 1 + 1 + 4);
+ public static final int SLAVE_HEADER_LEN = 0;
+ public static final int START_V3_HEADER_LEN = (2 + ST_SERVER_VER_LEN + 4);
+ public static final int ROTATE_HEADER_LEN = 8; // this
// is
// FROZEN
// (the
@@ -39,47 +40,48 @@ public final class FormatDescriptionLogEvent extends StartLogEventV3 {
// post-header
// is
// frozen)
- public static final int INTVAR_HEADER_LEN = 0;
- public static final int CREATE_FILE_HEADER_LEN = 4;
- public static final int APPEND_BLOCK_HEADER_LEN = 4;
- public static final int EXEC_LOAD_HEADER_LEN = 4;
- public static final int DELETE_FILE_HEADER_LEN = 4;
- public static final int NEW_LOAD_HEADER_LEN = LOAD_HEADER_LEN;
- public static final int RAND_HEADER_LEN = 0;
- public static final int USER_VAR_HEADER_LEN = 0;
- public static final int FORMAT_DESCRIPTION_HEADER_LEN = (START_V3_HEADER_LEN + 1 + LOG_EVENT_TYPES);
- public static final int XID_HEADER_LEN = 0;
- public static final int BEGIN_LOAD_QUERY_HEADER_LEN = APPEND_BLOCK_HEADER_LEN;
- public static final int ROWS_HEADER_LEN_V1 = 8;
- public static final int TABLE_MAP_HEADER_LEN = 8;
- public static final int EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN = (4 + 4 + 4 + 1);
- public static final int EXECUTE_LOAD_QUERY_HEADER_LEN = (QUERY_HEADER_LEN + EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN);
- public static final int INCIDENT_HEADER_LEN = 2;
- public static final int HEARTBEAT_HEADER_LEN = 0;
- public static final int IGNORABLE_HEADER_LEN = 0;
- public static final int ROWS_HEADER_LEN_V2 = 10;
- public static final int ANNOTATE_ROWS_HEADER_LEN = 0;
- public static final int BINLOG_CHECKPOINT_HEADER_LEN = 4;
- public static final int GTID_HEADER_LEN = 19;
- public static final int GTID_LIST_HEADER_LEN = 4;
+ public static final int INTVAR_HEADER_LEN = 0;
+ public static final int CREATE_FILE_HEADER_LEN = 4;
+ public static final int APPEND_BLOCK_HEADER_LEN = 4;
+ public static final int EXEC_LOAD_HEADER_LEN = 4;
+ public static final int DELETE_FILE_HEADER_LEN = 4;
+ public static final int NEW_LOAD_HEADER_LEN = LOAD_HEADER_LEN;
+ public static final int RAND_HEADER_LEN = 0;
+ public static final int USER_VAR_HEADER_LEN = 0;
+ public static final int FORMAT_DESCRIPTION_HEADER_LEN = (START_V3_HEADER_LEN + 1 + LOG_EVENT_TYPES);
+ public static final int XID_HEADER_LEN = 0;
+ public static final int BEGIN_LOAD_QUERY_HEADER_LEN = APPEND_BLOCK_HEADER_LEN;
+ public static final int ROWS_HEADER_LEN_V1 = 8;
+ public static final int TABLE_MAP_HEADER_LEN = 8;
+ public static final int EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN = (4 + 4 + 4 + 1);
+ public static final int EXECUTE_LOAD_QUERY_HEADER_LEN = (QUERY_HEADER_LEN + EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN);
+ public static final int INCIDENT_HEADER_LEN = 2;
+ public static final int HEARTBEAT_HEADER_LEN = 0;
+ public static final int IGNORABLE_HEADER_LEN = 0;
+ public static final int ROWS_HEADER_LEN_V2 = 10;
+ public static final int ANNOTATE_ROWS_HEADER_LEN = 0;
+ public static final int BINLOG_CHECKPOINT_HEADER_LEN = 4;
+ public static final int GTID_HEADER_LEN = 19;
+ public static final int GTID_LIST_HEADER_LEN = 4;
- public static final int POST_HEADER_LENGTH = 11;
+ public static final int POST_HEADER_LENGTH = 11;
public static final int BINLOG_CHECKSUM_ALG_DESC_LEN = 1;
public static final int[] checksumVersionSplit = { 5, 6, 1 };
public static final long checksumVersionProduct = (checksumVersionSplit[0] * 256 + checksumVersionSplit[1])
* 256 + checksumVersionSplit[2];
/**
- * The size of the fixed header which _all_ events have (for binlogs written by this version, this is equal to
- * LOG_EVENT_HEADER_LEN), except FORMAT_DESCRIPTION_EVENT and ROTATE_EVENT (those have a header of size
+ * The size of the fixed header which _all_ events have (for binlogs written
+ * by this version, this is equal to LOG_EVENT_HEADER_LEN), except
+ * FORMAT_DESCRIPTION_EVENT and ROTATE_EVENT (those have a header of size
* LOG_EVENT_MINIMAL_HEADER_LEN).
*/
- protected final int commonHeaderLen;
- protected int numberOfEventTypes;
+ protected final int commonHeaderLen;
+ protected int numberOfEventTypes;
/** The list of post-headers' lengthes */
- protected final short[] postHeaderLen;
- protected int[] serverVersionSplit = new int[3];
+ protected final short[] postHeaderLen;
+ protected int[] serverVersionSplit = new int[3];
public FormatDescriptionLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent)
throws IOException{
@@ -105,12 +107,15 @@ public final class FormatDescriptionLogEvent extends StartLogEventV3 {
calcServerVersionSplit();
long calc = getVersionProduct();
if (calc >= checksumVersionProduct) {
- /* the last bytes are the checksum alg desc and value (or value's room) */
+ /*
+ * the last bytes are the checksum alg desc and value (or value's
+ * room)
+ */
numberOfEventTypes -= BINLOG_CHECKSUM_ALG_DESC_LEN;
}
-
+
if (logger.isInfoEnabled()) logger.info("common_header_len= " + commonHeaderLen + ", number_of_event_types= "
- + numberOfEventTypes);
+ + numberOfEventTypes);
}
/** MySQL 5.0 format descriptions. */
@@ -147,7 +152,10 @@ public final class FormatDescriptionLogEvent extends StartLogEventV3 {
commonHeaderLen = LOG_EVENT_HEADER_LEN;
numberOfEventTypes = LOG_EVENT_TYPES;
- /* Note: all event types must explicitly fill in their lengths here. */
+ /*
+ * Note: all event types must explicitly fill in their lengths
+ * here.
+ */
postHeaderLen[START_EVENT_V3 - 1] = START_V3_HEADER_LEN;
postHeaderLen[QUERY_EVENT - 1] = QUERY_HEADER_LEN;
postHeaderLen[STOP_EVENT - 1] = STOP_HEADER_LEN;
@@ -171,11 +179,14 @@ public final class FormatDescriptionLogEvent extends StartLogEventV3 {
postHeaderLen[UPDATE_ROWS_EVENT_V1 - 1] = ROWS_HEADER_LEN_V1;
postHeaderLen[DELETE_ROWS_EVENT_V1 - 1] = ROWS_HEADER_LEN_V1;
/*
- * We here have the possibility to simulate a master of before we changed the table map id to be stored
- * in 6 bytes: when it was stored in 4 bytes (=> post_header_len was 6). This is used to test backward
- * compatibility. This code can be removed after a few months (today is Dec 21st 2005), when we know
- * that the 4-byte masters are not deployed anymore (check with Tomas Ulin first!), and the accompanying
- * test (rpl_row_4_bytes) too.
+ * We here have the possibility to simulate a master of before
+ * we changed the table map id to be stored in 6 bytes: when it
+ * was stored in 4 bytes (=> post_header_len was 6). This is
+ * used to test backward compatibility. This code can be removed
+ * after a few months (today is Dec 21st 2005), when we know
+ * that the 4-byte masters are not deployed anymore (check with
+ * Tomas Ulin first!), and the accompanying test
+ * (rpl_row_4_bytes) too.
*/
postHeaderLen[HEARTBEAT_LOG_EVENT - 1] = 0;
postHeaderLen[IGNORABLE_LOG_EVENT - 1] = IGNORABLE_HEADER_LEN;
@@ -195,17 +206,19 @@ public final class FormatDescriptionLogEvent extends StartLogEventV3 {
case 3: /* 4.0.x x>=2 */
/*
- * We build an artificial (i.e. not sent by the master) event, which describes what those old master
- * versions send.
+ * We build an artificial (i.e. not sent by the master) event,
+ * which describes what those old master versions send.
*/
serverVersion = "4.0";
commonHeaderLen = LOG_EVENT_MINIMAL_HEADER_LEN;
/*
- * The first new event in binlog version 4 is Format_desc. So any event type after that does not exist
- * in older versions. We use the events known by version 3, even if version 1 had only a subset of them
- * (this is not a problem: it uses a few bytes for nothing but unifies code; it does not make the slave
- * detect less corruptions).
+ * The first new event in binlog version 4 is Format_desc. So
+ * any event type after that does not exist in older versions.
+ * We use the events known by version 3, even if version 1 had
+ * only a subset of them (this is not a problem: it uses a few
+ * bytes for nothing but unifies code; it does not make the
+ * slave detect less corruptions).
*/
numberOfEventTypes = FORMAT_DESCRIPTION_EVENT - 1;
@@ -222,17 +235,19 @@ public final class FormatDescriptionLogEvent extends StartLogEventV3 {
case 1: /* 3.23 */
/*
- * We build an artificial (i.e. not sent by the master) event, which describes what those old master
- * versions send.
+ * We build an artificial (i.e. not sent by the master) event,
+ * which describes what those old master versions send.
*/
serverVersion = "3.23";
commonHeaderLen = OLD_HEADER_LEN;
/*
- * The first new event in binlog version 4 is Format_desc. So any event type after that does not exist
- * in older versions. We use the events known by version 3, even if version 1 had only a subset of them
- * (this is not a problem: it uses a few bytes for nothing but unifies code; it does not make the slave
- * detect less corruptions).
+ * The first new event in binlog version 4 is Format_desc. So
+ * any event type after that does not exist in older versions.
+ * We use the events known by version 3, even if version 1 had
+ * only a subset of them (this is not a problem: it uses a few
+ * bytes for nothing but unifies code; it does not make the
+ * slave detect less corruptions).
*/
numberOfEventTypes = FORMAT_DESCRIPTION_EVENT - 1;
@@ -251,7 +266,7 @@ public final class FormatDescriptionLogEvent extends StartLogEventV3 {
commonHeaderLen = 0;
}
}
-
+
public void calcServerVersionSplit() {
doServerVersionSplit(serverVersion, serverVersionSplit);
}
diff --git a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/IgnorableLogEvent.java b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/IgnorableLogEvent.java
index ccc49762..f991d872 100644
--- a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/IgnorableLogEvent.java
+++ b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/IgnorableLogEvent.java
@@ -6,19 +6,19 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
/**
*
* Base class for ignorable log events. Events deriving from
- this class can be safely ignored by slaves that cannot
- recognize them. Newer slaves, will be able to read and
- handle them. This has been designed to be an open-ended
- architecture, so adding new derived events shall not harm
- the old slaves that support ignorable log event mechanism
- (they will just ignore unrecognized ignorable events).
-
- @note The only thing that makes an event ignorable is that it has
- the LOG_EVENT_IGNORABLE_F flag set. It is not strictly necessary
- that ignorable event types derive from Ignorable_log_event; they may
- just as well derive from Log_event and pass LOG_EVENT_IGNORABLE_F as
- argument to the Log_event constructor.
-
+ * this class can be safely ignored by slaves that cannot
+ * recognize them. Newer slaves, will be able to read and
+ * handle them. This has been designed to be an open-ended
+ * architecture, so adding new derived events shall not harm
+ * the old slaves that support ignorable log event mechanism
+ * (they will just ignore unrecognized ignorable events).
+ *
+ * @note The only thing that makes an event ignorable is that it has
+ * the LOG_EVENT_IGNORABLE_F flag set. It is not strictly necessary
+ * that ignorable event types derive from Ignorable_log_event; they may
+ * just as well derive from Log_event and pass LOG_EVENT_IGNORABLE_F as
+ * argument to the Log_event constructor.
+ *
*
* @author jianghang 2013-4-8 上午12:36:29
* @version 1.0.3
diff --git a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/IncidentLogEvent.java b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/IncidentLogEvent.java
index ecbd3226..f0c03e56 100644
--- a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/IncidentLogEvent.java
+++ b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/IncidentLogEvent.java
@@ -5,12 +5,9 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
/**
* Class representing an incident, an occurance out of the ordinary, that
- * happened on the master.
- *
- * The event is used to inform the slave that something out of the ordinary
- * happened on the master that might cause the database to be in an inconsistent
- * state.
- *
+ * happened on the master. The event is used to inform the slave that something
+ * out of the ordinary happened on the master that might cause the database to
+ * be in an inconsistent state.
*