Reserve the persistent identifier.

        Note, the reserve method may be called multiple times, even if it was
        already reserved.

        :raises: :exc:`invenio_pidstore.errors.PIDInvalidAction` if the PID is
            not new or is not already reserved a PID.
        :returns: `True` if the PID is successfully reserved.

def reserve(self):
        """Reserve the persistent identifier.

        Note, the reserve method may be called multiple times, even if it was
        already reserved.

        :raises: :exc:`invenio_pidstore.errors.PIDInvalidAction` if the PID is
            not new or is not already reserved a PID.
        :returns: `True` if the PID is successfully reserved.
        """
        if not (self.is_new() or self.is_reserved()):
            raise PIDInvalidAction(
                "Persistent identifier is not new or reserved.")

        try:
            with db.session.begin_nested():
                self.status = PIDStatus.RESERVED
                db.session.add(self)
        except SQLAlchemyError:
            logger.exception("Failed to reserve PID.", extra=dict(pid=self))
            raise
        logger.info("Reserved PID.", extra=dict(pid=self))
        return True