Table of Contents

Class InFlightLookupTable<TKey, TWaiter>

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

Lookups in flight, keyed by what is being looked up, each with every requester waiting on it. Main thread only.

public sealed class InFlightLookupTable<TKey, TWaiter>

Type Parameters

TKey

What is being looked up.

TWaiter

Who is waiting for the answer.

Inheritance
InFlightLookupTable<TKey, TWaiter>
Inherited Members

Remarks

A second request joins the first. The naming system used to mark a key in flight with a bare flag, so a second connection asking for the same ID while the first fetch ran was simply dropped — no fetch of its own, and no share of the first one's answer (hot-path audit M18). Every requester now waits on the one fetch, and the answer goes to all of them.

A lookup that never answers is abandoned, not trusted forever. The answer comes back through the main-thread queue, which can refuse it when full. A key whose fetch has been out longer than the stale bound is treated as lost: the next request for it starts a new fetch and inherits the waiters, and SweepStale(DateTime, TimeSpan) drops one nobody asks for again.

Pure bookkeeping, generic over the waiter so the rule can be pinned without a connection.

Constructors

InFlightLookupTable(int, int, IEqualityComparer<TKey>, IEqualityComparer<TWaiter>)

Creates a table.

public InFlightLookupTable(int maxEntries, int maxWaitersPerEntry, IEqualityComparer<TKey> keyComparer = null, IEqualityComparer<TWaiter> waiterComparer = null)

Parameters

maxEntries int

Most keys in flight at once.

maxWaitersPerEntry int

Most requesters waiting on one key.

keyComparer IEqualityComparer<TKey>

Key comparer, or null for the default.

waiterComparer IEqualityComparer<TWaiter>

Waiter comparer, or null for the default.

Properties

Count

Keys currently in flight.

public int Count { get; }

Property Value

int

MaxEntries

Most keys in flight at once.

public int MaxEntries { get; }

Property Value

int

MaxWaitersPerEntry

Most requesters waiting on one key.

public int MaxWaitersPerEntry { get; }

Property Value

int

Methods

Clear()

Forgets everything.

public void Clear()

Join(TKey, TWaiter, DateTime, TimeSpan)

Adds a requester to the lookup for a key, and says whether the caller must start the fetch.

public InFlightLookupTable<TKey, TWaiter>.JoinResult Join(TKey key, TWaiter waiter, DateTime nowUtc, TimeSpan staleAfter)

Parameters

key TKey

What is being looked up.

waiter TWaiter

Who is asking. Asking twice waits once.

nowUtc DateTime

Now.

staleAfter TimeSpan

How long a fetch may be out before it is presumed lost.

Returns

InFlightLookupTable<TKey, TWaiter>.JoinResult

Started when there was no live lookup (a stale one is restarted, keeping its waiters), Joined when one is out, and Refused when the table is full.

Join(TKey, TWaiter, double, TimeSpan)

public InFlightLookupTable<TKey, TWaiter>.JoinResult Join(TKey key, TWaiter waiter, double nowSeconds, TimeSpan staleAfter)

Parameters

key TKey

What is being looked up.

waiter TWaiter

Who is asking.

nowSeconds double

Current NowSeconds reading.

staleAfter TimeSpan

How long a fetch may be out before it is presumed lost.

Returns

InFlightLookupTable<TKey, TWaiter>.JoinResult

As Join(TKey, TWaiter, DateTime, TimeSpan).

Remarks

The stale bound is a local duration: on the wall clock a host stepped forward presumed every fetch in flight lost at once and started each again. One table, one clock: see FishMMO.Server.Core.Collections.MonotonicInstant.

SweepStale(DateTime, TimeSpan)

Drops lookups out longer than staleAfter.

public int SweepStale(DateTime nowUtc, TimeSpan staleAfter)

Parameters

nowUtc DateTime
staleAfter TimeSpan

Returns

int

The number dropped.

SweepStale(double, TimeSpan)

public int SweepStale(double nowSeconds, TimeSpan staleAfter)

Parameters

nowSeconds double

Current NowSeconds reading.

staleAfter TimeSpan

How long a fetch may be out before it is presumed lost.

Returns

int

The number dropped.

TryComplete(TKey, List<TWaiter>)

Ends the lookup for a key and hands back everyone who was waiting on it.

public bool TryComplete(TKey key, List<TWaiter> waiters)

Parameters

key TKey

The key whose fetch finished (answered or not).

waiters List<TWaiter>

Receives the waiters. Not cleared first.

Returns

bool

True if the key was in flight.