Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 615ce63

Browse files
committed
Merge with development
2 parents 5306fc1 + 285a6da commit 615ce63

File tree

8 files changed

+30
-21
lines changed

8 files changed

+30
-21
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
4.0.0 (April 17, 2017)
2+
- Added support for murmur3 hashing native and cpp version for performance
13
2.2.1
24
- Ignore invalid Split fetched from Redis cache
35
2.2.0

splitio/hashfns/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from __future__ import absolute_import, division, print_function, \
77
unicode_literals
88

9+
from splitio.splits import HashAlgorithm
910
from splitio.hashfns import legacy
1011

1112
try:
@@ -23,8 +24,8 @@ def _murmur_hash(key, seed):
2324

2425

2526
_HASH_ALGORITHMS = {
26-
'legacy': legacy.legacy_hash,
27-
'murmur': _murmur_hash
27+
HashAlgorithm.LEGACY: legacy.legacy_hash,
28+
HashAlgorithm.MURMUR: _murmur_hash
2829
}
2930

3031

splitio/redis_support.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def missing_redis_dependencies(*args, **kwargs):
2323
from splitio.matchers import UserDefinedSegmentMatcher
2424
from splitio.metrics import BUCKETS
2525
from splitio.segments import Segment
26-
from splitio.splits import Split, SplitParser, HashAlgorithm
26+
from splitio.splits import Split, SplitParser
2727
from splitio.impressions import Impression
2828
from splitio.utils import bytes_to_string
2929

@@ -202,7 +202,6 @@ def add_split(self, split_name, split):
202202
def get_split(self, split_name):
203203

204204
to_decode = self._redis.get(self._get_split_key(split_name))
205-
206205
if to_decode is None:
207206
return None
208207

