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