Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to insert to a PostgreSQL master-slave config due to SequenceGenerator(NEXTVAL) issues #6167

Closed
mkurzeja opened this issue Dec 9, 2016 · 1 comment
Assignees
Labels
Milestone

Comments

@mkurzeja
Copy link
Contributor

mkurzeja commented Dec 9, 2016

Background: I have a master-slave connection and I'm using auto-generated id for my entity;

Doctrine ORM fails to insert data because it tries to get the sequence NEXTVAL value from a slave.

public function generate(EntityManager $em, $entity)
    {
        if ($this->_maxValue === null || $this->_nextValue == $this->_maxValue) {
            // Allocate new values
            $conn = $em->getConnection();
            $sql  = $conn->getDatabasePlatform()->getSequenceNextValSQL($this->_sequenceName);

            $this->_nextValue = (int)$conn->fetchColumn($sql); //this line fails
            $this->_maxValue  = $this->_nextValue + $this->_allocationSize;
        }

        return $this->_nextValue++;
    }

PostgreSQL allows to fetch nextval only from a master server, and using fetchColumn runs the query using a slave connection.

I could start a transaction before, but I assume this case should be handled by ORM.

In case someone tries to reproduce this issue, just start a PostgreSQL cluster (docker-compose and https://hub.docker.com/r/bitnami/postgresql/ might be helpful) and try to persist any entity with an auto-generated ID.

mkurzeja added a commit to mkurzeja/doctrine2 that referenced this issue Dec 9, 2016
mkurzeja added a commit to mkurzeja/doctrine2 that referenced this issue Dec 12, 2016
mkurzeja added a commit to mkurzeja/doctrine2 that referenced this issue Dec 12, 2016
mkurzeja added a commit to mkurzeja/doctrine2 that referenced this issue Dec 12, 2016
fesor pushed a commit to intellectsoft-uk/doctrine2 that referenced this issue Mar 13, 2017
Ocramius added a commit that referenced this issue Jun 21, 2017
Ocramius added a commit that referenced this issue Jun 21, 2017
@Ocramius Ocramius added the Bug label Jun 21, 2017
@Ocramius Ocramius self-assigned this Jun 21, 2017
@Ocramius Ocramius added this to the 2.6.0 milestone Jun 21, 2017
@Ocramius
Copy link
Member

Handled in #6168

gigi pushed a commit to gigi/doctrine2 that referenced this issue Nov 27, 2017
gigi pushed a commit to gigi/doctrine2 that referenced this issue Nov 27, 2017
gigi pushed a commit to gigi/doctrine2 that referenced this issue Nov 27, 2017
gigi pushed a commit to gigi/doctrine2 that referenced this issue Nov 27, 2017
gigi pushed a commit to gigi/doctrine2 that referenced this issue Nov 27, 2017
… is used instead of `fetchColumn`

(cherry picked from commit d2be4a2)
gigi pushed a commit to gigi/doctrine2 that referenced this issue Nov 27, 2017
…cblocks/return-types

(cherry picked from commit 462481e)
gigi pushed a commit to gigi/doctrine2 that referenced this issue Nov 27, 2017
…r readability and error messages

(cherry picked from commit a97c265)
gigi pushed a commit to gigi/doctrine2 that referenced this issue Nov 27, 2017
@lcobucci lcobucci modified the milestones: 2.6.0, 2.5.13 Nov 27, 2017
lcobucci added a commit that referenced this issue Nov 27, 2017
Backport #6167 from 2.6 to 2.5.x branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants