Skip to content

feat: Support specifying BufferStrategy when open a database#162

Merged
longbinlai merged 14 commits intoalibaba:mainfrom
zhanglei1949:expose-mem-level
Apr 10, 2026
Merged

feat: Support specifying BufferStrategy when open a database#162
longbinlai merged 14 commits intoalibaba:mainfrom
zhanglei1949:expose-mem-level

Conversation

@zhanglei1949
Copy link
Copy Markdown
Member

@zhanglei1949 zhanglei1949 commented Apr 2, 2026

User could specify the expected memory level to open the database:

  • M_LAZY: SyncToFile
  • M_FULL: InMemory
  • M_HUGE: HugePagePreferred

Fix #174
Fix #180

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@qodo-code-review
Copy link
Copy Markdown

Review Summary by Qodo

Add memory level configuration support to database initialization

✨ Enhancement

Grey Divider

Walkthroughs

Description
• Add memory_level parameter to Database initialization
• Support three memory level options: InMemory, SyncToFile, HugePagePreferred
• Enable flexible string aliases (camelCase, lowercase, snake_case) for memory levels
• Add comprehensive test coverage for all memory level configurations
Diagram
flowchart LR
  User["User specifies memory_level"] -->|Python API| PyDB["PyDatabase constructor"]
  PyDB -->|Parse string| Parser["parse_memory_level function"]
  Parser -->|Convert to enum| Config["NeugDBConfig.memory_level"]
  Config -->|Pass to| Open["NeugDB::Open"]
  Open -->|Log| Logging["VLOG with memory level info"]
Loading

Grey Divider

File Changes

1. tools/python_bind/neug/database.py ✨ Enhancement +7/-0

Add memory_level parameter to Python Database class

• Add memory_level parameter to Database.__init__() with default value "InMemory"
• Document three memory level options and their behaviors in docstring
• Pass memory_level to underlying PyDatabase C++ binding

tools/python_bind/neug/database.py


2. tools/python_bind/src/py_database.h ✨ Enhancement +4/-1

Add memory_level support to PyDatabase constructor

• Add memory_level parameter to PyDatabase constructor with default "InMemory"
• Parse memory level string and set config.memory_level before opening database
• Declare private parse_memory_level() method for string-to-enum conversion

tools/python_bind/src/py_database.h


3. tools/python_bind/src/py_database.cc ✨ Enhancement +21/-1

Implement memory level string parsing logic

• Include neug/config.h header for MemoryLevel enum
• Implement parse_memory_level() function supporting multiple string aliases
• Support canonical forms (InMemory, SyncToFile, HugePagePreferred) and variants (lowercase,
 snake_case)
• Throw exception for invalid memory level values

tools/python_bind/src/py_database.cc


View more (2)
4. src/main/neug_db.cc ✨ Enhancement +2/-1

Add memory level to database opening log

• Enhance logging in NeugDB::Open() to include memory level information
• Display configured memory level when opening database for debugging purposes

src/main/neug_db.cc


5. tools/python_bind/tests/test_db_init.py 🧪 Tests +72/-0

Add comprehensive memory level configuration tests

• Add test for default memory level behavior (InMemory)
• Add tests verifying all three memory level aliases (InMemory, SyncToFile, HugePagePreferred)
• Add test for invalid memory level error handling
• Total of 5 new test cases covering all memory level configurations

tools/python_bind/tests/test_db_init.py


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Copy Markdown

qodo-code-review Bot commented Apr 2, 2026

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider


Action required

1. Enum std::to_string fails 🐞 Bug ≡ Correctness
Description
NeugDB::Open calls std::to_string(config_.memory_level) even though memory_level is a scoped
enum (enum class MemoryLevel), which does not implicitly convert to a numeric type. This will
cause a C++ compilation failure in src/main/neug_db.cc.
Code

src/main/neug_db.cc[R108-109]

+  VLOG(1) << "Opening NeuGDB at " << work_dir_
+          << ", memory level: " << std::to_string(config_.memory_level);
Evidence
NeugDBConfig::memory_level is declared as MemoryLevel, and MemoryLevel is an enum class, so
it cannot be passed to std::to_string without an explicit cast. Other parts of the codebase
already use static_cast<int>(memory_level) before std::to_string, showing the expected pattern.

src/main/neug_db.cc[103-111]
include/neug/config.h.in[48-53]
src/storages/graph/edge_table.cc[570-574]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`std::to_string(config_.memory_level)` does not compile because `config_.memory_level` is a scoped enum (`enum class MemoryLevel`).

## Issue Context
`MemoryLevel` is defined as `enum class MemoryLevel : uint8_t`, and scoped enums do not implicitly convert to integers.

## Fix Focus Areas
- src/main/neug_db.cc[107-110]

## Suggested change
Update the log line to cast the enum to an integer (or implement a dedicated stringifier):

```cpp
VLOG(1) << "Opening NeuGDB at " << work_dir_
       << ", memory level: "
       << std::to_string(static_cast<int>(config_.memory_level));
```

(Optionally, replace the numeric value with a human-readable string via a small helper mapping `MemoryLevel` -> name.)

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

@zhanglei1949 zhanglei1949 requested a review from liulx20 April 2, 2026 07:19
Comment thread src/main/neug_db.cc
liulx20
liulx20 previously approved these changes Apr 2, 2026
liulx20
liulx20 previously approved these changes Apr 2, 2026
@longbinlai
Copy link
Copy Markdown
Collaborator

这个pr 更改了 python接口,那么至少应该改下这个文档:https://github.com/alibaba/neug/tree/main/doc/source/reference/python_api. 另外,我看到这个配置是 "InMemory"且是默认的配置,那么这个配置和 没有指定 path时候的 in-memory 模式到底是什么关系?这个有点confuse

@zhanglei1949
Copy link
Copy Markdown
Member Author

zhanglei1949 commented Apr 7, 2026

这个pr 更改了 python接口,那么至少应该改下这个文档:https://github.com/alibaba/neug/tree/main/doc/source/reference/python_api. 另外,我看到这个配置是 "InMemory"且是默认的配置,那么这个配置和 没有指定 path时候的 in-memory 模式到底是什么关系?这个有点confuse

已经将参数名字更改为BufferStrategy. 默认改为M_HUGE

@zhanglei1949 zhanglei1949 changed the title feat: Support specifying memory level when open a database feat: Support specifying BufferStrategy when open a database Apr 7, 2026
@zhanglei1949 zhanglei1949 requested a review from longbinlai April 8, 2026 07:47
Copy link
Copy Markdown
Collaborator

@longbinlai longbinlai left a comment

Choose a reason for hiding this comment

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

LGTM

@longbinlai longbinlai merged commit 632cd29 into alibaba:main Apr 10, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The documentation for constructors are not presented. Supports setting the memory_level parameter when starting the service via the Python API.

3 participants