Search in sources :

Example 6 with Clock

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

the class ClusterInfoTest method useAbandoned.

@Test
public void useAbandoned() throws InterruptedException {
    Clock clock = new Clock.Virtual();
    clock.waitUntil(System.currentTimeMillis());
    ClusterNodeInfo.setClock(clock);
    MemoryDocumentStore mem = new MemoryDocumentStore();
    DocumentNodeStore ns1 = new DocumentMK.Builder().setDocumentStore(mem).clock(clock).setAsyncDelay(0).setLeaseCheck(false).getNodeStore();
    DocumentStore ds = ns1.getDocumentStore();
    int cid = ns1.getClusterId();
    ClusterNodeInfoDocument cnid = ds.find(Collection.CLUSTER_NODES, "" + cid);
    assertNotNull(cnid);
    assertEquals(ClusterNodeState.ACTIVE.toString(), cnid.get(ClusterNodeInfo.STATE));
    ns1.dispose();
    long waitFor = 2000;
    // modify record to indicate "active" with a lease end in the future
    UpdateOp up = new UpdateOp("" + cid, false);
    up.set(ClusterNodeInfo.STATE, ClusterNodeState.ACTIVE.toString());
    long now = clock.getTime();
    up.set(ClusterNodeInfo.LEASE_END_KEY, now + waitFor);
    ds.findAndUpdate(Collection.CLUSTER_NODES, up);
    // try restart
    ns1 = new DocumentMK.Builder().setDocumentStore(mem).clock(clock).setAsyncDelay(0).setLeaseCheck(false).getNodeStore();
    assertEquals("should have re-used existing cluster id", cid, ns1.getClusterId());
    ns1.dispose();
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) Clock(org.apache.jackrabbit.oak.stats.Clock) Test(org.junit.Test)

Example 7 with Clock

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

the class ClusterInfoTest method readWriteMode.

@Test
public void readWriteMode() throws InterruptedException {
    MemoryDocumentStore mem = new MemoryDocumentStore();
    Clock clock = new Clock.Virtual();
    clock.waitUntil(System.currentTimeMillis());
    ClusterNodeInfo.setClock(clock);
    DocumentNodeStore ns1 = new DocumentMK.Builder().setDocumentStore(mem).setAsyncDelay(0).setLeaseCheck(false).setClusterId(1).getNodeStore();
    DocumentNodeStore ns2 = new DocumentMK.Builder().setDocumentStore(mem).setAsyncDelay(0).setLeaseCheck(false).setClusterId(2).getNodeStore();
    // Bring the current time forward to after the leaseTime which would have been 
    // updated in the DocumentNodeStore initialization.
    clock.waitUntil(clock.getTime() + ns1.getClusterInfo().getLeaseTime());
    ns1.getClusterInfo().setLeaseTime(0);
    ns1.getClusterInfo().setLeaseUpdateInterval(0);
    ns2.getClusterInfo().setLeaseTime(0);
    ns2.getClusterInfo().setLeaseUpdateInterval(0);
    List<ClusterNodeInfoDocument> list = mem.query(Collection.CLUSTER_NODES, "0", "a", Integer.MAX_VALUE);
    assertEquals(2, list.size());
    assertNull(mem.getReadPreference());
    assertNull(mem.getWriteConcern());
    mem.setReadWriteMode("read:primary, write:majority");
    assertEquals(ReadPreference.primary(), mem.getReadPreference());
    assertEquals(WriteConcern.MAJORITY, mem.getWriteConcern());
    UpdateOp op;
    // unknown modes: ignore
    op = new UpdateOp(list.get(0).getId(), false);
    op.set("readWriteMode", "read:xyz, write:abc");
    mem.findAndUpdate(Collection.CLUSTER_NODES, op);
    ns1.renewClusterIdLease();
    assertEquals(ReadPreference.primary(), mem.getReadPreference());
    assertEquals(WriteConcern.MAJORITY, mem.getWriteConcern());
    op = new UpdateOp(list.get(0).getId(), false);
    op.set("readWriteMode", "read:nearest, write:fsynced");
    mem.findAndUpdate(Collection.CLUSTER_NODES, op);
    ns1.renewClusterIdLease();
    assertEquals(ReadPreference.nearest(), mem.getReadPreference());
    assertEquals(WriteConcern.FSYNCED, mem.getWriteConcern());
    ns1.dispose();
    ns2.dispose();
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) Clock(org.apache.jackrabbit.oak.stats.Clock) Test(org.junit.Test)

Example 8 with Clock

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

the class ClusterInfoTest method renewLease.

