MCPcopy Create free account
hub / github.com/couchbase/moss / compactMaybe

Method compactMaybe

store_compact.go:17–125  ·  view source on GitHub ↗
(higher Snapshot,
	persistOptions StorePersistOptions)

Source from the content-addressed store, hash-verified

15)
16
17func (s *Store) compactMaybe(higher Snapshot,
18 persistOptions StorePersistOptions) (bool, error) {
19 if s.Options().CollectionOptions.ReadOnly {
20 return false, nil
21 }
22
23 compactionConcern := persistOptions.CompactionConcern
24 if compactionConcern <= 0 {
25 return false, nil
26 }
27
28 footer, err := s.snapshot()
29 if err != nil {
30 return false, err
31 }
32
33 defer footer.DecRef()
34
35 slocs, _ := footer.segmentLocs()
36
37 defer footer.DecRef()
38
39 var partialCompactStart int
40
41 if compactionConcern == CompactionAllow {
42 // First compute size of the incoming batch of data.
43 var incomingDataSize uint64
44 if higher != nil {
45 higherSS, ok := higher.(*segmentStack)
46 if ok {
47 higherStats := higherSS.Stats()
48 if higherStats != nil {
49 incomingDataSize = higherStats.CurBytes
50 }
51 }
52 }
53
54 // Try leveled compaction to same file.
55 var doCompact bool
56 partialCompactStart, doCompact =
57 calcPartialCompactionStart(slocs, incomingDataSize, s.options)
58 if doCompact {
59 compactionConcern = CompactionForce
60 } // Else append data to the end of the same file.
61 }
62
63 if compactionConcern != CompactionForce {
64 return false, nil
65 }
66
67 err = s.compact(footer, partialCompactStart, higher, persistOptions)
68 if err != nil {
69 if err == ErrNothingToCompact {
70 return false, nil // Swallow the error internally.
71 }
72 return false, err
73 }
74

Callers 1

persistMethod · 0.95

Calls 10

OptionsMethod · 0.95
snapshotMethod · 0.95
compactMethod · 0.95
removeFileOnCloseMethod · 0.95
segmentLocsMethod · 0.80
StatMethod · 0.80
StatsMethod · 0.65
NameMethod · 0.65
DecRefMethod · 0.45

Tested by

no test coverage detected