Copilot commented on code in PR #13382: URL: https://github.com/apache/trafficserver/pull/13382#discussion_r3617951297
########## src/iocore/cache/RamCacheCLFUS.h: ########## @@ -0,0 +1,99 @@ +/** @file + + Clocked Least Frequently Used by Size (CLFUS) RAM cache replacement policy. + + @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. + */ + +#pragma once + +// See https://cwiki.apache.org/confluence/display/TS/RamCache + +#include "P_RamCache.h" + +#include "iocore/eventsystem/IOBuffer.h" +#include "tscore/CryptoHash.h" +#include "tscore/List.h" + +#include <climits> +#include <cstdint> + +class EThread; +class StripeSM; + +struct RamCacheCLFUSEntry { + CryptoHash key; + uint64_t auxkey; + uint64_t hits; + uint32_t size; // memory used including padding in buffer + uint32_t len; // actual data length + uint32_t compressed_len; + union { + struct { + uint32_t compressed : 3; // compression type + uint32_t incompressible : 1; + uint32_t lru : 1; + uint32_t copy : 1; // copy-in-copy-out + } flag_bits; + uint32_t flags; + }; + LINK(RamCacheCLFUSEntry, lru_link); + LINK(RamCacheCLFUSEntry, hash_link); + Ptr<IOBufferData> data; +}; + +class RamCacheCLFUS : public RamCache +{ +public: + RamCacheCLFUS() {} + + // returns 1 on found/stored, 0 on not found/stored, if provided auxkey1 and auxkey2 must match + int get(CryptoHash *key, Ptr<IOBufferData> *ret_data, uint64_t auxkey = 0) override; + int put(CryptoHash *key, IOBufferData *data, uint32_t len, bool copy = false, uint64_t auxkey = 0) override; + int fixup(const CryptoHash *key, uint64_t old_auxkey, uint64_t new_auxkey) override; + int64_t size() const override; + + void init(int64_t max_bytes, StripeSM *stripe) override; + + void compress_entries(EThread *thread, int do_at_most = INT_MAX); + + // TODO move it to private. + StripeSM *stripe = nullptr; // for stats +private: Review Comment: Now that RamCacheCLFUS is in a header, the public `stripe` data member becomes part of the observable interface and can be mutated by any includer, which makes it harder to reason about invariants (and the comment indicates it wasn’t intended to be public). Consider moving it into the private section; the class’s methods (including `init()` and `compress_entries()`) can still access it normally. -- 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]
