HollowProducer.ReadState hardRestore(long versionDesired, HollowConsumer.BlobRetriever blobRetriever) { return restore(versionDesired, blobRetriever, (restoreFrom, restoreTo) -> HollowWriteStateCreator.populateUsingReadEngine(restoreTo, restoreFrom)); }
/** * Restores the data state to a desired version. * <p> * Data model {@link #initializeDataModel(Class[]) initialization} is required prior to * restoring the producer. This ensures that restoration can correctly compare the producer's * current data model with the data model of the restored data state and manage any differences * in those models (such as not restoring state for any types in the restoring data model not * present in the producer's current data model) * * @param versionDesired the desired version * @param blobRetriever the blob retriever * @return the read state of the restored state * @throws IllegalStateException if the producer's data model has not been initialized * @see #initializeDataModel(Class[]) */ public HollowProducer.ReadState restore(long versionDesired, HollowConsumer.BlobRetriever blobRetriever) { return restore(versionDesired, blobRetriever, (restoreFrom, restoreTo) -> restoreTo.restoreFrom(restoreFrom)); }
@Test public void testRestoreFailure() { HollowProducer producer = createProducer(tmpFolder, schema); long fakeVersion = 101; try { producer.restore(fakeVersion, blobRetriever); Assert.fail(); } catch(Exception expected) { } Assert.assertNotNull(lastRestoreStatus); Assert.assertEquals(Status.FAIL, lastRestoreStatus.getStatus()); }
private void restoreAndAssert(HollowProducer producer, long version, int size, int valueMultiplier, int valueFieldCount) { ReadState readState = producer.restore(version, blobRetriever); Assert.assertNotNull(lastRestoreStatus); Assert.assertEquals(Status.SUCCESS, lastRestoreStatus.getStatus()); Assert.assertEquals("Version should be the same", version, lastRestoreStatus.getDesiredVersion()); HollowObjectTypeReadState typeState = (HollowObjectTypeReadState) readState.getStateEngine().getTypeState("TestPojo"); BitSet populatedOrdinals = typeState.getPopulatedOrdinals(); Assert.assertEquals(size, populatedOrdinals.cardinality()); int ordinal = populatedOrdinals.nextSetBit(0); while (ordinal != -1) { GenericHollowObject obj = new GenericHollowObject(new HollowObjectGenericDelegate(typeState), ordinal); System.out.println("ordinal=" + ordinal + obj); int id = obj.getInt("id"); for (int i = 0; i < valueFieldCount; i++) { String valueFN = "v" + (i + 1); int value = id * valueMultiplier; Assert.assertEquals(valueFN, value, obj.getInt(valueFN)); } ordinal = populatedOrdinals.nextSetBit(ordinal + 1); } System.out.println("Asserted Correctness of version:" + version + "\n\n"); }
@Test public void testPublishAndRestore() { HollowProducer producer = createProducer(tmpFolder, schema); long version = testPublishV1(producer, 2, 10); producer.restore(version, blobRetriever); Assert.assertNotNull(lastRestoreStatus); Assert.assertEquals(Status.SUCCESS, lastRestoreStatus.getStatus()); Assert.assertEquals("Version should be the same", version, lastRestoreStatus.getDesiredVersion()); }
@Test public void producerRestoresAndProducesDelta() { HollowProducer producer = HollowProducer.withPublisher(blobStore) .withBlobStager(new HollowInMemoryBlobStager()) .build(); long v1 = runCycle(producer, 1); HollowProducer redeployedProducer = HollowProducer.withPublisher(blobStore) .withBlobStager(new HollowInMemoryBlobStager()) .build(); redeployedProducer.initializeDataModel(Integer.class); redeployedProducer.restore(v1, blobStore); long v2 = runCycle(producer, 2); Assert.assertNotNull(blobStore.retrieveDeltaBlob(v1)); Assert.assertEquals(v2, blobStore.retrieveDeltaBlob(v1).getToVersion()); }
backingProducer.restore(nextVersion, blobStore);