Skip to content

Commit

Permalink
Fixed bug with increase percent calculation #33
Browse files Browse the repository at this point in the history
  • Loading branch information
sebdah committed Apr 17, 2013
1 parent 24595b4 commit 6e11868
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions dynamic_dynamodb/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def ensure_provisioning(table_name):
if read_update_needed or write_update_needed:
logger.info(
'{0} - Changing provisioning to {1:d} '
'read unitss and {2:d} write units'.format(
'read units and {2:d} write units'.format(
table_name,
int(updated_read_units),
int(updated_write_units)))
Expand All @@ -40,7 +40,7 @@ def __ensure_provisioning_reads(table_name):
:returns: (bool, int) -- update_needed, updated_read_units
"""
update_needed = False
updated_read_units = statistics.get_consumed_read_units(table_name)
updated_read_units = statistics.get_provisioned_read_units(table_name)

consumed_read_units_percent = \
statistics.get_consumed_read_units_percent(table_name)
Expand Down Expand Up @@ -97,7 +97,7 @@ def __ensure_provisioning_writes(table_name):
:returns: (bool, int) -- update_needed, updated_write_units
"""
update_needed = False
updated_write_units = statistics.get_consumed_write_units(table_name)
updated_write_units = statistics.get_provisioned_write_units(table_name)

consumed_write_units_percent = \
statistics.get_consumed_write_units_percent(table_name)
Expand Down
24 changes: 12 additions & 12 deletions dynamic_dynamodb/core/calculators.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def decrease_reads_in_percent(table_name, current_provisioning, percent):
decrease = int(float(current_provisioning)*(float(percent)/100))
updated_provisioning = current_provisioning - decrease
logger.debug(
'Read provisioning will be decreased with {0:d} units'.format(
'Read provisioning will be decreased to {0:d} units'.format(
updated_provisioning))

if get_table_option(table_name, 'min_provisioned_writesprovisioned_reads') > 0:
Expand All @@ -43,10 +43,11 @@ def increase_reads_in_percent(table_name, current_provisioning, percent):
:param percent: How many percent should we increase with
:returns: int -- New provisioning value
"""
updated_provisioning = int(
increase = int(
float(current_provisioning)*(float(percent)/100+1))
updated_provisioning = current_provisioning + increase
logger.debug(
'Read provisioning will be increased with {0:d} units'.format(
'Read provisioning will be increased to {0:d} units'.format(
updated_provisioning))

if get_table_option(table_name, 'max_provisioned_reads') > 0:
Expand Down Expand Up @@ -75,7 +76,7 @@ def decrease_writes_in_percent(table_name, current_provisioning, percent):
decrease = int(float(current_provisioning)*(float(percent)/100))
updated_provisioning = current_provisioning - decrease
logger.debug(
'Write provisioning will be decreased with {0:d} units'.format(
'Write provisioning will be decreased to {0:d} units'.format(
updated_provisioning))

if get_table_option(table_name, 'min_provisioned_writes') > 0:
Expand All @@ -101,13 +102,12 @@ def increase_writes_in_percent(table_name, current_provisioning, percent):
:param percent: How many percent should we increase with
:returns: int -- New provisioning value
"""
updated_provisioning = int(
float(current_provisioning)*(float(percent)/100))
increase = int(float(current_provisioning)*(float(percent)/100))
updated_provisioning = current_provisioning + increase
logger.debug(
'Write provisioning will be increased with {0:d} units'.format(
'Write provisioning will be increased to {0:d} units'.format(
updated_provisioning))


if get_table_option(table_name, 'max_provisioned_writes') > 0:
if (updated_provisioning >
get_table_option(table_name, 'max_provisioned_writes')):
Expand All @@ -133,7 +133,7 @@ def decrease_reads_in_units(table_name, current_provisioning, units):
"""
updated_provisioning = int(current_provisioning) - int(units)
logger.debug(
'Read provisioning will be decreased with {0:d} units'.format(
'Read provisioning will be decreased to {0:d} units'.format(
updated_provisioning))

if get_table_option(table_name, 'min_provisioned_writesprovisioned_reads') > 0:
Expand Down Expand Up @@ -161,7 +161,7 @@ def increase_reads_in_units(table_name, current_provisioning, units):
"""
updated_provisioning = int(current_provisioning) + int(units)
logger.debug(
'Read provisioning will be increased with {0:d} units'.format(
'Read provisioning will be increased to {0:d} units'.format(
updated_provisioning))

if get_table_option(table_name, 'max_provisioned_reads') > 0:
Expand Down Expand Up @@ -189,7 +189,7 @@ def decrease_writes_in_units(table_name, current_provisioning, units):
"""
updated_provisioning = int(current_provisioning) - int(units)
logger.debug(
'Write provisioning will be decreased with {0:d} units'.format(
'Write provisioning will be decreased to {0:d} units'.format(
updated_provisioning))

if get_table_option(table_name, 'min_provisioned_writes') > 0:
Expand Down Expand Up @@ -217,7 +217,7 @@ def increase_writes_in_units(table_name, current_provisioning, units):
"""
updated_provisioning = int(current_provisioning) + int(units)
logger.debug(
'Write provisioning will be increased with {0:d} units'.format(
'Write provisioning will be increased to {0:d} units'.format(
updated_provisioning))

if get_table_option(table_name, 'max_provisioned_writes') > 0:
Expand Down
4 changes: 2 additions & 2 deletions dynamic_dynamodb/core/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def get_provisioned_read_units(table_name):
:returns: int -- Number of read units
"""
table = dynamodb.get_table(table_name)
logger.info('{0} - Provisioned read units: {1:d}'.format(
logger.debug('{0} - Provisioned read units: {1:d}'.format(
table_name, table.read_units))
return int(table.read_units)

Expand All @@ -158,6 +158,6 @@ def get_provisioned_write_units(table_name):
:returns: int -- Number of write units
"""
table = dynamodb.get_table(table_name)
logger.info('{0} - Provisioned write units: {1:d}'.format(
logger.debug('{0} - Provisioned write units: {1:d}'.format(
table_name, table.write_units))
return int(table.write_units)

0 comments on commit 6e11868

Please sign in to comment.