Search in sources :

Example 1 with ClusterNode

use of org.apache.jackrabbit.core.cluster.ClusterNode 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 ClusterNode

use of org.apache.jackrabbit.core.cluster.ClusterNode 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) ArrayList(java.util.ArrayList) NodeId(org.apache.jackrabbit.core.id.NodeId) 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)

Example 3 with ClusterNode

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

the class FileJournalTest method testClusterInitIncompleteMissingParam.

/**
     * Verify that <code>ClusterNode.stop</code> can be invoked even when
     * <code>ClusterNode.init</code> throws because the journal can not
     * be initialized. Note: this is done by omitting the required argument
     * <code>directory</code>.
     *
     * @throws Exception
     */
public void testClusterInitIncompleteMissingParam() throws Exception {
    JournalFactory jf = new JournalFactory() {

        public Journal getJournal(NamespaceResolver resolver) throws RepositoryException {
            try {
                FileJournal journal = new FileJournal();
                // no setDirectory() call here
                journal.init(CLUSTER_NODE_ID, resolver);
                return journal;
            } catch (JournalException e) {
                throw new RepositoryException("Expected failure", e);
            }
        }
    };
    ClusterConfig cc = new ClusterConfig(CLUSTER_NODE_ID, SYNC_DELAY, jf);
    SimpleClusterContext context = new SimpleClusterContext(cc);
    ClusterNode clusterNode = new ClusterNode();
    try {
        clusterNode.init(context);
        fail("Bad cluster configuration.");
    } catch (Exception e) {
    }
    clusterNode.stop();
}
Also used : ClusterNode(org.apache.jackrabbit.core.cluster.ClusterNode) SimpleClusterContext(org.apache.jackrabbit.core.cluster.SimpleClusterContext) NamespaceResolver(org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver) RepositoryException(javax.jcr.RepositoryException) RepositoryException(javax.jcr.RepositoryException) ClusterConfig(org.apache.jackrabbit.core.config.ClusterConfig)

Example 4 with ClusterNode

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

the class ConsistencyCheckerImplTest method createClusterNode.

private ClusterNode createClusterNode(String id) throws Exception {
    final MemoryJournal journal = new MemoryJournal() {

        protected boolean syncAgainOnNewRecords() {
            return true;
        }
    };
    JournalFactory jf = new JournalFactory() {

        public Journal getJournal(NamespaceResolver resolver) throws RepositoryException {
            return journal;
        }
    };
    ClusterConfig cc = new ClusterConfig(id, SYNC_DELAY, jf);
    SimpleClusterContext context = new SimpleClusterContext(cc);
    journal.setRepositoryHome(context.getRepositoryHome());
    journal.init(id, context.getNamespaceResolver());
    journal.setRecords(records);
    ClusterNode clusterNode = new ClusterNode();
    clusterNode.init(context);
    return clusterNode;
}
Also used : JournalFactory(org.apache.jackrabbit.core.journal.JournalFactory) ClusterNode(org.apache.jackrabbit.core.cluster.ClusterNode) SimpleClusterContext(org.apache.jackrabbit.core.cluster.SimpleClusterContext) NamespaceResolver(org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver) MemoryJournal(org.apache.jackrabbit.core.journal.MemoryJournal) ClusterConfig(org.apache.jackrabbit.core.config.ClusterConfig)

Example 5 with ClusterNode

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

the class ConsistencyCheck method doubleCheckErrors.

public void doubleCheckErrors() {
    if (!errors.isEmpty()) {
        log.info("Double checking errors");
        final ClusterNode clusterNode = handler.getContext().getClusterNode();
        if (clusterNode != null) {
            try {
                clusterNode.sync();
            } catch (ClusterException e) {
                log.error("Could not sync cluster node for double checking errors");
            }
        }
        final Iterator<ConsistencyCheckError> iterator = errors.iterator();
        while (iterator.hasNext()) {
            try {
                final ConsistencyCheckError error = iterator.next();
                if (!error.doubleCheck(handler, stateMgr)) {
                    log.info("False positive: " + error.toString());
                    iterator.remove();
                }
            } catch (RepositoryException e) {
                log.error("Failed to double check consistency error", e);
            } catch (IOException e) {
                log.error("Failed to double check consistency error", e);
            }
        }
    }
}
Also used : ClusterNode(org.apache.jackrabbit.core.cluster.ClusterNode) ClusterException(org.apache.jackrabbit.core.cluster.ClusterException) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException)

Aggregations

ClusterNode (org.apache.jackrabbit.core.cluster.ClusterNode)9 RepositoryException (javax.jcr.RepositoryException)6 IOException (java.io.IOException)4 SimpleClusterContext (org.apache.jackrabbit.core.cluster.SimpleClusterContext)4 ClusterConfig (org.apache.jackrabbit.core.config.ClusterConfig)4 NamespaceResolver (org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver)4 ClusterException (org.apache.jackrabbit.core.cluster.ClusterException)3 FileSystemException (org.apache.jackrabbit.core.fs.FileSystemException)3 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)3 ArrayList (java.util.ArrayList)2 AccessDeniedException (javax.jcr.AccessDeniedException)2 LoginException (javax.jcr.LoginException)2 NoSuchWorkspaceException (javax.jcr.NoSuchWorkspaceException)2 ChangeLogRecord (org.apache.jackrabbit.core.cluster.ChangeLogRecord)2 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)2 JournalException (org.apache.jackrabbit.core.journal.JournalException)2 TransactionException (org.apache.jackrabbit.data.core.TransactionException)2 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1