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
TKeyWhat is being looked up.
TWaiterWho 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
maxEntriesintMost keys in flight at once.
maxWaitersPerEntryintMost requesters waiting on one key.
keyComparerIEqualityComparer<TKey>Key comparer, or null for the default.
waiterComparerIEqualityComparer<TWaiter>Waiter comparer, or null for the default.
Properties
Count
Keys currently in flight.
public int Count { get; }
Property Value
MaxEntries
Most keys in flight at once.
public int MaxEntries { get; }
Property Value
MaxWaitersPerEntry
Most requesters waiting on one key.
public int MaxWaitersPerEntry { get; }
Property Value
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
keyTKeyWhat is being looked up.
waiterTWaiterWho is asking. Asking twice waits once.
nowUtcDateTimeNow.
staleAfterTimeSpanHow 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)
Join(TKey, TWaiter, DateTime, TimeSpan) for a table timed on MonotonicClock.
public InFlightLookupTable<TKey, TWaiter>.JoinResult Join(TKey key, TWaiter waiter, double nowSeconds, TimeSpan staleAfter)
Parameters
keyTKeyWhat is being looked up.
waiterTWaiterWho is asking.
nowSecondsdoubleCurrent NowSeconds reading.
staleAfterTimeSpanHow long a fetch may be out before it is presumed lost.
Returns
- InFlightLookupTable<TKey, TWaiter>.JoinResult
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
Returns
- int
The number dropped.
SweepStale(double, TimeSpan)
SweepStale(DateTime, TimeSpan) for a table timed on MonotonicClock.
public int SweepStale(double nowSeconds, TimeSpan staleAfter)
Parameters
nowSecondsdoubleCurrent NowSeconds reading.
staleAfterTimeSpanHow 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
keyTKeyThe key whose fetch finished (answered or not).
waitersList<TWaiter>Receives the waiters. Not cleared first.
Returns
- bool
True if the key was in flight.