_lock_and_read ( $id )

Acquires a lock on a session in DynamoDB using conditional updates.

WARNING: There is a while(true); in here.

Access

protected

Parameters

Parameter

Type

Required

Description

$id

string

Required

The session ID.

Returns

Type

Description

CFResponse

The response from DynamoDB.

Source

Method defined in extensions/dynamodbsessionhandler.class.php | Toggle source view (34 lines) | View on GitHub

protected function _lock_and_read($id)
{
    $now = time();
    $timeout = $now + $this->_max_lock_wait_time;

    do
    {
        // Acquire the lock
        $response = $this->_dynamodb->update_item(array(
            'TableName'        => $this->_table_name,
            'Key'              => array('HashKeyElement' => $this->_dynamodb->attribute($this->_id($id))),
            'AttributeUpdates' => array('lock' => $this->_dynamodb->attribute(1, 'update')),
            'Expected'         => array('lock' => array('Exists' => false)),
            'ReturnValues'     => 'ALL_NEW',
        ));

        // If lock succeeds (or times out), exit the loop, otherwise sleep and try again
        if ($response->isOK() || $now >= $timeout)
        {
            return $response;
        }
        elseif (stripos((string) $response->body->asXML(), 'ConditionalCheckFailedException') !== false)
        {
            usleep(rand($this->_min_lock_retry_utime, $this->_max_lock_retry_utime));

            $now = time();
        }
        else
        {
            return null;
        }
    }
    while (true);
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback