Skip to content

Commit

Permalink
CORE-414: fix state machine lock scaling issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Auris committed Jul 27, 2016
1 parent 11cd9a9 commit 3434698
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/Spryker/Zed/Oms/Business/Lock/TriggerLocker.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ public function acquire($identifier)
try {
$affectedRows = $stateMachineLockEntity->save();
} catch (PropelException $exception) {
throw new LockException('State machine trigger is locked.');
throw new LockException(sprintf(
'State machine trigger is locked. Propel exception: %s',
$exception->getMessage()
));
}

return $affectedRows > 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,10 @@ protected function buildIdentifierForOrderItemsLock(array $orderItems)
protected function buildIdentifierForOrderItemIdsLock(array $orderItemIds)
{
$orderItemIds = array_unique($orderItemIds);
array_walk($orderItemIds, 'intval');
asort($orderItemIds);
$identifier = implode('-', $orderItemIds);
$identifier = hash('sha512', $identifier);

return $identifier;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

namespace Spryker\Zed\StateMachine\Persistence\Propel;

use Orm\Zed\StateMachine\Persistence\Base\SpyStateMachineLock as BaseSpyStateMachineLock;
use Orm\Zed\Oms\Persistence\Base\SpyOmsStateMachineLock as BaseSpyOmsStateMachineLock;

abstract class AbstractSpyOmsStateMachineLock extends BaseSpyStateMachineLock
abstract class AbstractSpyOmsStateMachineLock extends BaseSpyOmsStateMachineLock
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ public function triggerEventsDataProvider()
$eventId = 'eventId';
$orderItems = $this->createOrderItems();
$orderItemIds = [10, 11, 12];
$orderItemsIdentifier = '10-11-12';
$singleOrderItemIdentifier = '10';
$orderItemsIdentifier = $this->hashIdentifier('10-11-12');
$singleOrderItemIdentifier = $this->hashIdentifier('10');

return [
['triggerEvent', $orderItemsIdentifier, $eventId, $orderItems, []],
['triggerEventForNewItem', $orderItemsIdentifier, $orderItems, []],
['triggerEventForNewOrderItems', $orderItemsIdentifier, $orderItemIds, []],
['triggerEventForOneOrderItem', $singleOrderItemIdentifier, $eventId, $singleOrderItemIdentifier, []],
['triggerEventForOneOrderItem', $singleOrderItemIdentifier, $eventId, $orderItemIds[0], []],
['triggerEventForOrderItems', $orderItemsIdentifier, $eventId, $orderItemIds, []],
];
}
Expand Down Expand Up @@ -168,7 +168,7 @@ public function testIdentifierGeneratedSameForOrderIdsDifferentOrderAndNotUnique
$testIdsList1 = ['100', '11', '12', '10', 11, 12];
$testIdsList2 = [12, 11, 100, '10'];

$expectedResult = '10-11-12-100';
$expectedResult = $this->hashIdentifier('10-11-12-100');

$lockedStateMachine = $this->createLockedStateMachine();

Expand All @@ -179,6 +179,16 @@ public function testIdentifierGeneratedSameForOrderIdsDifferentOrderAndNotUnique
$this->assertEquals($expectedResult, $generateIdentifierMethod->invoke($lockedStateMachine, $testIdsList2));
}

/**
* @param string $identifer
*
* @return string
*/
protected function hashIdentifier($identifer)
{
return hash('sha512', $identifer);
}

/**
* @param string $expectedIdentifier
*
Expand Down

0 comments on commit 3434698

Please sign in to comment.