From a1e4b1b9b5a25abf2f8d944a36f56989dda8f284 Mon Sep 17 00:00:00 2001 From: Mark Fletcher Date: Tue, 19 Sep 2017 21:12:15 -0700 Subject: [PATCH] Changed CreateReplicationSlot to return the consistent_point and snapshot_name. --- replication.go | 10 ++++++++-- replication_test.go | 6 +++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/replication.go b/replication.go index bfa81e54..b1329c6b 100644 --- a/replication.go +++ b/replication.go @@ -435,8 +435,14 @@ func (rc *ReplicationConn) StartReplication(slotName string, startLsn uint64, ti } // Create the replication slot, using the given name and output plugin. -func (rc *ReplicationConn) CreateReplicationSlot(slotName, outputPlugin string) (err error) { - _, err = rc.c.Exec(fmt.Sprintf("CREATE_REPLICATION_SLOT %s LOGICAL %s", slotName, outputPlugin)) +func (rc *ReplicationConn) CreateReplicationSlot(slotName, outputPlugin string) (consistentPoint string, snapshotName string, err error) { + var dummy string + var rows *Rows + rows, err = rc.sendReplicationModeQuery(fmt.Sprintf("CREATE_REPLICATION_SLOT %s LOGICAL %s", slotName, outputPlugin)) + defer rows.Close() + for rows.Next() { + rows.Scan(&dummy, &consistentPoint, &snapshotName, &dummy) + } return } diff --git a/replication_test.go b/replication_test.go index d75233c1..9989c982 100644 --- a/replication_test.go +++ b/replication_test.go @@ -56,7 +56,7 @@ func TestSimpleReplicationConnection(t *testing.T) { replicationConn := mustReplicationConnect(t, *replicationConnConfig) defer closeReplicationConn(t, replicationConn) - err = replicationConn.CreateReplicationSlot("pgx_test", "test_decoding") + _, _, err = replicationConn.CreateReplicationSlot("pgx_test", "test_decoding") if err != nil { t.Fatalf("replication slot create failed: %v", err) } @@ -178,7 +178,7 @@ func TestReplicationConn_DropReplicationSlot(t *testing.T) { replicationConn := mustReplicationConnect(t, *replicationConnConfig) defer closeReplicationConn(t, replicationConn) - err := replicationConn.CreateReplicationSlot("pgx_slot_test", "test_decoding") + _, _, err := replicationConn.CreateReplicationSlot("pgx_slot_test", "test_decoding") if err != nil { t.Logf("replication slot create failed: %v", err) } @@ -188,7 +188,7 @@ func TestReplicationConn_DropReplicationSlot(t *testing.T) { } // We re-create to ensure the drop worked. - err = replicationConn.CreateReplicationSlot("pgx_slot_test", "test_decoding") + _, _, err = replicationConn.CreateReplicationSlot("pgx_slot_test", "test_decoding") if err != nil { t.Logf("replication slot create failed: %v", err) }