forked from mtusi2026/mtusi2026lab6
feat: add bounded observability and verified SLO incident alerts
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
// Package memory implements synchronized storage within one bounded process.
|
||||
package memory
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"gitea.privcloud.tech/vlad_marlo/mtusi2026lab6/internal/config"
|
||||
"gitea.privcloud.tech/vlad_marlo/mtusi2026lab6/internal/model/dto"
|
||||
"gitea.privcloud.tech/vlad_marlo/mtusi2026lab6/internal/store"
|
||||
)
|
||||
|
||||
// Store owns all mutable state and its indexes under one lock.
|
||||
// Records are immutable once published; membership slices are copied on both
|
||||
// write and read boundaries. Its zero value is not usable; construct it with New.
|
||||
type Store struct {
|
||||
mu sync.RWMutex
|
||||
limits config.Memory
|
||||
users map[uuid.UUID]dto.UserDTO
|
||||
usernames map[string]uuid.UUID
|
||||
chats map[uuid.UUID]dto.ChatDTO
|
||||
userChats map[uuid.UUID][]dto.ChatDTO
|
||||
messages map[uuid.UUID][]dto.MessageDTO
|
||||
messageCount int
|
||||
usedBytes int
|
||||
lastTime time.Time
|
||||
}
|
||||
|
||||
var _ store.Interface = (*Store)(nil)
|
||||
|
||||
// New validates and copies capacity settings, then initializes an empty store.
|
||||
// It creates no files, goroutines or external connections.
|
||||
func New(cfg *config.Memory) (*Store, error) {
|
||||
if err := cfg.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Store{
|
||||
limits: *cfg,
|
||||
users: make(map[uuid.UUID]dto.UserDTO),
|
||||
usernames: make(map[string]uuid.UUID),
|
||||
chats: make(map[uuid.UUID]dto.ChatDTO),
|
||||
userChats: make(map[uuid.UUID][]dto.ChatDTO),
|
||||
messages: make(map[uuid.UUID][]dto.MessageDTO),
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user