Skip to content

Commit b52156c

Browse files
committed
Designate NULL_REGION_ID; add check when constructing Region
1 parent ceafdf5 commit b52156c

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/sentry/types/region.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ class Region:
4343
"""The region's category."""
4444

4545
def __post_init__(self) -> None:
46-
from sentry.utils.snowflake import REGION_ID
46+
from sentry.utils.snowflake import NULL_REGION_ID, REGION_ID
4747

4848
REGION_ID.validate(self.id)
49+
if self.id == NULL_REGION_ID:
50+
raise ValueError(f"Region ID {NULL_REGION_ID} is reserved for non-multi-region systems")
4951

5052
def to_url(self, path: str) -> str:
5153
return self.address + path

src/sentry/utils/snowflake.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ def validate(self, value):
6161
MAX_AVAILABLE_REGION_SEQUENCES = 1 << REGION_SEQUENCE.length
6262
assert MAX_AVAILABLE_REGION_SEQUENCES > 0
6363

64+
NULL_REGION_ID = 0
65+
6466

6567
def msb_0_ordering(value, width):
6668
"""
@@ -80,7 +82,7 @@ def generate_snowflake_id(redis_key: str) -> int:
8082
try:
8183
segment_values[REGION_ID] = get_local_region().id
8284
except RegionContextError: # expected if running in monolith mode
83-
segment_values[REGION_ID] = 0
85+
segment_values[REGION_ID] = NULL_REGION_ID
8486

8587
current_time = datetime.now().timestamp()
8688
# supports up to 130 years

0 commit comments

Comments
 (0)