Copilot commented on code in PR #13741:
URL: https://github.com/apache/trafficserver/pull/13741#discussion_r4120655645


##########
src/iocore/cache/unit_tests/test_StripeHashTable.cc:
##########
@@ -0,0 +1,125 @@
+/** @file
+
+  Catch-based unit tests for the stripe assignment hash table.
+
+  @section license License
+
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+ */
+
+#include "main.h"
+#include "test_doubles.h"
+
+#include "../P_CacheHosting.h"
+#include "../P_CacheInternal.h"
+#include "../StripeSM.h"
+
+#include <array>
+#include <cinttypes>
+#include <cstdio>
+#include <cstring>
+#include <memory>
+
+int  cache_vols           = 1;
+bool reuse_existing_cache = false;
+
+namespace
+{
+
+constexpr int      NUM_STRIPES  = 26;
+constexpr int      SAMPLE_IDX   = 16;
+constexpr uint64_t DIR_SKIP     = 8192;
+constexpr uint64_t STRIPE_BYTES = 1024ULL * 1024 * 1024 * 911;
+
+void
+set_hash_id(StripeSM &stripe, int idx)
+{
+  char buf[64];
+
+  snprintf(buf, sizeof(buf), "/dev/sd%c %" PRIu64 ":%" PRIu64, 'a' + idx, 
DIR_SKIP, static_cast<uint64_t>(stripe.len));
+  CryptoContext().hash_immediate(stripe.hash_id, buf, strlen(buf));
+}
+
+} // namespace
+
+// build_vol_hash_table gives each slot to the stripe owning the nearest 
random point, and a stripe's points depend only
+// on its own hash_id and len, so resizing one stripe cannot move a slot 
between two other stripes.
+TEST_CASE("Resizing one stripe moves hash table slots only to or from that 
stripe", "[cache][hosting]")
+{
+  CacheDisk disk;
+
+  init_disk(disk);
+
+  std::array<std::unique_ptr<StripeSM>, NUM_STRIPES> stripes;
+  StripeSM                                          *stripe_ptrs[NUM_STRIPES];
+
+  for (int i = 0; i < NUM_STRIPES; ++i) {
+    stripes[i]     = std::make_unique<StripeSM>(&disk, 
static_cast<off_t>(STRIPE_BYTES / STORE_BLOCK_SIZE), 0);

Review Comment:
   Each `StripeSM` here allocates a real directory from `len`; with the default 
8,000-byte estimated object size, one 911-GiB stripe requests about 1.14 GiB 
and the 26 stripes retain about 29.6 GiB (plus the resized sample). This test 
now runs in ordinary `ctest`, so it can exhaust memory on CI before reaching 
the hash-table assertions. Pass a test-specific large `avg_obj_size` via the 
constructor's fourth argument, or otherwise keep the synthetic stripes' 
directory allocations small while leaving their `len` values large.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to