github.com/weaviate/weaviate@v1.24.6/adapters/repos/db/lsmkv/store_backup.go (about) 1 // _ _ 2 // __ _____ __ ___ ___ __ _| |_ ___ 3 // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \ 4 // \ V V / __/ (_| |\ V /| | (_| | || __/ 5 // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___| 6 // 7 // Copyright © 2016 - 2024 Weaviate B.V. All rights reserved. 8 // 9 // CONTACT: hello@weaviate.io 10 // 11 12 package lsmkv 13 14 import ( 15 "context" 16 17 "github.com/pkg/errors" 18 "github.com/prometheus/client_golang/prometheus" 19 "github.com/weaviate/weaviate/usecases/monitoring" 20 ) 21 22 // PauseCompaction waits for all ongoing compactions to finish, 23 // then makes sure that no new compaction can be started. 24 // 25 // This is a preparatory stage for creating backups. 26 // 27 // A timeout should be specified for the input context as some 28 // compactions are long-running, in which case it may be better 29 // to fail the backup attempt and retry later, than to block 30 // indefinitely. 31 func (s *Store) PauseCompaction(ctx context.Context) error { 32 if err := s.cycleCallbacks.compactionCallbacksCtrl.Deactivate(ctx); err != nil { 33 return errors.Wrap(err, "long-running compaction in progress") 34 } 35 36 // TODO common_cycle_manager maybe not necessary, or to be replaced with store pause stats 37 for _, b := range s.bucketsByName { 38 label := b.dir 39 if monitoring.GetMetrics().Group { 40 label = "n/a" 41 } 42 if metric, err := monitoring.GetMetrics().BucketPauseDurations.GetMetricWithLabelValues(label); err == nil { 43 b.pauseTimer = prometheus.NewTimer(metric) 44 } 45 } 46 47 return nil 48 } 49 50 // ResumeCompaction starts the compaction cycle again. 51 // It errors if compactions were not paused 52 func (s *Store) ResumeCompaction(ctx context.Context) error { 53 s.cycleCallbacks.compactionCallbacksCtrl.Activate() 54 55 // TODO common_cycle_manager maybe not necessary, or to be replaced with store pause stats 56 for _, b := range s.bucketsByName { 57 if b.pauseTimer != nil { 58 b.pauseTimer.ObserveDuration() 59 } 60 } 61 62 return nil 63 } 64 65 // FlushMemtable flushes any active memtable and returns only once the memtable 66 // has been fully flushed and a stable state on disk has been reached. 67 // 68 // This is a preparatory stage for creating backups. 69 // 70 // A timeout should be specified for the input context as some 71 // flushes are long-running, in which case it may be better 72 // to fail the backup attempt and retry later, than to block 73 // indefinitely. 74 func (s *Store) FlushMemtables(ctx context.Context) error { 75 if err := s.cycleCallbacks.flushCallbacksCtrl.Deactivate(ctx); err != nil { 76 return errors.Wrap(err, "long-running memtable flush in progress") 77 } 78 defer s.cycleCallbacks.flushCallbacksCtrl.Activate() 79 80 flushMemtable := func(ctx context.Context, b *Bucket) (interface{}, error) { 81 return nil, b.FlushMemtable() 82 } 83 _, err := s.runJobOnBuckets(ctx, flushMemtable, nil) 84 return err 85 }