예제 #1
0
  public MockVoltDB(int clientPort, int adminPort, int httpPort, int drPort) {
    try {
      JSONObject obj = new JSONObject();
      JSONArray jsonArray = new JSONArray();
      jsonArray.put("127.0.0.1");
      obj.put("interfaces", jsonArray);
      obj.put("clientPort", clientPort);
      obj.put("adminPort", adminPort);
      obj.put("httpPort", httpPort);
      obj.put("drPort", drPort);
      m_localMetadata = obj.toString(4);

      m_catalog = new Catalog();
      m_catalog.execute("add / clusters " + m_clusterName);
      m_catalog.execute(
          "add "
              + m_catalog.getClusters().get(m_clusterName).getPath()
              + " databases "
              + m_databaseName);
      Cluster cluster = m_catalog.getClusters().get(m_clusterName);
      // Set a sane default for TestMessaging (at least)
      cluster.setHeartbeattimeout(10000);
      assert (cluster != null);

      try {
        m_hostMessenger.start();
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
      VoltZK.createPersistentZKNodes(m_hostMessenger.getZK());
      m_hostMessenger
          .getZK()
          .create(
              VoltZK.cluster_metadata + "/" + m_hostMessenger.getHostId(),
              getLocalMetadata().getBytes("UTF-8"),
              Ids.OPEN_ACL_UNSAFE,
              CreateMode.EPHEMERAL);

      m_hostMessenger.generateMailboxId(
          m_hostMessenger.getHSIdForLocalSite(HostMessenger.STATS_SITE_ID));
      m_statsAgent = new StatsAgent();
      m_statsAgent.registerMailbox(
          m_hostMessenger, m_hostMessenger.getHSIdForLocalSite(HostMessenger.STATS_SITE_ID));
      for (MailboxType type : MailboxType.values()) {
        m_mailboxMap.put(type, new LinkedList<MailboxNodeContent>());
      }
      m_mailboxMap
          .get(MailboxType.StatsAgent)
          .add(
              new MailboxNodeContent(
                  m_hostMessenger.getHSIdForLocalSite(HostMessenger.STATS_SITE_ID), null));
      m_siteTracker = new SiteTracker(m_hostId, m_mailboxMap);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
예제 #2
0
 public Cartographer(HostMessenger hostMessenger) {
   super(false);
   m_hostMessenger = hostMessenger;
   m_zk = hostMessenger.getZK();
   m_iv2Masters = new LeaderCache(m_zk, VoltZK.iv2masters, m_SPIMasterCallback);
   m_iv2Mpi = new LeaderCache(m_zk, VoltZK.iv2mpi, m_MPICallback);
   try {
     m_iv2Masters.start(true);
     m_iv2Mpi.start(true);
   } catch (Exception e) {
     VoltDB.crashLocalVoltDB("Screwed", true, e);
   }
 }
예제 #3
0
 public SpInitiator(
     HostMessenger messenger,
     Integer partition,
     StatsAgent agent,
     SnapshotCompletionMonitor snapMonitor,
     VoltDB.START_ACTION startAction) {
   super(
       VoltZK.iv2masters,
       messenger,
       partition,
       new SpScheduler(partition, new SiteTaskerQueue(), snapMonitor),
       "SP",
       agent,
       startAction);
   m_leaderCache =
       new LeaderCache(messenger.getZK(), VoltZK.iv2appointees, m_leadersChangeHandler);
   m_tickProducer = new TickProducer(m_scheduler.m_tasks);
 }
예제 #4
0
 public LeaderAppointer(
     HostMessenger hm,
     int numberOfPartitions,
     int kfactor,
     boolean partitionDetectionEnabled,
     SnapshotSchedule partitionSnapshotSchedule,
     boolean usingCommandLog,
     JSONObject topology,
     MpInitiator mpi) {
   m_hostMessenger = hm;
   m_zk = hm.getZK();
   m_kfactor = kfactor;
   m_topo = topology;
   m_MPI = mpi;
   m_partitionCount = numberOfPartitions;
   m_callbacks = new PartitionCallback[m_partitionCount];
   m_partitionWatchers = new BabySitter[m_partitionCount];
   m_iv2appointees = new LeaderCache(m_zk, VoltZK.iv2appointees);
   m_iv2masters = new LeaderCache(m_zk, VoltZK.iv2masters, m_masterCallback);
   m_partitionDetectionEnabled = partitionDetectionEnabled;
   m_partSnapshotSchedule = partitionSnapshotSchedule;
   m_usingCommandLog = usingCommandLog;
 }
예제 #5
0
  private void createAndRegisterAckMailboxes(
      final Set<Integer> localPartitions, HostMessenger messenger) {
    m_zk = messenger.getZK();
    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 HashMap<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");
                return;
              }

              final ExportDataSource eds = partitionSources.get(signature);
              if (eds == null) {
                exportLog.error(
                    "Received an export ack for partition "
                        + partition
                        + " source signature "
                        + signature
                        + " which does not exist on this node");
                return;
              }

              try {
                eds.ack(ackUSO);
              } 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(m_zk, partitionDN);

      ZKUtil.StringCallback cb = new ZKUtil.StringCallback();
      m_zk.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();
                  m_zk.getChildren(
                      m_mailboxesZKPath + "/" + partition,
                      constructMailboxChildWatcher(),
                      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);
    }
  }
예제 #6
0
  @Test
  public void testMultiHost() throws Exception {
    HostMessenger hm1 = createHostMessenger(0);

    final HostMessenger hm2 = createHostMessenger(1, false);

    final HostMessenger hm3 = createHostMessenger(2, false);

    final AtomicReference<Exception> exception = new AtomicReference<Exception>();
    Thread hm2Start =
        new Thread() {
          @Override
          public void run() {
            try {
              hm2.start();
            } catch (Exception e) {
              e.printStackTrace();
              exception.set(e);
            }
          }
        };
    Thread hm3Start =
        new Thread() {
          @Override
          public void run() {
            try {
              hm3.start();
            } catch (Exception e) {
              e.printStackTrace();
              exception.set(e);
            }
          }
        };

    hm2Start.start();
    hm3Start.start();
    hm2Start.join();
    System.out.println(hm2.getZK().getChildren(CoreZK.hostids, false));
    hm3Start.join();

    if (exception.get() != null) {
      fail(exception.get().toString());
    }

    List<String> root1 = hm1.getZK().getChildren("/", false);
    List<String> root2 = hm2.getZK().getChildren("/", false);
    List<String> root3 = hm3.getZK().getChildren("/", false);
    System.out.println(root1);
    System.out.println(root2);
    System.out.println(root3);
    assertTrue(root1.equals(root2));
    assertTrue(root2.equals(root3));

    List<String> hostids1 = hm1.getZK().getChildren(CoreZK.hostids, false);
    List<String> hostids2 = hm2.getZK().getChildren(CoreZK.hostids, false);
    List<String> hostids3 = hm3.getZK().getChildren(CoreZK.hostids, false);
    System.out.println(hostids1);
    System.out.println(hostids2);
    System.out.println(hostids3);
    assertTrue(hostids1.equals(hostids2));
    assertTrue(hostids2.equals(hostids3));

    List<String> hosts3;
    List<String> hosts1;
    hm2.shutdown();
    boolean success = false;
    for (int ii = 0; ii < (200 / 5); ii++) {
      hosts3 = hm3.getZK().getChildren(CoreZK.hosts, false);
      hosts1 = hm1.getZK().getChildren(CoreZK.hosts, false);
      if (hosts3.size() == 2 && hosts1.size() == 2 && hosts1.equals(hosts3)) {
        success = true;
        break;
      }
      Thread.sleep(5);
    }
    assertTrue(success);

    hm1.waitForGroupJoin(2);
    hm3.waitForGroupJoin(2);
  }