echo
----
----
-- (Issuing regular 1024*1KiB, 3x replicated writes that are not admitted.)


-- Flow token metrics from n1 after issuing 1024KiB, i.e. 1MiB 3x replicated writes
-- that are yet to get admitted. We see 3*1MiB=3MiB 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   | 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      
  kvadmission.flow_controller.regular_tokens_available   | 45 MiB   
  kvadmission.flow_controller.regular_tokens_deducted    | 3.0 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        | 1.0 MiB               
  75       | 2        | 1.0 MiB               
  75       | 3        | 1.0 MiB               


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


-- Flow token metrics from n1 after work gets admitted. We see 3MiB returns of
-- {regular,elastic} tokens, and the available capacities going back to what
-- they were. In #105185, by now we would've observed panics.
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    | 3.0 MiB  
  kvadmission.flow_controller.elastic_tokens_returned    | 3.0 MiB  
  kvadmission.flow_controller.elastic_tokens_unaccounted | 0 B      
  kvadmission.flow_controller.regular_tokens_available   | 48 MiB   
  kvadmission.flow_controller.regular_tokens_deducted    | 3.0 MiB  
  kvadmission.flow_controller.regular_tokens_returned    | 3.0 MiB  
  kvadmission.flow_controller.regular_tokens_unaccounted | 0 B      
----
----

# vim:ft=sql
