use of org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync in project jackrabbit-oak by apache.
the class StandbyTestIT method testSyncLoop.
/**
* OAK-2430
*/
@Test
public void testSyncLoop() throws Exception {
final int blobSize = 25 * 1024;
final int dataNodes = 5000;
FileStore primary = serverFileStore.fileStore();
FileStore secondary = clientFileStore.fileStore();
NodeStore store = SegmentNodeStoreBuilders.builder(primary).build();
try (StandbyServerSync serverSync = new StandbyServerSync(serverPort.getPort(), primary, MB);
StandbyClientSync clientSync = new StandbyClientSync(getServerHost(), serverPort.getPort(), secondary, false, getClientTimeout(), false, folder.newFolder())) {
serverSync.start();
byte[] data = addTestContent(store, "server", blobSize, dataNodes);
primary.flush();
for (int i = 0; i < 5; i++) {
String cp = store.checkpoint(Long.MAX_VALUE);
primary.flush();
clientSync.run();
assertEquals(primary.getHead(), secondary.getHead());
assertTrue(store.release(cp));
clientSync.cleanup();
assertTrue(secondary.getStats().getApproximateSize() > blobSize);
}
assertTrue(primary.getStats().getApproximateSize() > blobSize);
assertTrue(secondary.getStats().getApproximateSize() > blobSize);
PropertyState ps = secondary.getHead().getChildNode("root").getChildNode("server").getProperty("testBlob");
assertNotNull(ps);
assertEquals(Type.BINARY.tag(), ps.getType().tag());
Blob b = ps.getValue(Type.BINARY);
assertEquals(blobSize, b.length());
byte[] testData = new byte[blobSize];
ByteStreams.readFully(b.getNewStream(), testData);
assertArrayEquals(data, testData);
}
}
use of org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync in project jackrabbit-oak by apache.
the class StandbyTestIT method testSync.
@Test
public void testSync() throws Exception {
int blobSize = 5 * MB;
FileStore primary = serverFileStore.fileStore();
FileStore secondary = clientFileStore.fileStore();
NodeStore store = SegmentNodeStoreBuilders.builder(primary).build();
try (StandbyServerSync serverSync = new StandbyServerSync(serverPort.getPort(), primary, MB);
StandbyClientSync clientSync = new StandbyClientSync(getServerHost(), serverPort.getPort(), secondary, false, getClientTimeout(), false, folder.newFolder())) {
serverSync.start();
byte[] data = addTestContent(store, "server", blobSize, 150);
primary.flush();
clientSync.run();
assertEquals(primary.getHead(), secondary.getHead());
assertTrue(primary.getStats().getApproximateSize() > blobSize);
assertTrue(secondary.getStats().getApproximateSize() > blobSize);
PropertyState ps = secondary.getHead().getChildNode("root").getChildNode("server").getProperty("testBlob");
assertNotNull(ps);
assertEquals(Type.BINARY.tag(), ps.getType().tag());
Blob b = ps.getValue(Type.BINARY);
assertEquals(blobSize, b.length());
byte[] testData = new byte[blobSize];
ByteStreams.readFully(b.getNewStream(), testData);
assertArrayEquals(data, testData);
}
}
use of org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync in project jackrabbit-oak by apache.
the class SegmentTarFixture method attachStandby.
/**
* Attaches a standby instance located at index (n+i) in the cluster to the
* primary located at index i
*
* @param i
* the primary index
* @param n
* the number of primary instances in the cluster
* @param statsProvider
* statistics provider for the file/blob store(s)
* @param blobStore
* the blob store used by the primary (can be <code>null</code>)
* @throws InvalidFileStoreVersionException
* if an incorrect oak-segment-tar version is used
* @throws IOException
* if the file store manifest cannot be saved
*/
private void attachStandby(int i, int n, StatisticsProvider statsProvider, BlobStore blobStore) throws InvalidFileStoreVersionException, IOException {
FileStoreBuilder builder = fileStoreBuilder(new File(parentPath, "standby-" + i));
if (useBlobStore) {
if (shareBlobStore) {
builder.withBlobStore(blobStore);
} else {
blobStoreFixtures[n + i] = BlobStoreFixture.create(parentPath, true, dsCacheSize, statsProvider);
builder.withBlobStore(blobStoreFixtures[n + i].setUp());
}
}
SegmentGCOptions gcOptions = SegmentGCOptions.defaultGCOptions().setRetainedGenerations(1);
stores[n + i] = builder.withGCOptions(gcOptions).withMaxFileSize(maxFileSize).withStatisticsProvider(statsProvider).withSegmentCacheSize(segmentCacheSize).withMemoryMapping(memoryMapping).withSnfeListener(IGNORE_SNFE).build();
int port = 0;
try (ServerSocket socket = new ServerSocket(0)) {
port = socket.getLocalPort();
}
serverSyncs[i] = new StandbyServerSync(port, stores[i], 1 * MB, secure);
clientSyncs[i] = new StandbyClientSync("127.0.0.1", port, stores[n + i], secure, DEFAULT_TIMEOUT, false, new File(StandardSystemProperty.JAVA_IO_TMPDIR.value()));
if (!oneShotRun) {
serverSyncs[i].start();
clientSyncs[i].start();
executors[i] = Executors.newScheduledThreadPool(1);
executors[i].scheduleAtFixedRate(clientSyncs[i], 0, syncInterval, TimeUnit.SECONDS);
}
}
Aggregations