Skip to content

Commit 33a75e7

Browse files
authored
Fix query routing for TSDB distinct counter and frequency table delete operations. (#5451)
This was an oversight as part of GH-5317, and wasn't caught in tests because the test suite didn't actually run the tests against multiple databases. The easiest way to test this (other than depending on the tests to have the correct behavior) is to cross-reference the routing logic in the other mutation commands and make sure it's consistent.
1 parent f851209 commit 33a75e7

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/sentry/tsdb/redis.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,12 +506,12 @@ def make_temporary_key(key):
506506
def delete_distinct_counts(self, models, keys, start=None, end=None, timestamp=None):
507507
rollups = self.get_active_series(start, end, timestamp)
508508

509-
with self.cluster.map() as client:
509+
with self.cluster.fanout() as client:
510510
for rollup, series in rollups.items():
511511
for timestamp in series:
512512
for model in models:
513513
for key in keys:
514-
client.delete(
514+
client.target_key(key).delete(
515515
self.make_key(
516516
model,
517517
rollup,
@@ -722,10 +722,11 @@ def merge_frequencies(self, model, destination, sources, timestamp=None):
722722
def delete_frequencies(self, models, keys, start=None, end=None, timestamp=None):
723723
rollups = self.get_active_series(start, end, timestamp)
724724

725-
with self.cluster.map() as client:
725+
with self.cluster.fanout() as client:
726726
for rollup, series in rollups.items():
727727
for timestamp in series:
728728
for model in models:
729729
for key in keys:
730+
c = client.target_key(key)
730731
for k in self.make_frequency_table_keys(model, rollup, to_timestamp(timestamp), key):
731-
client.delete(k)
732+
c.delete(k)

tests/sentry/tsdb/test_redis.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,15 @@ def setUp(self):
2525
),
2626
vnodes=64,
2727
enable_frequency_sketches=True,
28+
hosts={
29+
i - 6: {'db': i} for i in xrange(6, 9)
30+
},
2831
)
2932

33+
def tearDown(self):
34+
with self.db.cluster.all() as client:
35+
client.flushdb()
36+
3037
def test_make_counter_key(self):
3138
result = self.db.make_counter_key(TSDBModel.project, 1368889980, 1)
3239
assert result == 'ts:1:1368889980:1'

0 commit comments

Comments
 (0)