Exemplo n.º 1
0
  /**
   * Get the last applied event. We first try the disk log then if that is absent try the catalog.
   * If there is nothing there we must be starting from scratch and return null.
   *
   * @return An event header or null if log is newly initialized
   * @throws InterruptedException
   * @throws ReplicatorException
   */
  public ReplDBMSHeader getLastAppliedEvent() throws ReplicatorException, InterruptedException {
    // Look for maximum sequence number in log and use that if available.
    if (diskLog != null) {

      long maxSeqno = diskLog.getMaxSeqno();
      if (maxSeqno > -1) {
        LogConnection conn = null;
        try {
          // Try to connect and find the event.
          THLEvent thlEvent = null;
          conn = diskLog.connect(true);
          conn.seek(maxSeqno);
          while ((thlEvent = conn.next(false)) != null && thlEvent.getSeqno() == maxSeqno) {
            // Return only the last fragment.
            if (thlEvent.getLastFrag()) {
              ReplEvent event = thlEvent.getReplEvent();
              if (event instanceof ReplDBMSEvent) return (ReplDBMSEvent) event;
              else if (event instanceof ReplControlEvent)
                return ((ReplControlEvent) event).getHeader();
            }
          }

          // If we did not find the last fragment of the event
          // we need to warn somebody.
          if (thlEvent != null)
            logger.warn("Unable to find last fragment of event: seqno=" + maxSeqno);
        } finally {
          conn.release();
        }
      }
    }

    // If that does not work, try the catalog.
    if (catalog != null) {
      return catalog.getLastEvent();
    }

    // If we get to this point, the log is newly initialized and there is no
    // such event to return.
    return null;
  }
Exemplo n.º 2
0
 /**
  * Disconnect from the log. Adapters must call this to free resources and avoid leaks.
  *
  * @param client a Disk log client to be disconnected
  * @throws ReplicatorException
  */
 public void disconnect(LogConnection client) throws ReplicatorException {
   client.release();
 }