15.7.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.Get the Available Snapshots Using JShellopg4j> 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]
Get the Available Snapshots Using JavaDeque<GraphMetaData> snapshots = session.getAvailableSnapshots(G); for( GraphMetaData metaData : snapshots ) { System.out.println( metaData ); }
Get the Available Snapshots Using Pythonsnapshots = 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.
Load an Updated Graph Using JShell
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 pgx> 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]
Load an Updated Graph Using JavaG = session.readGraphWithProperties( G.getConfig(), true ); Deque<GraphMetaData> snapshots = session.getAvailableSnapshots( G );
Load an Updated Graph Using PythonNote that there are twoG = session.read_graph_with_properties(G.config,update_if_not_fresh=True)
GraphMetaData
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.Get the Number of Vertices and Edges in a Graph Using JShellopg4j> G.getNumVertices() ==> 5 opg4j> G.geNumEdges() ==> 5
Get the Number of Vertices and Edges in a Graph Using Javaint vertices = G.getNumVertices(); long edges = G.getNumEdges();
Get the Number of Vertices and Edges in a Graph Using Pythonvertices = G.num_vertices edges = G.num_edges
Parent topic: Graph Versioning