Concurrency Problem

I am having a problem with concurrency when using MySQL and PHP + Propel 1.3. The following is a small example of the save method of the Propel object.

public function save(PropelPDO $con = null) {
    $con = Propel::getConnection();
    try {
        $con->beginTransaction();
        sleep(3); // ignore this, used for testing only
        parent::save($con);
        $foo = $this->getFoo(); // Propel object, triggers a SELECT

        // stuff is happening here...

        $foo->save($con);
        $con->commit();
    } catch (Exception $e) {
        $con->rollBack();
        throw $e;
    }
}

The problem is the $ foo object. Let them say that in a short period of time we get two method calls one by one. In some cases, if the second transaction reads $ foo ...

$foo = $this->getFoo();

... before the first transaction was able to save it ...

$foo->save($con);

... the $ foo read by the second transaction will be deprecated and bad things will happen.

How can I force lock objects on the Foo table so that subsequent transactions can only read from it after the first has completed its work?

EDIT: - -. , , ( $foo). . , $foo ( ). $foo, , .

+3
2

/, LastChgDate. "AND LastChgDate = thevalue". , , "- ", . , , . , INSERT, , .

+1

MySQL, , SELECT FOR UPDATE .

- GET_LOCK RELEASE_LOCK MySQL , .

. , MySQL, .

0

Source: https://habr.com/ru/post/1709541/


All Articles