Search in sources :

Example 1 with RedoLogManager

use of com.zimbra.cs.redolog.RedoLogManager in project zm-mailbox by Zimbra.

the class AllAccountsWaitSet method syncToCommitId.

/**
     * Given a CommitId, bring this waitset into sync using the RedoLog system
     *
     * @param commitIdStr
     * @throws ServiceException
     * @throws IOException
     */
private void syncToCommitId(String commitIdStr) throws ServiceException, IOException {
    assert (mBufferedCommits != null);
    assert (!Thread.holdsLock(this));
    //
    // Step one, go through the redo logs and get the redo logs set of mailboxes
    //
    RedoLogManager rmgr = RedoLogProvider.getInstance().getRedoLogManager();
    CommitId cid = CommitId.decodeFromString(commitIdStr);
    Pair<Set<Integer>, CommitId> changes = rmgr.getChangedMailboxesSince(cid);
    if (changes == null) {
        throw ServiceException.FAILURE("Unable to sync to commit id " + commitIdStr, null);
    }
    Set<Integer> mailboxes = changes.getFirst();
    for (Integer id : mailboxes) {
        try {
            Mailbox mbox = MailboxManager.getInstance().getMailboxById(id);
            if (mbox != null) {
                String accountId = mbox.getAccountId();
                synchronized (this) {
                    mCurrentSignalledSessions.add(accountId);
                }
            }
        } catch (ServiceException e) {
            ZimbraLog.session.warn("AllAccountsWaitSet skipping notification of mailbox id %d because we could not fetch it", id, e);
        }
    }
    mNextSeqNo = changes.getSecond().encodeToString();
    //
    synchronized (this) {
        for (Pair<String, String> /*commitId*/
        p : mBufferedCommits) {
            mCurrentSignalledSessions.add(p.getFirst());
            mNextSeqNo = p.getSecond();
        }
        // no more buffering!
        mBufferedCommits = null;
        if (mCurrentSignalledSessions.size() > 0) {
            trySendData();
        }
    }
}
Also used : Set(java.util.Set) EnumSet(java.util.EnumSet) Mailbox(com.zimbra.cs.mailbox.Mailbox) ServiceException(com.zimbra.common.service.ServiceException) CommitId(com.zimbra.cs.redolog.CommitId) RedoLogManager(com.zimbra.cs.redolog.RedoLogManager)

Aggregations

ServiceException (com.zimbra.common.service.ServiceException)1 Mailbox (com.zimbra.cs.mailbox.Mailbox)1 CommitId (com.zimbra.cs.redolog.CommitId)1 RedoLogManager (com.zimbra.cs.redolog.RedoLogManager)1 EnumSet (java.util.EnumSet)1 Set (java.util.Set)1