Search in sources :

Example 11 with Clock

use of org.apache.jackrabbit.oak.stats.Clock in project jackrabbit-oak by apache.

the class DocumentNodeStoreIT method modifiedResetWithDiff.

@Test
public void modifiedResetWithDiff() throws Exception {
    Clock clock = new Clock.Virtual();
    clock.waitUntil(System.currentTimeMillis());
    Revision.setClock(clock);
    DocumentStore docStore = new TimingDocumentStoreWrapper(ds) {

        @Override
        public void dispose() {
        // do not dispose yet
        }
    };
    DocumentNodeStore ns1 = new DocumentMK.Builder().setDocumentStore(docStore).setClusterId(1).setAsyncDelay(0).clock(clock).setDiffCache(AmnesiaDiffCache.INSTANCE).getNodeStore();
    NodeBuilder builder1 = ns1.getRoot().builder();
    builder1.child("node");
    removeMe.add(getIdFromPath("/node"));
    for (int i = 0; i < DocumentMK.MANY_CHILDREN_THRESHOLD; i++) {
        builder1.child("node-" + i);
        removeMe.add(getIdFromPath("/node/node-" + i));
    }
    ns1.merge(builder1, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    // make sure commit is visible to other node store instance
    ns1.runBackgroundOperations();
    DocumentNodeStore ns2 = new DocumentMK.Builder().setDocumentStore(docStore).setClusterId(2).setAsyncDelay(0).clock(clock).getNodeStore();
    NodeBuilder builder2 = ns2.getRoot().builder();
    builder2.child("node").child("child-a");
    removeMe.add(getIdFromPath("/node/child-a"));
    ns2.merge(builder2, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    // wait at least _modified resolution. in reality the wait may
    // not be necessary. e.g. when the clock passes the resolution boundary
    // exactly at this time
    clock.waitUntil(System.currentTimeMillis() + SECONDS.toMillis(MODIFIED_IN_SECS_RESOLUTION + 1));
    builder1 = ns1.getRoot().builder();
    builder1.child("node").child("child-b");
    removeMe.add(getIdFromPath("/node/child-b"));
    ns1.merge(builder1, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    // remember root for diff
    DocumentNodeState root1 = ns1.getRoot();
    builder1 = root1.builder();
    builder1.child("node").child("child-c");
    removeMe.add(getIdFromPath("/node/child-c"));
    ns1.merge(builder1, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    // remember root for diff
    DocumentNodeState root2 = ns1.getRoot();
    ns1.runBackgroundOperations();
    ns2.runBackgroundOperations();
    JsopDiff diff = new JsopDiff("", 0);
    ns1.compare(root2, root1, diff);
    // must report /node as changed
    assertEquals("^\"node\":{}", diff.toString());
    ns1.dispose();
    ns2.dispose();
}
Also used : TimingDocumentStoreWrapper(org.apache.jackrabbit.oak.plugins.document.util.TimingDocumentStoreWrapper) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) JsopDiff(org.apache.jackrabbit.oak.json.JsopDiff) Clock(org.apache.jackrabbit.oak.stats.Clock) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 12 with Clock

use of org.apache.jackrabbit.oak.stats.Clock in project jackrabbit-oak by apache.

the class DocumentNodeStoreSweepIT method crashAndRestart.

private static DocumentNodeStore crashAndRestart(DocumentNodeStore ns, FailingDocumentStore store) {
    DocumentStore s = ns.getDocumentStore();
    BlobStore bs = ns.getBlobStore();
    int clusterId = ns.getClusterId();
    int asyncDelay = ns.getAsyncDelay();
    Clock clock = ns.getClock();
    crash(ns, store);
    return new DocumentMK.Builder().setBlobStore(bs).setDocumentStore(s).setClusterId(clusterId).clock(clock).setAsyncDelay(asyncDelay).setLeaseCheck(false).getNodeStore();
}
Also used : Clock(org.apache.jackrabbit.oak.stats.Clock) BlobStore(org.apache.jackrabbit.oak.spi.blob.BlobStore)

Example 13 with Clock

use of org.apache.jackrabbit.oak.stats.Clock in project jackrabbit-oak by apache.

the class DocumentNodeStoreTest method diffMany.

// OAK-1970
@Test
public void diffMany() throws Exception {
    // make sure diffMany is used and not the new
    // journal diff introduced with OAK-4528
    System.setProperty("oak.disableJournalDiff", "true");
    Clock clock = new Clock.Virtual();
    clock.waitUntil(System.currentTimeMillis());
    Revision.setClock(clock);
    final List<Long> startValues = Lists.newArrayList();
    MemoryDocumentStore ds = new MemoryDocumentStore() {

        @Nonnull
        @Override
        public <T extends Document> List<T> query(Collection<T> collection, String fromKey, String toKey, String indexedProperty, long startValue, int limit) {
            if (indexedProperty != null) {
                startValues.add(startValue);
            }
            return super.query(collection, fromKey, toKey, indexedProperty, startValue, limit);
        }
    };
    DocumentNodeStore ns = builderProvider.newBuilder().clock(clock).setDocumentStore(ds).setAsyncDelay(0).getNodeStore();
    NodeBuilder builder = ns.getRoot().builder();
    NodeBuilder test = builder.child("test");
    for (int i = 0; i < DocumentMK.MANY_CHILDREN_THRESHOLD * 2; i++) {
        test.child("node-" + i);
    }
    merge(ns, builder);
    // 'wait one hour'
    clock.waitUntil(clock.getTime() + TimeUnit.HOURS.toMillis(1));
    // perform a change and use the resulting root as before state
    builder = ns.getRoot().builder();
    builder.child("foo");
    DocumentNodeState before = asDocumentNodeState(merge(ns, builder));
    NodeState beforeTest = before.getChildNode("test");
    // perform another change to span the diff across multiple revisions
    // this will prevent diff calls served from the local cache
    builder = ns.getRoot().builder();
    builder.child("bar");
    merge(ns, builder);
    // add a child node
    builder = ns.getRoot().builder();
    builder.child("test").child("bar");
    NodeState after = merge(ns, builder);
    NodeState afterTest = after.getChildNode("test");
    startValues.clear();
    // make sure diff is not served from node children cache entries
    ns.invalidateNodeChildrenCache();
    afterTest.compareAgainstBaseState(beforeTest, new DefaultNodeStateDiff());
    assertEquals(1, startValues.size());
    Revision localHead = before.getRootRevision().getRevision(ns.getClusterId());
    assertNotNull(localHead);
    long beforeModified = getModifiedInSecs(localHead.getTimestamp());
    // startValue must be based on the revision of the before state
    // and not when '/test' was last modified
    assertEquals(beforeModified, (long) startValues.get(0));
    System.clearProperty("oak.disableJournalDiff");
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) Clock(org.apache.jackrabbit.oak.stats.Clock) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) CONSTRAINT(org.apache.jackrabbit.oak.api.CommitFailedException.CONSTRAINT) DefaultNodeStateDiff(org.apache.jackrabbit.oak.spi.state.DefaultNodeStateDiff) AtomicLong(java.util.concurrent.atomic.AtomicLong) Test(org.junit.Test)

Example 14 with Clock

use of org.apache.jackrabbit.oak.stats.Clock in project jackrabbit-oak by apache.

the class LastRevRecoveryTest method setUp.

@Before
public void setUp() throws Exception {
    clock = new Clock.Virtual();
    clock.waitUntil(System.currentTimeMillis());
    Revision.setClock(clock);
    ClusterNodeInfo.setClock(clock);
    // disable lease check because we fiddle with the virtual clock
    final boolean leaseCheck = false;
    sharedStore = new MemoryDocumentStore();
    ds1 = builderProvider.newBuilder().clock(clock).setLeaseCheck(leaseCheck).setAsyncDelay(0).setDocumentStore(sharedStore).setClusterId(1).getNodeStore();
    c1Id = ds1.getClusterId();
    ds2 = builderProvider.newBuilder().clock(clock).setLeaseCheck(leaseCheck).setAsyncDelay(0).setDocumentStore(sharedStore).setClusterId(2).getNodeStore();
    c2Id = ds2.getClusterId();
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) Clock(org.apache.jackrabbit.oak.stats.Clock) Before(org.junit.Before)

Example 15 with Clock

use of org.apache.jackrabbit.oak.stats.Clock in project jackrabbit-oak by apache.

the class AsyncIndexUpdateTest method cpCleanupOrphaned.

// OAK-4826
@Test
public void cpCleanupOrphaned() throws Exception {
    Clock clock = Clock.SIMPLE;
    MemoryNodeStore store = new MemoryNodeStore();
    // prepare index and initial content
    NodeBuilder builder = store.getRoot().builder();
    createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null).setProperty(ASYNC_PROPERTY_NAME, "async");
    builder.child("testRoot").setProperty("foo", "abc");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    assertTrue("Expecting no checkpoints", store.listCheckpoints().size() == 0);
    IndexEditorProvider provider = new PropertyIndexEditorProvider();
    AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider);
    async.run();
    assertTrue("Expecting one checkpoint", store.listCheckpoints().size() == 1);
    String cp = store.listCheckpoints().iterator().next();
    Map<String, String> info = store.checkpointInfo(cp);
    builder = store.getRoot().builder();
    builder.child("testRoot").setProperty("foo", "def");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    // wait until currentTimeMillis() changes. this ensures
    // the created value for the checkpoint is different
    // from the previous checkpoint.
    clock.waitUntil(clock.getTime() + 1);
    async.run();
    assertTrue("Expecting one checkpoint", store.listCheckpoints().size() == 1);
    cp = store.listCheckpoints().iterator().next();
    // create a new checkpoint with the info from the first checkpoint
    // this simulates an orphaned checkpoint that should be cleaned up.
    // the created timestamp is set back in time because cleanup preserves
    // checkpoints within the lease time frame.
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(clock.getTime() - 2 * async.getLeaseTimeOut());
    info.put("created", ISO8601.format(c));
    assertNotNull(store.checkpoint(TimeUnit.HOURS.toMillis(1), info));
    assertTrue("Expecting two checkpoints", store.listCheckpoints().size() == 2);
    async.cleanUpCheckpoints();
    assertTrue("Expecting one checkpoint", store.listCheckpoints().size() == 1);
    assertEquals(cp, store.listCheckpoints().iterator().next());
}
Also used : MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) Calendar(java.util.Calendar) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Clock(org.apache.jackrabbit.oak.stats.Clock) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Aggregations

Clock (org.apache.jackrabbit.oak.stats.Clock)39 Test (org.junit.Test)24 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)21 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)19 Before (org.junit.Before)8 ChildNodeEntry (org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)3 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)2 BlobStore (org.apache.jackrabbit.oak.spi.blob.BlobStore)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 Calendar (java.util.Calendar)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 InitialContent (org.apache.jackrabbit.oak.InitialContent)1 Oak (org.apache.jackrabbit.oak.Oak)1 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)1 CONSTRAINT (org.apache.jackrabbit.oak.api.CommitFailedException.CONSTRAINT)1