Uploaded image for project: 'PHP ORMs'
  1. PHP ORMs
  2. PHPORM-99

Implement locking for Laravel cache component

    • Type: Icon: New Feature New Feature
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • laravel-4.3.0
    • Affects Version/s: None
    • Component/s: Laravel
    • None

      https://github.com/mongodb/laravel-mongodb/issues/2609

      • Laravel-mongodb Version: #.#.#
      • PHP Version: #.#.#
      • Database Driver & Version:

      Description:

      I have issue when store data to cache lock with MongoDB driver. error also occurs when dispatch a job implements ShouldBeUnique.

      Method acquire Illuminate\Cache\DatabaseLock catch QueryException to update record cache lock table. But with mongodb driver connection throw MongoDB\Driver\Exception\BulkWriteException so can not excute snippet code in catch block

      Illuminate\Cache\DatabaseLock

      public function acquire()
          {
              $acquired = false;        try {
                  $this->connection->table($this->table)->insert([
                      'key' => $this->name,
                      'owner' => $this->owner,
                      'expiration' => $this->expiresAt(),
                  ]);            $acquired = true;
              } catch (QueryException $e) {
                  $updated = $this->connection->table($this->table)
                      ->where('key', $this->name)
                      ->where(function ($query) {
                          return $query->where('owner', $this->owner)->orWhere('expiration', '<=', time());
                      })->update([
                          'owner' => $this->owner,
                          'expiration' => $this->expiresAt(),
                      ]);            $acquired = $updated >= 1;
              }        if (random_int(1, $this->lottery[1]) <= $this->lottery[0]) {
                  $this->connection->table($this->table)->where('expiration', '<=', time())->delete();
              }        return $acquired;
          } 

      Steps to reproduce

            Assignee:
            jerome.tamarelle@mongodb.com Jérôme Tamarelle
            Reporter:
            tom.selander@mongodb.com Tom Selander
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: