MCPcopy
hub / github.com/etcd-io/bbolt / mergeSpans

Method mergeSpans

internal/freelist/hashmap.go:173–219  ·  view source on GitHub ↗
(ids common.Pgids)

Source from the content-addressed store, hash-verified

171}
172
173func (f *hashMap) mergeSpans(ids common.Pgids) {
174 if len(ids) == 0 {
175 return
176 }
177 sort.Sort(ids)
178
179 common.Verify(func() {
180 ids1Freemap := f.idsFromFreemaps()
181 ids2Forward := f.idsFromForwardMap()
182 ids3Backward := f.idsFromBackwardMap()
183
184 if !reflect.DeepEqual(ids1Freemap, ids2Forward) {
185 panic(fmt.Sprintf("Detected mismatch, f.freemaps: %v, f.forwardMap: %v", f.freemaps, f.forwardMap))
186 }
187 if !reflect.DeepEqual(ids1Freemap, ids3Backward) {
188 panic(fmt.Sprintf("Detected mismatch, f.freemaps: %v, f.backwardMap: %v", f.freemaps, f.backwardMap))
189 }
190
191 prev := common.Pgid(0)
192 for _, id := range ids {
193 // The ids shouldn't have duplicated free ID.
194 if prev == id {
195 panic(fmt.Sprintf("detected duplicated free ID: %d in ids: %v", id, ids))
196 }
197 prev = id
198
199 // The ids shouldn't have any overlap with the existing f.freemaps.
200 if _, ok := ids1Freemap[id]; ok {
201 panic(fmt.Sprintf("detected overlapped free page ID: %d between ids: %v and existing f.freemaps: %v", id, ids, f.freemaps))
202 }
203 }
204 })
205
206 start := ids[0]
207 end := ids[0]
208 for i := 1; i < len(ids); i++ {
209 id := ids[i]
210 if id == end+1 {
211 end = id
212 continue
213 }
214
215 f.mergeWithExistingSpan(start, end)
216 start, end = id, id
217 }
218 f.mergeWithExistingSpan(start, end)
219}
220
221// mergeWithExistingSpan merges free span [start, end] with adjacent existing free spans (both backward and forward).
222func (f *hashMap) mergeWithExistingSpan(start, end common.Pgid) {

Callers

nothing calls this directly

Calls 6

idsFromFreemapsMethod · 0.95
idsFromForwardMapMethod · 0.95
idsFromBackwardMapMethod · 0.95
mergeWithExistingSpanMethod · 0.95
VerifyFunction · 0.92
PgidTypeAlias · 0.92

Tested by

no test coverage detected