start autocommit
This commit is contained in:
parent
c3d3619998
commit
c52a028505
3 changed files with 18 additions and 9 deletions
|
@ -74,7 +74,7 @@ func (c *Context) CleanUpRecordsByAge() error {
|
||||||
if ret.Error != nil {
|
if ret.Error != nil {
|
||||||
return errors.Wrap(ret.Error, "failed to delete records")
|
return errors.Wrap(ret.Error, "failed to delete records")
|
||||||
}
|
}
|
||||||
log.Printf("Deleted %d expired records older than %s", delRecords, c.maxDurationRetention)
|
log.Printf("max_records_age: deleting %d events (max age:%s)", delRecords, c.maxDurationRetention)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,7 +118,8 @@ func (c *Context) CleanUpRecordsByCount() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(sos) > 0 {
|
if len(sos) > 0 {
|
||||||
log.Printf("Deleting %d soft-deleted results out of %d total events (%d soft-deleted)", delRecords, count, len(sos))
|
//log.Printf("Deleting %d soft-deleted results out of %d total events (%d soft-deleted)", delRecords, count, len(sos))
|
||||||
|
log.Printf("max_records: deleting %d events. (%d soft-deleted)", delRecords, len(sos))
|
||||||
ret = delTx.Unscoped().Commit()
|
ret = delTx.Unscoped().Commit()
|
||||||
if ret.Error != nil {
|
if ret.Error != nil {
|
||||||
return errors.Wrap(ret.Error, "failed to delete records")
|
return errors.Wrap(ret.Error, "failed to delete records")
|
||||||
|
@ -129,8 +130,17 @@ func (c *Context) CleanUpRecordsByCount() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) AutoCommit() {
|
func (c *Context) StartAutoCommit() error {
|
||||||
log.Infof("starting autocommit")
|
//TBD : we shouldn't start auto-commit if we are in cli mode ?
|
||||||
|
c.PusherTomb.Go(func() error {
|
||||||
|
c.autoCommit()
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Context) autoCommit() {
|
||||||
|
log.Debugf("starting autocommit")
|
||||||
ticker := time.NewTicker(200 * time.Millisecond)
|
ticker := time.NewTicker(200 * time.Millisecond)
|
||||||
cleanUpTicker := time.NewTicker(1 * time.Minute)
|
cleanUpTicker := time.NewTicker(1 * time.Minute)
|
||||||
expireTicker := time.NewTicker(1 * time.Second)
|
expireTicker := time.NewTicker(1 * time.Second)
|
||||||
|
|
|
@ -84,10 +84,5 @@ func NewSQLite(cfg map[string]string) (*Context, error) {
|
||||||
if c.tx == nil {
|
if c.tx == nil {
|
||||||
return nil, fmt.Errorf("failed to begin sqlite transac : %s", err)
|
return nil, fmt.Errorf("failed to begin sqlite transac : %s", err)
|
||||||
}
|
}
|
||||||
//TBD : we shouldn't start auto-commit if we are in cli mode ?
|
|
||||||
c.PusherTomb.Go(func() error {
|
|
||||||
c.AutoCommit()
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,10 @@ func (p *pluginDB) Shutdown() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *pluginDB) StartAutoCommit() error {
|
||||||
|
return p.CTX.StartAutoCommit()
|
||||||
|
}
|
||||||
|
|
||||||
func (p *pluginDB) Init(config map[string]string) error {
|
func (p *pluginDB) Init(config map[string]string) error {
|
||||||
var err error
|
var err error
|
||||||
log.Debugf("sqlite config : %+v \n", config)
|
log.Debugf("sqlite config : %+v \n", config)
|
||||||
|
|
Loading…
Add table
Reference in a new issue