Skip to content

[Store] Add Go language bindings for Mooncake Store via C API#1659

Open
jiangyukunok wants to merge 1 commit intokvcache-ai:mainfrom
jiangyukunok:go-api-support
Open

[Store] Add Go language bindings for Mooncake Store via C API#1659
jiangyukunok wants to merge 1 commit intokvcache-ai:mainfrom
jiangyukunok:go-api-support

Conversation

@jiangyukunok
Copy link
Copy Markdown

@jiangyukunok jiangyukunok commented Mar 15, 2026

Description

Add Go language bindings for Mooncake Store, enabling Go programs to use Store operations (put, get, batch, zero-copy, buffer registration)

The structure of changes from top to bottom:

main.go            Example program / user application 
store_test.go      Tests 

store.go           Go API layer (calls C via CGo)
config.go          Go data types 
errors.go          Go error definitions 
           (CGo boundary)
store_c.h          C header (the "contract") 
store_c.cpp        C implementation (translates C → C++)

build.sh           Wires it all together

Also added WITH_STORE_GO build option to provide flexibilities.
Also updated the outdated .devcontainer/Dockerfile to have arm64 support.
Also added unit tests and integration tests.

Module

  • Transfer Engine (mooncake-transfer-engine)
  • Mooncake Store (mooncake-store)
  • Mooncake EP (mooncake-ep)
  • Integration (mooncake-integration)
  • P2P Store (mooncake-p2p-store)
  • Python Wheel (mooncake-wheel)
  • PyTorch Backend (mooncake-pg)
  • Mooncake RL (mooncake-rl)
  • CI/CD
  • Docs
  • Other

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Breaking change
  • Documentation update
  • Other

How Has This Been Tested?

Build verification: store_c.cpp compiles as part of libmooncake_store via CMake with WITH_STORE_GO=ON.
Nil-safety tests (TestNilStoreOperations, TestNewAndClose): verify safe behavior on nil handles and double-close. These run without a cluster.
Integration tests (TestPutGetRoundTrip, TestBatchExists, TestRemoveAll, TestHostname, TestReplicateConfig):
from CI test:

PASS
ok  	github.com/kvcache-ai/Mooncake/mooncake-store/go/mooncakestore	6.045s

Checklist

  • I have performed a self-review of my own code.
  • I have formatted my own code using ./scripts/code_format.sh before submitting.
  • I have updated the documentation.
  • I have added tests to prove my changes are effective.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly expands the interoperability of Mooncake Store by introducing official Go language bindings. This allows developers to leverage the high-performance, RDMA-capable distributed key-value store directly from their Go applications. The changes encompass the full spectrum of client-side operations, from basic data manipulation to advanced features like zero-copy transfers, all integrated with the existing C++ core via a new C API layer. The update also includes necessary build system adjustments and Dockerfile improvements to facilitate development and deployment across different architectures.

Highlights

  • Go Language Bindings: Added comprehensive Go language bindings for Mooncake Store, enabling Go programs to interact with the distributed key-value store.
  • Core Store Operations: Go bindings now support essential Mooncake Store operations including put, get, batch operations, existence checks, size retrieval, removal, and zero-copy buffer registration.
  • Build System Integration: Introduced a new CMake option WITH_STORE_GO to control the building of Go bindings and updated the build process to include the new C API and Go components.
  • Development Environment Enhancements: Updated the .devcontainer/Dockerfile to support arm64 architecture and a newer Go version (1.23.8), along with additional development dependencies.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • .devcontainer/Dockerfile
    • Updated Go version to 1.23.8 with architecture detection (arm64/amd64).
    • Added new build dependencies: libzstd-dev, libmsgpack-dev, libgflags-dev.
  • CMakeLists.txt
    • Added a new CMake option WITH_STORE_GO to control the building of Go bindings.
    • Configured a custom build target build_store_go to execute the Go build script when WITH_STORE_GO is enabled.
  • mooncake-store/go/build.sh
    • Created a new build.sh script to configure CGo compiler and linker flags, enabling the Go bindings to link against the Mooncake C++ libraries.
  • mooncake-store/go/examples/basic/main.go
    • Implemented a new example Go program (main.go) demonstrating core Mooncake Store operations like Put, Get, Exists, GetSize, and Remove.
  • mooncake-store/go/go.mod
    • Created a go.mod file to define the Go module for the Mooncake Store bindings, specifying Go version 1.23.
  • mooncake-store/go/mooncakestore/config.go
    • Defined the ReplicateConfig struct and DefaultReplicateConfig function for controlling data replication in the Go bindings.
  • mooncake-store/go/mooncakestore/errors.go
    • Introduced a set of custom error variables (e.g., ErrStoreNil, ErrPut, ErrNotFound) for the Go bindings.
  • mooncake-store/go/mooncakestore/store.go
    • Implemented the main Store struct and its methods, providing Go wrappers for the Mooncake Store C API functions, including lifecycle management, put/get operations, existence checks, and buffer registration.
  • mooncake-store/go/mooncakestore/store_test.go
    • Developed a suite of unit and integration tests for the Go bindings, verifying the functionality of New, Close, Put, Get, Exists, Remove, batch operations, and replication configuration.
  • mooncake-store/include/store_c.h
    • Created a new C header file (store_c.h) that declares the C API for Mooncake Store, including data types like mooncake_replicate_config_t and function prototypes for all store operations.
  • mooncake-store/src/CMakeLists.txt
    • Updated the MOONCAKE_STORE_SOURCES list to include the new store_c.cpp file, ensuring the C API implementation is built.
  • mooncake-store/src/store_c.cpp
    • Implemented the C API functions in store_c.cpp, which act as a wrapper around the existing C++ mooncake::RealClient, handling type conversions and resource management.
