Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
4d73577
feat(store): add optional RFC #1527 KV events publisher on master
cursoragent May 25, 2026
0278598
docs(conductor): add KV event field provenance matrix (SGLang vs mast…
cursoragent May 25, 2026
ac17fbc
fix(store): address KV events PR review feedback
cursoragent Jun 2, 2026
012bf0f
merge: resolve main into KV events branch
cursoragent Jun 2, 2026
a25f852
style(store): apply clang-format-20 to KV events changes
cursoragent Jun 5, 2026
642eef8
fix(store): fix KV events CI link failure when libzmq is absent
cursoragent Jun 5, 2026
d5c7a05
fix(store): link libzmq in Rust bindings when KV events enabled
cursoragent Jun 6, 2026
6e9a1d8
fix(store): link libzmq in Go CGO flags for KV events
cursoragent Jun 6, 2026
12d913c
ci: re-trigger build after runner disk-space failure
cursoragent Jun 6, 2026
6a75ae2
fix(store): disable KV events compile flag when libzmq is absent
cursoragent Jun 6, 2026
1caac0d
fix(store): address review comments — msgpack map_size, ZMQ leak, Put…
stmatengss Jun 7, 2026
1216fb6
fix(cmake): default ENABLE_KV_EVENTS to OFF
stmatengss Jun 7, 2026
c462efc
Merge remote-tracking branch 'origin4/main' into cursor/kv-event-publ…
stmatengss Jun 9, 2026
e4dbbc4
fix(store): align KV events publisher with RFC #1527 spec
cursoragent Jun 15, 2026
7abfdca
fix(store): address PR #2214 review and CI issues
cursoragent Jun 16, 2026
58046c3
merge: resolve main into KV events branch
cursoragent Jun 21, 2026
02b494f
merge: resolve main into KV events branch
cursoragent Jun 21, 2026
eb9f1fe
style: clang-format master_admin_service.cpp
cursoragent Jun 21, 2026
6e13367
fix(store): emit per-block KV events without global semantic fields
cursoragent Jun 22, 2026
e9fcf14
merge: resolve main and address ishandhanani review on KV events
cursoragent Jul 6, 2026
6d670b5
feat(store): include group ID in KV events
ishandhanani Jul 6, 2026
2f9df5b
Merge pull request #19 from kvcache-ai/idhanani/mooncake-2214-event-f…
stmatengss Jul 7, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ jobs:
export CGO_LDFLAGS="-L$GITHUB_WORKSPACE/build/mooncake-store/src -L$GITHUB_WORKSPACE/build/mooncake-store/src/cachelib_memory_allocator -L$GITHUB_WORKSPACE/build/mooncake-transfer-engine/src -L$GITHUB_WORKSPACE/build/mooncake-transfer-engine/src/common/base -L$GITHUB_WORKSPACE/build/mooncake-common -L$GITHUB_WORKSPACE/build/mooncake-common/etcd -lmooncake_store -lcachelib_memory_allocator -ltransfer_engine -lbase -lasio -letcd_wrapper -lstdc++ -lnuma -lglog -lgflags -libverbs -lmlx5 -ljsoncpp -lzstd -lcurl -luring -lasan -lm -lgcov -lxxhash"
# Link cudart if CUDA is available (needed for D2H staging in mooncake_store)
if [ -d /usr/local/cuda/lib64 ]; then export CGO_LDFLAGS="$CGO_LDFLAGS -L/usr/local/cuda/lib64 -lcudart"; fi
# KV events publisher (optional; linked when libzmq is installed)
if ldconfig -p 2>/dev/null | grep -q libzmq; then export CGO_LDFLAGS="$CGO_LDFLAGS -lzmq"; fi
ASAN_OPTIONS=detect_leaks=0:verify_asan_link_order=0 MC_METADATA_SERVER=http://127.0.0.1:8080/metadata go test -v ./tests/...
kill $MASTER_PID 2>/dev/null || true
shell: bash
Expand Down
1 change: 1 addition & 0 deletions dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ if [ "$OS" = "ubuntu" ] || [ "$OS" = "debian" ]; then
liburing-dev \
libjemalloc-dev \
libmsgpack-dev \
libzmq3-dev \
libzstd-dev \
libasio-dev \
libxxhash-dev \
Expand Down
113 changes: 113 additions & 0 deletions docs/source/design/conductor/indexer-api-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,116 @@ normalizes `BlockStored` and `BlockRemoved` into the internal prefix index.
Registration metadata supplies fields such as `modelname`, `tenant_id`,
`instance_id`, `block_size`, and `additionalsalt` when the engine event does
not carry the full standardized envelope.

### Mooncake Store master publisher

`mooncake_master` can optionally publish RFC #1527 events when
`enable_kv_events=true`. The publisher binds a ZMQ PUB socket
(`kv_events_bind_endpoint`) and emits the same three-frame batch format used by
vLLM/SGLang: empty topic, big-endian sequence number, and a msgpack payload
`[timestamp, [events], dp_rank]`.

Each event map uses RFC #1527 field names (`event_type`, `seq_hashes`,
`backend_id`, `medium`, and so on). When `kv_events_emit_object_key` is enabled
(default), the map also includes `object_key` with the Mooncake store key so
Dynamo and other consumers can match on `sha256` + Mooncake key format without
requiring decimal/`0x` `seq_hash` encoding. When `kv_events_emit_legacy_compat`
is enabled (default), the map also includes vLLM-compatible aliases such as
`type` and `block_hashes` so Dynamo relay mode can forward events without an
adapter.

