echo
----
----
-- (Issuing 1x1MiB, 3x replicated elastic write that's not admitted.)


-- Flow token metrics from n1 after issuing 1x1MiB elastic 3x replicated write
-- that's not admitted. We see 1*1MiB*3=3MiB deductions of elastic tokens with
-- no corresponding returns.
SELECT name, crdb_internal.humanize_bytes(value::INT8)
    FROM crdb_internal.node_metrics
   WHERE name LIKE '%kvadmission%elastic_tokens%'
ORDER BY name ASC;

  kvadmission.flow_controller.elastic_tokens_available   | 21 MiB   
  kvadmission.flow_controller.elastic_tokens_deducted    | 3.0 MiB  
  kvadmission.flow_controller.elastic_tokens_returned    | 0 B      
  kvadmission.flow_controller.elastic_tokens_unaccounted | 0 B      


-- (Wait for range to quiesce.)


-- (Allow below-raft admission to proceed. We've disabled the fallback token
-- dispatch mechanism so no tokens are returned yet -- quiesced ranges don't
-- use the piggy-backed token return mechanism since there's no raft traffic.)


-- Flow token metrics from n1 after work gets admitted but fallback token
-- dispatch mechanism is disabled. Deducted elastic tokens from remote stores
-- are yet to be returned. Tokens for the local store are.
SELECT name, crdb_internal.humanize_bytes(value::INT8)
    FROM crdb_internal.node_metrics
   WHERE name LIKE '%kvadmission%elastic_tokens%'
ORDER BY name ASC;

  kvadmission.flow_controller.elastic_tokens_available   | 22 MiB   
  kvadmission.flow_controller.elastic_tokens_deducted    | 3.0 MiB  
  kvadmission.flow_controller.elastic_tokens_returned    | 1.0 MiB  
  kvadmission.flow_controller.elastic_tokens_unaccounted | 0 B      


-- (Enable the piggyback token dispatch mechanism.)


-- (Unquiesce the range.)


-- Flow token metrics from n1 after work gets admitted and all elastic tokens
-- are returned through the piggyback mechanism.
SELECT name, crdb_internal.humanize_bytes(value::INT8)
    FROM crdb_internal.node_metrics
   WHERE name LIKE '%kvadmission%elastic_tokens%'
ORDER BY name ASC;

  kvadmission.flow_controller.elastic_tokens_available   | 24 MiB   
  kvadmission.flow_controller.elastic_tokens_deducted    | 3.0 MiB  
  kvadmission.flow_controller.elastic_tokens_returned    | 3.0 MiB  
  kvadmission.flow_controller.elastic_tokens_unaccounted | 0 B      
----
----

# vim:ft=sql
