def pretxnopenhook(ui, repo, **kwargs):
    """Verify replication log is working before starting transaction.

    It doesn't make sense to perform a lot of work only to find out that the
    replication log can not be written to. So we check replication log
    writability when we open transactions so we fail fast.
    """
    with ui.kafkainteraction():
        try:
            repo.producerlog('PRETXNOPEN_HEARTBEATSENDING')
            vcsrproducer.send_heartbeat(ui.replicationproducer,
                                        partition=repo.replicationpartition)
            repo.producerlog('PRETXNOPEN_HEARTBEATSENT')
        except Exception as e:
            repo.producerlog('EXCEPTION', '%s: %s' % (
                             e, traceback.format_exc()))
            ui.warn('replication log not available; all writes disabled\n')
            return 1

    repo._replicationinfo = {
        'pushkey': [],
        'changegroup': False,
        'obsolescence': {},
        # Stuff a copy of served heads so we can determine after close
        # whether they changed and we need to write a message.
        'pre_served_heads': repo.filtered('served').heads(),
    }
Beispiel #2
0
def initcommand(orig, ui, dest, **opts):
    with ui.kafkainteraction():
        # Send a heartbeat before we create the repo to ensure the replication
        # system is online. This helps guard against us creating the repo
        # and replication being offline.
        producer = ui.replicationproducer
        # TODO this should ideally go to same partition as replication event.
        for partition in sorted(ui.replicationpartitions):
            vcsrproducer.send_heartbeat(producer, partition=partition)
            break

        res = orig(ui, dest=dest, **opts)

        # init aborts if the repo already existed or in case of error. So we
        # can only get here if we created a repo.
        path = os.path.normpath(os.path.abspath(os.path.expanduser(dest)))
        if not os.path.exists(path):
            raise util.Abort('could not find created repo at %s' % path)

        repo = hg.repository(ui, path)
        gd = 'generaldelta' in repo.requirements

        # TODO we should delete the repo if we can't write this message.
        vcsrproducer.record_new_hg_repo(producer,
                                        repo.replicationwireprotopath,
                                        partition=repo.replicationpartition,
                                        generaldelta=gd)
        ui.status(_('(recorded repository creation in replication log)\n'))

        return res
def pretxnclosehook(ui, repo, **kwargs):
    """Check for writeable replication log before transaction close.

    We perform one final check for replication log writeability immediately
    before the transaction closes. We'll abort the transaction if the
    replication log can't be written to.
    """
    with ui.kafkainteraction():
        try:
            repo.producerlog('PRETXNCLOSE_HEARTBEATSENDING')
            vcsrproducer.send_heartbeat(ui.replicationproducer,
                                        repo.replicationpartition)
            repo.producerlog('PRETXNCLOSE_HEARTBEATSENT')
        except Exception as e:
            repo.producerlog('EXCEPTION', '%s: %s' % (
                e, traceback.format_exc()))
            ui.warn('replication log not available; cannot close transaction\n')
            return True

    # If our set of served heads changed in the course of this transaction,
    # schedule the writing of a message to reflect this. The message can be
    # used by downstream consumers to influence which heads are exposed to
    # clients.
    heads = repo.filtered('served').heads()

    if heads != repo._replicationinfo['pre_served_heads']:
        tr = repo.currenttransaction()
        tr.addpostclose('vcsreplicator-record-heads-change',
                        lambda tr: repo._afterlock(
                            functools.partial(sendheadsmessage, ui, repo)))
def pretxnclosehook(ui, repo, **kwargs):
    try:
        vcsrproducer.send_heartbeat(ui.replicationproducer,
                                    repo.replicationpartition)
    except Exception:
        ui.warn('replication log not available; cannot close transaction\n')
        return True
def initcommand(orig, ui, dest, **opts):
    with ui.kafkainteraction():
        # Send a heartbeat before we create the repo to ensure the replication
        # system is online. This helps guard against us creating the repo
        # and replication being offline.
        producer = ui.replicationproducer
        # TODO this should ideally go to same partition as replication event.
        for partition in sorted(ui.replicationpartitions):
            vcsrproducer.send_heartbeat(producer, partition=partition)
            break

        res = orig(ui, dest=dest, **opts)

        # init aborts if the repo already existed or in case of error. So we
        # can only get here if we created a repo.
        path = os.path.normpath(os.path.abspath(os.path.expanduser(dest)))
        if not os.path.exists(path):
            raise util.Abort('could not find created repo at %s' % path)

        repo = hg.repository(ui, path)
        gd = 'generaldelta' in repo.requirements

        # TODO we should delete the repo if we can't write this message.
        vcsrproducer.record_new_hg_repo(producer, repo.replicationwireprotopath,
                                        partition=repo.replicationpartition,
                                        generaldelta=gd)
        ui.status(_('(recorded repository creation in replication log)\n'))

        return res
def sendheartbeat(ui):
    """Send a heartbeat message through the replication system.

    This is useful to see if the replication mechanism is writable.
    """
    try:
        for partition in ui.replicationpartitions:
            vcsrproducer.send_heartbeat(ui.replicationproducer,
                                        partition=partition)
    except kafkacommon.KafkaError as e:
        raise error.Abort('error sending heartbeat: %s' % e.message)

    ui.status(_('wrote heartbeat message into replication log\n'))
