Search in sources :

Example 41 with NodeDocument

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

the class RDBDocumentSerializerTest method testSimpleString.

@Test
public void testSimpleString() {
    RDBRow row = new RDBRow("_foo", 1L, true, 1l, 2l, 3l, "{}", null);
    NodeDocument doc = this.ser.fromRow(Collection.NODES, row);
    assertEquals("_foo", doc.getId());
    assertEquals(true, doc.hasBinary());
    assertEquals(true, doc.get(NodeDocument.DELETED_ONCE));
    assertEquals(2L, doc.getModCount().longValue());
}
Also used : NodeDocument(org.apache.jackrabbit.oak.plugins.document.NodeDocument) Test(org.junit.Test)

Example 42 with NodeDocument

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

the class UtilsTest method alignWithExternalRevisions.

@Test
public void alignWithExternalRevisions() throws Exception {
    Clock c = new Clock.Virtual();
    c.waitUntil(System.currentTimeMillis());
    // past
    Revision lastRev1 = new Revision(c.getTime() - 1000, 0, 1);
    // future
    Revision lastRev2 = new Revision(c.getTime() + 1000, 0, 2);
    // create a root document
    NodeDocument doc = new NodeDocument(new MemoryDocumentStore(), c.getTime());
    UpdateOp op = new UpdateOp(Utils.getIdFromPath("/"), true);
    NodeDocument.setLastRev(op, lastRev1);
    NodeDocument.setLastRev(op, lastRev2);
    UpdateUtils.applyChanges(doc, op);
    // must not wait even if revision is in the future
    Utils.alignWithExternalRevisions(doc, c, 2);
    assertThat(c.getTime(), is(lessThan(lastRev2.getTimestamp())));
    // must wait until after lastRev2 timestamp
    Utils.alignWithExternalRevisions(doc, c, 1);
    assertThat(c.getTime(), is(greaterThan(lastRev2.getTimestamp())));
}
Also used : Revision(org.apache.jackrabbit.oak.plugins.document.Revision) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) UpdateOp(org.apache.jackrabbit.oak.plugins.document.UpdateOp) Clock(org.apache.jackrabbit.oak.stats.Clock) NodeDocument(org.apache.jackrabbit.oak.plugins.document.NodeDocument) Test(org.junit.Test)

Example 43 with NodeDocument

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

the class RecoveryCommand method execute.

@Override
public void execute(String... args) throws Exception {
    MapFactory.setInstance(new MapDBMapFactory());
    Closer closer = Closer.create();
    String h = "recovery mongodb://host:port/database { dryRun }";
    try {
        NodeStore store = Utils.bootstrapNodeStore(args, closer, h);
        if (!(store instanceof DocumentNodeStore)) {
            System.err.println("Recovery only available for DocumentNodeStore");
            System.exit(1);
        }
        DocumentNodeStore dns = (DocumentNodeStore) store;
        if (!(dns.getDocumentStore() instanceof MongoDocumentStore)) {
            System.err.println("Recovery only available for MongoDocumentStore");
            System.exit(1);
        }
        MongoDocumentStore docStore = (MongoDocumentStore) dns.getDocumentStore();
        LastRevRecoveryAgent agent = new LastRevRecoveryAgent(dns);
        MongoMissingLastRevSeeker seeker = new MongoMissingLastRevSeeker(docStore, dns.getClock());
        CloseableIterable<NodeDocument> docs = seeker.getCandidates(0);
        closer.register(docs);
        boolean dryRun = Arrays.asList(args).contains("dryRun");
        agent.recover(docs, dns.getClusterId(), dryRun);
    } catch (Throwable e) {
        throw closer.rethrow(e);
    } finally {
        closer.close();
    }
}
Also used : Closer(com.google.common.io.Closer) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MapDBMapFactory(org.apache.jackrabbit.oak.plugins.document.util.MapDBMapFactory) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) LastRevRecoveryAgent(org.apache.jackrabbit.oak.plugins.document.LastRevRecoveryAgent) NodeDocument(org.apache.jackrabbit.oak.plugins.document.NodeDocument) MongoDocumentStore(org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore) MongoMissingLastRevSeeker(org.apache.jackrabbit.oak.plugins.document.mongo.MongoMissingLastRevSeeker)

Aggregations

NodeDocument (org.apache.jackrabbit.oak.plugins.document.NodeDocument)43 Test (org.junit.Test)14 Lock (java.util.concurrent.locks.Lock)11 UpdateOp (org.apache.jackrabbit.oak.plugins.document.UpdateOp)8 DBObject (com.mongodb.DBObject)6 ArrayList (java.util.ArrayList)6 Nonnull (javax.annotation.Nonnull)6 DocumentStoreException (org.apache.jackrabbit.oak.plugins.document.DocumentStoreException)6 BasicDBObject (com.mongodb.BasicDBObject)5 ExecutionException (java.util.concurrent.ExecutionException)5 Stopwatch (com.google.common.base.Stopwatch)4 DBCollection (com.mongodb.DBCollection)4 Revision (org.apache.jackrabbit.oak.plugins.document.Revision)4 DBCursor (com.mongodb.DBCursor)3 QueryBuilder (com.mongodb.QueryBuilder)3 Callable (java.util.concurrent.Callable)3 AbstractDocumentStoreTest (org.apache.jackrabbit.oak.plugins.document.AbstractDocumentStoreTest)3 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)2 MongoException (com.mongodb.MongoException)2 ReadPreference (com.mongodb.ReadPreference)2