@Override public T withSlotName(String slotName) { this.slotName = slotName; return self(); } }
@Override public ChainedStreamBuilder replicationStream() { return new ReplicationStreamBuilder(connection); }
@Override public T withStartPosition(LogSequenceNumber lsn) { this.startPosition = lsn; return self(); }
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; }
pgConnection().getReplicationAPI() .createReplicationSlot() .logical() .withSlotName(slotName) .withOutputPlugin(postgresPluginName) .make();
private PGReplicationStream initializeReplication(String query, CommonOptions options, ReplicationType replicationType) throws SQLException { LOGGER.log(Level.FINEST, " FE=> StartReplication(query: {0})", query); configureSocketTimeout(options); CopyDual copyDual = (CopyDual) queryExecutor.startCopy(query, true); return new V3PGReplicationStream( copyDual, options.getStartLSNPosition(), options.getStatusInterval(), replicationType ); }
@Override public ChainedCreateReplicationSlotBuilder createReplicationSlot() { return new ReplicationCreateSlotBuilder(connection); }
private void configureSocketTimeout(CommonOptions options) throws PSQLException { if (options.getStatusInterval() == 0) { return; } try { int previousTimeOut = pgStream.getSocket().getSoTimeout(); int minimalTimeOut; if (previousTimeOut > 0) { minimalTimeOut = Math.min(previousTimeOut, options.getStatusInterval()); } else { minimalTimeOut = options.getStatusInterval(); } pgStream.getSocket().setSoTimeout(minimalTimeOut); } catch (IOException ioe) { throw new PSQLException(GT.tr("The connection attempt failed."), PSQLState.CONNECTION_UNABLE_TO_CONNECT, ioe); } }
private void createRplStream() throws SQLException { this.stream = this.rplConnection.getReplicationAPI() .replicationStream() .logical() .withSlotName(this.jdbcConfig.getSlotName()) .withSlotOption("include-xids", true) .withSlotOption("skip-empty-xacts", true) .withStatusInterval(5, TimeUnit.SECONDS) .start(); log.info("GetRplStream success,slot:{}", this.slotName); }
private void createRplSlot() throws SQLException { try { this.rplConnection.getReplicationAPI() .createReplicationSlot() .logical() .withSlotName(this.jdbcConfig.getSlotName()) .withOutputPlugin("test_decoding") .make(); } catch (SQLException e) { String msg = "ERROR: replication slot \"" + this.jdbcConfig.getSlotName() + "\" already exists"; if (msg.equals(e.getMessage())) { return; } throw e; } log.info("GetRplSlot success,slot:{}", this.slotName); }
@Override public T withSlotName(String slotName) { this.slotName = slotName; return self(); } }
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; }
pgConnection().getReplicationAPI() .createReplicationSlot() .logical() .withSlotName(slotName) .withOutputPlugin(postgresPluginName) .make();
@Override public T withStatusInterval(int time, TimeUnit format) { statusIntervalMs = (int) TimeUnit.MILLISECONDS.convert(time, format); return self(); }
.logical() .withSlotName(replicationSlotName) .withSlotOption("include-xids", false) .withStatusInterval(replicationStatusIntervalInMilliseconds, TimeUnit.MILLISECONDS) .withStartPosition(lsn) .start();