Skip to content

Commit d5efe94

Browse files
committed
more comments
1 parent 01d473f commit d5efe94

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+743
-15
lines changed

src/SciSharp.MySQL.Replication/ChecksumType.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,19 @@
44

55
namespace SciSharp.MySQL.Replication
66
{
7+
/// <summary>
8+
/// Defines the types of checksums used in MySQL replication events.
9+
/// </summary>
710
public enum ChecksumType : int
811
{
12+
/// <summary>
13+
/// No checksum is used.
14+
/// </summary>
915
NONE = 0,
16+
17+
/// <summary>
18+
/// CRC32 checksum algorithm is used.
19+
/// </summary>
1020
CRC32 = 4
1121
}
1222
}

src/SciSharp.MySQL.Replication/DefaultCharset.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,19 @@
33

44
namespace SciSharp.MySQL.Replication
55
{
6+
/// <summary>
7+
/// Represents charset information for MySQL replication.
8+
/// </summary>
69
public class DefaultCharset
710
{
11+
/// <summary>
12+
/// Gets or sets the default collation ID for the charset.
13+
/// </summary>
814
public int DefaultCharsetCollation { get; set; }
915

16+
/// <summary>
17+
/// Gets or sets a dictionary mapping charset IDs to their corresponding collation IDs.
18+
/// </summary>
1019
public Dictionary<int, int> CharsetCollations { get; set; }
1120
}
1221
}

src/SciSharp.MySQL.Replication/Events/CellValue.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,20 @@
77

88
namespace SciSharp.MySQL.Replication
99
{
10+
/// <summary>
11+
/// Represents a value of a cell in a row, containing both old and new values.
12+
/// Used in replication events to track changes between states of a row.
13+
/// </summary>
1014
public class CellValue
1115
{
16+
/// <summary>
17+
/// Gets or sets the old value of the cell.
18+
/// </summary>
1219
public object OldValue { get; set; }
1320

21+
/// <summary>
22+
/// Gets or sets the new value of the cell.
23+
/// </summary>
1424
public object NewValue { get; set; }
1525
}
1626
}

src/SciSharp.MySQL.Replication/Events/DefaultEventFactory.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,18 @@
33

