Search in sources :

Example 1 with LocalMailbox

use of org.voltdb.messaging.LocalMailbox in project voltdb by VoltDB.

the class OpsAgent method registerMailbox.

public void registerMailbox(final HostMessenger hostMessenger, final long hsId) {
    m_messenger = hostMessenger;
    hostMessenger.generateMailboxId(hsId);
    m_mailbox = new LocalMailbox(hostMessenger, hsId) {

        @Override
        public void deliver(final VoltMessage message) {
            m_es.submit(new Runnable() {

                @Override
                public void run() {
                    handleMailboxMessage(message);
                }
            });
        }
    };
    hostMessenger.registerMailbox(m_mailbox);
}
Also used : VoltMessage(org.voltcore.messaging.VoltMessage) LocalMailbox(org.voltdb.messaging.LocalMailbox)

Example 2 with LocalMailbox

use of org.voltdb.messaging.LocalMailbox in project voltdb by VoltDB.

the class ExportGeneration method createAndRegisterAckMailboxes.

private void createAndRegisterAckMailboxes(final Set<Integer> localPartitions, HostMessenger messenger) {
    m_mailboxesZKPath = VoltZK.exportGenerations + "/" + m_timestamp + "/" + "mailboxes";
    m_mbox = new LocalMailbox(messenger) {

        @Override
        public void deliver(VoltMessage message) {
            if (message instanceof BinaryPayloadMessage) {
                BinaryPayloadMessage bpm = (BinaryPayloadMessage) message;
                ByteBuffer buf = ByteBuffer.wrap(bpm.m_payload);
                final int partition = buf.getInt();
                final int length = buf.getInt();
                byte[] stringBytes = new byte[length];
                buf.get(stringBytes);
                String signature = new String(stringBytes, Constants.UTF8ENCODING);
                final long ackUSO = buf.getLong();
                final boolean runEveryWhere = (buf.getShort() == (short) 1);
                final Map<String, ExportDataSource> partitionSources = m_dataSourcesByPartition.get(partition);
                if (partitionSources == null) {
                    exportLog.error("Received an export ack for partition " + partition + " which does not exist on this node, partitions = " + m_dataSourcesByPartition);
                    return;
                }
                final ExportDataSource eds = partitionSources.get(signature);
                if (eds == null) {
                    exportLog.warn("Received an export ack for partition " + partition + " source signature " + signature + " which does not exist on this node, sources = " + partitionSources);
                    return;
                }
                try {
                    eds.ack(ackUSO, runEveryWhere);
                } catch (RejectedExecutionException ignoreIt) {
                // ignore it: as it is already shutdown
                }
            } else {
                exportLog.error("Receive unexpected message " + message + " in export subsystem");
            }
        }
    };
    messenger.createMailbox(null, m_mbox);
    for (Integer partition : localPartitions) {
        final String partitionDN = m_mailboxesZKPath + "/" + partition;
        ZKUtil.asyncMkdirs(messenger.getZK(), partitionDN);
        ZKUtil.StringCallback cb = new ZKUtil.StringCallback();
        messenger.getZK().create(partitionDN + "/" + m_mbox.getHSId(), null, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL, cb, null);
    }
    ListenableFuture<?> fut = m_childUpdatingThread.submit(new Runnable() {

        @Override
        public void run() {
            List<Pair<Integer, ZKUtil.ChildrenCallback>> callbacks = new ArrayList<Pair<Integer, ZKUtil.ChildrenCallback>>();
            for (Integer partition : localPartitions) {
                ZKUtil.ChildrenCallback callback = new ZKUtil.ChildrenCallback();
                messenger.getZK().getChildren(m_mailboxesZKPath + "/" + partition, constructMailboxChildWatcher(messenger), callback, null);
                callbacks.add(Pair.of(partition, callback));
            }
            for (Pair<Integer, ZKUtil.ChildrenCallback> p : callbacks) {
                final Integer partition = p.getFirst();
                List<String> children = null;
                try {
                    children = p.getSecond().getChildren();
                } catch (InterruptedException e) {
                    Throwables.propagate(e);
                } catch (KeeperException e) {
                    Throwables.propagate(e);
                }
                ImmutableList.Builder<Long> mailboxes = ImmutableList.builder();
                for (String child : children) {
                    if (child.equals(Long.toString(m_mbox.getHSId())))
                        continue;
                    mailboxes.add(Long.valueOf(child));
                }
                ImmutableList<Long> mailboxHsids = mailboxes.build();
                for (ExportDataSource eds : m_dataSourcesByPartition.get(partition).values()) {
                    eds.updateAckMailboxes(Pair.of(m_mbox, mailboxHsids));
                }
            }
        }
    });
    try {
        fut.get();
    } catch (Throwable t) {
        Throwables.propagate(t);
    }
}
Also used : ImmutableList(com.google_voltpatches.common.collect.ImmutableList) BinaryPayloadMessage(org.voltcore.messaging.BinaryPayloadMessage) ZKUtil(org.voltcore.zk.ZKUtil) VoltMessage(org.voltcore.messaging.VoltMessage) LocalMailbox(org.voltdb.messaging.LocalMailbox) ImmutableList(com.google_voltpatches.common.collect.ImmutableList) ArrayList(java.util.ArrayList) List(java.util.List) Pair(org.voltcore.utils.Pair) ByteBuffer(java.nio.ByteBuffer) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) Map(java.util.Map) CatalogMap(org.voltdb.catalog.CatalogMap) KeeperException(org.apache.zookeeper_voltpatches.KeeperException)

Aggregations

VoltMessage (org.voltcore.messaging.VoltMessage)2 LocalMailbox (org.voltdb.messaging.LocalMailbox)2 ImmutableList (com.google_voltpatches.common.collect.ImmutableList)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 KeeperException (org.apache.zookeeper_voltpatches.KeeperException)1 BinaryPayloadMessage (org.voltcore.messaging.BinaryPayloadMessage)1 Pair (org.voltcore.utils.Pair)1 ZKUtil (org.voltcore.zk.ZKUtil)1 CatalogMap (org.voltdb.catalog.CatalogMap)1