Documentation
¶
Overview ¶
Package database provides database connection utilities for SQLite and LevelDB. It handles database creation, connection management, and path building for multi-shard databases.
Package database provides fragmentation management for distributed data across shards. It uses LevelDB to maintain a global schema that maps row IDs to their respective shards.
Index ¶
- Constants
- Variables
- func CleanPath(p string) string
- func CreateLevelDBDatabase(params ...string) (*leveldb.DB, error)
- func CreateSQLiteDatabase(params ...string) (*sql.DB, error)
- func FragmentationAdd(shard int64, keys ...string) error
- func FragmentationExists(key string) (bool, error)
- func FragmentationGet(rowID string) (int64, error)
- func FragmentationRemove(key string) error
- func FragmentationUpdate(key string, newShard int64) error
Constants ¶
const ( // GlobalSchemaPath is the default path for the fragmentation schema database GlobalSchemaPath = "GlobalSchema" // DefaultBaseDir is the default base directory for database files DefaultBaseDir = "Database/" )
Variables ¶
var ( ErrInvalidPath = errors.New("invalid path: at least 2 path components required") ErrDatabaseOpen = errors.New("failed to open database") ErrDirectoryCreate = errors.New("failed to create directory") )
Common errors for database operations
var ( ErrShardNotFound = errors.New("shard not found for the given key") ErrFragmentationWrite = errors.New("failed to write fragmentation entry") ErrFragmentationRead = errors.New("failed to read fragmentation entry") ErrShardConversion = errors.New("failed to convert shard to int64") ErrEmptyKey = errors.New("key cannot be empty") )
Fragmentation errors
Functions ¶
func CreateLevelDBDatabase ¶
CreateLevelDBDatabase creates and returns a LevelDB database connection. Params should include at least the base directory and shard name. Optional third parameter specifies the database filename or subfolder.
Example usage:
db, err := CreateLevelDBDatabase("Database/", "Common", "Shard_0.sqlite")
Returns a *leveldb.DB connection and any error encountered.
func CreateSQLiteDatabase ¶
CreateSQLiteDatabase creates and returns a SQLite database connection. Params should include at least the base directory and shard name. Optional third parameter specifies the database filename.
Example usage:
db, err := CreateSQLiteDatabase("Database/", "UserData", "users.db")
Returns a *sql.DB connection and any error encountered.
func FragmentationAdd ¶
FragmentationAdd adds one or more fragment entries to the global schema. Each key is mapped to the specified shard number.
Parameters:
- shard: The shard number to associate with the keys
- keys: One or more keys to add to the fragmentation schema
Returns an error if any database operation fails.
func FragmentationExists ¶
FragmentationExists checks if a key exists in the fragmentation schema.
Parameters:
- key: The key to check
Returns true if the key exists, false otherwise.
func FragmentationGet ¶
FragmentationGet retrieves the shard number for a given row ID.
Parameters:
- rowID: The row ID to look up in the fragmentation schema
Returns the shard number and any error encountered.
func FragmentationRemove ¶
FragmentationRemove removes a fragment entry from the global schema.
Parameters:
- key: The key to remove from the fragmentation schema
Returns an error if the database operation fails.
func FragmentationUpdate ¶
FragmentationUpdate updates the shard assignment for an existing key.
Parameters:
- key: The key to update
- newShard: The new shard number to assign
Returns an error if the key doesn't exist or if the update fails.
Types ¶
This section is empty.