One user-space repair task per eligible HWE debug-diag / compile-deploy base ID: 320 admitted (C 218, C++ 97, build scripts 5), 1 skipped by the content filter. Each ships a public spec with a check-to-basis table, at least two defects with single-fix fixtures, a symptom-masking fixture and an alternative correct implementation. Claude re-checked all 320: structure, the HWE quality items and trace6 Docker calibration receipts against current digests (320/320 USABLE). Difficulty is unmeasured. Known follow-up: 212 tasks use 120 ad-hoc family names; the next batch maps them to the canonical list. The batch's 1,256-line progress log stays in its factory report and the 36-local branch batch15-hwe. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
253 lines
7.4 KiB
C++
253 lines
7.4 KiB
C++
#include "cache.hpp"
|
|
namespace tile {
|
|
bool Key::operator<(const Key& other) const {
|
|
if (tenant != other.tenant) {
|
|
return tenant < other.tenant;
|
|
}
|
|
return name < other.name;
|
|
}
|
|
Key Registry::index_key(const Key& key) {
|
|
return key;
|
|
}
|
|
std::shared_ptr<Payload> Registry::find(const Key& key) const {
|
|
const auto found = entries_.find(index_key(key));
|
|
if (found == entries_.end()) {
|
|
return {};
|
|
}
|
|
return found->second.observed.lock();
|
|
}
|
|
void Registry::store(const Key& key, const std::shared_ptr<Payload>& object) {
|
|
Entry entry;
|
|
entry.key = key;
|
|
entry.observed = object;
|
|
entries_[index_key(key)] = std::move(entry);
|
|
}
|
|
std::size_t Registry::erase(const Key& key) {
|
|
return entries_.erase(index_key(key));
|
|
}
|
|
std::size_t Registry::retire(const std::string& tenant) {
|
|
std::size_t removed = 0;
|
|
auto current = entries_.begin();
|
|
while (current != entries_.end()) {
|
|
if (current->second.key.tenant == tenant) {
|
|
current = entries_.erase(current);
|
|
++removed;
|
|
} else {
|
|
++current;
|
|
}
|
|
}
|
|
return removed;
|
|
}
|
|
std::size_t Registry::clear() {
|
|
const std::size_t removed = entries_.size();
|
|
entries_.clear();
|
|
return removed;
|
|
}
|
|
std::size_t Registry::sweep() {
|
|
std::size_t removed = 0;
|
|
auto current = entries_.begin();
|
|
while (current != entries_.end()) {
|
|
if (current->second.observed.expired()) {
|
|
current = entries_.erase(current);
|
|
++removed;
|
|
} else {
|
|
++current;
|
|
}
|
|
}
|
|
return removed;
|
|
}
|
|
std::array<long long, 3> Registry::counts() const {
|
|
long long live = 0;
|
|
long long expired = 0;
|
|
for (const auto& pair : entries_) {
|
|
if (pair.second.observed.expired()) {
|
|
++expired;
|
|
} else {
|
|
++live;
|
|
}
|
|
}
|
|
return {static_cast<long long>(entries_.size()), live, expired};
|
|
}
|
|
Service::Service() : ledger_(std::make_shared<Ledger>()) {
|
|
slots_.fill(nullptr);
|
|
}
|
|
Numbers Service::missing() {
|
|
return {2};
|
|
}
|
|
Numbers Service::invalid() {
|
|
return {1};
|
|
}
|
|
Numbers Service::object_result(const std::shared_ptr<Payload>& object) {
|
|
return {0, object->serial(), object->checksum()};
|
|
}
|
|
Numbers Service::acquire(std::size_t slot, const Key& key, std::size_t size, unsigned seed) {
|
|
auto object = registry_.find(key);
|
|
if (!object) {
|
|
object = std::make_shared<Payload>(ledger_, size, seed);
|
|
registry_.store(key, object);
|
|
}
|
|
slots_[slot] = object;
|
|
return object_result(object);
|
|
}
|
|
Numbers Service::lookup(std::size_t slot, const Key& key) {
|
|
auto object = registry_.find(key);
|
|
if (!object) {
|
|
return missing();
|
|
}
|
|
slots_[slot] = object;
|
|
return object_result(object);
|
|
}
|
|
Numbers Service::copy(std::size_t source, std::size_t destination) {
|
|
if (!slots_[source]) {
|
|
return missing();
|
|
}
|
|
slots_[destination] = slots_[source];
|
|
return {0, slots_[destination]->serial()};
|
|
}
|
|
Numbers Service::move(std::size_t source, std::size_t destination) {
|
|
if (!slots_[source]) {
|
|
return missing();
|
|
}
|
|
const long long serial = slots_[source]->serial();
|
|
if (source != destination) {
|
|
slots_[destination] = std::move(slots_[source]);
|
|
}
|
|
return {0, serial};
|
|
}
|
|
Numbers Service::drop(std::size_t slot) {
|
|
slots_[slot].reset();
|
|
return {0};
|
|
}
|
|
Numbers Service::drop_all() {
|
|
const std::size_t count = occupied();
|
|
for (auto& slot : slots_) {
|
|
slot.reset();
|
|
}
|
|
return {0, static_cast<long long>(count)};
|
|
}
|
|
Numbers Service::view(std::size_t slot) const {
|
|
const auto& object = slots_[slot];
|
|
if (!object) {
|
|
return missing();
|
|
}
|
|
return {0, object->serial(), static_cast<long long>(object->size()), object->checksum()};
|
|
}
|
|
Numbers Service::owners(std::size_t slot) const {
|
|
const auto& object = slots_[slot];
|
|
if (!object) {
|
|
return missing();
|
|
}
|
|
long long count = 0;
|
|
for (const auto& owner : slots_) {
|
|
if (owner == object) {
|
|
++count;
|
|
}
|
|
}
|
|
return {0, object->serial(), count};
|
|
}
|
|
Numbers Service::write(std::size_t slot, std::size_t offset, unsigned value) {
|
|
const auto& object = slots_[slot];
|
|
if (!object) {
|
|
return missing();
|
|
}
|
|
if (!object->write(offset, value)) {
|
|
return invalid();
|
|
}
|
|
return {0, object->checksum()};
|
|
}
|
|
Numbers Service::fill(std::size_t slot, std::size_t offset, std::size_t count, unsigned value) {
|
|
const auto& object = slots_[slot];
|
|
if (!object) {
|
|
return missing();
|
|
}
|
|
if (!object->fill(offset, count, value)) {
|
|
return invalid();
|
|
}
|
|
return {0, object->checksum()};
|
|
}
|
|
Numbers Service::resize(std::size_t slot, std::size_t length, unsigned seed) {
|
|
const auto& object = slots_[slot];
|
|
if (!object) {
|
|
return missing();
|
|
}
|
|
object->resize(length, seed);
|
|
return {0, object->checksum()};
|
|
}
|
|
Numbers Service::read(std::size_t slot, std::size_t offset, std::size_t count) const {
|
|
const auto& object = slots_[slot];
|
|
if (!object) {
|
|
return missing();
|
|
}
|
|
Numbers output;
|
|
if (!object->read(offset, count, output)) {
|
|
return invalid();
|
|
}
|
|
return output;
|
|
}
|
|
Numbers Service::copy_range(std::size_t source, std::size_t source_offset,
|
|
std::size_t destination, std::size_t destination_offset, std::size_t count) {
|
|
const auto& from = slots_[source];
|
|
const auto& to = slots_[destination];
|
|
if (!from || !to) {
|
|
return missing();
|
|
}
|
|
if (!from->copy_range(source_offset, *to, destination_offset, count)) {
|
|
return invalid();
|
|
}
|
|
return {0, to->checksum()};
|
|
}
|
|
Numbers Service::swap(std::size_t left, std::size_t right) {
|
|
slots_[left].swap(slots_[right]);
|
|
const auto& left_object = slots_[left];
|
|
const auto& right_object = slots_[right];
|
|
const long long left_serial = left_object ? left_object->serial() : 0;
|
|
const long long right_serial = right_object ? right_object->serial() : 0;
|
|
return {0, left_serial, right_serial};
|
|
}
|
|
Numbers Service::compare(std::size_t left, std::size_t right) const {
|
|
const auto& first = slots_[left];
|
|
const auto& second = slots_[right];
|
|
if (!first || !second) {
|
|
return missing();
|
|
}
|
|
const bool same_identity = first == second;
|
|
const bool same_payload = first->same_bytes(*second);
|
|
return {0, same_identity ? 1 : 0, same_payload ? 1 : 0};
|
|
}
|
|
Numbers Service::erase(const Key& key) {
|
|
return {0, static_cast<long long>(registry_.erase(key))};
|
|
}
|
|
Numbers Service::retire(const std::string& tenant) {
|
|
return {0, static_cast<long long>(registry_.retire(tenant))};
|
|
}
|
|
Numbers Service::clear() {
|
|
return {0, static_cast<long long>(registry_.clear())};
|
|
}
|
|
Numbers Service::sweep() {
|
|
return {0, static_cast<long long>(registry_.sweep())};
|
|
}
|
|
Numbers Service::cache() const {
|
|
const auto counts = registry_.counts();
|
|
return {0, counts[0], counts[1], counts[2]};
|
|
}
|
|
std::size_t Service::occupied() const {
|
|
std::size_t count = 0;
|
|
for (const auto& slot : slots_) {
|
|
if (slot) {
|
|
++count;
|
|
}
|
|
}
|
|
return count;
|
|
}
|
|
Numbers Service::stats() const {
|
|
const auto counts = registry_.counts();
|
|
return {0, ledger_->created, ledger_->destroyed, ledger_->live(), ledger_->live_bytes,
|
|
static_cast<long long>(occupied()), counts[0]};
|
|
}
|
|
Numbers Service::deaths() const {
|
|
Numbers result = {0, static_cast<long long>(ledger_->deaths.size())};
|
|
result.insert(result.end(), ledger_->deaths.begin(), ledger_->deaths.end());
|
|
return result;
|
|
}
|
|
}
|