Object keys may encode the rolling `seq_hash` as a decimal or `0x`-prefixed
hex string; when `seq_hash` cannot be parsed, events are still published if
`kv_events_emit_object_key=true` (with an empty `seq_hashes` array). Configure
`backend_id` to identify the cache owner (for example a per-node storage
daemon) and register the bind endpoint with the indexer using publisher type
`Mooncake`.

### Field provenance matrix (SGLang vs master vs indexer registration)

In decoupled deployments (inference workers + Mooncake host/disk pool), the
global KV indexer merges **three sources of truth**. Use this table when
splitting publishers or writing PR/integration notes.

**Legend**

| Symbol | Meaning |
|---|---|
| **SGLang** | Inference engine ZMQ KV events (`BlockStored` / `BlockRemoved` / `AllBlocksCleared`) |
| **Master** | `mooncake_master` optional RFC #1527 publisher (`enable_kv_events`) |
| **Register** | Indexer HTTP `POST /register` (or CLI `--workers`) — not carried on the event wire |
| **S+M** | Either source may supply; must agree on value for the stream |
| **—** | Not applicable for that event type |

#### Envelope and stream identity

| Field | SGLang | Master | Register | Notes |
|---|---|---|---|---|
| `event_id` | Yes | Yes | — | Each publisher maintains its own monotonic counter per stream. |
| `timestamp` | Yes | Yes | — | Informational only; not used for ordering. |
| `event_type` | Yes | Yes | — | `stored` / `removed` / `cleared`. |
| `model_name` | S+M | S+M | S+M | Register uses `modelname`. Static config on master; runtime on engine. |
| `block_size` | Yes | S+M | Yes | Required for token↔block mapping. Master uses `kv_events_block_size` if set. |
| `additional_salt` | Yes | S+M | S+M | Register uses `additionalsalt`. Hash namespace salt from engine; master only static string. |
| `lora_name` | Yes | — | S+M | Engine knows active LoRA; master has no adapter context. |
| `tenant_id` | S+M | S+M | Yes | Register default `default`. |
| `backend_id` | S+M | Yes | — | **Master**: storage daemon / pool owner. **SGLang**: often worker id; in decoupled mode prefer master=`daemon`, engine via **Register** `instance_id`. |
| `medium` | Yes | Partial | — | **SGLang**: `GPU`, `CPU_PINNED`, `DISK`, `EXTERNAL`, etc. **Master**: only `cpu` / `disk` (host/disk pool), never GPU. |
| `dp_rank` | Yes | S+M | Yes | SGLang may override per batch (`attn_dp_rank`). Master uses static `kv_events_dp_rank`. |

#### `stored` payload

| Field | SGLang | Master | Register | Notes |
|---|---|---|---|---|
| `seq_hashes` | Yes | Conditional | — | **Required from SGLang** for correct prefix index. Master: single hash when key is decimal/`0x` u64; empty array when only `object_key` is used. |
| `object_key` | — | Yes | — | Mooncake store key (`kv_events_emit_object_key`, default on). Used by Dynamo for sha256+key matching. |
| `block_hashes` (legacy) | Yes | Conditional | — | Alias of `seq_hashes` when `kv_events_emit_legacy_compat` is enabled on master. |
| `parent_hash` | Yes | — | — | Radix parent link; master has no sequence tree. |
| `parent_block_hash` (legacy) | Yes | — | — | Same as `parent_hash`. |
| `base_block_idx` | Yes | Partial | — | Depth of first block in batch; master uses `0` for standalone pool blocks. |
| `token_ids` | Yes | — | — | Required for `/query` by tokens or hash recomputation when engine is non-standard. |
| `block_size` (in-event) | Yes | — | — | Per-block token count in SGLang `BlockStored`; master uses envelope-level config only. |

