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


-- Flow token metrics from n1 after issuing 5 regular 1MiB 3x replicated writes
-- that are yet to get admitted. We see 5*1MiB*3=15MiB deductions of
-- {regular,elastic} tokens with no corresponding returns.
SELECT name, crdb_internal.humanize_bytes(value::INT8)
    FROM crdb_internal.node_metrics
   WHERE name LIKE '%kvadmission%tokens%'
ORDER BY name ASC;

  kvadmission.flow_controller.elastic_tokens_available   | 9.0 MiB  
  kvadmission.flow_controller.elastic_tokens_deducted    | 15 MiB   
  kvadmission.flow_controller.elastic_tokens_returned    | 0 B      
  kvadmission.flow_controller.elastic_tokens_unaccounted | 0 B      
  kvadmission.flow_controller.regular_tokens_available   | 33 MiB   
  kvadmission.flow_controller.regular_tokens_deducted    | 15 MiB   
  kvadmission.flow_controller.regular_tokens_returned    | 0 B      
  kvadmission.flow_controller.regular_tokens_unaccounted | 0 B      


-- Observe the total tracked tokens per-stream on n1.
SELECT range_id, store_id, crdb_internal.humanize_bytes(total_tracked_tokens::INT8)
    FROM crdb_internal.kv_flow_control_handles

  range_id | store_id | total_tracked_tokens  
-----------+----------+-----------------------
  75       | 1        | 5.0 MiB               
  75       | 2        | 5.0 MiB               
  75       | 3        | 5.0 MiB               


-- Observe the individual tracked tokens per-stream on the scratch range.
SELECT range_id, store_id, priority, crdb_internal.humanize_bytes(tokens::INT8)
    FROM crdb_internal.kv_flow_token_deductions

  range_id | store_id |  priority  | tokens   
-----------+----------+------------+----------
  75       | 1        | normal-pri | 1.0 MiB  
  75       | 1        | normal-pri | 1.0 MiB  
  75       | 1        | normal-pri | 1.0 MiB  
  75       | 1        | normal-pri | 1.0 MiB  
  75       | 1        | normal-pri | 1.0 MiB  
  75       | 2        | normal-pri | 1.0 MiB  
  75       | 2        | normal-pri | 1.0 MiB  
  75       | 2        | normal-pri | 1.0 MiB  
  75       | 2        | normal-pri | 1.0 MiB  
  75       | 2        | normal-pri | 1.0 MiB  
  75       | 3        | normal-pri | 1.0 MiB  
  75       | 3        | normal-pri | 1.0 MiB  
  75       | 3        | normal-pri | 1.0 MiB  
  75       | 3        | normal-pri | 1.0 MiB  
  75       | 3        | normal-pri | 1.0 MiB  


-- (Allow below-raft admission to proceed.)


-- Observe flow token dispatch metrics from n1.
SELECT name, value
    FROM crdb_internal.node_metrics
   WHERE name LIKE '%kvadmission.flow_token_dispatch.local_regular%'
ORDER BY name ASC;

  kvadmission.flow_token_dispatch.local_regular | 5  


-- Observe flow token dispatch metrics from n2.
SELECT name, value
    FROM crdb_internal.node_metrics
   WHERE name LIKE '%kvadmission.flow_token_dispatch.remote_regular%'
ORDER BY name ASC;

  kvadmission.flow_token_dispatch.remote_regular | 5  


-- Flow token metrics from n1 after work gets admitted. We see 15MiB returns of
-- {regular,elastic} tokens, and the available capacities going back to what
-- they were.
SELECT name, crdb_internal.humanize_bytes(value::INT8)
    FROM crdb_internal.node_metrics
   WHERE name LIKE '%kvadmission%tokens%'
ORDER BY name ASC;

  kvadmission.flow_controller.elastic_tokens_available   | 24 MiB  
  kvadmission.flow_controller.elastic_tokens_deducted    | 15 MiB  
  kvadmission.flow_controller.elastic_tokens_returned    | 15 MiB  
  kvadmission.flow_controller.elastic_tokens_unaccounted | 0 B     
  kvadmission.flow_controller.regular_tokens_available   | 48 MiB  
  kvadmission.flow_controller.regular_tokens_deducted    | 15 MiB  
  kvadmission.flow_controller.regular_tokens_returned    | 15 MiB  
  kvadmission.flow_controller.regular_tokens_unaccounted | 0 B     
----
----

# vim:ft=sql
