@Override public void readPending(ReplicationMessageProcessor processor) throws SQLException, InterruptedException { ByteBuffer read = stream.readPending(); // the lsn we started from is inclusive, so we need to avoid sending back the same message twice if (read == null || lsnLong >= stream.getLastReceiveLSN().asLong()) { return; } deserializeMessages(read, processor); }
private void doFlushLsn(LogSequenceNumber lsn) throws SQLException { stream.setFlushedLSN(lsn); stream.setAppliedLSN(lsn); stream.forceUpdateStatus(); }
@Override public void close() throws SQLException { processWarnings(true); stream.close(); }
@Override public void read(ReplicationMessageProcessor processor) throws SQLException, InterruptedException { ByteBuffer read = stream.read(); // the lsn we started from is inclusive, so we need to avoid sending back the same message twice if (lsnLong >= stream.getLastReceiveLSN().asLong()) { return; } deserializeMessages(read, processor); }
ByteBuffer messageBuffer = stream.readPending(); .parse(JSonMapper.fromJson(messageString, PostgresWalMessage.class), stream.getLastReceiveLSN().asLong(), replicationSlotName) .forEach(eventConsumer); stream.setAppliedLSN(stream.getLastReceiveLSN()); stream.setFlushedLSN(stream.getLastReceiveLSN()); stream.close(); connection.close(); } catch (SQLException e) {
private void receiveStream() throws SQLException { assert !stream.isClosed(); assert !connection.isClosed(); //non blocking receive message ByteBuffer msg = stream.readPending(); if (msg == null) { TimeUtils.sleepInMills(10L); return; } int offset = msg.arrayOffset(); byte[] source = msg.array(); int length = source.length - offset; LogSequenceNumber lsn = stream.getLastReceiveLSN(); InvokeContext ctx = new InvokeContext(); ctx.setMessage(new String(source, offset, length)); ctx.setJdbcUrl(this.jdbcConfig.getUrl()); ctx.setJdbcUser(this.jdbcConfig.getUsername()); ctx.setJdbcPass(this.jdbcConfig.getPassword()); ctx.setSlotName(this.slotName); ctx.setServerId(this.serverId); ctx.setLsn(lsn.asLong()); eventParser.parse(ctx); //feedback stream.setAppliedLSN(lsn); stream.setFlushedLSN(lsn); }
private void deserializeMessages(ByteBuffer buffer, ReplicationMessageProcessor processor) throws SQLException, InterruptedException { lastReceivedLSN = stream.getLastReceiveLSN(); messageDecoder.processMessage(buffer, processor, typeRegistry); }
private PGReplicationStream startPgReplicationStream(final LogSequenceNumber lsn, Function<ChainedLogicalStreamBuilder, ChainedLogicalStreamBuilder> configurator) throws SQLException { assert lsn != null; ChainedLogicalStreamBuilder streamBuilder = pgConnection() .getReplicationAPI() .replicationStream() .logical() .withSlotName(slotName) .withStartPosition(lsn); streamBuilder = configurator.apply(streamBuilder); if (statusUpdateIntervalMillis != null && statusUpdateIntervalMillis > 0) { streamBuilder.withStatusInterval(statusUpdateIntervalMillis, TimeUnit.MILLISECONDS); } PGReplicationStream stream = streamBuilder.start(); // TODO DBZ-508 get rid of this // Needed by tests when connections are opened and closed in a fast sequence try { Thread.sleep(10); } catch (Exception e) { } stream.forceUpdateStatus(); return stream; }
@Override public void read(ReplicationMessageProcessor processor) throws SQLException, InterruptedException { ByteBuffer read = stream.read(); // the lsn we started from is inclusive, so we need to avoid sending back the same message twice if (lsnLong >= stream.getLastReceiveLSN().asLong()) { return; } deserializeMessages(read, processor); }
private void deserializeMessages(ByteBuffer buffer, ReplicationMessageProcessor processor) throws SQLException, InterruptedException { lastReceivedLSN = stream.getLastReceiveLSN(); messageDecoder.processMessage(buffer, processor, typeRegistry); }
private PGReplicationStream startPgReplicationStream(final LogSequenceNumber lsn, Function<ChainedLogicalStreamBuilder, ChainedLogicalStreamBuilder> configurator) throws SQLException { assert lsn != null; ChainedLogicalStreamBuilder streamBuilder = pgConnection() .getReplicationAPI() .replicationStream() .logical() .withSlotName(slotName) .withStartPosition(lsn); streamBuilder = configurator.apply(streamBuilder); if (statusUpdateIntervalMillis != null && statusUpdateIntervalMillis > 0) { streamBuilder.withStatusInterval(statusUpdateIntervalMillis, TimeUnit.MILLISECONDS); } PGReplicationStream stream = streamBuilder.start(); // TODO DBZ-508 get rid of this // Needed by tests when connections are opened and closed in a fast sequence try { Thread.sleep(10); } catch (Exception e) { } stream.forceUpdateStatus(); return stream; }
private void doFlushLsn(LogSequenceNumber lsn) throws SQLException { stream.setFlushedLSN(lsn); stream.setAppliedLSN(lsn); stream.forceUpdateStatus(); }
@Override public void readPending(ReplicationMessageProcessor processor) throws SQLException, InterruptedException { ByteBuffer read = stream.readPending(); // the lsn we started from is inclusive, so we need to avoid sending back the same message twice if (read == null || lsnLong >= stream.getLastReceiveLSN().asLong()) { return; } deserializeMessages(read, processor); }
@Override public void close() throws SQLException { processWarnings(true); stream.close(); }