Struct NpgsqlLogSequenceNumber
- Namespace
- NpgsqlTypes
- Assembly
- Npgsql.dll
Wraps a PostgreSQL Write-Ahead Log Sequence Number (see: https://www.postgresql.org/docs/current/datatype-pg-lsn.html)
public readonly struct NpgsqlLogSequenceNumber : IEquatable<NpgsqlLogSequenceNumber>, IComparable<NpgsqlLogSequenceNumber>
- Implements
- Inherited Members
Remarks
Log Sequence Numbers are a fundamental concept of the PostgreSQL Write-Ahead Log and by that of PostgreSQL replication. See https://www.postgresql.org/docs/current/wal-internals.html for what they represent.
This struct provides conversions from/to string and ulong and beyond that tries to port the methods and operators in https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/backend/utils/adt/pg_lsn.c but nothing more.
Constructors
NpgsqlLogSequenceNumber(ulong)
Initializes a new instance of NpgsqlLogSequenceNumber.
public NpgsqlLogSequenceNumber(ulong value)
Parameters
value
ulongThe value to wrap.
Fields
Invalid
Zero is used indicate an invalid Log Sequence Number. No XLOG record can begin at zero.
public static readonly NpgsqlLogSequenceNumber Invalid
Field Value
Methods
CompareTo(NpgsqlLogSequenceNumber)
Compares this instance to a specified NpgsqlLogSequenceNumber and returns an indication of their relative values.
public int CompareTo(NpgsqlLogSequenceNumber value)
Parameters
value
NpgsqlLogSequenceNumberA NpgsqlLogSequenceNumber instance to compare to this instance.
Returns
- int
A signed number indicating the relative values of this instance and
value
.
Equals(NpgsqlLogSequenceNumber)
Returns a value indicating whether this instance is equal to a specified NpgsqlLogSequenceNumber instance.
public bool Equals(NpgsqlLogSequenceNumber other)
Parameters
other
NpgsqlLogSequenceNumberA NpgsqlLogSequenceNumber instance to compare to this instance.
Returns
Equals(object?)
Returns a value indicating whether this instance is equal to a specified object.
public override bool Equals(object? obj)
Parameters
obj
objectAn object to compare to this instance
Returns
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer hash code.
Larger(NpgsqlLogSequenceNumber, NpgsqlLogSequenceNumber)
Returns the larger of two NpgsqlLogSequenceNumber values.
public static NpgsqlLogSequenceNumber Larger(NpgsqlLogSequenceNumber value1, NpgsqlLogSequenceNumber value2)
Parameters
value1
NpgsqlLogSequenceNumberThe first value to compare.
value2
NpgsqlLogSequenceNumberThe second value to compare.
Returns
- NpgsqlLogSequenceNumber
The larger of the two NpgsqlLogSequenceNumber values.
Parse(ReadOnlySpan<char>)
Converts the span representation of a Log Sequence Number to a NpgsqlLogSequenceNumber instance.
public static NpgsqlLogSequenceNumber Parse(ReadOnlySpan<char> s)
Parameters
s
ReadOnlySpan<char>A span containing the characters that represent the Log Sequence Number to convert.
Returns
- NpgsqlLogSequenceNumber
A NpgsqlLogSequenceNumber equivalent to the Log Sequence Number specified in
s
.
Exceptions
- OverflowException
The
s
parameter represents a number less than MinValue or greater than MaxValue.- FormatException
The
s
parameter is not in the right format.
Parse(string)
Converts the string representation of a Log Sequence Number to a NpgsqlLogSequenceNumber instance.
public static NpgsqlLogSequenceNumber Parse(string s)
Parameters
s
stringA string that represents the Log Sequence Number to convert.
Returns
- NpgsqlLogSequenceNumber
A NpgsqlLogSequenceNumber equivalent to the Log Sequence Number specified in
s
.
Exceptions
- ArgumentNullException
The
s
parameter is null.- OverflowException
The
s
parameter represents a number less than MinValue or greater than MaxValue.- FormatException
The
s
parameter is not in the right format.
Smaller(NpgsqlLogSequenceNumber, NpgsqlLogSequenceNumber)
Returns the smaller of two NpgsqlLogSequenceNumber values.
public static NpgsqlLogSequenceNumber Smaller(NpgsqlLogSequenceNumber value1, NpgsqlLogSequenceNumber value2)
Parameters
value1
NpgsqlLogSequenceNumberThe first value to compare.
value2
NpgsqlLogSequenceNumberThe second value to compare.
Returns
- NpgsqlLogSequenceNumber
The smaller of the two NpgsqlLogSequenceNumber values.
ToString()
Converts the numeric value of this instance to its equivalent string representation.
public override string ToString()
Returns
- string
The string representation of the value of this instance, consisting of two hexadecimal numbers of up to 8 digits each, separated by a slash
TryParse(ReadOnlySpan<char>, out NpgsqlLogSequenceNumber)
Tries to convert the span representation of a Log Sequence Number to an NpgsqlLogSequenceNumber instance. A return value indicates whether the conversion succeeded or failed.
public static bool TryParse(ReadOnlySpan<char> s, out NpgsqlLogSequenceNumber result)
Parameters
s
ReadOnlySpan<char>A span containing the characters that represent the Log Sequence Number to convert.
result
NpgsqlLogSequenceNumberWhen this method returns, contains a NpgsqlLogSequenceNumber instance equivalent to the Log Sequence Number contained in
s
, if the conversion succeeded, or the default value for NpgsqlLogSequenceNumber (0
) if the conversion failed. The conversion fails if thes
parameter is empty, is not in the right format, or represents a number less than MinValue or greater than MaxValue. This parameter is passed uninitialized; any value originally supplied in result will be overwritten.
Returns
TryParse(string, out NpgsqlLogSequenceNumber)
Tries to convert the string representation of a Log Sequence Number to an NpgsqlLogSequenceNumber instance. A return value indicates whether the conversion succeeded or failed.
public static bool TryParse(string s, out NpgsqlLogSequenceNumber result)
Parameters
s
stringA string that represents the Log Sequence Number to convert.
result
NpgsqlLogSequenceNumberWhen this method returns, contains a NpgsqlLogSequenceNumber instance equivalent to the Log Sequence Number contained in
s
, if the conversion succeeded, or the default value for NpgsqlLogSequenceNumber (0
) if the conversion failed. The conversion fails if thes
parameter is null or Empty, is not in the right format, or represents a number less than MinValue or greater than MaxValue. This parameter is passed uninitialized; any value originally supplied in result will be overwritten.
Returns
Operators
operator +(NpgsqlLogSequenceNumber, double)
Add the number of bytes to a NpgsqlLogSequenceNumber instance, giving a new NpgsqlLogSequenceNumber instance. Handles both positive and negative numbers of bytes.
public static NpgsqlLogSequenceNumber operator +(NpgsqlLogSequenceNumber lsn, double nbytes)
Parameters
lsn
NpgsqlLogSequenceNumberThe NpgsqlLogSequenceNumber instance representing a write-ahead log location.
nbytes
doubleThe number of bytes to add.
Returns
- NpgsqlLogSequenceNumber
A new NpgsqlLogSequenceNumber instance.
Exceptions
- OverflowException
The resulting NpgsqlLogSequenceNumber instance would represent a number greater than MaxValue.
operator ==(NpgsqlLogSequenceNumber, NpgsqlLogSequenceNumber)
Returns a value that indicates whether two specified instances of NpgsqlLogSequenceNumber are equal.
public static bool operator ==(NpgsqlLogSequenceNumber value1, NpgsqlLogSequenceNumber value2)
Parameters
value1
NpgsqlLogSequenceNumberThe first Log Sequence Number to compare.
value2
NpgsqlLogSequenceNumberThe second Log Sequence Number to compare.
Returns
explicit operator ulong(NpgsqlLogSequenceNumber)
Converts the value of a NpgsqlLogSequenceNumber instance to a 64-bit unsigned integer value.
public static explicit operator ulong(NpgsqlLogSequenceNumber value)
Parameters
value
NpgsqlLogSequenceNumberA NpgsqlLogSequenceNumber instance
Returns
- ulong
The contents of
value
as 64-bit unsigned integer.
explicit operator NpgsqlLogSequenceNumber(ulong)
Converts the value of a 64-bit unsigned integer to a NpgsqlLogSequenceNumber instance.
public static explicit operator NpgsqlLogSequenceNumber(ulong value)
Parameters
value
ulongA 64-bit unsigned integer.
Returns
- NpgsqlLogSequenceNumber
A new instance of NpgsqlLogSequenceNumber initialized to
value
.
operator >(NpgsqlLogSequenceNumber, NpgsqlLogSequenceNumber)
Returns a value indicating whether a specified NpgsqlLogSequenceNumber instance is greater than another specified NpgsqlLogSequenceNumber instance.
public static bool operator >(NpgsqlLogSequenceNumber value1, NpgsqlLogSequenceNumber value2)
Parameters
value1
NpgsqlLogSequenceNumberThe first value to compare.
value2
NpgsqlLogSequenceNumberThe second value to compare.
Returns
operator >=(NpgsqlLogSequenceNumber, NpgsqlLogSequenceNumber)
Returns a value indicating whether a specified NpgsqlLogSequenceNumber instance is greater than or equal to another specified NpgsqlLogSequenceNumber instance.
public static bool operator >=(NpgsqlLogSequenceNumber value1, NpgsqlLogSequenceNumber value2)
Parameters
value1
NpgsqlLogSequenceNumberThe first value to compare.
value2
NpgsqlLogSequenceNumberThe second value to compare.
Returns
operator !=(NpgsqlLogSequenceNumber, NpgsqlLogSequenceNumber)
Returns a value that indicates whether two specified instances of NpgsqlLogSequenceNumber are not equal.
public static bool operator !=(NpgsqlLogSequenceNumber value1, NpgsqlLogSequenceNumber value2)
Parameters
value1
NpgsqlLogSequenceNumberThe first Log Sequence Number to compare.
value2
NpgsqlLogSequenceNumberThe second Log Sequence Number to compare.
Returns
operator <(NpgsqlLogSequenceNumber, NpgsqlLogSequenceNumber)
Returns a value indicating whether a specified NpgsqlLogSequenceNumber instance is less than another specified NpgsqlLogSequenceNumber instance.
public static bool operator <(NpgsqlLogSequenceNumber value1, NpgsqlLogSequenceNumber value2)
Parameters
value1
NpgsqlLogSequenceNumberThe first value to compare.
value2
NpgsqlLogSequenceNumberThe second value to compare.
Returns
operator <=(NpgsqlLogSequenceNumber, NpgsqlLogSequenceNumber)
Returns a value indicating whether a specified NpgsqlLogSequenceNumber instance is less than or equal to another specified NpgsqlLogSequenceNumber instance.
public static bool operator <=(NpgsqlLogSequenceNumber value1, NpgsqlLogSequenceNumber value2)
Parameters
value1
NpgsqlLogSequenceNumberThe first value to compare.
value2
NpgsqlLogSequenceNumberThe second value to compare.
Returns
operator -(NpgsqlLogSequenceNumber, NpgsqlLogSequenceNumber)
Subtracts two specified NpgsqlLogSequenceNumber values.
public static ulong operator -(NpgsqlLogSequenceNumber first, NpgsqlLogSequenceNumber second)
Parameters
first
NpgsqlLogSequenceNumberThe first NpgsqlLogSequenceNumber value.
second
NpgsqlLogSequenceNumberThe second NpgsqlLogSequenceNumber value.
Returns
- ulong
The number of bytes separating those write-ahead log locations.
operator -(NpgsqlLogSequenceNumber, double)
Subtract the number of bytes from a NpgsqlLogSequenceNumber instance, giving a new NpgsqlLogSequenceNumber instance. Handles both positive and negative numbers of bytes.
public static NpgsqlLogSequenceNumber operator -(NpgsqlLogSequenceNumber lsn, double nbytes)
Parameters
lsn
NpgsqlLogSequenceNumberThe NpgsqlLogSequenceNumber instance representing a write-ahead log location.
nbytes
doubleThe number of bytes to subtract.
Returns
- NpgsqlLogSequenceNumber
A new NpgsqlLogSequenceNumber instance.
Exceptions
- OverflowException
The resulting NpgsqlLogSequenceNumber instance would represent a number less than MinValue.