mirror of
https://github.com/safing/portbase
synced 2025-09-01 10:09:50 +00:00
Clean up database package
This commit is contained in:
parent
ddc773a9f2
commit
7011bde0fe
7 changed files with 18 additions and 21 deletions
|
@ -30,12 +30,12 @@ type Controller struct {
|
|||
}
|
||||
|
||||
// newController creates a new controller for a storage.
|
||||
func newController(storageInt storage.Interface) (*Controller, error) {
|
||||
func newController(storageInt storage.Interface) *Controller {
|
||||
return &Controller{
|
||||
storage: storageInt,
|
||||
migrating: abool.NewBool(false),
|
||||
hibernating: abool.NewBool(false),
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ReadOnly returns whether the storage is read only.
|
||||
|
@ -221,7 +221,7 @@ func (c *Controller) MaintainThorough() error {
|
|||
|
||||
// Shutdown shuts down the storage.
|
||||
func (c *Controller) Shutdown() error {
|
||||
// aquire full locks
|
||||
// acquire full locks
|
||||
c.readLock.Lock()
|
||||
defer c.readLock.Unlock()
|
||||
c.writeLock.Lock()
|
||||
|
|
|
@ -51,12 +51,7 @@ func getController(name string) (*Controller, error) {
|
|||
return nil, fmt.Errorf(`could not start database %s (type %s): %s`, name, registeredDB.StorageType, err)
|
||||
}
|
||||
|
||||
// create controller
|
||||
controller, err = newController(storageInt)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(`could not create controller for database %s: %s`, name, err)
|
||||
}
|
||||
|
||||
controller = newController(storageInt)
|
||||
controllers[name] = controller
|
||||
return controller, nil
|
||||
}
|
||||
|
@ -87,11 +82,7 @@ func InjectDatabase(name string, storageInt storage.Interface) (*Controller, err
|
|||
return nil, fmt.Errorf(`database not of type "injected"`)
|
||||
}
|
||||
|
||||
controller, err := newController(storageInt)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(`could not create controller for database %s: %s`, name, err)
|
||||
}
|
||||
|
||||
controller := newController(storageInt)
|
||||
controllers[name] = controller
|
||||
return controller, nil
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ func TestDatabaseSystem(t *testing.T) {
|
|||
go func() {
|
||||
time.Sleep(10 * time.Second)
|
||||
fmt.Println("===== TAKING TOO LONG - PRINTING STACK TRACES =====")
|
||||
pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
|
||||
_ = pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
|
||||
os.Exit(1)
|
||||
}()
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ type RegisteredHook struct {
|
|||
h Hook
|
||||
}
|
||||
|
||||
// RegisterHook registeres a hook for records matching the given query in the database.
|
||||
// RegisterHook registers a hook for records matching the given query in the database.
|
||||
func RegisterHook(q *query.Query, hook Hook) (*RegisteredHook, error) {
|
||||
_, err := q.Check()
|
||||
if err != nil {
|
||||
|
|
|
@ -80,7 +80,7 @@ func (i *Interface) checkCache(key string) (record.Record, bool) {
|
|||
|
||||
func (i *Interface) updateCache(r record.Record) {
|
||||
if i.cache != nil {
|
||||
i.cache.Set(r.Key(), r)
|
||||
_ = i.cache.Set(r.Key(), r)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -69,11 +69,17 @@ func MaintainRecordStates() error {
|
|||
}
|
||||
|
||||
for _, r := range toDelete {
|
||||
c.storage.Delete(r.DatabaseKey())
|
||||
err := c.storage.Delete(r.DatabaseKey())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, r := range toExpire {
|
||||
r.Meta().Delete()
|
||||
return c.Put(r)
|
||||
err := c.Put(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -148,10 +148,10 @@ func registryWriter() {
|
|||
select {
|
||||
case <-time.After(1 * time.Hour):
|
||||
if writeRegistrySoon.SetToIf(true, false) {
|
||||
saveRegistry(true)
|
||||
_ = saveRegistry(true)
|
||||
}
|
||||
case <-shutdownSignal:
|
||||
saveRegistry(true)
|
||||
_ = saveRegistry(true)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue