-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathbackground_mgr_tombstone_compaction.go
More file actions
77 lines (60 loc) · 2.41 KB
/
background_mgr_tombstone_compaction.go
File metadata and controls
77 lines (60 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2012-Present Couchbase, Inc.
//
// Use of this software is governed by the Business Source License included
// in the file licenses/BSL-Couchbase.txt. As of the Change Date specified
// in that file, in accordance with the Business Source License, use of this
// software will be governed by the Apache License, Version 2.0, included in
// the file licenses/APL2.txt.
package db
import (
"context"
"sync/atomic"
"time"
"github.com/couchbase/sync_gateway/base"
)
// =====================================================================
// Tombstone Compaction Implementation of Background Manager Process
// =====================================================================
type TombstoneCompactionManager struct {
PurgedDocCount int64
}
var _ BackgroundManagerProcessI = &TombstoneCompactionManager{}
func NewTombstoneCompactionManager() *BackgroundManager {
return &BackgroundManager{
name: "tombstone_compaction",
Process: &TombstoneCompactionManager{},
terminator: base.NewSafeTerminator(),
}
}
func (t *TombstoneCompactionManager) Init(ctx context.Context, options map[string]interface{}, clusterStatus []byte) error {
database := options["database"].(*Database)
database.DbStats.Database().CompactionTombstoneStartTime.Set(time.Now().UTC().Unix())
return nil
}
func (t *TombstoneCompactionManager) Run(ctx context.Context, options map[string]interface{}, persistClusterStatusCallback updateStatusCallbackFunc, terminator *base.SafeTerminator) error {
database := options["database"].(*Database)
defer atomic.CompareAndSwapUint32(&database.CompactState, DBCompactRunning, DBCompactNotRunning)
updateStatusCallback := func(docsPurged *int) {
atomic.StoreInt64(&t.PurgedDocCount, int64(*docsPurged))
}
_, err := database.Compact(ctx, true, updateStatusCallback, terminator, false)
if err != nil {
return err
}
return nil
}
type TombstoneManagerResponse struct {
BackgroundManagerStatus
DocsPurged int64 `json:"docs_purged"`
}
func (t *TombstoneCompactionManager) GetProcessStatus(backgroundManagerStatus BackgroundManagerStatus) ([]byte, []byte, error) {
retStatus := TombstoneManagerResponse{
BackgroundManagerStatus: backgroundManagerStatus,
DocsPurged: atomic.LoadInt64(&t.PurgedDocCount),
}
statusJSON, err := base.JSONMarshal(retStatus)
return statusJSON, nil, err
}
func (t *TombstoneCompactionManager) ResetStatus() {
atomic.StoreInt64(&t.PurgedDocCount, 0)
}