Search in sources :

Example 1 with MissingLastRevSeeker

use of org.apache.jackrabbit.oak.plugins.document.MissingLastRevSeeker in project jackrabbit-oak by apache.

the class MongoMissingLastRevSeekerTest method completeResult.

@Test
public void completeResult() throws Exception {
    final int NUM_DOCS = 200;
    // populate the store
    List<UpdateOp> ops = Lists.newArrayList();
    for (int i = 0; i < NUM_DOCS; i++) {
        UpdateOp op = new UpdateOp(getIdFromPath("/node-" + i), true);
        NodeDocument.setModified(op, new Revision(i * 5000, 0, 1));
        ops.add(op);
    }
    assertTrue(store.create(NODES, ops));
    Set<String> ids = Sets.newHashSet();
    boolean updated = false;
    MissingLastRevSeeker seeker = builder.createMissingLastRevSeeker();
    for (NodeDocument doc : seeker.getCandidates(0)) {
        if (!updated) {
            // as soon as we have the first document, update /node-0
            UpdateOp op = new UpdateOp(getIdFromPath("/node-0"), false);
            // and push out the _modified timestamp
            NodeDocument.setModified(op, new Revision(NUM_DOCS * 5000, 0, 1));
            // even after the update the document matches the query
            assertNotNull(store.findAndUpdate(NODES, op));
            updated = true;
        }
        if (doc.getPath().startsWith("/node-")) {
            ids.add(doc.getId());
        }
    }
    // seeker must return all documents
    assertEquals(NUM_DOCS, ids.size());
}
Also used : Revision(org.apache.jackrabbit.oak.plugins.document.Revision) UpdateOp(org.apache.jackrabbit.oak.plugins.document.UpdateOp) MissingLastRevSeeker(org.apache.jackrabbit.oak.plugins.document.MissingLastRevSeeker) NodeDocument(org.apache.jackrabbit.oak.plugins.document.NodeDocument) Test(org.junit.Test)

Example 2 with MissingLastRevSeeker

use of org.apache.jackrabbit.oak.plugins.document.MissingLastRevSeeker in project jackrabbit-oak by apache.

the class RevisionsCommand method sweep.

private void sweep(RevisionsOptions options, Closer closer) throws IOException {
    int clusterId = options.getClusterId();
    if (clusterId <= 0) {
        System.err.println("clusterId option is required for " + RevisionsOptions.CMD_SWEEP + " command");
        return;
    }
    DocumentMK.Builder builder = createDocumentMKBuilder(options, closer);
    if (builder == null) {
        System.err.println("revisions mode only available for DocumentNodeStore");
        return;
    }
    DocumentStore store = builder.getDocumentStore();
    // cluster node must be inactive
    for (ClusterNodeInfoDocument doc : ClusterNodeInfoDocument.all(store)) {
        if (doc.getClusterId() == clusterId && doc.isActive()) {
            System.err.println("cannot sweep revisions for active " + "clusterId " + clusterId);
            return;
        }
    }
    // the root document must have a _lastRev entry for the clusterId
    if (!getRootDocument(store).getLastRev().containsKey(clusterId)) {
        System.err.println("store does not have changes with " + "clusterId " + clusterId);
        return;
    }
    builder.setReadOnlyMode();
    DocumentNodeStore ns = builder.getNodeStore();
    closer.register(asCloseable(ns));
    MissingLastRevSeeker seeker = builder.createMissingLastRevSeeker();
    SweepHelper.sweep(store, new RevisionContextWrapper(ns, clusterId), seeker);
}
Also used : ClusterNodeInfoDocument(org.apache.jackrabbit.oak.plugins.document.ClusterNodeInfoDocument) DocumentStore(org.apache.jackrabbit.oak.plugins.document.DocumentStore) RevisionContextWrapper(org.apache.jackrabbit.oak.plugins.document.RevisionContextWrapper) MissingLastRevSeeker(org.apache.jackrabbit.oak.plugins.document.MissingLastRevSeeker) DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore)

Aggregations

MissingLastRevSeeker (org.apache.jackrabbit.oak.plugins.document.MissingLastRevSeeker)2 ClusterNodeInfoDocument (org.apache.jackrabbit.oak.plugins.document.ClusterNodeInfoDocument)1 DocumentMK (org.apache.jackrabbit.oak.plugins.document.DocumentMK)1 DocumentNodeStore (org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore)1 DocumentStore (org.apache.jackrabbit.oak.plugins.document.DocumentStore)1 NodeDocument (org.apache.jackrabbit.oak.plugins.document.NodeDocument)1 Revision (org.apache.jackrabbit.oak.plugins.document.Revision)1 RevisionContextWrapper (org.apache.jackrabbit.oak.plugins.document.RevisionContextWrapper)1 UpdateOp (org.apache.jackrabbit.oak.plugins.document.UpdateOp)1 Test (org.junit.Test)1