Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.

Commit fb1478e

Browse files
authored
Merge pull request #1167 from grafana/mt-update-ttl-tweaks
mt-update-ttl tweak default concurrency, stats fix, properly use logrus
2 parents 61ea62a + 4035610 commit fb1478e

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

cmd/mt-update-ttl/main.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ var (
4242

4343
startTs = flag.Int("start-timestamp", 0, "timestamp at which to start, defaults to 0")
4444
endTs = flag.Int("end-timestamp", math.MaxInt32, "timestamp at which to stop, defaults to int max")
45-
numThreads = flag.Int("threads", 1, "number of workers to use to process data")
45+
numThreads = flag.Int("threads", 10, "number of workers to use to process data")
4646

4747
verbose = flag.Bool("verbose", false, "show every record being processed")
4848

@@ -85,7 +85,7 @@ func main() {
8585
session, err := NewCassandraStore()
8686

8787
if err != nil {
88-
panic(fmt.Sprintf("Failed to instantiate cassandra: %s", err))
88+
log.Fatalf("Failed to instantiate cassandra: %s", err)
8989
}
9090

9191
update(session, ttl, tableIn, tableOut)
@@ -182,26 +182,26 @@ func worker(id int, jobs <-chan string, wg *sync.WaitGroup, session *gocql.Sessi
182182
query = fmt.Sprintf("INSERT INTO %s (data, key, ts) values(?,?,?) USING TTL %d", tableOut, newTTL)
183183
}
184184
if *verbose {
185-
log.Printf("id=%d processing rownum=%d table=%q key=%q ts=%d query=%q data='%x'\n", id, atomic.LoadUint64(&doneRows)+1, tableIn, key, ts, query, data)
185+
log.Infof("id=%d processing rownum=%d table=%q key=%q ts=%d query=%q data='%x'\n", id, atomic.LoadUint64(&doneRows)+1, tableIn, key, ts, query, data)
186186
}
187187

188188
err := session.Query(query, data, key, ts).Exec()
189189
if err != nil {
190-
fmt.Fprintf(os.Stderr, "ERROR: id=%d failed updating %s %s %d: %q", id, tableOut, key, ts, err)
190+
log.Errorf("id=%d failed updating %s %s %d: %q", id, tableOut, key, ts, err)
191191
}
192192

193193
doneRowsSnap := atomic.AddUint64(&doneRows, 1)
194194
if doneRowsSnap%10000 == 0 {
195195
doneKeysSnap := atomic.LoadUint64(&doneKeys)
196196
completeness := completenessEstimate(token)
197-
log.Printf("WORKING: id=%d processed %d keys, %d rows. (last token: %d, completeness estimate %.1f%%)", id, doneKeysSnap, doneRowsSnap, token, completeness*100)
197+
log.Infof("WORKING: id=%d processed %d keys, %d rows. (last token: %d, completeness estimate %.1f%%)", id, doneKeysSnap, doneRowsSnap, token, completeness*100)
198198
}
199199
}
200200
err := iter.Close()
201201
if err != nil {
202202
doneKeysSnap := atomic.LoadUint64(&doneKeys)
203203
doneRowsSnap := atomic.LoadUint64(&doneRows)
204-
fmt.Fprintf(os.Stderr, "ERROR: id=%d failed querying %s: %q. processed %d keys, %d rows", id, tableIn, err, doneKeysSnap, doneRowsSnap)
204+
log.Errorf("id=%d failed querying %s: %q. processed %d keys, %d rows", id, tableIn, err, doneKeysSnap, doneRowsSnap)
205205
}
206206
atomic.AddUint64(&doneKeys, 1)
207207
}
@@ -227,11 +227,13 @@ func update(session *gocql.Session, ttl int, tableIn, tableOut string) {
227227
close(jobs)
228228
err := keyItr.Close()
229229
if err != nil {
230-
fmt.Fprintf(os.Stderr, "ERROR: failed querying %s: %q. processed %d keys, %d rows", tableIn, err, doneKeys, doneRows)
230+
doneKeysSnap := atomic.LoadUint64(&doneKeys)
231+
doneRowsSnap := atomic.LoadUint64(&doneRows)
232+
log.Errorf("failed querying %s: %q. processed %d keys, %d rows", tableIn, err, doneKeysSnap, doneRowsSnap)
231233
wg.Wait()
232234
os.Exit(2)
233235
}
234236

235237
wg.Wait()
236-
log.Printf("DONE. Processed %d keys, %d rows", doneKeys, doneRows)
238+
log.Infof("DONE. Processed %d keys, %d rows", doneKeys, doneRows)
237239
}

docs/tools.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ Flags:
553553
-start-timestamp int
554554
timestamp at which to start, defaults to 0
555555
-threads int
556-
number of workers to use to process data (default 1)
556+
number of workers to use to process data (default 10)
557557
-verbose
558558
show every record being processed
559559
```

0 commit comments

Comments
 (0)