コード例 #1
0
ファイル: CurrentImpl.java プロジェクト: cmjonze/bkdb
 public MyStats getStats(int site) throws Exception {
   MyStats s = new MyStats();
   ReplicationStats rs = envs[site].getReplicationStats(StatsConfig.DEFAULT);
   s.egen = rs.getElectionGen();
   s.elections = rs.getElections();
   s.envId = rs.getEnvId();
   s.master = rs.getMaster();
   ReplicationManagerStats rms = envs[site].getReplicationManagerStats(StatsConfig.DEFAULT);
   s.permFailedCount = rms.getPermFailed();
   return s;
 }
コード例 #2
0
ファイル: CurrentImpl.java プロジェクト: cmjonze/bkdb
    synchronized void awaitNewmaster(Environment site, long deadline) throws Exception {
      long now;

      for (; ; ) {
        ReplicationStats s = site.getReplicationStats(StatsConfig.DEFAULT);

        // am I the master?
        //
        if (s.getEnvId() == s.getMaster()) {
          break;
        }

        if ((now = System.currentTimeMillis()) >= deadline)
          throw new Exception("aborted by timeout");
        long waitTime = deadline - now;
        wait(waitTime);
        if (panic) throw new Exception("aborted by panic in DB");
      }
    }
コード例 #3
0
ファイル: RepmgrElectionTest.java プロジェクト: mcandre/db
  @Test
  public void startConductor() {
    Vector<RepmgrElectionTest> workers = new Vector<RepmgrElectionTest>(NUM_WORKER_THREADS);

    // Start the worker threads
    for (int i = 0; i < NUM_WORKER_THREADS; i++) {
      RepmgrElectionTest worker;
      worker = new RepmgrElectionTest(i, i == 0 ? -1 : 0);
      worker.run();
      workers.add(worker);
    }

    // Ensure that the first site is master.
    ReplicationStats rs = null;
    try {
      rs = workers.elementAt(0).dbenv.getReplicationStats(StatsConfig.DEFAULT);
    } catch (DatabaseException dbe) {
      fail("Unexpected database exception came from get replication stats." + dbe);
    }

    assertTrue(rs.getEnvId() == rs.getMaster());

    // Stop the master
    try {
      workers.elementAt(0).dbenv.close();
      workers.elementAt(0).dbenv = null;
      workers.elementAt(0).envConfig = null;
    } catch (DatabaseException dbe) {
      fail("Unexpected database exception came during shutdown." + dbe);
    }

    // Ensure the election is completed.
    try {
      java.lang.Thread.sleep(5000);
    } catch (InterruptedException ie) {
    } // Do nothing if interrupted.

    // Ensure that the site with priority = 75 is selected as new master.
    try {
      rs = workers.elementAt(1).dbenv.getReplicationStats(StatsConfig.DEFAULT);
    } catch (DatabaseException dbe) {
      fail("Unexpected database exception came from get replication stats." + dbe);
    }

    assertTrue(rs.getEnvId() == rs.getMaster());

    // Re-start original master using the new master as bootstrap helper.
    RepmgrElectionTest rejoin = new RepmgrElectionTest(0, 1);
    rejoin.run();
    workers.remove(0);
    workers.insertElementAt(rejoin, 0);

    // Close all the sites and remove their environment contents.
    for (int i = 0; i < NUM_WORKER_THREADS; i++) {
      try {
        if (workers.elementAt(i).dbenv != null) {
          workers.elementAt(i).dbenv.close();
          workers.elementAt(i).dbenv = null;
          workers.elementAt(i).envConfig = null;
        }
      } catch (DatabaseException dbe) {
        fail("Unexpected database exception came during shutdown." + dbe);
      }
    }
  }