in sdk/src/Core/Sampling/Reservior.cs [53:86]
internal ReserviorDecision BorrowOrTake(TimeStamp current, bool canBorrow)
{
_lock.EnterWriteLock();
try
{
CalibrateThisSec(current);
// Don't borrow if the quota is available and fresh
if (Quota != null && Quota >= 0 && TTL != null && TTL.Time >= current.Time)
{
if(_takenThisSec >= Quota)
{
return ReserviorDecision.No;
}
_takenThisSec += 1;
return ReserviorDecision.Take;
}
if (canBorrow) // Otherwise try to borrow if the quota is not present or expired.
{
if(_borrowedThisSec >= 1)
{
return ReserviorDecision.No;
}
_borrowedThisSec += 1;
return ReserviorDecision.Borrow;
}
return ReserviorDecision.No;
}
finally
{
_lock.ExitWriteLock();
}
}