echo
----
----
(Sending 1 MiB put request to develop a send queue)


(Sent 1 MiB put request)


-- Send queue metrics from n1, n3's send queue should have 1 MiB for s3.
SELECT name, crdb_internal.humanize_bytes(value::INT8)
    FROM crdb_internal.node_metrics
   WHERE name LIKE '%kvflowcontrol%send_queue%'
     AND name != 'kvflowcontrol.send_queue.count'
ORDER BY name ASC;

  kvflowcontrol.send_queue.bytes                                    | 1.0 MiB  
  kvflowcontrol.send_queue.prevent.count                            | 0 B      
  kvflowcontrol.send_queue.scheduled.deducted_bytes                 | 0 B      
  kvflowcontrol.send_queue.scheduled.force_flush                    | 0 B      
  kvflowcontrol.tokens.send.elastic.deducted.force_flush_send_queue | 0 B      
  kvflowcontrol.tokens.send.elastic.deducted.prevent_send_queue     | 0 B      
  kvflowcontrol.tokens.send.regular.deducted.prevent_send_queue     | 0 B      


-- Observe the total tracked tokens per-stream on n1, s3's entries will still
-- be tracked here.
SELECT range_id, store_id, crdb_internal.humanize_bytes(total_tracked_tokens::INT8)
    FROM crdb_internal.kv_flow_control_handles_v2

  range_id | store_id | total_tracked_tokens  
-----------+----------+-----------------------
  75       | 1        | 0 B                   
  75       | 2        | 0 B                   
  75       | 3        | 4.0 MiB               
  75       | 4        | 0 B                   
  75       | 5        | 0 B                   


-- Per-store tokens available from n1, these should reflect the lack of tokens 
-- for s3.
SELECT store_id,
     crdb_internal.humanize_bytes(available_eval_regular_tokens),
     crdb_internal.humanize_bytes(available_eval_elastic_tokens),
     crdb_internal.humanize_bytes(available_send_regular_tokens),
     crdb_internal.humanize_bytes(available_send_elastic_tokens)
  FROM crdb_internal.kv_flow_controller_v2
  ORDER BY store_id ASC;

  store_id | eval_regular_available | eval_elastic_available | send_regular_available | send_elastic_available  
-----------+------------------------+------------------------+------------------------+-------------------------
  1        | 4.0 MiB                | 2.0 MiB                | 4.0 MiB                | 2.0 MiB                 
  2        | 4.0 MiB                | 2.0 MiB                | 4.0 MiB                | 2.0 MiB                 
  3        | 0 B                    | -3.0 MiB               | 0 B                    | -2.0 MiB                
  4        | 4.0 MiB                | 2.0 MiB                | 4.0 MiB                | 2.0 MiB                 
  5        | 4.0 MiB                | 2.0 MiB                | 4.0 MiB                | 2.0 MiB                 


-- Issuing RelocateRange:
--   before=[0 1 2 3 4]
--   after =[5 0 1 2 3]
-- Transferring the lease: false.


(Sending 1 MiB put request to the relocated range)


(Sent 1 MiB put request to the relocated range)


-- 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_v2

  range_id | store_id | total_tracked_tokens  
-----------+----------+-----------------------
  75       | 1        | 0 B                   
  75       | 2        | 0 B                   
  75       | 3        | 4.0 MiB               
  75       | 4        | 0 B                   
  75       | 6        | 0 B                   


-- (Allowing below-raft admission to proceed on n3.)


-- Send queue and flow token metrics from n1. All tokens should be returned.
SELECT name, crdb_internal.humanize_bytes(value::INT8)
    FROM crdb_internal.node_metrics
   WHERE name LIKE '%kvflowcontrol%send_queue%'
     AND name != 'kvflowcontrol.send_queue.count'
