(higher Snapshot, persistOptions StorePersistOptions)
| 15 | ) |
| 16 | |
| 17 | func (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 |
no test coverage detected