Browse Source

start autocommit

Thibault bui Koechlin 5 years ago
parent
commit
c52a028505
3 changed files with 18 additions and 9 deletions
  1. 14 4
      pkg/sqlite/commit.go
  2. 0 5
      pkg/sqlite/sqlite.go
  3. 4 0
      plugins/backend/sqlite.go

+ 14 - 4
pkg/sqlite/commit.go

@@ -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)

+ 0 - 5
pkg/sqlite/sqlite.go

@@ -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
 }

+ 4 - 0
plugins/backend/sqlite.go

@@ -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)