story: DGR-038 Implement isolated shard-local Hot KV State
This commit is contained in:
@@ -64,6 +64,19 @@ meshnet::worker::FlowLimits LimitsFromEnv() {
|
||||
return limits;
|
||||
}
|
||||
|
||||
bool PositiveEnv(const char* name, uint32_t* out, std::string* error) {
|
||||
if (const char* value = std::getenv(name)) {
|
||||
char* end = nullptr;
|
||||
const unsigned long parsed = std::strtoul(value, &end, 10);
|
||||
if (end == value || *end != '\0' || parsed == 0 || parsed > UINT32_MAX) {
|
||||
*error = std::string("invalid ") + name;
|
||||
return false;
|
||||
}
|
||||
*out = static_cast<uint32_t>(parsed);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IdentityFromEnv(meshnet::worker::WorkerIdentity* identity, std::string* error) {
|
||||
const auto required = [&](const char* name, std::string* out) -> bool {
|
||||
const char* value = std::getenv(name);
|
||||
@@ -100,6 +113,14 @@ bool IdentityFromEnv(meshnet::worker::WorkerIdentity* identity, std::string* err
|
||||
}
|
||||
identity->injected_death_after_executions = static_cast<uint32_t>(parsed);
|
||||
}
|
||||
if (!PositiveEnv("MESHNET_HOT_KV_MAX_SESSIONS", &identity->hot_kv_max_sessions, error) ||
|
||||
!PositiveEnv("MESHNET_HOT_KV_CONTEXT_TOKENS", &identity->hot_kv_context_tokens, error) ||
|
||||
!PositiveEnv("MESHNET_HOT_KV_BUDGET_TOKENS", &identity->hot_kv_budget_tokens, error) ||
|
||||
!PositiveEnv("MESHNET_HOT_KV_TTL_SECONDS", &identity->hot_kv_ttl_seconds, error)) return false;
|
||||
if (identity->hot_kv_budget_tokens < identity->hot_kv_context_tokens) {
|
||||
*error = "MESHNET_HOT_KV_BUDGET_TOKENS must cover one session context";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user