ORDER BY name ASC;

  kvflowcontrol.send_queue.bytes                                    | 0 B  
  kvflowcontrol.send_queue.prevent.count                            | 0 B  
  kvflowcontrol.send_queue.scheduled.deducted_bytes                 | 0 B  
  kvflowcontrol.send_queue.scheduled.force_flush                    | 0 B  
  kvflowcontrol.tokens.send.elastic.deducted.force_flush_send_queue | 0 B  
  kvflowcontrol.tokens.send.elastic.deducted.prevent_send_queue     | 0 B  
  kvflowcontrol.tokens.send.regular.deducted.prevent_send_queue     | 0 B  
SELECT store_id,
     crdb_internal.humanize_bytes(available_eval_regular_tokens),
     crdb_internal.humanize_bytes(available_eval_elastic_tokens),
     crdb_internal.humanize_bytes(available_send_regular_tokens),
     crdb_internal.humanize_bytes(available_send_elastic_tokens)
  FROM crdb_internal.kv_flow_controller_v2
  ORDER BY store_id ASC;

  store_id | eval_regular_available | eval_elastic_available | send_regular_available | send_elastic_available  
-----------+------------------------+------------------------+------------------------+-------------------------
  1        | 4.0 MiB                | 2.0 MiB                | 4.0 MiB                | 2.0 MiB                 
  2        | 4.0 MiB                | 2.0 MiB                | 4.0 MiB                | 2.0 MiB                 
  3        | 4.0 MiB                | 2.0 MiB                | 4.0 MiB                | 2.0 MiB                 
  4        | 4.0 MiB                | 2.0 MiB                | 4.0 MiB                | 2.0 MiB                 
  5        | 4.0 MiB                | 2.0 MiB                | 4.0 MiB                | 2.0 MiB                 
  6        | 4.0 MiB                | 2.0 MiB                | 4.0 MiB                | 2.0 MiB                 


-- Send queue and flow token metrics from leaseholder n1.
-- All tokens should be returned.
SELECT name, crdb_internal.humanize_bytes(value::INT8)
    FROM crdb_internal.node_metrics
   WHERE name LIKE '%kvflowcontrol%send_queue%'
     AND name != 'kvflowcontrol.send_queue.count'
ORDER BY name ASC;

  kvflowcontrol.send_queue.bytes                                    | 0 B  
  kvflowcontrol.send_queue.prevent.count                            | 0 B  
  kvflowcontrol.send_queue.scheduled.deducted_bytes                 | 0 B  
  kvflowcontrol.send_queue.scheduled.force_flush                    | 0 B  
  kvflowcontrol.tokens.send.elastic.deducted.force_flush_send_queue | 0 B  
  kvflowcontrol.tokens.send.elastic.deducted.prevent_send_queue     | 0 B  
  kvflowcontrol.tokens.send.regular.deducted.prevent_send_queue     | 0 B  
SELECT store_id,
     crdb_internal.humanize_bytes(available_eval_regular_tokens),
     crdb_internal.humanize_bytes(available_eval_elastic_tokens),
     crdb_internal.humanize_bytes(available_send_regular_tokens),
     crdb_internal.humanize_bytes(available_send_elastic_tokens)
  FROM crdb_internal.kv_flow_controller_v2
  ORDER BY store_id ASC;

  store_id | eval_regular_available | eval_elastic_available | send_regular_available | send_elastic_available  
-----------+------------------------+------------------------+------------------------+-------------------------
  1        | 4.0 MiB                | 2.0 MiB                | 4.0 MiB                | 2.0 MiB                 
  2        | 4.0 MiB                | 2.0 MiB                | 4.0 MiB                | 2.0 MiB                 
  3        | 4.0 MiB                | 2.0 MiB                | 4.0 MiB                | 2.0 MiB                 
  4        | 4.0 MiB                | 2.0 MiB                | 4.0 MiB                | 2.0 MiB                 
  5        | 4.0 MiB                | 2.0 MiB                | 4.0 MiB                | 2.0 MiB                 
  6        | 4.0 MiB                | 2.0 MiB                | 4.0 MiB                | 2.0 MiB                 
----
----

# vim:ft=sql
