Skip to content

Commit

Permalink
add make publish and use random offset for buffer.clock()
Browse files Browse the repository at this point in the history
  • Loading branch information
numberoverzero committed Jan 6, 2017
1 parent b1ed4ac commit 0860589
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
.PHONY: cov docs
.PHONY: cov docs publish

cov:
scripts/individual_coverage.sh

docs:
cd docs && $(MAKE) html
firefox docs/_build/html/index.html

publish:
python setup.py sdist bdist_wheel
twine upload dist/*
rm -fr build dist .egg bloop.egg-info
17 changes: 13 additions & 4 deletions bloop/stream/buffer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import heapq
import random


def jitter():
"""Used to advance a monotonic clock by a small amount"""
return random.randint(1, 5)


def heap_item(clock, record, shard):
Expand Down Expand Up @@ -85,6 +91,7 @@ def clock(self):
.. code-block:: python
>>> buffer = RecordBuffer()
>>> buffer.clock()
3
>>> buffer.clock()
Expand All @@ -97,7 +104,9 @@ def clock(self):
:return: A unique clock value guaranteed to be larger than every previous value
:rtype: int
"""
# Try to prevent collisions from someone accessing the underlying int. This offset
# ensures __monotonic_integer will never have the same value as any call to clock().
self.__monotonic_integer += 2
return self.__monotonic_integer - 1
# Try to prevent collisions from someone accessing the underlying int.
# This offset ensures _RecordBuffer__monotonic_integer will never have
# the same value as any call to clock().
value = self.__monotonic_integer + jitter()
self.__monotonic_integer = value + jitter()
return value
1 change: 1 addition & 0 deletions requirements-to-freeze.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ pytest
sphinx
sphinx_rtd_theme
tox
twine

0 comments on commit 0860589

Please sign in to comment.