Search in sources :

Example 1 with ChangeLogRecord

use of org.apache.jackrabbit.core.cluster.ChangeLogRecord in project jackrabbit by apache.

the class SearchIndex method getChangeLogRecords.

/**
 * Polls the underlying journal for events of the type ChangeLogRecord that
 * happened after a given revision, on a given workspace.
 *
 * @param revision
 *            starting revision
 * @param workspace
 *            the workspace name
 * @return
 */
private List<ChangeLogRecord> getChangeLogRecords(long revision, final String workspace) {
    log.debug("Get changes from the Journal for revision {} and workspace {}.", revision, workspace);
    ClusterNode cn = getContext().getClusterNode();
    if (cn == null) {
        return Collections.emptyList();
    }
    Journal journal = cn.getJournal();
    final List<ChangeLogRecord> events = new ArrayList<ChangeLogRecord>();
    ClusterRecordDeserializer deserializer = new ClusterRecordDeserializer();
    RecordIterator records = null;
    try {
        records = journal.getRecords(revision);
        while (records.hasNext()) {
            Record record = records.nextRecord();
            if (!record.getProducerId().equals(cn.getId())) {
                continue;
            }
            ClusterRecord r = null;
            try {
                r = deserializer.deserialize(record);
            } catch (JournalException e) {
                log.error("Unable to read revision '" + record.getRevision() + "'.", e);
            }
            if (r == null) {
                continue;
            }
            r.process(new ClusterRecordProcessor() {

                public void process(ChangeLogRecord record) {
                    String eventW = record.getWorkspace();
                    if (eventW != null ? eventW.equals(workspace) : workspace == null) {
                        events.add(record);
                    }
                }

                public void process(LockRecord record) {
                }

                public void process(NamespaceRecord record) {
                }

                public void process(NodeTypeRecord record) {
                }

                public void process(PrivilegeRecord record) {
                }

                public void process(WorkspaceRecord record) {
                }
            });
        }
    } catch (JournalException e1) {
        log.error(e1.getMessage(), e1);
    } finally {
        if (records != null) {
            records.close();
        }
    }
    return events;
}
Also used : ClusterNode(org.apache.jackrabbit.core.cluster.ClusterNode) RecordIterator(org.apache.jackrabbit.core.journal.RecordIterator) ClusterRecord(org.apache.jackrabbit.core.cluster.ClusterRecord) JournalException(org.apache.jackrabbit.core.journal.JournalException) ArrayList(java.util.ArrayList) LockRecord(org.apache.jackrabbit.core.cluster.LockRecord) NamespaceRecord(org.apache.jackrabbit.core.cluster.NamespaceRecord) Journal(org.apache.jackrabbit.core.journal.Journal) ClusterRecordDeserializer(org.apache.jackrabbit.core.cluster.ClusterRecordDeserializer) WorkspaceRecord(org.apache.jackrabbit.core.cluster.WorkspaceRecord) NodeTypeRecord(org.apache.jackrabbit.core.cluster.NodeTypeRecord) PrivilegeRecord(org.apache.jackrabbit.core.cluster.PrivilegeRecord) ClusterRecordProcessor(org.apache.jackrabbit.core.cluster.ClusterRecordProcessor) ChangeLogRecord(org.apache.jackrabbit.core.cluster.ChangeLogRecord) ClusterRecord(org.apache.jackrabbit.core.cluster.ClusterRecord) Record(org.apache.jackrabbit.core.journal.Record) NamespaceRecord(org.apache.jackrabbit.core.cluster.NamespaceRecord) ChangeLogRecord(org.apache.jackrabbit.core.cluster.ChangeLogRecord) PrivilegeRecord(org.apache.jackrabbit.core.cluster.PrivilegeRecord) NodeTypeRecord(org.apache.jackrabbit.core.cluster.NodeTypeRecord) LockRecord(org.apache.jackrabbit.core.cluster.LockRecord) WorkspaceRecord(org.apache.jackrabbit.core.cluster.WorkspaceRecord)

Example 2 with ChangeLogRecord

use of org.apache.jackrabbit.core.cluster.ChangeLogRecord in project jackrabbit by apache.

the class SearchIndex method checkPendingJournalChanges.

/**
 * In the case of an initial index build operation, this checks if there are
 * some new nodes pending in the journal and tries to preemptively delete
 * them, to keep the index consistent.
 *
 * See JCR-3162
 *
 * @param context
 * @throws IOException
 */
private void checkPendingJournalChanges(QueryHandlerContext context) {
    ClusterNode cn = context.getClusterNode();
    if (cn == null) {
        return;
    }
    List<NodeId> addedIds = new ArrayList<NodeId>();
    long rev = cn.getRevision();
    List<ChangeLogRecord> changes = getChangeLogRecords(rev, context.getWorkspace());
    Iterator<ChangeLogRecord> iterator = changes.iterator();
    while (iterator.hasNext()) {
        ChangeLogRecord record = iterator.next();
        for (ItemState state : record.getChanges().addedStates()) {
            if (!state.isNode()) {
                continue;
            }
            addedIds.add((NodeId) state.getId());
        }
    }
    if (!addedIds.isEmpty()) {
        Collection<NodeState> empty = Collections.emptyList();
        try {
            updateNodes(addedIds.iterator(), empty.iterator());
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
}
Also used : ClusterNode(org.apache.jackrabbit.core.cluster.ClusterNode) NodeState(org.apache.jackrabbit.core.state.NodeState) ItemState(org.apache.jackrabbit.core.state.ItemState) NodeId(org.apache.jackrabbit.core.id.NodeId) ArrayList(java.util.ArrayList) ChangeLogRecord(org.apache.jackrabbit.core.cluster.ChangeLogRecord) FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) SAXException(org.xml.sax.SAXException) JournalException(org.apache.jackrabbit.core.journal.JournalException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) RepositoryException(javax.jcr.RepositoryException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) InvalidQueryException(javax.jcr.query.InvalidQueryException)

Aggregations

ArrayList (java.util.ArrayList)2 ChangeLogRecord (org.apache.jackrabbit.core.cluster.ChangeLogRecord)2 ClusterNode (org.apache.jackrabbit.core.cluster.ClusterNode)2 JournalException (org.apache.jackrabbit.core.journal.JournalException)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 RepositoryException (javax.jcr.RepositoryException)1 InvalidQueryException (javax.jcr.query.InvalidQueryException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 ClusterRecord (org.apache.jackrabbit.core.cluster.ClusterRecord)1 ClusterRecordDeserializer (org.apache.jackrabbit.core.cluster.ClusterRecordDeserializer)1 ClusterRecordProcessor (org.apache.jackrabbit.core.cluster.ClusterRecordProcessor)1 LockRecord (org.apache.jackrabbit.core.cluster.LockRecord)1 NamespaceRecord (org.apache.jackrabbit.core.cluster.NamespaceRecord)1 NodeTypeRecord (org.apache.jackrabbit.core.cluster.NodeTypeRecord)1 PrivilegeRecord (org.apache.jackrabbit.core.cluster.PrivilegeRecord)1 WorkspaceRecord (org.apache.jackrabbit.core.cluster.WorkspaceRecord)1 FileSystemException (org.apache.jackrabbit.core.fs.FileSystemException)1 NodeId (org.apache.jackrabbit.core.id.NodeId)1 Journal (org.apache.jackrabbit.core.journal.Journal)1