deleteTables remove tables idx0, ..., idx1-1.
(toDel []*table.Table)
| 78 | |
| 79 | // deleteTables remove tables idx0, ..., idx1-1. |
| 80 | func (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. |
no test coverage detected