Add initial implementation of Agate snapshot library

Introduces core functionality for the Agate library, including snapshot creation, restoration, listing, and deletion. Adds examples for basic usage, gRPC proto definitions, and build/configuration files such as `go.mod` and `Makefile`. The implementation establishes the framework for store integration and placeholder server functionality.
This commit is contained in:
2025-04-24 02:44:16 +03:00
commit 7e9cea9227
20 changed files with 2649 additions and 0 deletions

42
stores/stores.go Normal file
View File

@ -0,0 +1,42 @@
package stores
import (
"fmt"
"path/filepath"
"unprism.ru/KRBL/agate/store"
"unprism.ru/KRBL/agate/store/filesystem"
"unprism.ru/KRBL/agate/store/sqlite"
)
// NewDefaultMetadataStore creates a new SQLite-based metadata store.
func NewDefaultMetadataStore(metadataDir string) (store.MetadataStore, error) {
dbPath := filepath.Join(metadataDir, "snapshots.db")
return sqlite.NewSQLiteStore(dbPath)
}
// NewDefaultBlobStore creates a new filesystem-based blob store.
func NewDefaultBlobStore(blobsDir string) (store.BlobStore, error) {
return filesystem.NewFileSystemStore(blobsDir)
}
// InitDefaultStores initializes both metadata and blob stores with default implementations.
// Returns the initialized stores or an error if initialization fails.
func InitDefaultStores(baseDir string) (store.MetadataStore, store.BlobStore, error) {
metadataDir := filepath.Join(baseDir, "metadata")
blobsDir := filepath.Join(baseDir, "blobs")
metadataStore, err := NewDefaultMetadataStore(metadataDir)
if err != nil {
return nil, nil, fmt.Errorf("failed to initialize metadata store: %w", err)
}
blobStore, err := NewDefaultBlobStore(blobsDir)
if err != nil {
// Clean up if blob store initialization fails
metadataStore.Close()
return nil, nil, fmt.Errorf("failed to initialize blob store: %w", err)
}
return metadataStore, blobStore, nil
}