Table of Contents

Class KickRequestReadWindow

Namespace
FishMMO.Database.Data
Assembly
FishMMO-DB.dll

Where a game server's poll of the kick requests has got to, and which requests it has already handled, on the database clock. Pure bookkeeping: no database, no network, one poll at a time.

public sealed class KickRequestReadWindow
Inheritance
KickRequestReadWindow
Inherited Members

Remarks

Why the database clock. A request is stamped by the database when it is written. The poller's cursor used to be seeded from its own host clock and compared with those stamps: a host running ahead of the database skipped every kick stamped inside the lead, for good. Every instant here comes from the database, through KickRequestPage, and the one local measurement — how long ago the reader started — only ever reaches the database as a duration (FirstReadLookbackSeconds).

Why a window and not a cursor. A request becomes visible when its transaction commits, some time after its stamp: a ban writes its kick inside a longer transaction, stamped at that transaction's start. Two writers can therefore commit in the opposite order to their stamps, and a strict (time, id) cursor that has moved past a stamp before its row committed never sees the row. So the poll reads from Watermark, held CommitWindow behind what it has settled, and skips what it has already handled (SnapshotHandled(out long[], out DateTime[])), as the chat pump does (ChatReadWindow). A kick is acted on exactly once as long as it commits within the window of its stamp.

Why handled is (id, stamp). Requests are upserted per account: kicking an account that already has a row keeps the row's ID and moves its stamp. Keyed on the ID alone, that second kick would be skipped as already handled.

Why a floor. Nothing before the reader's first read is re-read by the window's reach back; the first read itself starts at the moment the reader began watching.

Constructors

KickRequestReadWindow(TimeSpan)

Creates a window with the given commit window.

public KickRequestReadWindow(TimeSpan commitWindow)

Parameters

commitWindow TimeSpan

Properties

CommitWindow

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

public TimeSpan CommitWindow { get; }

Property Value

TimeSpan

HandledCount

Requests handled that the next read could still return.

public int HandledCount { get; }

Property Value

int

Watermark

The oldest stamp the next read starts from, or null before the first read. Only ever moves forward.

public DateTime? Watermark { get; }

Property Value

DateTime?

Methods

BuildQuery(int, double)

The query for the next read.

public KickRequestPollQuery BuildQuery(int pageSize, double secondsSinceReaderStarted)

Parameters

pageSize int

Most requests to return.

secondsSinceReaderStarted double

How long ago the reader began watching, by its own monotonic clock. Used only by a first read; see FirstReadLookbackSeconds.

Returns

KickRequestPollQuery

CompleteRead(DateTime, DateTime, DateTime?)

Settles a completed read: moves the watermark and forgets requests it has passed. Called after every read that returned, including one that returned nothing, or an idle reader's window never advances. Not called after a read that failed, so it is read again.

public void CompleteRead(DateTime readFromUtc, DateTime readStartedUtc, DateTime? unsettledFromUtc)

Parameters

readFromUtc DateTime

The stamp the read started from (ReadFromUtc).

readStartedUtc DateTime

The database clock taken before the read (ReadStartedUtc).

unsettledFromUtc DateTime?

See UnsettledFrom(bool, DateTime?, DateTime?).

IsHandled(long, DateTime)

Whether this request, at this stamp, has already been handled.

public bool IsHandled(long id, DateTime timeCreatedUtc)

Parameters

id long
timeCreatedUtc DateTime

Returns

bool

MarkHandled(long, DateTime)

Records one request as handled: its kick is on its way, or it was found stale. Only a request that was actually settled is recorded, so one that could not be handed on is read again.

public bool MarkHandled(long id, DateTime timeCreatedUtc)

Parameters

id long
timeCreatedUtc DateTime

Returns

bool

True the first time; false for a request already handled at this stamp.

Reset()

Forgets everything, for a reader that is starting again.

public void Reset()

SnapshotHandled(out long[], out DateTime[])

The requests handled that the next read could return again, for the read to skip.

public void SnapshotHandled(out long[] ids, out DateTime[] stamps)

Parameters

ids long[]
stamps DateTime[]

UnsettledFrom(bool, DateTime?, DateTime?)

Where a read left requests unsettled, as the stamp to read from again, or null when it settled everything up to the moment it started.

public static DateTime? UnsettledFrom(bool drained, DateTime? lastRowUtc, DateTime? firstUnsettledUtc)

Parameters

drained bool

Whether the page came back short.

lastRowUtc DateTime?

The stamp of the page's last request, or null for an empty page.

firstUnsettledUtc DateTime?

The stamp of the first request the read could not hand on, or null when it handed on every one it was given.

Returns

DateTime?

Remarks

A request that could not be handed on, and everything after it, is still owed; a full page says nothing about the requests after its last row. Only a short page with nothing refused has read everything that had committed when the read started.