Beispiel #7
0
def pretxnclosehook(ui, repo, **kwargs):
    """Check for writeable replication log before transaction close.

    We perform one final check for replication log writeability immediately
    before the transaction closes. We'll abort the transaction if the
    replication log can't be written to.
    """
    with ui.kafkainteraction():
        try:
            repo.producerlog("PRETXNCLOSE_HEARTBEATSENDING")
            vcsrproducer.send_heartbeat(ui.replicationproducer, repo.replicationpartition)
            repo.producerlog("PRETXNCLOSE_HEARTBEATSENT")
        except Exception:
            repo.producerlog("EXCEPTION", traceback.format_exc())
            ui.warn("replication log not available; cannot close transaction\n")
            return True
Beispiel #8
0
def sendheartbeat(ui):
    """Send a heartbeat message through the replication system.

    This is useful to see if the replication mechanism is writable.
    """
    with ui.kafkainteraction():
        try:
            partitions = ui.replicationpartitions
            for partition in partitions:
                ui.status("sending heartbeat to partition %d\n" % partition)
                vcsrproducer.send_heartbeat(ui.replicationproducer, partition=partition)
        except kafkacommon.KafkaError as e:
            ui.producerlog("<unknown>", "EXCEPTION", traceback.format_exc())
            raise error.Abort("error sending heartbeat: %s" % e.message)

    ui.status(_("wrote heartbeat message into %d partitions\n") % len(partitions))
Beispiel #9
0
def sendheartbeat(ui):
    """Send a heartbeat message through the replication system.

    This is useful to see if the replication mechanism is writable.
    """
    with ui.kafkainteraction():
        try:
            partitions = ui.replicationpartitions
            for partition in partitions:
                ui.status('sending heartbeat to partition %d\n' % partition)
                vcsrproducer.send_heartbeat(ui.replicationproducer,
                                            partition=partition)
        except kafkacommon.KafkaError as e:
            ui.producerlog('<unknown>', 'EXCEPTION', traceback.format_exc())
            raise error.Abort('error sending heartbeat: %s' % e.message)

    ui.status(
        _('wrote heartbeat message into %d partitions\n') % len(partitions))
Beispiel #10
0
def pretxnclosehook(ui, repo, **kwargs):
    """Check for writeable replication log before transaction close.

    We perform one final check for replication log writeability immediately
    before the transaction closes. We'll abort the transaction if the
    replication log can't be written to.
    """
    with ui.kafkainteraction():
        try:
            repo.producerlog('PRETXNCLOSE_HEARTBEATSENDING')
            vcsrproducer.send_heartbeat(ui.replicationproducer,
                                        repo.replicationpartition)
            repo.producerlog('PRETXNCLOSE_HEARTBEATSENT')
        except Exception:
            repo.producerlog('EXCEPTION', traceback.format_exc())
            ui.warn(
                'replication log not available; cannot close transaction\n')
            return True
Beispiel #11
0
def pretxnopenhook(ui, repo, **kwargs):
    """Verify replication log is working before starting transaction.

    It doesn't make sense to perform a lot of work only to find out that the
    replication log can not be written to. So we check replication log
    writability when we open transactions so we fail fast.
    """
    with ui.kafkainteraction():
        try:
            repo.producerlog("PRETXNOPEN_HEARTBEATSENDING")
            vcsrproducer.send_heartbeat(ui.replicationproducer, partition=repo.replicationpartition)
            repo.producerlog("PRETXNOPEN_HEARTBEATSENT")
        except Exception:
            repo.producerlog("EXCEPTION", traceback.format_exc())
            ui.warn("replication log not available; all writes disabled\n")
            return 1

    repo._replicationinfo = {"pushkey": [], "changegroup": False}
def pretxnopenhook(ui, repo, **kwargs):
    """Verify replication log is working before starting transaction.

    It doesn't make sense to perform a lot of work only to find out that the
    replication log can not be written to. So we check replication log
    writability when we open transactions so we fail fast.
    """
    try:
        vcsrproducer.send_heartbeat(ui.replicationproducer,
                                    partition=repo.replicationpartition)
    except Exception:
        ui.warn('replication log not available; all writes disabled\n')
        return 1

    repo._replicationinfo = {
        'pushkey': [],
        'changegroup': False,
    }
Beispiel #13
0
def pretxnopenhook(ui, repo, **kwargs):
    """Verify replication log is working before starting transaction.

    It doesn't make sense to perform a lot of work only to find out that the
    replication log can not be written to. So we check replication log
    writability when we open transactions so we fail fast.
    """
    with ui.kafkainteraction():
        try:
            repo.producerlog('PRETXNOPEN_HEARTBEATSENDING')
            vcsrproducer.send_heartbeat(ui.replicationproducer,
                                        partition=repo.replicationpartition)
            repo.producerlog('PRETXNOPEN_HEARTBEATSENT')
        except Exception:
            repo.producerlog('EXCEPTION', traceback.format_exc())
            ui.warn('replication log not available; all writes disabled\n')
            return 1

    repo._replicationinfo = {
        'pushkey': [],
        'changegroup': False,
        'obsolescence': {},
    }