100 tasks from the HWE arm-linux code-gen pool (outside the lk/man/pth range given to batch 22), each with at least one independent contract-edge defect and plain public docs. Claude reviewed 100/100 USABLE against current digests; no ID or source overlap with main or batch 22. Difficulty is unmeasured. progress.md records the wrap-up: all Codex sessions and Qwen schedulers stopped for the user's rollout, Qwen results so far (57 HARD of 373), and what is left on each batch branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
160 lines
3.7 KiB
C++
160 lines
3.7 KiB
C++
#include "durable.hpp"
|
|
namespace durable {
|
|
Domain::Domain() : next_sequence_(1)
|
|
{
|
|
}
|
|
bool Domain::valid_id(int id)
|
|
{
|
|
return id >= 1 && id <= 32;
|
|
}
|
|
bool Domain::valid_topic(int topic)
|
|
{
|
|
return topic >= 1 && topic <= 8;
|
|
}
|
|
bool Domain::valid_durability(int durability)
|
|
{
|
|
return durability == 0 || durability == 1;
|
|
}
|
|
bool Domain::valid_depth(int depth)
|
|
{
|
|
return depth >= 1 && depth <= 16;
|
|
}
|
|
bool Domain::valid_capacity(int capacity)
|
|
{
|
|
return capacity >= 1 && capacity <= 64;
|
|
}
|
|
bool Domain::valid_payload(Number payload)
|
|
{
|
|
return payload >= -1000000 && payload <= 1000000;
|
|
}
|
|
int Domain::writer_arguments(int id, int topic, int durability, int depth) const
|
|
{
|
|
if (!valid_id(id)) {
|
|
return -22;
|
|
}
|
|
if (!valid_topic(topic)) {
|
|
return -22;
|
|
}
|
|
if (!valid_durability(durability)) {
|
|
return -22;
|
|
}
|
|
if (!valid_depth(depth)) {
|
|
return -22;
|
|
}
|
|
return 0;
|
|
}
|
|
int Domain::reader_arguments(int id, int topic, int durability, int capacity) const
|
|
{
|
|
if (!valid_id(id)) {
|
|
return -22;
|
|
}
|
|
if (!valid_topic(topic)) {
|
|
return -22;
|
|
}
|
|
if (!valid_durability(durability)) {
|
|
return -22;
|
|
}
|
|
if (!valid_capacity(capacity)) {
|
|
return -22;
|
|
}
|
|
return 0;
|
|
}
|
|
int Domain::open_writer(int id, int topic, int durability, int depth)
|
|
{
|
|
int result = writer_arguments(id, topic, durability, depth);
|
|
if (result != 0) {
|
|
return result;
|
|
}
|
|
if (writers_.find(id) != writers_.end()) {
|
|
return -17;
|
|
}
|
|
const auto old = generations_.find(id);
|
|
const Number generation = old == generations_.end() ? 1 : old->second + 1;
|
|
Writer writer;
|
|
writer.id = id;
|
|
writer.generation = generation;
|
|
writer.topic = topic;
|
|
writer.durability = durability;
|
|
writer.depth = depth;
|
|
writer.published = 0;
|
|
writers_.emplace(id, writer);
|
|
generations_[id] = generation;
|
|
histories_.attach(id, generation, topic, durability, depth);
|
|
return 0;
|
|
}
|
|
int Domain::close_writer(int id)
|
|
{
|
|
auto found = writers_.find(id);
|
|
if (found == writers_.end()) {
|
|
return -2;
|
|
}
|
|
histories_.release(id, found->second.generation);
|
|
writers_.erase(found);
|
|
return 0;
|
|
}
|
|
int Domain::set_depth(int id, int depth)
|
|
{
|
|
auto found = writers_.find(id);
|
|
if (found == writers_.end()) {
|
|
return -2;
|
|
}
|
|
if (!valid_depth(depth)) {
|
|
return -22;
|
|
}
|
|
Writer &writer = found->second;
|
|
histories_.resize(id, writer.generation, depth);
|
|
writer.depth = depth;
|
|
return 0;
|
|
}
|
|
Sample Domain::make_sample(Writer &writer, Number payload)
|
|
{
|
|
Sample sample;
|
|
sample.sequence = next_sequence_;
|
|
sample.writer = writer.id;
|
|
sample.generation = writer.generation;
|
|
sample.topic = writer.topic;
|
|
sample.payload = (writer.published + 1) * 10;
|
|
sample.replayed = 0;
|
|
++next_sequence_;
|
|
++writer.published;
|
|
return sample;
|
|
}
|
|
Number Domain::commit(Writer &writer, Number payload)
|
|
{
|
|
const Sample sample = make_sample(writer, payload);
|
|
histories_.remember(sample);
|
|
broadcast(sample);
|
|
return sample.sequence;
|
|
}
|
|
int Domain::publish(int id, Number payload, Number &sequence)
|
|
{
|
|
auto found = writers_.find(id);
|
|
if (found == writers_.end()) {
|
|
return -2;
|
|
}
|
|
if (!valid_payload(payload)) {
|
|
return -22;
|
|
}
|
|
sequence = commit(found->second, payload);
|
|
return 0;
|
|
}
|
|
int Domain::history(int id, std::vector<Sample> &out) const
|
|
{
|
|
const auto found = writers_.find(id);
|
|
if (found == writers_.end()) {
|
|
return -2;
|
|
}
|
|
std::vector<Sample> result = histories_.read(id, found->second.generation);
|
|
out.swap(result);
|
|
return 0;
|
|
}
|
|
void Domain::reset()
|
|
{
|
|
writers_.clear();
|
|
readers_.clear();
|
|
generations_.clear();
|
|
histories_.reset();
|
|
next_sequence_ = 1;
|
|
}
|
|
}
|