Activity
  • No specific activity has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces Go language bindings for the Mooncake Store, enabling Go applications to interact with the store. The changes are comprehensive, including a C API layer, a Go wrapper using CGo, build system updates, and example code. The implementation correctly handles CGo memory management and provides a clean interface. My review focuses on improving portability, maintainability, and demonstrating best practices. I've identified a potential portability issue with the use of the long type in the C API, and suggested improvements to the Dockerfile and the Go example code for better maintainability and correctness.

@stmatengss stmatengss self-assigned this Mar 15, 2026
@jiangyukunok jiangyukunok force-pushed the go-api-support branch 4 times, most recently from c0ccdb5 to 829d4d1 Compare March 15, 2026 04:44
@jiangyukunok jiangyukunok marked this pull request as ready for review March 15, 2026 04:53
@jiangyukunok jiangyukunok force-pushed the go-api-support branch 2 times, most recently from cf6a861 to 8130442 Compare March 15, 2026 17:02
@stmatengss stmatengss requested a review from Copilot March 15, 2026 17:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a C ABI surface for Mooncake Store and a new Go module that uses cgo to call that C API, enabling Go applications to use core Store operations (setup/init/health, put/get, batch operations, remove, hostname, and buffer registration). It also wires Go bindings into the top-level build via an optional CMake target, updates CI to run Go tests, and updates the devcontainer to install Go on both amd64/arm64.

Changes:

  • Added store_c.h/store_c.cpp C API wrapper around mooncake::RealClient and built it into libmooncake_store.
  • Added Go bindings (mooncakestore package), example program, and unit/integration tests.
  • Added WITH_STORE_GO CMake option + CI workflow steps + devcontainer updates to support building/testing Go bindings.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 14 comments.

Show a summary per file
File Description
mooncake-store/src/store_c.cpp Implements the C ABI wrapper around RealClient for lifecycle/ops/batch/buffer registration
mooncake-store/src/CMakeLists.txt Adds store_c.cpp to the Mooncake Store library sources
mooncake-store/include/store_c.h Declares the C ABI contract for the new bindings
mooncake-store/go/mooncakestore/store.go Go API layer calling into store_c.h via cgo
mooncake-store/go/mooncakestore/config.go Go-side replication config types/defaults
mooncake-store/go/mooncakestore/errors.go Go error definitions for the binding layer
mooncake-store/go/mooncakestore/store_test.go Unit + integration tests for Go bindings (currently mixed in one file)
mooncake-store/go/examples/basic/main.go Example Go application using the bindings
mooncake-store/go/go.mod Defines the Go module and Go language version
mooncake-store/go/build.sh Build helper wiring include/link flags for cgo and example build
CMakeLists.txt Adds WITH_STORE_GO option and custom target to build Go bindings
.github/workflows/ci.yml Runs Go binding unit + integration tests in CI
.devcontainer/Dockerfile Installs Go (amd64/arm64) and additional deps for local dev

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@jiangyukunok jiangyukunok force-pushed the go-api-support branch 9 times, most recently from a011d94 to 37027c3 Compare March 15, 2026 20:31
@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 0% with 117 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
mooncake-store/src/store_c.cpp 0.00% 117 Missing ⚠️

📢 Thoughts on this report? Let us know!

@jiangyukunok
Copy link
Copy Markdown
Author

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 0% with 117 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
mooncake-store/src/store_c.cpp 0.00% 117 Missing ⚠️
📢 Thoughts on this report? Let us know!

store_c.cpp is a thin forwarding layer, it's fully exercised by the Go integration tests, which passed;
C++ coverage tools can't track calls that come in through CGo;
The underlying RealClient methods that store_c.cpp delegates to already have their own C++ test coverage.

@stmatengss
Copy link
Copy Markdown
Collaborator

I think it is important. How to publish a Go package and expose its APIs?

@stmatengss
Copy link
Copy Markdown
Collaborator

LGTM. But I think we can opt for current organization. (mooncake-store => go => mooncakestore)

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.

Move test files to a separate directory?

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.

We can spilt this feature into two parts (1) support mooncake store c API. (2) support GO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants