Java Code Examples for com.taobao.tddl.dbsync.binlog.LogEvent#getServerId()
The following examples show how to use
com.taobao.tddl.dbsync.binlog.LogEvent#getServerId() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalBinLogConnection.java From canal-1.1.3 with Apache License 2.0 | 4 votes |
public void dump(String binlogfilename, Long binlogPosition, SinkFunction func) throws IOException { File current = new File(directory, binlogfilename); FileLogFetcher fetcher = new FileLogFetcher(bufferSize); LogDecoder decoder = new LogDecoder(LogEvent.UNKNOWN_EVENT, LogEvent.ENUM_END_EVENT); LogContext context = new LogContext(); try { fetcher.open(current, binlogPosition); context.setLogPosition(new LogPosition(binlogfilename, binlogPosition)); while (running) { boolean needContinue = true; LogEvent event = null; while (fetcher.fetch()) { event = decoder.decode(fetcher, context); if (event == null) { continue; } if (serverId != 0 && event.getServerId() != serverId) { throw new ServerIdNotMatchException("unexpected serverId " + serverId + " in binlog file !"); } if (!func.sink(event)) { needContinue = false; break; } } fetcher.close(); // 关闭上一个文件 parserFinish(current.getName()); if (needContinue) {// 读取下一个 File nextFile; if (needWait) { nextFile = binlogs.waitForNextFile(current); } else { nextFile = binlogs.getNextFile(current); } if (nextFile == null) { break; } current = nextFile; fetcher.open(current); context.setLogPosition(new LogPosition(nextFile.getName())); } else { break;// 跳出 } } } catch (InterruptedException e) { logger.warn("LocalBinLogConnection dump interrupted"); } finally { if (fetcher != null) { fetcher.close(); } } }
Example 2
Source File: LocalBinLogConnection.java From canal-1.1.3 with Apache License 2.0 | 4 votes |
public void dump(long timestampMills, SinkFunction func) throws IOException { List<File> currentBinlogs = binlogs.currentBinlogs(); File current = currentBinlogs.get(currentBinlogs.size() - 1); long timestampSeconds = timestampMills / 1000; String binlogFilename = null; long binlogFileOffset = 0; FileLogFetcher fetcher = new FileLogFetcher(bufferSize); LogDecoder decoder = new LogDecoder(); decoder.handle(LogEvent.FORMAT_DESCRIPTION_EVENT); decoder.handle(LogEvent.QUERY_EVENT); decoder.handle(LogEvent.XID_EVENT); LogContext context = new LogContext(); try { fetcher.open(current); context.setLogPosition(new LogPosition(current.getName())); while (running) { boolean needContinue = true; String lastXidLogFilename = current.getName(); long lastXidLogFileOffset = 0; binlogFilename = lastXidLogFilename; binlogFileOffset = lastXidLogFileOffset; while (fetcher.fetch()) { LogEvent event = decoder.decode(fetcher, context); if (event != null) { if (serverId != 0 && event.getServerId() != serverId) { throw new ServerIdNotMatchException("unexpected serverId " + serverId + " in binlog file !"); } if (event.getWhen() > timestampSeconds) { break; } needContinue = false; if (LogEvent.QUERY_EVENT == event.getHeader().getType()) { if (StringUtils.endsWithIgnoreCase(((QueryLogEvent) event).getQuery(), "BEGIN")) { binlogFilename = lastXidLogFilename; binlogFileOffset = lastXidLogFileOffset; } else if (StringUtils.endsWithIgnoreCase(((QueryLogEvent) event).getQuery(), "COMMIT")) { lastXidLogFilename = current.getName(); lastXidLogFileOffset = event.getLogPos(); } } else if (LogEvent.XID_EVENT == event.getHeader().getType()) { lastXidLogFilename = current.getName(); lastXidLogFileOffset = event.getLogPos(); } else if (LogEvent.FORMAT_DESCRIPTION_EVENT == event.getHeader().getType()) { lastXidLogFilename = current.getName(); lastXidLogFileOffset = event.getLogPos(); } } } if (needContinue) {// 读取下一个 fetcher.close(); // 关闭上一个文件 File nextFile = binlogs.getBefore(current); if (nextFile == null) { break; } current = nextFile; fetcher.open(current); context.setLogPosition(new LogPosition(current.getName())); } else { break;// 跳出 } } } finally { if (fetcher != null) { fetcher.close(); } } dump(binlogFilename, binlogFileOffset, func); }
Example 3
Source File: LocalBinLogConnection.java From canal-1.1.3 with Apache License 2.0 | 4 votes |
@Override public void dump(String binlogfilename, Long binlogPosition, MultiStageCoprocessor coprocessor) throws IOException { File current = new File(directory, binlogfilename); if (!current.exists()) { throw new CanalParseException("binlog:" + binlogfilename + " is not found"); } FileLogFetcher fetcher = new FileLogFetcher(bufferSize); LogDecoder decoder = new LogDecoder(LogEvent.UNKNOWN_EVENT, LogEvent.ENUM_END_EVENT); LogContext context = new LogContext(); try { fetcher.open(current, binlogPosition); context.setLogPosition(new LogPosition(binlogfilename, binlogPosition)); while (running) { boolean needContinue = true; LogEvent event = null; while (fetcher.fetch()) { event = decoder.decode(fetcher, context); if (event == null) { continue; } if (serverId != 0 && event.getServerId() != serverId) { throw new ServerIdNotMatchException("unexpected serverId " + serverId + " in binlog file !"); } if (!coprocessor.publish(event)) { needContinue = false; break; } } fetcher.close(); // 关闭上一个文件 parserFinish(binlogfilename); if (needContinue) {// 读取下一个 File nextFile; if (needWait) { nextFile = binlogs.waitForNextFile(current); } else { nextFile = binlogs.getNextFile(current); } if (nextFile == null) { break; } current = nextFile; fetcher.open(current); binlogfilename = nextFile.getName(); } else { break;// 跳出 } } } catch (InterruptedException e) { logger.warn("LocalBinLogConnection dump interrupted"); } finally { if (fetcher != null) { fetcher.close(); } } }
Example 4
Source File: LocalBinLogConnection.java From canal-1.1.3 with Apache License 2.0 | 4 votes |
@Override public void dump(long timestampMills, MultiStageCoprocessor coprocessor) throws IOException { List<File> currentBinlogs = binlogs.currentBinlogs(); File current = currentBinlogs.get(currentBinlogs.size() - 1); long timestampSeconds = timestampMills / 1000; String binlogFilename = null; long binlogFileOffset = 0; FileLogFetcher fetcher = new FileLogFetcher(bufferSize); LogDecoder decoder = new LogDecoder(); decoder.handle(LogEvent.FORMAT_DESCRIPTION_EVENT); decoder.handle(LogEvent.QUERY_EVENT); decoder.handle(LogEvent.XID_EVENT); LogContext context = new LogContext(); try { fetcher.open(current); context.setLogPosition(new LogPosition(current.getName())); while (running) { boolean needContinue = true; String lastXidLogFilename = current.getName(); long lastXidLogFileOffset = 0; binlogFilename = lastXidLogFilename; binlogFileOffset = lastXidLogFileOffset; while (fetcher.fetch()) { LogEvent event = decoder.decode(fetcher, context); if (event != null) { if (serverId != 0 && event.getServerId() != serverId) { throw new ServerIdNotMatchException("unexpected serverId " + serverId + " in binlog file !"); } if (event.getWhen() > timestampSeconds) { break; } needContinue = false; if (LogEvent.QUERY_EVENT == event.getHeader().getType()) { if (StringUtils.endsWithIgnoreCase(((QueryLogEvent) event).getQuery(), "BEGIN")) { binlogFilename = lastXidLogFilename; binlogFileOffset = lastXidLogFileOffset; } else if (StringUtils.endsWithIgnoreCase(((QueryLogEvent) event).getQuery(), "COMMIT")) { lastXidLogFilename = current.getName(); lastXidLogFileOffset = event.getLogPos(); } } else if (LogEvent.XID_EVENT == event.getHeader().getType()) { lastXidLogFilename = current.getName(); lastXidLogFileOffset = event.getLogPos(); } else if (LogEvent.FORMAT_DESCRIPTION_EVENT == event.getHeader().getType()) { lastXidLogFilename = current.getName(); lastXidLogFileOffset = event.getLogPos(); } } } if (needContinue) {// 读取下一个 fetcher.close(); // 关闭上一个文件 File nextFile = binlogs.getBefore(current); if (nextFile == null) { break; } current = nextFile; fetcher.open(current); context.setLogPosition(new LogPosition(current.getName())); } else { break;// 跳出 } } } finally { if (fetcher != null) { fetcher.close(); } } dump(binlogFilename, binlogFileOffset, coprocessor); }
Example 5
Source File: LocalBinLogConnection.java From canal with Apache License 2.0 | 4 votes |
public void dump(String binlogfilename, Long binlogPosition, SinkFunction func) throws IOException { File current = new File(directory, binlogfilename); FileLogFetcher fetcher = new FileLogFetcher(bufferSize); LogDecoder decoder = new LogDecoder(LogEvent.UNKNOWN_EVENT, LogEvent.ENUM_END_EVENT); LogContext context = new LogContext(); try { fetcher.open(current, binlogPosition); context.setLogPosition(new LogPosition(binlogfilename, binlogPosition)); while (running) { boolean needContinue = true; LogEvent event = null; while (fetcher.fetch()) { event = decoder.decode(fetcher, context); if (event == null) { continue; } if (serverId != 0 && event.getServerId() != serverId) { throw new ServerIdNotMatchException("unexpected serverId " + serverId + " in binlog file !"); } if (!func.sink(event)) { needContinue = false; break; } } fetcher.close(); // 关闭上一个文件 parserFinish(current.getName()); if (needContinue) {// 读取下一个 File nextFile; if (needWait) { nextFile = binlogs.waitForNextFile(current); } else { nextFile = binlogs.getNextFile(current); } if (nextFile == null) { break; } current = nextFile; fetcher.open(current); context.setLogPosition(new LogPosition(nextFile.getName())); } else { break;// 跳出 } } } catch (InterruptedException e) { logger.warn("LocalBinLogConnection dump interrupted"); } finally { if (fetcher != null) { fetcher.close(); } } }
Example 6
Source File: LocalBinLogConnection.java From canal with Apache License 2.0 | 4 votes |
public void dump(long timestampMills, SinkFunction func) throws IOException { List<File> currentBinlogs = binlogs.currentBinlogs(); File current = currentBinlogs.get(currentBinlogs.size() - 1); long timestampSeconds = timestampMills / 1000; String binlogFilename = null; long binlogFileOffset = 0; FileLogFetcher fetcher = new FileLogFetcher(bufferSize); LogDecoder decoder = new LogDecoder(); decoder.handle(LogEvent.FORMAT_DESCRIPTION_EVENT); decoder.handle(LogEvent.QUERY_EVENT); decoder.handle(LogEvent.XID_EVENT); LogContext context = new LogContext(); try { fetcher.open(current); context.setLogPosition(new LogPosition(current.getName())); while (running) { boolean needContinue = true; String lastXidLogFilename = current.getName(); long lastXidLogFileOffset = 0; binlogFilename = lastXidLogFilename; binlogFileOffset = lastXidLogFileOffset; while (fetcher.fetch()) { LogEvent event = decoder.decode(fetcher, context); if (event != null) { if (serverId != 0 && event.getServerId() != serverId) { throw new ServerIdNotMatchException("unexpected serverId " + serverId + " in binlog file !"); } if (event.getWhen() > timestampSeconds) { break; } needContinue = false; if (LogEvent.QUERY_EVENT == event.getHeader().getType()) { if (StringUtils.endsWithIgnoreCase(((QueryLogEvent) event).getQuery(), "BEGIN")) { binlogFilename = lastXidLogFilename; binlogFileOffset = lastXidLogFileOffset; } else if (StringUtils.endsWithIgnoreCase(((QueryLogEvent) event).getQuery(), "COMMIT")) { lastXidLogFilename = current.getName(); lastXidLogFileOffset = event.getLogPos(); } } else if (LogEvent.XID_EVENT == event.getHeader().getType()) { lastXidLogFilename = current.getName(); lastXidLogFileOffset = event.getLogPos(); } else if (LogEvent.FORMAT_DESCRIPTION_EVENT == event.getHeader().getType()) { lastXidLogFilename = current.getName(); lastXidLogFileOffset = event.getLogPos(); } } } if (needContinue) {// 读取下一个 fetcher.close(); // 关闭上一个文件 File nextFile = binlogs.getBefore(current); if (nextFile == null) { break; } current = nextFile; fetcher.open(current); context.setLogPosition(new LogPosition(current.getName())); } else { break;// 跳出 } } } finally { if (fetcher != null) { fetcher.close(); } } dump(binlogFilename, binlogFileOffset, func); }
Example 7
Source File: LocalBinLogConnection.java From canal with Apache License 2.0 | 4 votes |
@Override public void dump(String binlogfilename, Long binlogPosition, MultiStageCoprocessor coprocessor) throws IOException { File current = new File(directory, binlogfilename); if (!current.exists()) { throw new CanalParseException("binlog:" + binlogfilename + " is not found"); } FileLogFetcher fetcher = new FileLogFetcher(bufferSize); LogDecoder decoder = new LogDecoder(LogEvent.UNKNOWN_EVENT, LogEvent.ENUM_END_EVENT); LogContext context = new LogContext(); try { fetcher.open(current, binlogPosition); context.setLogPosition(new LogPosition(binlogfilename, binlogPosition)); while (running) { boolean needContinue = true; LogEvent event = null; while (fetcher.fetch()) { event = decoder.decode(fetcher, context); if (event == null) { continue; } if (serverId != 0 && event.getServerId() != serverId) { throw new ServerIdNotMatchException("unexpected serverId " + serverId + " in binlog file !"); } if (!coprocessor.publish(event)) { needContinue = false; break; } } fetcher.close(); // 关闭上一个文件 parserFinish(binlogfilename); if (needContinue) {// 读取下一个 File nextFile; if (needWait) { nextFile = binlogs.waitForNextFile(current); } else { nextFile = binlogs.getNextFile(current); } if (nextFile == null) { break; } current = nextFile; fetcher.open(current); binlogfilename = nextFile.getName(); } else { break;// 跳出 } } } catch (InterruptedException e) { logger.warn("LocalBinLogConnection dump interrupted"); } finally { if (fetcher != null) { fetcher.close(); } } }
Example 8
Source File: LocalBinLogConnection.java From canal with Apache License 2.0 | 4 votes |
@Override public void dump(long timestampMills, MultiStageCoprocessor coprocessor) throws IOException { List<File> currentBinlogs = binlogs.currentBinlogs(); File current = currentBinlogs.get(currentBinlogs.size() - 1); long timestampSeconds = timestampMills / 1000; String binlogFilename = null; long binlogFileOffset = 0; FileLogFetcher fetcher = new FileLogFetcher(bufferSize); LogDecoder decoder = new LogDecoder(); decoder.handle(LogEvent.FORMAT_DESCRIPTION_EVENT); decoder.handle(LogEvent.QUERY_EVENT); decoder.handle(LogEvent.XID_EVENT); LogContext context = new LogContext(); try { fetcher.open(current); context.setLogPosition(new LogPosition(current.getName())); while (running) { boolean needContinue = true; String lastXidLogFilename = current.getName(); long lastXidLogFileOffset = 0; binlogFilename = lastXidLogFilename; binlogFileOffset = lastXidLogFileOffset; while (fetcher.fetch()) { LogEvent event = decoder.decode(fetcher, context); if (event != null) { if (serverId != 0 && event.getServerId() != serverId) { throw new ServerIdNotMatchException("unexpected serverId " + serverId + " in binlog file !"); } if (event.getWhen() > timestampSeconds) { break; } needContinue = false; if (LogEvent.QUERY_EVENT == event.getHeader().getType()) { if (StringUtils.endsWithIgnoreCase(((QueryLogEvent) event).getQuery(), "BEGIN")) { binlogFilename = lastXidLogFilename; binlogFileOffset = lastXidLogFileOffset; } else if (StringUtils.endsWithIgnoreCase(((QueryLogEvent) event).getQuery(), "COMMIT")) { lastXidLogFilename = current.getName(); lastXidLogFileOffset = event.getLogPos(); } } else if (LogEvent.XID_EVENT == event.getHeader().getType()) { lastXidLogFilename = current.getName(); lastXidLogFileOffset = event.getLogPos(); } else if (LogEvent.FORMAT_DESCRIPTION_EVENT == event.getHeader().getType()) { lastXidLogFilename = current.getName(); lastXidLogFileOffset = event.getLogPos(); } } } if (needContinue) {// 读取下一个 fetcher.close(); // 关闭上一个文件 File nextFile = binlogs.getBefore(current); if (nextFile == null) { break; } current = nextFile; fetcher.open(current); context.setLogPosition(new LogPosition(current.getName())); } else { break;// 跳出 } } } finally { if (fetcher != null) { fetcher.close(); } } dump(binlogFilename, binlogFileOffset, coprocessor); }