コード例 #1
0
 internal ReplicationSystemIdentification(string systemId, uint timeline, NpgsqlLogSequenceNumber xLogPos, string dbName)
 {
     SystemId = systemId;
     Timeline = timeline;
     XLogPos  = xLogPos;
     DbName   = dbName;
 }
コード例 #2
0
 internal StreamAbortMessage Populate(NpgsqlLogSequenceNumber walStart, NpgsqlLogSequenceNumber walEnd, DateTime serverClock,
                                      uint transactionXid, uint subtransactionXid)
 {
     base.Populate(walStart, walEnd, serverClock, transactionXid);
     SubtransactionXid = subtransactionXid;
     return(this);
 }
コード例 #3
0
 internal FullDeleteMessage Populate(
     NpgsqlLogSequenceNumber walStart, NpgsqlLogSequenceNumber walEnd, DateTime serverClock, uint?transactionXid, uint relationId, ReadOnlyMemory <TupleData> oldRow)
 {
     base.Populate(walStart, walEnd, serverClock, transactionXid, relationId);
     OldRow = oldRow;
     return(this);
 }
コード例 #4
0
 internal StreamStartMessage Populate(NpgsqlLogSequenceNumber walStart, NpgsqlLogSequenceNumber walEnd, DateTime serverClock,
                                      uint transactionXid, byte streamSegmentIndicator)
 {
     base.Populate(walStart, walEnd, serverClock, transactionXid);
     StreamSegmentIndicator = streamSegmentIndicator;
     return(this);
 }
        /// <summary>
        /// Instructs the server to start streaming the WAL for physical replication, starting at WAL location
        /// <paramref name="walLocation"/>. The server can reply with an error, for example if the requested
        /// section of the WAL has already been recycled.
        /// </summary>
        /// <remarks>
        /// If the client requests a timeline that's not the latest but is part of the history of the server, the server
        /// will stream all the WAL on that timeline starting from the requested start point up to the point where the
        /// server switched to another timeline.
        /// </remarks>
        /// <param name="slot">
        /// The replication slot that will be updated as replication progresses so that the server
        /// knows which WAL segments are still needed by the standby.
        /// </param>
        /// <param name="walLocation">The WAL location to begin streaming at.</param>
        /// <param name="cancellationToken">The token to be used for stopping the replication.</param>
        /// <param name="timeline">Streaming starts on timeline tli.</param>
        /// <returns>A <see cref="Task{T}"/> representing an <see cref="IAsyncEnumerable{NpgsqlXLogDataMessage}"/> that
        /// can be used to stream WAL entries in form of <see cref="XLogDataMessage"/> instances.</returns>
        public IAsyncEnumerable <XLogDataMessage> StartReplication(PhysicalReplicationSlot?slot,
                                                                   NpgsqlLogSequenceNumber walLocation,
                                                                   CancellationToken cancellationToken,
                                                                   uint timeline = default)
        {
            using (NoSynchronizationContextScope.Enter())
                return(StartPhysicalReplication(slot, walLocation, cancellationToken, timeline));

            async IAsyncEnumerable <XLogDataMessage> StartPhysicalReplication(PhysicalReplicationSlot?slot,
                                                                              NpgsqlLogSequenceNumber walLocation,
                                                                              [EnumeratorCancellation] CancellationToken cancellationToken,
                                                                              uint timeline)
            {
                var builder = new StringBuilder("START_REPLICATION");

                if (slot != null)
                {
                    builder.Append(" SLOT ").Append(slot.Name);
                }
                builder.Append(" PHYSICAL ").Append(walLocation);
                if (timeline != default)
                {
                    builder.Append(" TIMELINE ").Append(timeline.ToString(CultureInfo.InvariantCulture));
                }

                var enumerator = StartReplicationInternalWrapper(builder.ToString(), bypassingStream: false, cancellationToken);

                while (await enumerator.MoveNextAsync())
                {
                    yield return(enumerator.Current);
                }
            }
        }
コード例 #6
0
ファイル: DeleteMessage.cs プロジェクト: TonicAI/npgsql
 private protected DeleteMessage Populate(
     NpgsqlLogSequenceNumber walStart, NpgsqlLogSequenceNumber walEnd, DateTime serverClock, uint?transactionXid, uint relationId)
 {
     base.Populate(walStart, walEnd, serverClock, transactionXid);
     RelationId = relationId;
     return(this);
 }