@@ -665,9 +664,12 @@ def _parse_matcher_in_segment(self, partial_split, matcher, block_until_ready=Fa
665664

666665

667666
class RedisSplit(Split):
668-
def __init__(self, name, seed, killed, default_treatment, traffic_type_name, status, change_number, conditions=None, segment_cache=None, algo=HashAlgorithm.LEGACY):
669-
"""A split implementation that mantains a reference to the segment cache so segments can
670-
be easily pickled and unpickled.
667+
def __init__(self, name, seed, killed, default_treatment, traffic_type_name,
668+
status, change_number, conditions=None, segment_cache=None,
669+
algo=None):
670+
'''
671+
A split implementation that mantains a reference to the segment cache
672+
so segments can be easily pickled and unpickled.
671673
:param name: Name of the feature
672674
:type name: unicode
673675
:param seed: Seed
@@ -680,8 +682,10 @@ def __init__(self, name, seed, killed, default_treatment, traffic_type_name, sta
680682
:type conditions: list
681683
:param segment_cache: A segment cache
682684
:type segment_cache: SegmentCache
683-
"""
684-
super(RedisSplit, self).__init__(name, seed, killed, default_treatment, traffic_type_name, status, change_number, conditions)
685+
'''
686+
super(RedisSplit, self).__init__(name, seed, killed, default_treatment,
687+
traffic_type_name, status,
688+
change_number, conditions, algo)
685689
self._segment_cache = segment_cache
686690

687691
@property

splitio/splits.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,13 @@ class HashAlgorithm(Enum):
3434
"""
3535
Hash algorithm names
3636
"""
37-
LEGACY = "legacy"
38-
MURMUR = "murmur"
37+
LEGACY = 1
38+
MURMUR = 2
3939

4040

4141
class Split(object):
4242
def __init__(self, name, seed, killed, default_treatment, traffic_type_name,
43-
status, change_number, conditions=None,
44-
algo=HashAlgorithm.LEGACY):
43+
status, change_number, conditions=None, algo=None):
4544
"""
4645
A class that represents a split. It associates a feature name with a set
4746
of matchers (responsible of telling which condition to use) and

splitio/tests/test_splits.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from unittest import TestCase
1111

12+
import json
1213
from splitio.splits import (InMemorySplitFetcher, SelfRefreshingSplitFetcher, SplitChangeFetcher,
1314
ApiSplitChangeFetcher, SplitParser, AllKeysSplit,
1415
CacheBasedSplitFetcher, HashAlgorithm)
@@ -20,7 +21,7 @@
2021
from splitio.hashfns.legacy import legacy_hash
2122
from splitio.redis_support import get_redis, RedisSegmentCache, RedisSplitParser
2223
from splitio.uwsgi import get_uwsgi, UWSGISegmentCache, UWSGISplitParser
23-
import json
24+
2425

2526
class InMemorySplitFetcherTests(TestCase):
2627
def setUp(self):

splitio/tests/test_splitters.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def test_with_sample_data(self):
118118
"""
119119
Tests basic hash against expected values using alphanumeric values
120120
"""
121-
hashfn = _HASH_ALGORITHMS['legacy']
121+
hashfn = _HASH_ALGORITHMS[HashAlgorithm.LEGACY]
122122
with open(join(dirname(__file__), 'sample-data.jsonl')) as f:
123123
for line in map(loads, f):
124124
seed, key, hash_, bucket = line
@@ -128,7 +128,7 @@ def test_with_non_alpha_numeric_sample_data(self):
128128
"""
129129
Tests basic hash against expected values using non alphanumeric values
130130
"""
131-
hashfn = _HASH_ALGORITHMS['legacy']
131+
hashfn = _HASH_ALGORITHMS[HashAlgorithm.LEGACY]
132132
with io.open(join(dirname(__file__), 'sample-data-non-alpha-numeric.jsonl'), 'r', encoding='utf-8') as f:
133133
for line in map(loads, f):
134134
seed, key, hash_, bucket = line
@@ -138,7 +138,7 @@ def test_murmur_with_sample_data(self):
138138
"""
139139
Tests murmur32 hash against expected values using alphanumeric values
140140
"""
141-
hashfn = _HASH_ALGORITHMS['murmur']
141+
hashfn = _HASH_ALGORITHMS[HashAlgorithm.MURMUR]
142142
with open(join(dirname(__file__), 'murmur3-sample-data-v2.csv')) as f:
143143
for line in f:
144144
seed, key, hash_, bucket = line.split(',')
@@ -148,7 +148,7 @@ def test_murmur_with_non_alpha_numeric_sample_data(self):
148148
"""
149149
Tests murmur32 hash against expected values using non alphanumeric values
150150
"""
151-
hashfn = _HASH_ALGORITHMS['murmur']
151+
hashfn = _HASH_ALGORITHMS[HashAlgorithm.MURMUR]
152152
with io.open(join(dirname(__file__), 'murmur3-sample-data-non-alpha-numeric-v2.csv'), 'r', encoding='utf-8') as f:
153153
for line in f:
154154
seed, key, hash_, bucket = line.split(',')

splitio/uwsgi.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ def _parse_matcher_in_segment(self, partial_split, matcher, block_until_ready=Fa
389389
return delegate
390390

391391
class UWSGISplit(Split):
392-
def __init__(self, name, seed, killed, default_treatment, traffic_type_name, status, change_number, conditions=None, segment_cache=None, algo=HashAlgorithm.LEGACY):
392+
def __init__(self, name, seed, killed, default_treatment, traffic_type_name, status, change_number, conditions=None, segment_cache=None, algo=None):
393393
"""A split implementation that mantains a reference to the segment cache so segments can
394394
be easily pickled and unpickled.
395395
:param name: Name of the feature
@@ -405,7 +405,9 @@ def __init__(self, name, seed, killed, default_treatment, traffic_type_name, sta
405405
:param segment_cache: A segment cache
406406
:type segment_cache: SegmentCache
407407
"""
408-
super(UWSGISplit, self).__init__(name, seed, killed, default_treatment, traffic_type_name, status, change_number, conditions)
408+
super(UWSGISplit, self).__init__(
409+
name, seed, killed, default_treatment, traffic_type_name, status,
410+
change_number, conditions, algo)
409411
self._segment_cache = segment_cache
410412

411413
@property

splitio/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '2.2.1'
1+
__version__ = '4.0.0'

0 commit comments

Comments
 (0)