27.8.2 Creating a Snapshot via Refreshing
You can create a snapshot via refreshing by performing the following
steps:
- Create a session and load the graph into memory.
- Check the available snapshots of the graph with
PgxSession.getAvailableSnapshots()
method.opg4j> session.getAvailableSnapshots(G) ==> GraphMetaData [getNumVertices()=4, getNumEdges()=4, memoryMb=0, dataSourceVersion=1453315103000, creationRequestTimestamp=1453315122669 (2016-01-20 10:38:42.669), creationTimestamp=1453315122685 (2016-01-20 10:38:42.685), vertexIdType=integer, edgeIdType=long]
Deque<GraphMetaData> snapshots = session.getAvailableSnapshots(G); for( GraphMetaData metaData : snapshots ) { System.out.println( metaData ); }
snapshots = session.get_available_snapshots(G) for metadata in snapshots: print(metadata)
- Edit the source file to contain an additional vertex and an additional edge or insert two rows in the database.
- Reload the updated graph within the same session as you loaded the original
graph. A new snapshot is created.
opg4j> var G = session.readGraphWithProperties( G.getConfig(), true ) ==> PGX Graph named 'sample_2' bound to PGX session 'a1744e86-65fb-4bd1-b2dc-5458b20954a9' registered at PGX Server Instance running in embedded mode opg4j> session.getAvailableSnapshots(G) ==> GraphMetaData [getNumVertices()=4, getNumEdges()=4, memoryMb=0, dataSourceVersion=1453315103000, creationRequestTimestamp=1453315122669 (2016-01-20 10:38:42.669), creationTimestamp=1453315122685 (2016-01-20 10:38:42.685), vertexIdType=integer, edgeIdType=long] ==> GraphMetaData [getNumVertices()=5, getNumEdges()=5, memoryMb=3, dataSourceVersion=1452083654000, creationRequestTimestamp=1453314938744 (2016-01-20 10:35:38.744), creationTimestamp=1453314938833 (2016-01-20 10:35:38.833), vertexIdType=integer, edgeIdType=long]
G = session.readGraphWithProperties( G.getConfig(), true ); Deque<GraphMetaData> snapshots = session.getAvailableSnapshots( G );
G = session.read_graph_with_properties(G.config,update_if_not_fresh=True)
Note that there are twoGraphMetaData
objects in the call for available snapshots, one with 4 vertices and 4 edges and one with 5 vertices and 5 edges. - Verify that the graph variable points to the newly loaded graph using
getNumVertices()
andgetNumEdges()
methods.
Parent topic: Graph Versioning