MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / Compact

Method Compact

internal/utils/bfs/meta_file.go:304–341  ·  view source on GitHub ↗

Compact the meta file TODO 考虑自动Compact的时机(脏数据比例?)

()

Source from the content-addressed store, hash-verified

302// Compact the meta file
303// TODO 考虑自动Compact的时机(脏数据比例?)
304func (this *MetaFile) Compact() error {
305 this.mu.Lock()
306 defer this.mu.Unlock()
307
308 var buf = bytes.NewBuffer(nil)
309 for hash, lazyHeader := range this.headerMap {
310 header, err := lazyHeader.FileHeaderUnsafe()
311 if err != nil {
312 return err
313 }
314
315 blockBytes, err := header.Encode(hash)
316 if err != nil {
317 return err
318 }
319 buf.Write(blockBytes)
320 }
321
322 AckWriteThread()
323 err := this.fp.Truncate(int64(buf.Len()))
324 ReleaseWriteThread()
325 if err != nil {
326 return err
327 }
328
329 AckReadThread()
330 _, err = this.fp.Seek(0, io.SeekStart)
331 ReleaseReadThread()
332 if err != nil {
333 return err
334 }
335
336 AckWriteThread()
337 _, err = this.fp.Write(buf.Bytes())
338 ReleaseWriteThread()
339 this.isModified = true
340 return err
341}
342
343func (this *MetaFile) SyncUnsafe() error {
344 if !this.isModified {

Callers 6

TestMetaFile_CompactFunction · 0.45
TestFileHeader_CompactFunction · 0.45
WriteCloseMethod · 0.45

Calls 13

AckWriteThreadFunction · 0.85
ReleaseWriteThreadFunction · 0.85
AckReadThreadFunction · 0.85
ReleaseReadThreadFunction · 0.85
SeekMethod · 0.80
BytesMethod · 0.80
EncodeMethod · 0.65
WriteMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45
FileHeaderUnsafeMethod · 0.45
TruncateMethod · 0.45

Tested by 5

TestMetaFile_CompactFunction · 0.36
TestFileHeader_CompactFunction · 0.36