<div dir="ltr">







<p class=""><span class="">Hi Vilobh,  </span></p>
<p class=""><span class="">Here is my thoughts on how Delimiter uses generation-id to guarantee  sequencing. Please correct me if I understand it wrong.</span></p>
<p class=""><span class="">First, the Delimiter need to introduce another model ResourceProvider who has two attributes:</span></p>
<ul class="">
<li class=""><span class="">resource_id </span></li>
<li class=""><span class="">generation_id</span></li>
</ul>
<p class=""><span class="">The followings are the steps of how to consume a quota:</span></p>
<p class=""><span class="">Step 1. Check if there is enough available quota </span></p>
<p class=""><span class="">    If yes, then get the $generation_id <i> </i>by querying the model ResourceProvider with the given resource_id </span>which is the point in time view of resource usage.</p>
<p class=""><span class="">    If no, terminate the process of consuming the quota and return the message of “No enough quotas available."</span></p>
<p class=""><span class="">Step 2. Consume the quota.</span></p>
<p class=""><span class="">   2.1 Begin transaction</span></p>
<p class=""><span class="">   2.2 Update the QuotaUsage model: QuotaUsage.in_use = QuotaUsage.in_use + amount of quota requested.</span></p>
<p class=""><span class="">   2.3 Get the $generation_id by querying the ResourceProvider by the given resource_id.</span></p>
<p class=""><span class="">        If t</span>he $generation_id is larger than the $generation_id in Step 1, then roll back transaction and GOTO step 1.</p>
<p class=""><span class="">           this case means there is someone else has changed the QuotaUsage during this process.</span></p>
<p class="">        If the $generation_id is the same as the $generation_id in Step 1, then increase the ResourceProvider.generation_id by one and</p>
<p class=""><span class="">        Commit the transaction. Done!</span></p>
<p class=""><span class="">        Note: no case the $generation_id is less than the $generation_id in Step 1 because the $generation_id is nondecreasing.</span></p>
<p class=""><br><span class=""></span></p>
<p class=""><span class="">— Qijing</span></p></div>