Table of Contents

Class ChatPumpCursor

Namespace
FishMMO.Server.Core.World.SceneServer
Assembly
FishMMO.Server.dll

Where one scene server's cross-server chat pump has got to, and what it has already handled. Pure bookkeeping on the database clock: no network, no database, main thread only.

public sealed class ChatPumpCursor
Inheritance
ChatPumpCursor
Inherited Members

Remarks

Why a window and not a cursor. A chat row is stamped by the database clock when its INSERT runs and becomes visible when its transaction commits. Two writers can commit in the opposite order to their stamps, so a strict (time, id) cursor that has moved past a row's stamp before the row committed never sees it: the whisper, party or guild line is lost on every other scene server (hot-path audit H5). The pump therefore reads from Watermark, held CommitWindow behind what it has settled, and skips by ID what it has already handled (SnapshotSeenIds()). A row is caught as long as it commits within the window of its stamp.

Why a key has a start. The pump asks only for rows relevant to someone this server hosts. The window then has a side effect a strict cursor did not: a player who arrives from another scene server makes their party, guild and name relevant here, and the next read reaches back a whole window — re-delivering lines the server they left had already shown them. So a key that becomes relevant is only wanted from the start of the read BEFORE the one that first asks for it (BeginRead(ICollection<ChatPumpKey>)). That is exactly the exposure the strict cursor had: lines stamped between this server's last read and the arrival may reach the player twice, as they always could; nothing older does.

Why a floor. Nothing stamped before this server's first read is ever read. The window reaches back from each read, and without the floor the second read would replay the window before the server started pumping.

Constructors

ChatPumpCursor(TimeSpan)

Creates a cursor with the given commit window.

public ChatPumpCursor(TimeSpan commitWindow)

Parameters

commitWindow TimeSpan

Properties

CommitWindow

How long after its stamp a row may commit and still be read.

public TimeSpan CommitWindow { get; }

Property Value

TimeSpan

KeyCount

Keys currently relevant.

public int KeyCount { get; }

Property Value

int

LastReadStartedUtc

The database clock at the start of the last completed read, or null before the first.

public DateTime? LastReadStartedUtc { get; }

Property Value

DateTime?

SeenCount

Rows handled that the next read could still return.

public int SeenCount { get; }

Property Value

int

Watermark

The oldest stamp the next read starts from, or null before the first read, which starts at the database's own "now". Only ever moves forward.

public DateTime? Watermark { get; }

Property Value

DateTime?

Methods

Admit(long, DateTime, ChatPumpKey)

Decides whether one row the read returned is delivered, and records it as handled either way.

public bool Admit(long id, DateTime timeCreatedUtc, ChatPumpKey key)

Parameters

id long

The row's ID.

timeCreatedUtc DateTime

The row's database-clock stamp.

key ChatPumpKey

The row's relevance key.

Returns

bool

True to deliver. False for a row already handled, or one stamped before its key became relevant here — which the server the player came from was responsible for.

BeginRead(ICollection<ChatPumpKey>)

Records the keys the next read asks for. A key new since the last call is wanted from the start of the previous read; a key no longer asked for is forgotten.

public void BeginRead(ICollection<ChatPumpKey> relevantKeys)

Parameters

relevantKeys ICollection<ChatPumpKey>

Every key this server hosts right now.

CompleteRead(DateTime, bool, DateTime?)

Settles a completed read: moves the watermark and forgets rows it has passed.

public void CompleteRead(DateTime readStartedUtc, bool drained, DateTime? lastRowTimeUtc)

Parameters

readStartedUtc DateTime

The database clock taken before the read's first page.

drained bool

True if the read caught up; false if it stopped at its page limit.

lastRowTimeUtc DateTime?

The stamp of the last row read, or null if none were.

PinFloor(DateTime)

Pins the floor at the start of a first read whose rows never reached this cursor.

public void PinFloor(DateTime readStartedUtc)

Parameters

readStartedUtc DateTime

The database clock taken before that read's first page.

Remarks

The first read has no watermark and starts at the database's "now". If its rows are lost on the way back (the main-thread queue refused them), nothing recorded where it started, and the next read would start at a later "now" and skip everything committed in between. Pinning its start here makes the next read cover that span. Does nothing once a read has completed.

Reset()

Forgets everything, for a server that is starting its pump again.

public void Reset()

SnapshotSeenIds()

The IDs of the rows handled that the next read could return again, for the read to skip.

public long[] SnapshotSeenIds()

Returns

long[]