MCPcopy
hub / github.com/perkeep/perkeep / Collect

Method Collect

pkg/gc/gc.go:123–198  ·  view source on GitHub ↗

Collect performs a garbage collection.

(ctx context.Context)

Source from the content-addressed store, hash-verified

121
122// Collect performs a garbage collection.
123func (c *Collector) Collect(ctx context.Context) (err error) {
124 if c.World == nil {
125 return errors.New("no World")
126 }
127 if c.Marker == nil {
128 return errors.New("no Marker")
129 }
130 if c.Roots == nil {
131 return errors.New("no Roots")
132 }
133 if c.Sweeper == nil {
134 return errors.New("no Sweeper")
135 }
136 if c.ItemEnumerator == nil {
137 return errors.New("no ItemEnumerator")
138 }
139 if c.Deleter == nil {
140 return errors.New("no Deleter")
141 }
142 if err := c.World.Stop(); err != nil {
143 return err
144 }
145 defer func() {
146 startErr := c.World.Start()
147 if err == nil {
148 err = startErr
149 }
150 }()
151
152 // Mark.
153 roots := make(chan Item, buffered)
154 markCtx, cancelMark := context.WithCancel(ctx)
155 var marker syncutil.Group
156 marker.Go(func() error {
157 defer cancelMark()
158 for it := range roots {
159 if err := c.markItem(markCtx, it, true); err != nil {
160 return err
161 }
162 }
163 return nil
164 })
165 marker.Go(func() error {
166 return c.Roots.Enumerate(markCtx, roots)
167 })
168 if err := marker.Err(); err != nil {
169 return fmt.Errorf("Mark failure: %v", err)
170 }
171
172 // Sweep.
173 all := make(chan Item, buffered)
174 sweepCtx, cancelSweep := context.WithCancel(ctx)
175 var sweeper syncutil.Group
176 sweeper.Go(func() error {
177 return c.Sweeper.Enumerate(sweepCtx, all)
178 })
179 sweeper.Go(func() error {
180 defer cancelSweep()

Callers 1

TestCollectorFunction · 0.95

Calls 7

markItemMethod · 0.95
StopMethod · 0.65
StartMethod · 0.65
EnumerateMethod · 0.65
IsMarkedMethod · 0.65
DeleteMethod · 0.65
ErrMethod · 0.45

Tested by 1

TestCollectorFunction · 0.76