44
namespace SciSharp.MySQL.Replication
55
{
6-
6+
/// <summary>
7+
/// Default implementation of the log event factory that creates events of a specified type.
8+
/// </summary>
9+
/// <typeparam name="TEventType">The type of log event to create.</typeparam>
710
class DefaultEventFactory<TEventType> : ILogEventFactory
811
where TEventType : LogEvent, new()
912
{
13+
/// <summary>
14+
/// Creates a new instance of a log event.
15+
/// </summary>
16+
/// <param name="context">The context information for creating the event.</param>
17+
/// <returns>A new instance of the specified log event type.</returns>
1018
public LogEvent Create(object context)
1119
{
1220
return new TEventType();

src/SciSharp.MySQL.Replication/Events/DeleteRowsEvent.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
namespace SciSharp.MySQL.Replication
99
{
10+
/// <summary>
11+
/// Represents a MySQL binary log event that contains rows deleted from a table.
12+
/// This event is generated for a delete operation on a row in a MySQL table.
13+
/// </summary>
1014
public sealed class DeleteRowsEvent : RowsEvent
1115
{
1216
public DeleteRowsEvent()

src/SciSharp.MySQL.Replication/Events/EmptyPayloadEvent.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,17 @@
33

44
namespace SciSharp.MySQL.Replication
55
{
6+
/// <summary>
7+
/// Represents a log event with an empty payload.
8+
/// This is used for events that don't contain any additional data beyond their headers.
9+
/// </summary>
610
public sealed class EmptyPayloadEvent : LogEvent
711
{
12+
/// <summary>
13+
/// Decodes the body of the empty payload event, which contains no data.
14+
/// </summary>
15+
/// <param name="reader">The sequence reader containing the binary data.</param>
16+
/// <param name="context">The context for decoding.</param>
817
protected internal override void DecodeBody(ref SequenceReader<byte> reader, object context)
918
{
1019

src/SciSharp.MySQL.Replication/Events/ErrorEvent.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,32 @@
55

66
namespace SciSharp.MySQL.Replication
77
{
8+
/// <summary>
9+
/// Represents an error event in the MySQL binary log.
10+
/// Contains information about errors that occurred during the replication process.
11+
/// </summary>
812
public sealed class ErrorEvent : LogEvent
913
{
14+
/// <summary>
15+
/// Gets the error code associated with this error event.
16+
/// </summary>
1017
public short ErrorCode { get; private set; }
18+
19+
/// <summary>
20+
/// Gets the SQL state code, a standard error code consisting of five characters.
21+
/// </summary>
1122
public string SqlState { get; private set; }
23+
24+
/// <summary>
25+
/// Gets the human-readable error message.
26+
/// </summary>
1227
public String ErrorMessage { get; private set; }
28+
29+
/// <summary>
30+
/// Decodes the body of the error event from the binary log.
31+
/// </summary>
32+
/// <param name="reader">The sequence reader containing the binary data.</param>
33+
/// <param name="context">The context for decoding.</param>
1334
protected internal override void DecodeBody(ref SequenceReader<byte> reader, object context)
1435
{
1536
reader.TryReadLittleEndian(out short errorCode);
@@ -28,6 +49,10 @@ protected internal override void DecodeBody(ref SequenceReader<byte> reader, obj
2849
ErrorMessage = reader.Sequence.Slice(reader.Consumed).GetString(Encoding.UTF8);
2950
}
3051

52+
/// <summary>
53+
/// Returns a string representation of the error event.
54+
/// </summary>
55+
/// <returns>A string containing the event type, SQL state, and error message.</returns>
3156
public override string ToString()
3257
{
3358
return $"{EventType.ToString()}\r\nSqlState: {SqlState}\r\nErrorMessage: {ErrorMessage}";

src/SciSharp.MySQL.Replication/Events/NotImplementedEvent.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,19 @@
33

44
namespace SciSharp.MySQL.Replication
55
{
6+
/// <summary>
7+
/// Represents a placeholder for log event types that have not been implemented yet.
8+
/// This event is used when the system encounters an event type that it recognizes
9+
/// but doesn't have specific handling logic for.
10+
/// </summary>
611
public sealed class NotImplementedEvent : LogEvent
712
{
13+
/// <summary>
14+
/// Decodes the body of the not implemented event. This implementation is intentionally
15+
/// empty as the event doesn't process any content.
16+
/// </summary>
17+
/// <param name="reader">The sequence reader containing the binary data.</param>
18+
/// <param name="context">The context for decoding.</param>
819
protected internal override void DecodeBody(ref SequenceReader<byte> reader, object context)
920
{
1021

src/SciSharp.MySQL.Replication/Events/RowEventFlags.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,31 @@
77

88
namespace SciSharp.MySQL.Replication
99
{
10+
/// <summary>
11+
/// Specifies flags that provide additional information about rows events in MySQL replication.
12+
/// These flags describe configuration settings and state information for row operations.
13+
/// </summary>
1014
[Flags]
1115
public enum RowsEventFlags : byte
1216
{
17+
/// <summary>
18+
/// Indicates the end of a statement.
19+
/// </summary>
1320
EndOfStatement = 0x01,
21+
22+
/// <summary>
23+
/// Indicates that foreign key checks are disabled.
24+
/// </summary>
1425
NoForeignKeyChecks = 0x02,
26+
27+
/// <summary>
28+
/// Indicates that unique key checks are disabled.
29+
/// </summary>
1530
NoUniqueKeyChecks = 0x04,
31+
32+
/// <summary>
33+
/// Indicates that row has a columns bitmap.
34+
/// </summary>
1635
RowHasAColumns = 0x08
1736
}
1837
}

src/SciSharp.MySQL.Replication/Events/UpdateRowsEvent.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,52 @@
66

77
namespace SciSharp.MySQL.Replication
88
{
9+
/// <summary>
10+
/// Represents a MySQL binary log event that contains rows updated in a table.
11+
/// This event is generated for an update operation on rows in a MySQL table and
12+
/// contains both the before and after values of the affected rows.
13+
/// </summary>
914
public sealed class UpdateRowsEvent : RowsEvent
1015
{
16+
/// <summary>
17+
/// Gets the bitmap indicating which columns are included in the before-update image.
18+
/// </summary>
1119
public BitArray IncludedColumnsBeforeUpdate { get; private set; }
1220

21+
/// <summary>
22+
/// Reads the included columns bitmaps from the binary representation.
23+
/// For update events, this includes both the before and after update column bitmaps.
24+
/// </summary>
25+
/// <param name="reader">The sequence reader containing the binary data.</param>
1326
protected override void ReadIncludedColumns(ref SequenceReader<byte> reader)
1427
{
1528
var columnCount = (int)reader.ReadLengthEncodedInteger();
1629
IncludedColumnsBeforeUpdate = reader.ReadBitArray(columnCount);
1730
IncludedColumns = reader.ReadBitArray(columnCount);
1831
}
1932

33+
/// <summary>
34+
/// Reads the row data from the binary representation, including both
35+
/// before and after values for updated rows.
36+
/// </summary>
37+
/// <param name="reader">The sequence reader containing the binary data.</param>
38+
/// <param name="includedColumns">The bitmap of columns present in the row data.</param>
39+
/// <param name="tableMap">The table mapping information.</param>
40+
/// <param name="columnCount">The number of columns.</param>
2041
protected override void ReadData(ref SequenceReader<byte> reader, BitArray includedColumns, TableMapEvent tableMap, int columnCount)
2142
{
2243
RowSet = ReadUpdatedRows(ref reader, tableMap, IncludedColumnsBeforeUpdate, includedColumns, columnCount);
2344
}
2445

46+
/// <summary>
47+
/// Reads the updated rows data from the binary representation.
48+
/// </summary>
49+
/// <param name="reader">The sequence reader containing the binary data.</param>
50+
/// <param name="tableMap">The table mapping information.</param>
51+
/// <param name="includedColumnsBeforeUpdate">The bitmap of columns included in the before-update image.</param>
52+
/// <param name="includedColumns">The bitmap of columns included in the after-update image.</param>
53+
/// <param name="columnCount">The number of columns.</param>
54+
/// <returns>A RowSet containing the updated rows data with both before and after values.</returns>
2555
private RowSet ReadUpdatedRows(ref SequenceReader<byte> reader, TableMapEvent tableMap, BitArray includedColumnsBeforeUpdate, BitArray includedColumns, int columnCount)
2656
{
2757
var columnCountBeforeUpdate = GetIncludedColumnCount(IncludedColumnsBeforeUpdate);
@@ -56,6 +86,10 @@ private RowSet ReadUpdatedRows(ref SequenceReader<byte> reader, TableMapEvent ta
5686
};
5787
}
5888

89+
/// <summary>
90+
/// Returns a string representation of the UpdateRowsEvent.
91+
/// </summary>
92+
/// <returns>A string containing the event type, table ID, and before/after row values.</returns>
5993
public override string ToString()
6094
{
6195
var sb = new StringBuilder();

src/SciSharp.MySQL.Replication/Events/WriteRowsEvent.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@
77

88
namespace SciSharp.MySQL.Replication
99
{
10+
/// <summary>
11+
/// Represents a MySQL binary log event that contains rows inserted into a table.
12+
/// This event is generated for an insert operation on a MySQL table.
13+
/// </summary>
1014
public sealed class WriteRowsEvent : RowsEvent
1115
{
12-
16+
/// <summary>
17+
/// Initializes a new instance of the <see cref="WriteRowsEvent"/> class.
18+
/// </summary>
1319
public WriteRowsEvent()
1420
: base()
1521
{

src/SciSharp.MySQL.Replication/Events/XIDEvent.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,22 @@
55

66
namespace SciSharp.MySQL.Replication
77
{
8+
/// <summary>
9+
/// Represents a MySQL XID_EVENT that marks the end of a transaction that modifies data.
10+
/// This event contains the transaction ID used for the binary log.
11+
/// </summary>
812
public sealed class XIDEvent : LogEvent
913
{
14+
/// <summary>
15+
/// Gets or sets the ID of the transaction.
16+
/// </summary>
1017
public long TransactionID { get; set; }
1118

19+
/// <summary>
20+
/// Decodes the body of the XID event from the binary representation.
21+
/// </summary>
22+
/// <param name="reader">The sequence reader containing the binary data.</param>
23+
/// <param name="context">The context for decoding.</param>
1224
protected internal override void DecodeBody(ref SequenceReader<byte> reader, object context)
1325
{
1426
reader.TryReadLittleEndian(out long tarnsID);

src/SciSharp.MySQL.Replication/ILogEventFactory.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@
44

55
namespace SciSharp.MySQL.Replication
66
{
7+
/// <summary>
8+
/// Interface for factories that create log events from context objects.
9+
/// </summary>
710
interface ILogEventFactory
811
{
12+
/// <summary>
13+
/// Creates a log event from the provided context.
14+
/// </summary>
15+
/// <param name="context">The context object containing data to create the log event.</param>
16+
/// <returns>A new log event instance.</returns>
917
LogEvent Create(object context);
1018
}
1119
}

src/SciSharp.MySQL.Replication/IMySQLDataType.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,17 @@
55

66
namespace SciSharp.MySQL.Replication
77
{
8+
/// <summary>
9+
/// Interface that defines MySQL data type read operations.
10+
/// </summary>
811
internal interface IMySQLDataType
912
{
13+
/// <summary>
14+
/// Reads a value from the sequence reader based on the metadata.
15+
/// </summary>
16+
/// <param name="reader">The sequence reader containing binary data.</param>
17+
/// <param name="meta">Metadata that describes the data format.</param>
18+
/// <returns>The deserialized object value.</returns>
1019
object ReadValue(ref SequenceReader<byte> reader, int meta);
1120
}
1221
}

src/SciSharp.MySQL.Replication/IReplicationClient.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,46 @@
55

66
namespace SciSharp.MySQL.Replication
77
{
8+
/// <summary>
9+
/// Interface for MySQL replication client that handles database event streaming.
10+
/// </summary>
811
public interface IReplicationClient
912
{
13+
/// <summary>
14+
/// Connects to a MySQL server with the specified credentials.
15+
/// </summary>
16+
/// <param name="server">The server address to connect to.</param>
17+
/// <param name="username">The username for authentication.</param>
18+
/// <param name="password">The password for authentication.</param>
19+
/// <param name="serverId">The server ID to use for the replication client.</param>
20+
/// <returns>A task that represents the asynchronous login operation and contains the login result.</returns>
1021
Task<LoginResult> ConnectAsync(string server, string username, string password, int serverId);
1122

23+
/// <summary>
24+
/// Receives the next log event from the server.
25+
/// </summary>
26+
/// <returns>A task representing the asynchronous receive operation and containing the log event.</returns>
1227
ValueTask<LogEvent> ReceiveAsync();
1328

29+
/// <summary>
30+
/// Closes the connection to the server.
31+
/// </summary>
32+
/// <returns>A task representing the asynchronous close operation.</returns>
1433
ValueTask CloseAsync();
1534

35+
/// <summary>
36+
/// Starts the continuous receiving of log events from the server.
37+
/// </summary>
1638
void StartReceive();
1739

40+
/// <summary>
41+
/// Event triggered when a log event package is received.
42+
/// </summary>
1843
event PackageHandler<LogEvent> PackageHandler;
1944

45+
/// <summary>
46+
/// Event triggered when the connection is closed.
47+
/// </summary>
2048
event EventHandler Closed;
2149
}
2250
}

0 commit comments

Comments
 (0)