bneradt commented on code in PR #11396:
URL: https://github.com/apache/trafficserver/pull/11396#discussion_r1619608745


##########
src/proxy/hdrs/XPACK.cc:
##########
@@ -559,7 +578,47 @@ XpackDynamicTableStorage::write(const char *name, uint32_t 
name_len, const char
 }
 
 void
-XpackDynamicTableStorage::erase(uint32_t name_len, uint32_t value_len)
+XpackDynamicTableStorage::erase(uint32_t to_erase)
+{
+  // Ensure that _tail is not overcoming _head.
+  ink_release_assert(to_erase <= this->size());
+  this->_tail = (this->_tail + to_erase) % this->_capacity;
+}
+
+uint32_t
+XpackDynamicTableStorage::size() const
+{
+  if (this->_tail <= this->_head) {
+    return this->_head - this->_tail;
+  } else {
+    return this->_capacity - this->_tail + this->_head;
+  }
+}
+bool
+XpackDynamicTableStorage::will_overrun(uint32_t size) const
+{
+  if (this->_head == this->_capacity - 1) {
+    return size > this->_capacity;
+  }
+  return size > (this->_capacity - this->_head);
+}
+
+bool
+XpackDynamicTableStorage::update_maximum_size(uint32_t new_maximum_size)
 {
-  this->_tail = (this->_tail + (name_len + value_len)) % this->_data_size;
+  if (new_maximum_size <= this->_capacity) {
+    // We never shrink our memory for the data storage because we don't support
+    // arbitrary eviction from it. The XpackDynamicTable class keeps track of
+    // field sizes and therefore can evict properly.
+    return true;
+  }
+  uint32_t const new_data_size = new_maximum_size * 2;
+  this->_data = reinterpret_cast<uint8_t *>(ats_realloc(this->_data, 
new_data_size));

Review Comment:
   Thank you for explaining this further to me on slack!
   
   Yes, you are write that things are more complicated after space is expanded. 
As you suggested, I now call `insert_entry` for each active entry after the 
resize so that the offsets are appropriate in the dynamic table and the entries 
are laid out appropriately in the storage. I added a unit test for this as well.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to