Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Database Connection Management and Improve Storage Lifecycle Handling #846

Merged
merged 8 commits into from
Feb 18, 2025

Conversation

ArnoChenFx
Copy link
Contributor

This PR refactors the database connection management for PostgreSQL, Oracle, and TiDB by introducing a ClientManager class. It also enhances the lifecycle management of storage components in LightRAG, ensuring consistency and better maintainability.

Key Changes:

  1. Unified Database Initialization for All Backends:

    • Previously, PostgreSQL, Oracle, and TiDB could not be automatically created and configured like other backends when used outside the lightrag_server environment. This update ensures that all backends now exhibit consistent behavior.
  2. Decoupled Backend Implementations from lightrag_server:

    • Previously, lightrag_server explicitly imported and initialized PostgreSQL, Oracle, and TiDB, which increased backend maintenance complexity and violated the principle of backend isolation.
    • With this refactor, these backends are now fully self-contained within their respective implementation files, restoring modularity and reducing unnecessary dependencies in the server code.
  3. Improved Storage Lifecycle Management:

    • Added initialize() and finalize() methods to StorageNameSpace to handle storage setup and cleanup.
    • LightRAG now explicitly manages storage lifecycle with initialize_storages() and finalize_storages(), ensuring proper resource management.

Benefits:

  • Consistent Behavior Across Backends: PostgreSQL, Oracle, and TiDB now behave like other backends, automatically initializing when needed.
  • Reduced Maintenance Complexity: Backend implementations are now self-contained, making them easier to maintain and extend.
  • Improved Modularity: Decouples backend logic from the server, making the system more flexible and scalable.

Testing:

  • Verified that PostgreSQL, Oracle, and TiDB are now automatically initialized and configured correctly.
  • Confirmed that storage lifecycle methods are called appropriately during server startup and shutdown.

@YanSte
Copy link
Contributor

YanSte commented Feb 18, 2025

Thanks a lot, I will have a look. 🙏🏻

@YanSte
Copy link
Contributor

YanSte commented Feb 18, 2025

Really nice feature 🙏🏻

@YanSte
Copy link
Contributor

YanSte commented Feb 18, 2025

Let me know when is good I will test it directly.

@ArnoChenFx
Copy link
Contributor Author

Let me know when is good I will test it directly.

It‘s ready for test!

@YanSte
Copy link
Contributor

YanSte commented Feb 18, 2025

Let's go, I merge it. In case of issues we update directly.

@YanSte YanSte merged commit ccb117e into HKUDS:main Feb 18, 2025
1 check passed
@YanSte
Copy link
Contributor

YanSte commented Feb 18, 2025

Got some error see my issue: #849

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.

2 participants