15.7.2 Creating a Snapshot via Refreshing

You can create a snapshot via refreshing by performing the following steps:

  1. Create a session and load the graph into memory.
  2. Check the available snapshots of the graph with PgxSession.getAvailableSnapshots() method.
    Get the Available Snapshots Using JShell
    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]
    Get the Available Snapshots Using Java
    Deque<GraphMetaData> snapshots = session.getAvailableSnapshots(G);
    for( GraphMetaData metaData : snapshots ) {
      System.out.println( metaData );
    }
    Get the Available Snapshots Using Python
    snapshots = session.get_available_snapshots(G)
    for metadata in snapshots:
        print(metadata)
  3. Edit the source file to contain an additional vertex and an additional edge or insert two rows in the database.
  4. 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 Java
    G = session.readGraphWithProperties( G.getConfig(), true );
    
    Deque<GraphMetaData> snapshots = session.getAvailableSnapshots( G );
    Load an Updated Graph Using Python
    G = session.read_graph_with_properties(G.config,update_if_not_fresh=True)
    Note that there are two GraphMetaData objects in the call for available snapshots, one with 4 vertices and 4 edges and one with 5 vertices and 5 edges.
  5. Verify that the graph variable points to the newly loaded graph using getNumVertices() and getNumEdges() methods.
    Get the Number of Vertices and Edges in a Graph Using JShell
    opg4j> G.getNumVertices()
    ==> 5
    opg4j> G.geNumEdges()
    ==> 5
    Get the Number of Vertices and Edges in a Graph Using Java
    int vertices = G.getNumVertices();
    long edges = G.getNumEdges();
    Get the Number of Vertices and Edges in a Graph Using Python
    vertices = G.num_vertices
    edges = G.num_edges