#### `removed` payload

| Field | SGLang | Master | Register | Notes |
|---|---|---|---|---|
| `seq_hashes` | Yes | Conditional | — | **Required** on wire for strict RFC consumers. Master emits one hash when parseable, else empty with `object_key`. |
| `base_block_idx` | Yes | — | — | Optional but recommended for observability. |

#### `cleared` payload

| Field | SGLang | Master | Register | Notes |
|---|---|---|---|---|
| (no extra fields) | — | — | — | Event is envelope-only. |
| `cleared` / `AllBlocksCleared` | Yes | — | — | Engine `reset()` / full cache flush. Master does not emit today. |

#### Indexer / router plane (not in KV event JSON)

| Field | SGLang | Master | Register | Notes |
|---|---|---|---|---|
| `instance_id` | — | — | Yes | Router-facing schedule target. Distinct from `backend_id`. |
| `endpoint` | — | — | Yes | ZMQ PUB to subscribe (SGLang or master bind address). |
| `replay_endpoint` | — | — | Yes | Optional gap replay (engine ROUTER). |
| `type` | — | — | Yes | Publisher kind: `vLLM`, `SGLang`, `Mooncake`, etc. |

#### Recommended split for Dynamo global KV indexer

```mermaid
flowchart LR
SGLang["SGLang ZMQ"]
Master["Mooncake master ZMQ"]
Reg["POST /register"]
Idx["Global KV indexer"]

SGLang -->|"GPU + HiCache tiers<br/>tokens, parent_hash, seq_hashes, lora"| Idx
Master -->|"Host/Disk pool<br/>backend_id, medium=cpu|disk"| Idx
Reg -->|"instance_id, model, block_size"| Idx
```

| Capability | Primary source |
|---|---|
| GPU prefix hits, LoRA-aware hashes, parent chain, multi-block batches | **SGLang** |
| Pooled host/disk replica visibility | **Master** (if keys encode `seq_hash`) |
| Request routing target | **Register** (`instance_id`) |
| Tiered `/query` response (`gpu` / `cpu` / `disk`) | Merge **SGLang** + **Master** events (see RFC #1403) |
3 changes: 3 additions & 0 deletions mooncake-store/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
project(MooncakeStore VERSION 2.0.0)

option(ENABLE_KV_EVENTS
"Build master KV events ZMQ publisher (requires libzmq when ON)" OFF)

# Extract version components for C++ usage
set(MOONCAKE_STORE_VERSION ${PROJECT_VERSION})

Expand Down
10 changes: 9 additions & 1 deletion mooncake-store/conf/master.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,13 @@
"client_live_ttl_sec": 60,
"enable_http_metadata_server": false,
"http_metadata_server_host": "0.0.0.0",
"http_metadata_server_port": 8080
"http_metadata_server_port": 8080,
"enable_kv_events": false,
"kv_events_bind_endpoint": "tcp://0.0.0.0:5557",
"kv_events_model_name": "",
"kv_events_backend_id": "",
"kv_events_tenant_id": "default",
Comment on lines +26 to +28

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need these configurations.

"kv_events_block_size": 0,
"kv_events_dp_rank": 0,
"kv_events_emit_object_key": true
}
7 changes: 7 additions & 0 deletions mooncake-store/go/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ fi

CGO_LDFLAGS+=" -luring"

# KV events publisher (optional; linked when libzmq is installed).
if ldconfig -p 2>/dev/null | grep -q libzmq \
|| [ -f /usr/lib/x86_64-linux-gnu/libzmq.so ] \
|| [ -f /usr/lib/libzmq.so ]; then
CGO_LDFLAGS+=" -lzmq"
fi

