Skip to content

Commit

Permalink
fix(bigtable/bttest): make table gc release memory
Browse files Browse the repository at this point in the history
We had a problem where we were unable to run the emulator for extended periods in dev environments without giving it huge amounts of RAM, even if we had quite aggressive GC policies applied to the tables.
This fixes that by making GC delete empty rows and columns.
  • Loading branch information
philpearl committed Apr 14, 2021
1 parent 1204de8 commit b90537d
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion bigtable/bttest/inmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -1242,13 +1242,23 @@ func (t *table) gc() {
return
}

// It isn't clear whether it's safe to delete within the iterator, so we do
// not
var toDelete []btree.Item
t.rows.Ascend(func(i btree.Item) bool {
r := i.(*row)
r.mu.Lock()
r.gc(rules)
if len(r.families) == 0 {
toDelete = append(toDelete, i)
}
r.mu.Unlock()
return true
})

for _, i := range toDelete {
t.rows.Delete(i)
}
}

type byRowKey []*row
Expand Down Expand Up @@ -1334,7 +1344,15 @@ func (r *row) gc(rules map[string]*btapb.GcRule) {
continue
}
for col, cs := range fam.cells {
r.families[fam.name].cells[col] = applyGC(cs, rule)
cs = applyGC(cs, rule)
if len(cs) == 0 {
delete(fam.cells, col)
} else {
fam.cells[col] = cs
}
}
if len(fam.cells) == 0 {
delete(r.families, fam.name)
}
}
}
Expand Down

0 comments on commit b90537d

Please sign in to comment.