コード例 #7
0
ファイル: IndexUpdateMessage.cs プロジェクト: TonicAI/npgsql
 internal IndexUpdateMessage Populate(
     NpgsqlLogSequenceNumber walStart, NpgsqlLogSequenceNumber walEnd, DateTime serverClock, uint?transactionXid, uint relationId,
     ReadOnlyMemory <TupleData> newRow, ReadOnlyMemory <TupleData> keyRow)
 {
     base.Populate(walStart, walEnd, serverClock, transactionXid, relationId, newRow);
     KeyRow = keyRow;
     return(this);
 }
コード例 #8
0
 internal BeginMessage Populate(NpgsqlLogSequenceNumber walStart, NpgsqlLogSequenceNumber walEnd, DateTime serverClock,
                                NpgsqlLogSequenceNumber transactionFinalLsn, DateTime transactionCommitTimestamp, uint transactionXid)
 {
     base.Populate(walStart, walEnd, serverClock, transactionXid);
     TransactionFinalLsn        = transactionFinalLsn;
     TransactionCommitTimestamp = transactionCommitTimestamp;
     return(this);
 }
コード例 #9
0
    internal TestDecodingData Populate(
        NpgsqlLogSequenceNumber walStart, NpgsqlLogSequenceNumber walEnd, DateTime serverClock, string data)
    {
        base.Populate(walStart, walEnd, serverClock);

        Data = data;

        return(this);
    }
コード例 #10
0
ファイル: TruncateMessage.cs プロジェクト: YohDeadfall/npgsql
 internal TruncateMessage Populate(
     NpgsqlLogSequenceNumber walStart, NpgsqlLogSequenceNumber walEnd, DateTime serverClock, uint?transactionXid, TruncateOptions options,
     ReadOnlyArrayBuffer <RelationMessage> relations)
 {
     base.Populate(walStart, walEnd, serverClock, transactionXid);
     Options   = options;
     Relations = relations;
     return(this);
 }
コード例 #11
0
    internal XLogDataMessage Populate(
        NpgsqlLogSequenceNumber walStart, NpgsqlLogSequenceNumber walEnd, DateTime serverClock, Stream data)
    {
        base.Populate(walStart, walEnd, serverClock);

        Data = data;

        return(this);
    }
コード例 #12
0
 internal InsertMessage Populate(
     NpgsqlLogSequenceNumber walStart, NpgsqlLogSequenceNumber walEnd, DateTime serverClock, uint?transactionXid, uint relationId,
     ReadOnlyMemory <TupleData> newRow)
 {
     base.Populate(walStart, walEnd, serverClock, transactionXid);
     RelationId = relationId;
     NewRow     = newRow;
     return(this);
 }
コード例 #13
0
 internal TypeMessage Populate(
     NpgsqlLogSequenceNumber walStart, NpgsqlLogSequenceNumber walEnd, DateTime serverClock, uint?transactionXid, uint typeId, string ns, string name)
 {
     base.Populate(walStart, walEnd, serverClock, transactionXid);
     TypeId    = typeId;
     Namespace = ns;
     Name      = name;
     return(this);
 }
コード例 #14
0
 internal LogicalDecodingMessage Populate(NpgsqlLogSequenceNumber walStart, NpgsqlLogSequenceNumber walEnd, DateTime serverClock,
                                          uint?transactionXid, byte flags, NpgsqlLogSequenceNumber messageLsn, string prefix, Stream data)
 {
     base.Populate(walStart, walEnd, serverClock, transactionXid);
     Flags      = flags;
     MessageLsn = messageLsn;
     Prefix     = prefix;
     Data       = data;
     return(this);
 }
コード例 #15
0
    internal UpdateMessage Populate(
        NpgsqlLogSequenceNumber walStart, NpgsqlLogSequenceNumber walEnd, DateTime serverClock, uint?transactionXid,
        RelationMessage relation)
    {
        base.Populate(walStart, walEnd, serverClock, transactionXid);

        Relation = relation;

        return(this);
    }
コード例 #16
0
ファイル: StreamCommitMessage.cs プロジェクト: lillo42/npgsql
 internal StreamCommitMessage Populate(NpgsqlLogSequenceNumber walStart, NpgsqlLogSequenceNumber walEnd, DateTime serverClock,
                                       uint transactionXid, byte flags, NpgsqlLogSequenceNumber commitLsn, NpgsqlLogSequenceNumber transactionEndLsn, DateTime transactionCommitTimestamp)
 {
     base.Populate(walStart, walEnd, serverClock, transactionXid);
     Flags                      = flags;
     CommitLsn                  = commitLsn;
     TransactionEndLsn          = transactionEndLsn;
     TransactionCommitTimestamp = transactionCommitTimestamp;
     return(this);
 }
