/** * Updates the sequence number stored in the catalog trep_commit_seqno. If the catalog is disabled * we do nothing, which allows us to run unit tests easily without a DBMS present. * * @throws ReplicatorException Thrown if update is unsuccessful */ public void updateCommitSeqno(THLEvent thlEvent) throws ReplicatorException { if (catalog == null) { if (logger.isDebugEnabled()) logger.debug("Seqno update is disabled: seqno=" + thlEvent.getSeqno()); } else { try { catalog.updateCommitSeqnoTable(thlEvent); } catch (SQLException e) { throw new THLException( "Unable to update commit sequence number: seqno=" + thlEvent.getSeqno() + " event id=" + thlEvent.getEventId(), e); } } }
/** * 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; }