Documentation
¶
Overview ¶
Package graphdb provides a connection pool for Kuzu graph databases. It manages multiple connections to different Kuzu DBs, identified by namespace ID, and handles memory allocation for these connections. The pool ensures efficient reuse of connections and provides mechanisms for periodic maintenance to close unused databases and free up memory.
Index ¶
Constants ¶
const ConnectionDuration = 20 * time.Minute
const MaintenanceInterval = 1 * time.Minute
const MaxBufferSize = 200 * 1024 * 1024 // 200 MB
const MaxConnections = 10 // maximum number of connections to single database
const MaxVirtMem = 1024 * 1024 * 1024 // 1GB - this is needed to avoid hitting max virtual memory limit
const MinBufferSize = 10 * 1024 * 1024 // 10 MB
const QueryTimeoutSeconds = 15
Variables ¶
This section is empty.
Functions ¶
func RequiredBufferSize ¶
Types ¶
type Client ¶
type Client struct {
NamespaceID uint64 // namespace ID (currently only project namespace ID)
GraphIndexDir string // top-level directory
DbPath string // kuzu database file path
}
A Client represents basic information about graph DB for a specific namespace (base index directory, directory with database and metadata files for the namespace).
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
A Connection represents a single connection to a Kuzu DB. The connection can be reused for multiple requests but should not be used by multiple requests at the same time.
func NewConnection ¶
func NewConnection(db *Database) (*Connection, error)
func (*Connection) Acquire ¶
func (c *Connection) Acquire() bool
func (*Connection) Query ¶
func (c *Connection) Query(q string) *QueryResult
func (*Connection) Release ¶
func (c *Connection) Release()
type ConnectionPool ¶
type ConnectionPool struct {
// contains filtered or unexported fields
}
A ConnectionPool keeps and maintains a pool of open connections to Kuzu DBs. There can be multiple connections to different DBs (identified by namespace ID). Each DB connection reserves a memory buffer, size of buffer equals to DB file size. Each DB connection can have multiple connections to allow concurrent access to the same DB, maximum connections to the same DB is 10
It returns a Connection object which can be used to execute DB queries. Make sure to call Release() on this object when done so the connection can be reused.
func NewConnectionPool ¶
func NewConnectionPool(memLimit uint64) *ConnectionPool
func (*ConnectionPool) Connect ¶
func (pool *ConnectionPool) Connect(path string) (*Connection, error)
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
A Database represents a Kuzu DB, there can be multiple connections opened to the same DB.
func (*Database) GetConnection ¶
func (db *Database) GetConnection() (*Connection, error)
type QueryRequest ¶
type QueryRequest struct {
Query string `json:"query,omitempty"`
NamespaceID uint64 `json:"namespace_id,omitempty"`
}
func NewQueryRequest ¶
func NewQueryRequest(r *http.Request) (*QueryRequest, error)