コード例 #17
0
        internal FullUpdateMessage Populate(
            NpgsqlLogSequenceNumber walStart, NpgsqlLogSequenceNumber walEnd, DateTime serverClock, uint relationId,
            ReadOnlyMemory <TupleData> newRow, ReadOnlyMemory <TupleData> oldRow)
        {
            base.Populate(walStart, walEnd, serverClock, relationId, newRow);

            OldRow = oldRow;

            return(this);
        }
コード例 #18
0
ファイル: KeyDeleteMessage.cs プロジェクト: Octonica/npgsql
        internal KeyDeleteMessage Populate(
            NpgsqlLogSequenceNumber walStart, NpgsqlLogSequenceNumber walEnd, DateTime serverClock, uint relationId,
            ReadOnlyMemory <TupleData> keyRow)
        {
            base.Populate(walStart, walEnd, serverClock, relationId);

            KeyRow = keyRow;

            return(this);
        }
コード例 #19
0
ファイル: TruncateMessage.cs プロジェクト: veikkoeeva/npgsql
        internal TruncateMessage Populate(
            NpgsqlLogSequenceNumber walStart, NpgsqlLogSequenceNumber walEnd, DateTime serverClock, TruncateOptions options,
            uint[] relationIds)
        {
            base.Populate(walStart, walEnd, serverClock);

            Options     = options;
            RelationIds = relationIds;

            return(this);
        }
コード例 #20
0
        internal OriginMessage Populate(
            NpgsqlLogSequenceNumber walStart, NpgsqlLogSequenceNumber walEnd, DateTime serverClock, NpgsqlLogSequenceNumber originCommitLsn,
            string originName)
        {
            base.Populate(walStart, walEnd, serverClock);

            OriginCommitLsn = originCommitLsn;
            OriginName      = originName;

            return(this);
        }
コード例 #21
0
        internal UpdateMessage Populate(
            NpgsqlLogSequenceNumber walStart, NpgsqlLogSequenceNumber walEnd, DateTime serverClock, uint?transactionXid,
            RelationMessage relation, ushort numColumns)
        {
            base.Populate(walStart, walEnd, serverClock, transactionXid, relation);

            _key.Reset(numColumns, relation.RowDescription);
            _newRow.Reset(numColumns, relation.RowDescription);

            return(this);
        }
コード例 #22
0
 internal RelationMessage Populate(
     NpgsqlLogSequenceNumber walStart, NpgsqlLogSequenceNumber walEnd, DateTime serverClock, uint?transactionXid, uint relationId, string ns,
     string relationName, char relationReplicaIdentitySetting, ReadOnlyArrayBuffer <Column> columns)
 {
     base.Populate(walStart, walEnd, serverClock, transactionXid);
     RelationId   = relationId;
     Namespace    = ns;
     RelationName = relationName;
     RelationReplicaIdentitySetting = relationReplicaIdentitySetting;
     Columns = columns;
     return(this);
 }
コード例 #23
0
ファイル: RelationMessage.cs プロジェクト: lillo42/npgsql
    internal RelationMessage Populate(
        NpgsqlLogSequenceNumber walStart, NpgsqlLogSequenceNumber walEnd, DateTime serverClock, uint?transactionXid, uint relationId, string ns,
        string relationName, ReplicaIdentitySetting relationReplicaIdentitySetting)
    {
        base.Populate(walStart, walEnd, serverClock, transactionXid);

        RelationId      = relationId;
        Namespace       = ns;
        RelationName    = relationName;
        ReplicaIdentity = relationReplicaIdentitySetting;

        return(this);
    }
コード例 #24
0
        /// <summary>
        /// Instructs the server to start streaming the WAL for physical replication, starting at WAL location
        /// <paramref name="walLocation"/>. The server can reply with an error, for example if the requested
        /// section of the WAL has already been recycled.
        /// </summary>
        /// <remarks>
        /// If the client requests a timeline that's not the latest but is part of the history of the server, the server
        /// will stream all the WAL on that timeline starting from the requested start point up to the point where the
        /// server switched to another timeline.
        /// </remarks>
        /// <param name="slot">
        /// The replication slot that will be updated as replication progresses so that the server
        /// knows which WAL segments are still needed by the standby.
        /// </param>
        /// <param name="walLocation">The WAL location to begin streaming at.</param>
        /// <param name="cancellationToken">The token to be used for stopping the replication.</param>
        /// <param name="timeline">Streaming starts on timeline tli.</param>
        /// <returns>A <see cref="Task{T}"/> representing an <see cref="IAsyncEnumerable{NpgsqlXLogDataMessage}"/> that
        /// can be used to stream WAL entries in form of <see cref="XLogDataMessage"/> instances.</returns>
        public IAsyncEnumerable <XLogDataMessage> StartReplication(PhysicalReplicationSlot?slot,
                                                                   NpgsqlLogSequenceNumber walLocation,
                                                                   CancellationToken cancellationToken,
                                                                   uint timeline = default)
        {
            using var _ = NoSynchronizationContextScope.Enter();

            var builder = new StringBuilder("START_REPLICATION");

            if (slot != null)
            {
                builder.Append(" SLOT ").Append(slot.Name);
            }
            builder.Append(" PHYSICAL ").Append(walLocation);
            if (timeline != default)
            {
                builder.Append(" TIMELINE ").Append(timeline.ToString(CultureInfo.InvariantCulture));
            }

            return(StartReplicationInternal(builder.ToString(), bypassingStream: false, cancellationToken));
        }
