Skip to content

Commit

Permalink
fix(eap-spans): Drop indexes on attribute keys bucket 0 (#6213)
Browse files Browse the repository at this point in the history
  • Loading branch information
phacops authored Aug 22, 2024
1 parent 6f2c599 commit 1a6af79
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
9 changes: 6 additions & 3 deletions snuba/migrations/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,15 +517,18 @@ def __init__(
table_name: str,
index_name: str,
target: OperationTarget = OperationTarget.UNSET,
run_async: bool = False,
):
super().__init__(storage_set, target=target)
self.__table_name = table_name
self.__index_name = index_name
self.__run_async = run_async

def format_sql(self) -> str:
return (
f"ALTER TABLE {self.__table_name} DROP INDEX IF EXISTS {self.__index_name};"
)
settings = ""
if self.__run_async:
settings = " SETTINGS mutations_sync=0"
return f"ALTER TABLE {self.__table_name} DROP INDEX IF EXISTS {self.__index_name}{settings};"


class DropIndices(SqlOperation):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from typing import Sequence

from snuba.clusters.storage_sets import StorageSetKey
from snuba.migrations import migration, operations


class Migration(migration.ClickhouseNodeMigration):
blocking = False

def forwards_ops(self) -> Sequence[operations.SqlOperation]:
return [
operations.DropIndex(
storage_set=StorageSetKey.EVENTS_ANALYTICS_PLATFORM,
table_name="eap_spans_local",
index_name=index_name,
target=operations.OperationTarget.LOCAL,
run_async=True,
)
for bucket in {0}
for index_name in {f"bf_attr_num_{bucket}", f"bf_attr_str_{bucket}"}
]

def backwards_ops(self) -> Sequence[operations.SqlOperation]:
return []
9 changes: 9 additions & 0 deletions tests/migrations/test_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@ def test_drop_index() -> None:
)


def test_drop_index_async() -> None:
assert (
DropIndex(
StorageSetKey.EVENTS, "test_table", "index_1", run_async=True
).format_sql()
== "ALTER TABLE test_table DROP INDEX IF EXISTS index_1 SETTINGS mutations_sync=0;"
)


def test_insert_into_select() -> None:
assert (
InsertIntoSelect(
Expand Down

0 comments on commit 1a6af79

Please sign in to comment.