Skip to content

Commit 227e58d

Browse files
committed
(BIDS-2550) add column filter to ClearByPrefix misc command
1 parent 1750b56 commit 227e58d

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

cmd/misc/main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ func main() {
255255
case "debug-blocks":
256256
err = debugBlocks()
257257
case "clear-bigtable":
258-
clearBigtable(opts.Table, opts.Family, opts.Key, opts.DryRun, bt)
258+
clearBigtable(opts.Table, opts.Family, opts.Columns, opts.Key, opts.DryRun, bt)
259259
case "index-old-eth1-blocks":
260260
indexOldEth1Blocks(opts.StartBlock, opts.EndBlock, opts.BatchSize, opts.DataConcurrency, opts.Transformers, bt, erigonClient)
261261
case "update-aggregation-bits":
@@ -923,7 +923,7 @@ func compareRewards(dayStart uint64, dayEnd uint64, validator uint64, bt *db.Big
923923

924924
}
925925

926-
func clearBigtable(table string, family string, key string, dryRun bool, bt *db.Bigtable) {
926+
func clearBigtable(table string, family string, columns string, key string, dryRun bool, bt *db.Bigtable) {
927927

928928
if !dryRun {
929929
confirmation := utils.CmdPrompt(fmt.Sprintf("Are you sure you want to delete all big table entries starting with [%v] for family [%v]?", key, family))
@@ -946,7 +946,7 @@ func clearBigtable(table string, family string, key string, dryRun bool, bt *db.
946946
// if err != nil {
947947
// logrus.Fatal(err)
948948
// }
949-
err := bt.ClearByPrefix(table, family, key, dryRun)
949+
err := bt.ClearByPrefix(table, family, columns, key, dryRun)
950950

951951
if err != nil {
952952
logrus.Fatalf("error deleting from bigtable: %v", err)

db/bigtable_common.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"eth2-exporter/utils"
77
"fmt"
88
"sort"
9+
"strings"
910
"time"
1011

1112
gcp_bigtable "cloud.google.com/go/bigtable"
@@ -74,7 +75,7 @@ func (bigtable *Bigtable) WriteBulk(mutations *types.BulkMutations, table *gcp_b
7475
return nil
7576
}
7677

77-
func (bigtable *Bigtable) ClearByPrefix(table string, family, prefix string, dryRun bool) error {
78+
func (bigtable *Bigtable) ClearByPrefix(table string, family, columns, prefix string, dryRun bool) error {
7879
if family == "" || prefix == "" {
7980
return fmt.Errorf("please provide family [%v] and prefix [%v]", family, prefix)
8081
}
@@ -106,6 +107,8 @@ func (bigtable *Bigtable) ClearByPrefix(table string, family, prefix string, dry
106107

107108
mutsDelete := types.NewBulkMutations(MAX_BATCH_MUTATIONS)
108109

110+
columnsSlice := strings.Split(columns, ",")
111+
109112
keysCount := 0
110113
err := btTable.ReadRows(context.Background(), rowRange, func(row gcp_bigtable.Row) bool {
111114

@@ -126,7 +129,13 @@ func (bigtable *Bigtable) ClearByPrefix(table string, family, prefix string, dry
126129
}
127130

128131
mutDelete := gcp_bigtable.NewMutation()
129-
mutDelete.DeleteRow()
132+
if columns == "" {
133+
mutDelete.DeleteRow()
134+
} else {
135+
for _, f := range columnsSlice {
136+
mutDelete.DeleteCellsInColumn(family, f)
137+
}
138+
}
130139
mutsDelete.Keys = append(mutsDelete.Keys, row_.Row)
131140
mutsDelete.Muts = append(mutsDelete.Muts, mutDelete)
132141
keysCount++

0 commit comments

Comments
 (0)