コード例 #25
0
        // [Test]
        public async Task NpgsqlLogSequenceNumber()
        {
            var expected1 = new NpgsqlLogSequenceNumber(42949672971ul);

            Assert.AreEqual(expected1, NpgsqlTypes.NpgsqlLogSequenceNumber.Parse("A/B"));
            await using var conn = await OpenConnectionAsync();

            using var cmd   = conn.CreateCommand();
            cmd.CommandText = "SELECT 'A/B'::pg_lsn, @p::pg_lsn";
            cmd.Parameters.AddWithValue("p", NpgsqlDbType.PgLsn, expected1);
            await using var reader = await cmd.ExecuteReaderAsync();

            reader.Read();
            var result1 = reader.GetFieldValue <NpgsqlLogSequenceNumber>(0);
            var result2 = reader.GetFieldValue <NpgsqlLogSequenceNumber>(1);

            Assert.AreEqual(expected1, result1);
            Assert.AreEqual(42949672971ul, (ulong)result1);
            Assert.AreEqual("A/B", result1.ToString());
            Assert.AreEqual(expected1, result2);
            Assert.AreEqual(42949672971ul, (ulong)result2);
            Assert.AreEqual("A/B", result2.ToString());
        }
コード例 #26
0
 /// <summary>
 /// Instructs the server to start streaming the WAL for logical replication, starting at WAL location
 /// <paramref name="walLocation"/>. The server can reply with an error, for example if the requested
 /// section of WAL has already been recycled.
 /// </summary>
 /// <remarks>
 /// If the client requests a timeline that's not the latest but is part of the history of the server, the server
 /// will stream all the WAL on that timeline starting from the requested start point up to the point where the
 /// server switched to another timeline.
 /// </remarks>
 /// <param name="walLocation">The WAL location to begin streaming at.</param>
 /// <param name="cancellationToken">The token to be used for stopping the replication.</param>
 /// <param name="timeline">Streaming starts on timeline tli.</param>
 /// <returns>A <see cref="Task{T}"/> representing an <see cref="IAsyncEnumerable{NpgsqlXLogDataMessage}"/> that
 /// can be used to stream WAL entries in form of <see cref="XLogDataMessage"/> instances.</returns>
 public IAsyncEnumerable <XLogDataMessage> StartReplication(
     NpgsqlLogSequenceNumber walLocation, CancellationToken cancellationToken, ulong timeline = default)
 => StartReplication(slot: null, walLocation: walLocation, timeline: timeline, cancellationToken: cancellationToken);
コード例 #27
0
 public bool NpgsqlLogSequenceNumber_equals(NpgsqlLogSequenceNumber lsn, object?obj)
 => lsn.Equals(obj);
コード例 #28
0
 internal new StreamStopMessage Populate(NpgsqlLogSequenceNumber walStart, NpgsqlLogSequenceNumber walEnd, DateTime serverClock)
 {
     base.Populate(walStart, walEnd, serverClock);
     return(this);
 }
コード例 #29
0
    private protected void Populate(NpgsqlLogSequenceNumber walStart, NpgsqlLogSequenceNumber walEnd, DateTime serverClock, uint transactionXid)
    {
        base.Populate(walStart, walEnd, serverClock);

        TransactionXid = transactionXid;
    }
コード例 #30
0
ファイル: ReplicationMessage.cs プロジェクト: lillo42/npgsql
 private protected void Populate(NpgsqlLogSequenceNumber walStart, NpgsqlLogSequenceNumber walEnd, DateTime serverClock)
 {
     WalStart    = walStart;
     WalEnd      = walEnd;
     ServerClock = serverClock;
 }