if [ "$USE_ETCD" = "ON" ]; then
if [ "$USE_ETCD_LEGACY" = "ON" ]; then
CGO_LDFLAGS+=" -letcd-cpp-api -lprotobuf -lgrpc++ -lgrpc"
Expand Down
36 changes: 36 additions & 0 deletions mooncake-store/include/kv_event/key_util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spec vs implementation review (RFC #1527 master KV publisher)

Overall the implementation matches the spec in #1527 quite closely:

  • Optional ZMQ PUB publisher on mooncake_master with RFC [RFC]: Kv Events API Standardization #1527 fields and vLLM-compatible aliases
  • Config surface on MasterConfig/flags/JSON, and Rust/Go build hooks for libzmq
  • Event hooks on PutEnd, Remove, and eviction paths, plus /kv_events/status HTTP endpoint
  • Tests for key parsing and disabled publisher path

Below are concrete line-level checks and a few small nits:

  1. Build/feature flagging and deps
  • mooncake-store/CMakeLists.txt + src/CMakeLists.txt + rust/build.rs + go/build.sh + dependencies.sh
    • ✅ Matches spec: ZMQ is optional, discovered via CMake/Rust/go build scripts, and ENABLE_KV_EVENTS defaults to OFF.
    • ✅ Fatal error when ENABLE_KV_EVENTS=ON but libzmq is missing is reasonable and matches “requires libzmq when ON”.
    • ✅ Rust and Go branches only link -lzmq when the library is present.
  1. Config surface (flags + JSON + structs)
  • mooncake-store/src/master.cpp (DEFINE_* for enable_kv_events, kv_events_*) and wiring into MasterConfig via InitMasterConf + LoadConfigFromCmdline
  • mooncake-store/conf/master.json and mooncake-store/include/master_config.h
    • ✅ Fields match the spec: enable_kv_events, kv_events_bind_endpoint, kv_events_model_name, kv_events_backend_id, kv_events_tenant_id, kv_events_block_size, kv_events_dp_rank, plus kv_events_additional_salt, kv_events_lora_name, kv_events_emit_legacy_compat, kv_events_emit_object_key.
    • ✅ Default tenant_id = "default" matches the spec.
    • 🔍 Minor: JSON only exposes kv_events_emit_object_key; kv_events_emit_legacy_compat is flag-only (no JSON default). That’s acceptable, but if you want full config parity, you might consider adding it to master.json as well.
  1. Key parsing and seq_hashes behavior
  • mooncake-store/include/kv_event/key_util.h
    • ✅ Implements decimal or 0x/0X hex u64 parsing from the entire object key, which aligns with the spec’s “object keys may encode rolling seq_hash as decimal or 0x-prefixed hex string; reject mixed strings like 123abc”.
    • ✅ Returns nullopt on partial or invalid parses.
  1. Publisher config and stub behavior
  • KvEventConfig (include/kv_event/kv_event_config.h) and stubbed KvEventPublisher when ZMQ is absent
    • ✅ Config fields and defaults match the RFC: enabled, bind_endpoint, model_name, backend_id, tenant_id, additional_salt, lora_name, block_size, dp_rank, emit_legacy_compat_fields, emit_object_key.
    • ✅ Stub implementation is a no-op but still exposes ParseSeqHashFromObjectKey and GetStats, which fits the “disabled emitter is safe noop” requirement.
  1. Wire format and field matrix
  • mooncake-store/src/kv_event/kv_event_publisher.cpp
    • ✅ ZMQ framing: three frames (topic="", big-endian sequence, msgpack payload) matches the spec and vLLM/SGLang format.
    • ✅ Top-level payload is [timestamp_ms, [events], dp_rank].
    • ✅ Each event map uses RFC field names plus optional legacy aliases:
      • Envelope: event_id, timestamp, event_type, model_name, block_size, additional_salt, lora_name, tenant_id, backend_id, medium, dp_rank, seq_hashes.
      • Optional: object_key (when emit_object_key), type + block_hashes (when emit_legacy_compat_fields).
      • Stored-specific: base_block_idx, parent_hash, token_ids, and parent_block_hash when legacy is enabled.
      • Removed-specific: base_block_idx.
    • ✅ event_type values stored/removed match the spec; legacy type BlockStored/BlockRemoved are present.
    • ✅ block_size and dp_rank are nullable (nil) when not set, which matches the optional envelope semantics.
    • ✅ seq_hashes behavior matches the matrix:
      • Single-element array when the object key parses as u64.
      • Empty array when parsing fails but emit_object_key=true (falling back to object_key only).
    • ✅ object_key is always emitted when emit_object_key is enabled, independently of parse result, which matches the text.
    • 🔍 Potential spec nuance: the spec notes that block_size is required for token↔block mapping. Here, you allow block_size=0 and pack nil. That’s consistent with a “best-effort” publisher, but for strict RFC consumers you might want to either (a) enforce nonzero block_size when enable_kv_events=true or (b) document that master publisher is not suitable for token-level queries without that set.
  1. Event hooks and semantics
  • mooncake-store/src/master_service.cpp and header declarations
    • ✅ PutEnd calls PublishKvStored, so successful writes emit stored events.
    • ✅ Remove calls PublishKvRemoved(key, metadata, tenant_id), so user-initiated deletes emit removed events.
    • ✅ Eviction paths:
      • EvictDiskReplica publishes removed when disk replicas are erased.
      • BatchEvict and NoFBatchEvict publish removed for CPU/disk evictions with the appropriate medium (cpu or disk).
      • PublishKvRemovedAfterEvict handles both freed_bytes>0 and complete-metadata removal cases, which covers the spec’s “eviction paths” requirement.
    • ✅ MediumForReplicaType/MediumForMetadata restrict master to "cpu"/"disk" mediums, matching the spec’s statement that master never emits GPU tiers.
    • ✅ BuildKvEventConfig pulls through all the expected kv_events_* fields from config.
    • ✅ KV publisher is initialized once in MasterService and guarded with enabled() checks, so it’s truly optional.
  1. Admin HTTP surface
  • mooncake-store/src/master_admin_service.cpp + include/master_admin_service.h
    • ✅ Adds GET /kv_events/status returning enabled, published_batches, published_events, dropped_events, and skipped_unparsed_keys via JSON, matching the spec.
    • ✅ MasterAdminServer::HandleKvEventsStatus delegates to WrappedMasterService::GetKvEventStats() / KvEventsEnabled() as expected.
  1. RPC layer and stats plumbing
  • mooncake-store/include/rpc_service.h and src/rpc_service.cpp
    • ✅ Exposes KvEventsEnabled() and GetKvEventStats() from WrappedMasterService down into MasterService, matching the admin handler usage.
  1. Tests
  • mooncake-store/tests/kv_event_publisher_test.cpp + tests/CMakeLists.txt
    • ✅ Confirms ParseSeqHashFromObjectKey decimal/hex behavior and invalid-input handling.
    • ✅ Confirms that a disabled KvEventPublisher publishes no events and doesn’t crash.
    • 🔍 Suggestion (non-blocking): adding a small ENABLE_KV_EVENTS test that constructs a publisher with a dummy inproc endpoint and validates the basic msgpack structure would more directly exercise the batch format, but that’s beyond the current spec.
  1. Docs
  • docs/source/design/conductor/indexer-api-design.md
    • ✅ New “Mooncake Store master publisher” section and field provenance matrix align with the RFC description and the actual implementation (field names, sources, and recommended split between SGLang/master/register).

Conclusion

  • From a spec-compliance standpoint, the PR looks correct and complete for the master-side KV events publisher.
  • The only minor gaps I see are:
    • kv_events_emit_legacy_compat is flag-only (not surfaced in master.json).
    • block_size is allowed to be unset even when events are enabled; if strict RFC consumers rely on it, you might consider enforcing it or clearly documenting that master events without block_size are for observability only.

Otherwise this aligns well with issue #1527. ✅


🤖 Generated by Qoder • Fix in Qoder


#include <cstdint>
#include <optional>
#include <string>

namespace mooncake {

// Parses object keys encoded as decimal or 0x-prefixed hex u64 hashes.
inline std::optional<uint64_t> ParseSeqHashFromObjectKey(
const std::string& object_key) {
if (object_key.empty()) {
return std::nullopt;
}
try {
size_t idx = 0;
if (object_key.size() >= 2 &&
(object_key[0] == '0' &&
(object_key[1] == 'x' || object_key[1] == 'X'))) {
uint64_t value = std::stoull(object_key, &idx, 16);
if (idx == object_key.size()) {
return value;
}
return std::nullopt;
}
uint64_t value = std::stoull(object_key, &idx, 10);
if (idx == object_key.size()) {
return value;
}
} catch (const std::exception&) {
return std::nullopt;
}
return std::nullopt;
}

} // namespace mooncake
26 changes: 26 additions & 0 deletions mooncake-store/include/kv_event/kv_event_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include <cstdint>
#include <string>

namespace mooncake {

// Configuration for the optional KV Events publisher (RFC #1527).
struct KvEventConfig {
bool enabled{false};
// ZMQ PUB bind address, e.g. "tcp://0.0.0.0:5557".
std::string bind_endpoint;
std::string model_name;
std::string backend_id;
std::string tenant_id{"default"};
std::string additional_salt;
std::string lora_name;
uint32_t block_size{0};
uint32_t dp_rank{0};
// Emit legacy vLLM/SGLang field names alongside RFC #1527 fields.
bool emit_legacy_compat_fields{true};
// Emit Mooncake object_key for consumers that match on store key format.
bool emit_object_key{true};
};

} // namespace mooncake
121 changes: 121 additions & 0 deletions mooncake-store/include/kv_event/kv_event_publisher.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#pragma once

#include <atomic>
#include <condition_variable>
#include <cstdint>
#include <deque>
#include <memory>
#include <mutex>
#include <optional>
#include <string>
#include <thread>
#include <vector>

#include "kv_event/kv_event_config.h"
#include "kv_event/key_util.h"

namespace mooncake {

#if defined(MOONCAKE_ENABLE_KV_EVENTS) && MOONCAKE_ENABLE_KV_EVENTS

// Publishes standardized KV cache events (RFC #1527) over ZMQ for indexers.
class KvEventPublisher {
public:
explicit KvEventPublisher(KvEventConfig config);
~KvEventPublisher();

KvEventPublisher(const KvEventPublisher&) = delete;
KvEventPublisher& operator=(const KvEventPublisher&) = delete;

bool enabled() const { return config_.enabled; }

// Non-blocking enqueue; never drops events (unbounded queue).
// tenant_id empty uses config_.tenant_id (RFC envelope default).
void PublishStored(const std::string& object_key, const std::string& medium,
const std::string& tenant_id = "");
void PublishRemoved(const std::string& object_key,
const std::string& medium,
const std::string& tenant_id = "");

struct Stats {
uint64_t published_batches{0};
uint64_t published_events{0};
uint64_t dropped_events{0};
uint64_t skipped_unparsed_keys{0};
};
Stats GetStats() const;

static std::optional<uint64_t> ParseSeqHashFromObjectKey(
const std::string& object_key) {
return mooncake::ParseSeqHashFromObjectKey(object_key);
}

private:
enum class EventKind { kStored, kRemoved };

struct PendingEvent {
EventKind kind;
std::string object_key;
std::string medium;
std::string tenant_id;
};

void Enqueue(PendingEvent event);
void WorkerLoop();
void PublishBatch(const std::vector<PendingEvent>& batch);
void DrainRemainingQueue(std::vector<PendingEvent>& batch);

KvEventConfig config_;
void* zmq_context_{nullptr};
void* zmq_socket_{nullptr};

mutable std::mutex queue_mutex_;
std::deque<PendingEvent> queue_;
std::condition_variable queue_cv_;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing include <condition_variable>

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No require

std::thread worker_;
std::atomic<bool> stop_{false};

std::atomic<uint64_t> next_event_id_{1};
std::atomic<uint64_t> next_zmq_sequence_{1};

std::atomic<uint64_t> published_batches_{0};
std::atomic<uint64_t> published_events_{0};
std::atomic<uint64_t> dropped_events_{0};
std::atomic<uint64_t> skipped_unparsed_keys_{0};
};

#else

// Stub when mooncake_store is built without libzmq (ENABLE_KV_EVENTS=OFF).
class KvEventPublisher {
public:
explicit KvEventPublisher(KvEventConfig config)
: config_(std::move(config)) {}

bool enabled() const { return false; }

void PublishStored(const std::string&, const std::string&,
const std::string& = "") {}
void PublishRemoved(const std::string&, const std::string&,
const std::string& = "") {}

struct Stats {
uint64_t published_batches{0};
uint64_t published_events{0};
uint64_t dropped_events{0};
uint64_t skipped_unparsed_keys{0};
};
Stats GetStats() const { return {}; }

static std::optional<uint64_t> ParseSeqHashFromObjectKey(
const std::string& object_key) {
return mooncake::ParseSeqHashFromObjectKey(object_key);
}

private:
KvEventConfig config_;
};

#endif

} // namespace mooncake
2 changes: 2 additions & 0 deletions mooncake-store/include/master_admin_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class MasterAdminServer {
coro_http::coro_http_response& resp);
void HandleBatchQueryKeys(coro_http::coro_http_request& req,
coro_http::coro_http_response& resp);
void HandleKvEventsStatus(coro_http::coro_http_request& req,
coro_http::coro_http_response& resp);

void RegisterHandler();

Expand Down
Loading
Loading