start autocommit

This commit is contained in:
Thibault bui Koechlin 2020-06-27 11:07:14 +02:00
parent c3d3619998
commit c52a028505
3 changed files with 18 additions and 9 deletions

View file

@ -74,7 +74,7 @@ func (c *Context) CleanUpRecordsByAge() error {
if ret.Error != nil {
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
}
@ -118,7 +118,8 @@ func (c *Context) CleanUpRecordsByCount() error {
}
}
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()
if ret.Error != nil {
return errors.Wrap(ret.Error, "failed to delete records")
@ -129,8 +130,17 @@ func (c *Context) CleanUpRecordsByCount() error {
return nil
}
func (c *Context) AutoCommit() {
log.Infof("starting autocommit")
func (c *Context) StartAutoCommit() error {
//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)
cleanUpTicker := time.NewTicker(1 * time.Minute)
expireTicker := time.NewTicker(1 * time.Second)

View file

@ -84,10 +84,5 @@ func NewSQLite(cfg map[string]string) (*Context, error) {
if c.tx == nil {
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
}

View file

@ -23,6 +23,10 @@ func (p *pluginDB) Shutdown() error {
return nil
}
func (p *pluginDB) StartAutoCommit() error {
return p.CTX.StartAutoCommit()
}
func (p *pluginDB) Init(config map[string]string) error {
var err error
log.Debugf("sqlite config : %+v \n", config)