Search in sources :

Example 16 with Key

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

the class DocumentStoreStatsIT method removeConditional.

@Test
public void removeConditional() throws Exception {
    Revision r = Revision.newRevision(1);
    Key modified = new Key(MODIFIED_IN_SECS, null);
    Condition c = newEqualsCondition(getModifiedInSecs(r.getTimestamp()));
    Map<String, Map<Key, Condition>> ids = Maps.newHashMap();
    for (int i = 0; i < 10; i++) {
        String id = testName.getMethodName() + "-" + i;
        ids.put(id, singletonMap(modified, c));
        UpdateOp up = new UpdateOp(id, true);
        NodeDocument.setModified(up, r);
        ds.create(Collection.NODES, singletonList(up));
        removeMe.add(id);
    }
    DocumentStoreStatsCollector coll = mock(DocumentStoreStatsCollector.class);
    configureStatsCollector(coll);
    ds.remove(Collection.NODES, ids);
    verify(coll).doneRemove(anyLong(), eq(Collection.NODES), eq(10));
}
Also used : Condition.newEqualsCondition(org.apache.jackrabbit.oak.plugins.document.UpdateOp.Condition.newEqualsCondition) Condition(org.apache.jackrabbit.oak.plugins.document.UpdateOp.Condition) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Key(org.apache.jackrabbit.oak.plugins.document.UpdateOp.Key) Test(org.junit.Test)

Example 17 with Key

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

the class DocumentNodeStoreTest method failFastOnBranchConflict.

@Test
public void failFastOnBranchConflict() throws Exception {
    final AtomicInteger mergeAttempts = new AtomicInteger();
    MemoryDocumentStore store = new MemoryDocumentStore() {

        @Override
        public <T extends Document> T findAndUpdate(Collection<T> collection, UpdateOp update) {
            for (Key k : update.getConditions().keySet()) {
                if (k.getName().equals(NodeDocument.COLLISIONS)) {
                    mergeAttempts.incrementAndGet();
                    break;
                }
            }
            return super.findAndUpdate(collection, update);
        }
    };
    DocumentNodeStore ds = builderProvider.newBuilder().setDocumentStore(store).setAsyncDelay(0).getNodeStore();
    DocumentNodeState root = ds.getRoot();
    DocumentNodeStoreBranch b = ds.createBranch(root);
    // branch state is now Unmodified
    NodeBuilder builder = root.builder();
    builder.child("foo");
    b.setRoot(builder.getNodeState());
    // branch state is now InMemory
    for (int i = 0; i < DocumentMK.UPDATE_LIMIT; i++) {
        builder.child("bar").setProperty("p-" + i, "foo");
    }
    b.setRoot(builder.getNodeState());
    // branch state is now Persisted
    // create conflict with persisted branch
    NodeBuilder nb = ds.getRoot().builder();
    nb.child("bar").setProperty("p", "bar");
    merge(ds, nb);
    mergeAttempts.set(0);
    try {
        b.merge(EmptyHook.INSTANCE, CommitInfo.EMPTY);
        fail("must fail with CommitFailedException");
    } catch (CommitFailedException e) {
    // expected
    }
    assertTrue("too many merge attempts: " + mergeAttempts.get(), mergeAttempts.get() <= 1);
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Key(org.apache.jackrabbit.oak.plugins.document.UpdateOp.Key) Test(org.junit.Test)

Example 18 with Key

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

the class NodeDocumentSweeperTest method sweepUncommittedBeforeHead.

@Test
public void sweepUncommittedBeforeHead() throws Exception {
    Revision uncommitted = ns.newRevision();
    NodeBuilder b = ns.getRoot().builder();
    b.child("test");
    merge(ns, b);
    ns.runBackgroundUpdateOperations();
    UpdateOp op = new UpdateOp(getIdFromPath("/test"), false);
    op.setMapEntry("foo", uncommitted, "value");
    setCommitRoot(op, uncommitted, 0);
    setModified(op, uncommitted);
    assertNotNull(store.findAndUpdate(NODES, op));
    List<UpdateOp> ops = Lists.newArrayList();
    Revision nextSweepStart = sweep(ops);
    assertEquals(ns.getHeadRevision().getRevision(ns.getClusterId()), nextSweepStart);
    assertEquals(1, ops.size());
    op = ops.get(0);
    Map<Key, Operation> changes = op.getChanges();
    assertEquals(2, changes.size());
    Operation o = changes.get(new Key(COMMIT_ROOT, uncommitted));
    assertNotNull(o);
    assertEquals(REMOVE_MAP_ENTRY, o.type);
    o = changes.get(new Key("foo", uncommitted));
    assertNotNull(o);
    assertEquals(REMOVE_MAP_ENTRY, o.type);
}
Also used : Operation(org.apache.jackrabbit.oak.plugins.document.UpdateOp.Operation) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Key(org.apache.jackrabbit.oak.plugins.document.UpdateOp.Key) Test(org.junit.Test)

Example 19 with Key

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

the class NodeDocumentSweeperTest method updatePre18Branch.

@Test
public void updatePre18Branch() throws Exception {
    String branchRev = mk.branch(null);
    branchRev = mk.commit("/", "+\"foo\":{}", branchRev, null);
    mk.merge(branchRev, null);
    ns.runBackgroundUpdateOperations();
    // simulate a pre 1.8 branch commit by removing the branch commit entry
    NodeDocument doc = store.find(NODES, getIdFromPath("/foo"));
    assertNotNull(doc);
    assertEquals(1, doc.getLocalBranchCommits().size());
    UpdateOp op = new UpdateOp(doc.getId(), false);
    for (Revision r : doc.getLocalBranchCommits()) {
        NodeDocument.removeBranchCommit(op, r);
    }
    assertNotNull(store.findAndUpdate(NODES, op));
    List<UpdateOp> ops = Lists.newArrayList();
    Revision nextSweepStart = sweep(ops);
    assertEquals(ns.getHeadRevision().getRevision(ns.getClusterId()), nextSweepStart);
    assertEquals(1, ops.size());
    op = ops.get(0);
    Map<Key, Operation> changes = op.getChanges();
    assertEquals(1, changes.size());
    Key k = changes.keySet().iterator().next();
    assertEquals("_bc", k.getName());
    assertEquals(SET_MAP_ENTRY, changes.get(k).type);
}
Also used : Operation(org.apache.jackrabbit.oak.plugins.document.UpdateOp.Operation) Key(org.apache.jackrabbit.oak.plugins.document.UpdateOp.Key) Test(org.junit.Test)

Aggregations

Key (org.apache.jackrabbit.oak.plugins.document.UpdateOp.Key)19 Map (java.util.Map)12 Operation (org.apache.jackrabbit.oak.plugins.document.UpdateOp.Operation)12 Test (org.junit.Test)8 TreeMap (java.util.TreeMap)6 Condition (org.apache.jackrabbit.oak.plugins.document.UpdateOp.Condition)6 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)5 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)5 HashMap (java.util.HashMap)4 DocumentStoreException (org.apache.jackrabbit.oak.plugins.document.DocumentStoreException)4 Stopwatch (com.google.common.base.Stopwatch)3 BasicDBObject (com.mongodb.BasicDBObject)3 Nonnull (javax.annotation.Nonnull)3 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 BulkWriteOperation (com.mongodb.BulkWriteOperation)2 DBCollection (com.mongodb.DBCollection)2 DBObject (com.mongodb.DBObject)2 MongoException (com.mongodb.MongoException)2 QueryBuilder (com.mongodb.QueryBuilder)2