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();
}
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();
}
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");
}
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();
}
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());
}
Aggregations