MCPcopy
hub / github.com/dgraph-io/badger / deleteTables

Method deleteTables

level_handler.go:80–103  ·  view source on GitHub ↗

deleteTables remove tables idx0, ..., idx1-1.

(toDel []*table.Table)

Source from the content-addressed store, hash-verified

78
79// deleteTables remove tables idx0, ..., idx1-1.
80func (s *levelHandler) deleteTables(toDel []*table.Table) error {
81 s.Lock() // s.Unlock() below
82
83 toDelMap := make(map[uint64]struct{})
84 for _, t := range toDel {
85 toDelMap[t.ID()] = struct{}{}
86 }
87
88 // Make a copy as iterators might be keeping a slice of tables.
89 var newTables []*table.Table
90 for _, t := range s.tables {
91 _, found := toDelMap[t.ID()]
92 if !found {
93 newTables = append(newTables, t)
94 continue
95 }
96 s.totalSize -= t.Size()
97 }
98 s.tables = newTables
99
100 s.Unlock() // Unlock s _before_ we DecrRef our tables, which can be slow.
101
102 return decrRefs(toDel)
103}
104
105// replaceTables will replace tables[left:right] with newTables. Note this EXCLUDES tables[right].
106// You must call decr() to delete the old tables _after_ writing the update to the manifest.

Callers 1

runCompactDefMethod · 0.80

Calls 3

decrRefsFunction · 0.85
IDMethod · 0.80
SizeMethod · 0.45

Tested by

no test coverage detected