refactor: Hold service pointer in database instance#763
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses Issue #757 by enforcing a single active NeugDBService per NeugDB instance, tracking service association inside the database and rejecting conflicting operations while serving.
Changes:
- Add
NeugDB↔NeugDBServiceassociation tracking via an atomicactive_service_, with register/unregister hooks and aHasActiveService()query. - Reject
NeugDBServicecreation when one is already associated with the sameNeugDB, and rejectNeugDB::Connect()/NeugDB::Close()while a service is active. - Add unit tests covering single-service enforcement, init-failure rollback, and blocking connect/close while serving.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unittest/test_db_svc.cc | Adds unit tests for single-service enforcement and blocked DB operations while serving. |
| src/server/neug_db_service.cc | Unregisters the service from the DB on destruction. |
| src/main/neug_db.cc | Implements service registration tracking; blocks Connect()/Close() while serving; adjusts destructor close behavior. |
| include/neug/server/neug_db_service.h | Registers/unregisters service association during construction (with rollback on init failure) and documents the constraint. |
| include/neug/main/neug_db.h | Declares service association API and stores the active service pointer atomically. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
4 tasks
zhanglei1949
force-pushed
the
zl/fix-db-svc-rel
branch
from
July 23, 2026 08:39
132567c to
7c0c7c4
Compare
liulx20
reviewed
Jul 23, 2026
|
|
||
| // The NeugDBService currently associated with this database, nullptr if | ||
| // none. At most one service can be associated at any given time. | ||
| std::atomic<NeugDBService*> active_service_{nullptr}; |
Collaborator
There was a problem hiding this comment.
Why do we need atomic here,Is there a race condition?
Member
Author
There was a problem hiding this comment.
Changed to raw pointer. The thread safety will be guarded by the mutex.
liulx20
approved these changes
Jul 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #757