feat(storage): add native MySQL namespace and identity pilots
Add resumable checked migrations and explicit schema administration commands. Port ML budgets, namespaces, identity and group persistence with three-backend contracts. Keep MySQL unavailable as the full application backend.
This commit is contained in:
1 parent
0c7897d695
commit
6a67fd9afe
40 files changed
+3087
-94
No files matched your search
@@ -0,0 +1,54 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
|
||||
"github.com/go-sql-driver/mysql"
|
||||
"pageswiki/internal/machinelearning"
|
||||
)
|
||||
|
||||
func mysqlDuplicate(err error) bool {
|
||||
var e *mysql.MySQLError
|
||||
return errors.As(err, &e) && e.Number == 1062
|
||||
}
|
||||
func (s *Store) mlConfig(ctx context.Context, domain string) (string, error) {
|
||||
return s.GetConfigInDomainContext(ctx, domain, machineLearningConfigKey)
|
||||
}
|
||||
|
||||
// MySQLMLRepository deliberately exposes ONLY the ported ML component. Returning
|
||||
// *Store would allow unported methods to silently execute SQLite-specific SQL.
|
||||
// Caller supplies a separately prepared MySQL 8.4+ InnoDB pilot database.
|
||||
// This is not a Pages server constructor, whole-app migration or deployment option.
|
||||
type MySQLMLRepository struct{ store *Store }
|
||||
|
||||
func NewMySQLMLRepository(database *sql.DB) *MySQLMLRepository {
|
||||
return &MySQLMLRepository{store: &Store{DB: database, sqlBackend: storeMySQL}}
|
||||
}
|
||||
func mlMySQLError(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
for _, known := range []error{ErrMachineLearningConflict, ErrMLAlreadyReserved, ErrMLBudget, machinelearning.ErrNotAllowed, machinelearning.ErrPolicy, context.Canceled, context.DeadlineExceeded} {
|
||||
if errors.Is(err, known) {
|
||||
return known
|
||||
}
|
||||
}
|
||||
return errors.New("MySQL ML operation failed")
|
||||
}
|
||||
func (r *MySQLMLRepository) Policy(ctx context.Context, domain string) (machinelearning.Policy, error) {
|
||||
p, e := r.store.MachineLearningPolicy(ctx, domain)
|
||||
return p, mlMySQLError(e)
|
||||
}
|
||||
func (r *MySQLMLRepository) SavePolicy(ctx context.Context, domain, base string, p machinelearning.Policy) (machinelearning.Policy, error) {
|
||||
p, e := r.store.SaveMachineLearningPolicy(ctx, domain, base, p)
|
||||
return p, mlMySQLError(e)
|
||||
}
|
||||
func (r *MySQLMLRepository) Reserve(ctx context.Context, domain, id, path, generation string, inputs []machinelearning.Input) (machinelearning.Request, error) {
|
||||
q, e := r.store.ReserveMLInput(ctx, domain, id, path, generation, inputs)
|
||||
return q, mlMySQLError(e)
|
||||
}
|
||||
func (r *MySQLMLRepository) Finish(ctx context.Context, domain, id string, completed bool, tokens int64) error {
|
||||
return mlMySQLError(r.store.FinishMLInput(ctx, domain, id, completed, tokens))
|
||||
}
|
||||
Reference in new issue
Block a user