# Walk through the basics of the datadriven syntax.

init
----
[regular] 0B tokens available
[elastic] 0B tokens available

# Try to admit two requests of 1B each, at incrementing log positions. The
# first requests tries the fast path and fails admission, and gets added to the
# work queue's internal heap.
admit tenant=t1 pri=normal-pri create-time=1.001us size=1B range=r1 origin=n1 log-position=4/20
----
[regular] try-get=1B available=0B => insufficient tokens

# Observe that the physical stats show that the actual work was done, but the
# work is virtually enqueued in the work queue for deferred admission.
print
----
physical-stats: work-count=1 written-bytes=1B ingested-bytes=0B
[regular work queue]: len(tenant-heap)=1 top-tenant=t1
 tenant=t1 weight=1 fifo-threshold=low-pri used=0B
  [0: pri=normal-pri create-time=1.001µs size=1B range=r1 origin=n1 log-position=4/20]
[elastic work queue]: len(tenant-heap)=0

# Admit a second request. Since there's already a request waiting, we don't get
# the fast path.
admit tenant=t1 pri=normal-pri create-time=1.002us size=1B range=r1 origin=n1 log-position=4/21 ingested=true
----

# Observe both waiting requests.
print
----
physical-stats: work-count=2 written-bytes=1B ingested-bytes=1B
[regular work queue]: len(tenant-heap)=1 top-tenant=t1
 tenant=t1 weight=1 fifo-threshold=low-pri used=0B
  [0: pri=normal-pri create-time=1.001µs size=1B range=r1 origin=n1 log-position=4/20]
  [1: pri=normal-pri create-time=1.002µs size=1B range=r1 origin=n1 log-position=4/21 ingested ]
[elastic work queue]: len(tenant-heap)=0

# Produce 2B worth of regular tokens.
granter class=regular adjust-tokens=+2B
----
[regular] 2B tokens available
[elastic] 0B tokens available

# Grant admission requests. Since we have 2B worth of tokens, and 2 waiting
# requests wanting 1B each, we're able to admit both. We do so in log-position
# order.
grant class=regular
----
admitted [tenant=t1 pri=normal-pri create-time=1.001µs size=1B range=r1 origin=n1 log-position=4/20]
admitted [tenant=t1 pri=normal-pri create-time=1.002µs size=1B range=r1 origin=n1 log-position=4/21 ingested]

# Pretty print granter state to show no more available tokens. We've consumed
# the 2B above.
granter adjust-tokens=+0B
----
[regular] 0B tokens available
[elastic] 0B tokens available

# Observe the empty tenant heaps (all work was admitted) and 2B worth of used
# tokens for t1.
print
----
physical-stats: work-count=2 written-bytes=1B ingested-bytes=1B
[regular work queue]: len(tenant-heap)=0
 tenant=t1 weight=1 fifo-threshold=low-pri used=2B
[elastic work queue]: len(tenant-heap)=0

# vim:ft=sh