@Test
public void renewLease() throws InterruptedException {
    MemoryDocumentStore mem = new MemoryDocumentStore();
    Clock clock = new Clock.Virtual();
    clock.waitUntil(System.currentTimeMillis());
    ClusterNodeInfo.setClock(clock);
    DocumentNodeStore ns = new DocumentMK.Builder().setDocumentStore(mem).setAsyncDelay(0).setLeaseCheck(false).getNodeStore();
    ClusterNodeInfo info = ns.getClusterInfo();
    assertNotNull(info);
    // current lease end
    long leaseEnd = getLeaseEndTime(ns);
    // wait a bit, 1sec less than leaseUpdateTime (10sec-1sec by default)
    clock.waitUntil(clock.getTime() + ClusterNodeInfo.DEFAULT_LEASE_UPDATE_INTERVAL_MILLIS - 1000);
    // must not renew lease right now
    ns.renewClusterIdLease();
    assertEquals(leaseEnd, getLeaseEndTime(ns));
    // wait some more time
    clock.waitUntil(clock.getTime() + 2000);
    // now the lease must be renewed
    ns.renewClusterIdLease();
    assertTrue(getLeaseEndTime(ns) > leaseEnd);
    ns.dispose();
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) Clock(org.apache.jackrabbit.oak.stats.Clock) Test(org.junit.Test)

Example 9 with Clock

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

the class SharedBlobStoreGCTest method setUp.

@Before
public void setUp() throws Exception {
    log.debug("In setUp()");
    clock = new Clock.Virtual();
    clock.waitUntil(Revision.getCurrentTimestamp());
    DataStoreUtils.time = clock.getTime();
    File rootFolder = folder.newFolder();
    BlobStore blobeStore1 = getBlobStore(rootFolder);
    DocumentNodeStore ds1 = new DocumentMK.Builder().setAsyncDelay(0).setDocumentStore(new MemoryDocumentStore()).setBlobStore(blobeStore1).clock(clock).getNodeStore();
    String repoId1 = ClusterRepositoryInfo.getOrCreateId(ds1);
    // Register the unique repository id in the data store
    ((SharedDataStore) blobeStore1).addMetadataRecord(new ByteArrayInputStream(new byte[0]), SharedStoreRecordType.REPOSITORY.getNameFromId(repoId1));
    BlobStore blobeStore2 = getBlobStore(rootFolder);
    DocumentNodeStore ds2 = new DocumentMK.Builder().setAsyncDelay(0).setDocumentStore(new MemoryDocumentStore()).setBlobStore(blobeStore2).clock(clock).getNodeStore();
    String repoId2 = ClusterRepositoryInfo.getOrCreateId(ds2);
    // Register the unique repository id in the data store
    ((SharedDataStore) blobeStore2).addMetadataRecord(new ByteArrayInputStream(new byte[0]), SharedStoreRecordType.REPOSITORY.getNameFromId(repoId2));
    cluster1 = new Cluster(ds1, repoId1, 20);
    cluster1.init();
    log.debug("Initialized {}", cluster1);
    cluster2 = new Cluster(ds2, repoId2, 100);
    cluster2.init();
    log.debug("Initialized {}", cluster2);
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) ByteArrayInputStream(java.io.ByteArrayInputStream) SharedDataStore(org.apache.jackrabbit.oak.plugins.blob.SharedDataStore) Clock(org.apache.jackrabbit.oak.stats.Clock) File(java.io.File) GarbageCollectableBlobStore(org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore) DataStoreBlobStore(org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore) BlobStore(org.apache.jackrabbit.oak.spi.blob.BlobStore) Before(org.junit.Before)

Example 10 with Clock

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

the class DocumentNodeStoreTest method clusterWithClockDifferences.

// OAK-3388
@Test
public void clusterWithClockDifferences() throws Exception {
    MemoryDocumentStore store = new MemoryDocumentStore();
    long now = System.currentTimeMillis();
    Clock c1 = new Clock.Virtual();
    c1.waitUntil(now);
    Revision.setClock(c1);
    DocumentNodeStore ns1 = builderProvider.newBuilder().clock(c1).setDocumentStore(store).setAsyncDelay(0).setClusterId(1).getNodeStore();
    NodeBuilder b1 = ns1.getRoot().builder();
    b1.child("node");
    merge(ns1, b1);
    // make /node visible
    ns1.runBackgroundOperations();
    Revision.resetClockToDefault();
    Clock c2 = new Clock.Virtual();
    // c2 is five seconds ahead
    c2.waitUntil(now + 5000);
    Revision.setClock(c2);
    DocumentNodeStore ns2 = builderProvider.newBuilder().clock(c2).setDocumentStore(store).setAsyncDelay(0).setClusterId(2).getNodeStore();
    // ns2 sees /node
    assertTrue(ns2.getRoot().hasChildNode("node"));
    // remove /node on ns2
    NodeBuilder b2 = ns2.getRoot().builder();
    b2.child("node").remove();
    merge(ns2, b2);
    ns2.runBackgroundOperations();
    // add /node again on ns1
    Revision.resetClockToDefault();
    Revision.setClock(c1);
    ns1.runBackgroundOperations();
    b1 = ns1.getRoot().builder();
    assertFalse(b1.hasChildNode("node"));
    b1.child("node");
    merge(ns1, b1);
    ns1.runBackgroundOperations();
    // check if /node is visible on ns2
    Revision.resetClockToDefault();
    Revision.setClock(c2);
    ns2.runBackgroundOperations();
    b2 = ns2.getRoot().builder();
    assertTrue(b2.hasChildNode("node"));
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) 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