16.3.3 グラフの公開
他のセッションで参照できるように、グラフ・サーバー(PGX)にロードされるグラフを公開できます。同様に、グラフのスナップショットを他のセッションで使用可能にすることもできます。
スナップショットを含むグラフの公開
グラフをグラフ・サーバーにロードした後、グラフのすべてのスナップショットを他のセッション(同じユーザーの下)に表示する場合は、publishWithSnapshots()
メソッドを使用します。グラフがスナップショットとともに公開されると、各スナップショットのGraphMetaData
情報も他のセッションで使用できるようになります。ただし、null
であるグラフ構成は除きます。
publishWithSnapshots()
メソッドをコールすると、全スナップショットの永続プロパティがすべて公開され、他のセッションから参照できるようになります。一時プロパティはセッション非公開であるため、明示的に公開する必要があります。公開されると、すべてのプロパティが読取り専用になります。したがって、引数を指定せずにpublishWithSnapshots()
をコールすると、一時プロパティは公開されません。
publishWithSnapshots()
メソッドを使用してグラフを公開すると、グラフ名は、セッションに対してプライベートなネームスペースからパブリック・ネームスペースに移動します。同じ名前を持つグラフがすでに公開されている場合、publishWithSnapshots()
メソッドは失敗し、例外が発生します。
opg4j> graph.publishWithSnapshots()
graph.publishWithSnapshots();
>>> graph.publish_with_snapshots()
特定の一時プロパティを公開する場合は、次の例に示すように、publishWithSnapshots()
コール内でそれらをリストできます:
opg4j> var prop1 = graph.createVertexProperty(PropertyType.INTEGER, "prop1")
opg4j> prop1.fill(0)
opg4j> var cost = graph.createEdgeProperty(PropertyType.DOUBLE, "cost")
opg4j> cost.fill(0d)
opg4j> graph.publishWithSnapshots(List.of(prop1), List.of(cost))
VertexProperty<Integer, Integer> prop1 = graph.createVertexProperty(PropertyType.INTEGER, "prop1");
prop1.fill(0);
EdgeProperty<Double> cost = graph.createEdgeProperty(PropertyType.DOUBLE, "cost");
cost.fill(0d);
Collection<VertexProperty<?, ?>> vertexProps = Arrays.asList(prop1);
Collection<EdgeProperty<?>> edgeProps = Arrays.asList(cost);
graph.publishWithSnapshots(vertexProps,edgeProps);
または、次の例に示すように、組込みのVertexProperty.ALL
およびEdgeProperty.ALL
をpublishWithSnapshots()
に渡すことで、すべてのプロパティを一度に公開できます。
opg4j> var prop1 = graph.createVertexProperty(PropertyType.INTEGER, "prop1")
opg4j> prop1.fill(0)
opg4j> var cost = graph.createEdgeProperty(PropertyType.DOUBLE, "cost")
opg4j> cost.fill(0d)
opg4j> graph.publishWithSnapshots(VertexProperty.ALL, EdgeProperty.ALL)
VertexProperty<Integer, Integer> prop1 = graph.createVertexProperty(PropertyType.INTEGER, "prop1");
prop1.fill(0);
EdgeProperty<Double> cost = graph.createEdgeProperty(PropertyType.DOUBLE, "cost");
cost.fill(0d);
Collection<VertexProperty<?, ?>> vertexProps = Arrays.asList(prop);
Collection<EdgeProperty<?>> edgeProps = Arrays.asList(cost);
graph.publishWithSnapshots(VertexProperty.ALL, EdgeProperty.ALL);
スナップショットの作成後、新しいスナップショットのプロパティは、古いスナップショットのプロパティの公開状態を継承します。これは、プロパティが古いスナップショットで公開されている場合、新しいスナップショットにも公開されることを意味します。それ以外の場合は、新しいスナップショットでセッションがプライベートのままになります。この動作は、enable_snapshot_properties_publish_state_propagation flag
で構成できます(「グラフ・サーバー(PGX)エンジンの構成パラメータ」を参照)。デフォルトでは、このフラグは有効になっています。ただし、値をfalseに設定することで無効にできます。この場合、プロパティの公開状態は、新しいスナップショットの作成時に無視され、新しいスナップショットのプロパティはセッションに対してプライベートになります。
ノート:
デフォルトでは、publishWithSnapshots()
のコールは最新のスナップショットでのみ許可されます。古いスナップショットでpublishWithSnapshots()
をコールすると、例外が発生します。任意のスナップショットでpublishWithSnapshots()
をコールできるようにするには、pgx.conf
ファイルのenable_snapshot_properties_publish_state_propagation
構成フィールドをfalse
に設定します。
opg4j> var prop1 = graph.createVertexProperty(PropertyType.INTEGER, "prop1")
opg4j> prop1.fill(0)
opg4j> var prop2 = graph.createVertexProperty(PropertyType.INTEGER, "prop2")
opg4j> prop2.fill(0)
opg4j> var cost = graph.createEdgeProperty(PropertyType.DOUBLE, "cost")
opg4j> cost.fill(0d)
// the example intentionally avoids publishing prop2
opg4j> graph.publishWithSnapshots(List.of(prop1), List.of(cost))
opg4j> var snapshot = graph.createChangeSet().buildNewSnapshot()
opg4j> snapshot.getVertexProperty("prop1").isPublished()
=> true
opg4j> snapshot.getVertexProperty("prop2").isPublished()
=> false
opg4j> snapshot.getEdgeProperty("cost").isPublished()
=> true
// publish prop2 in snapshot, this will make it published in future snapshots too
// but not in the previous snapshots
opg4j> snapshot.getVertexProperty("prop2").publish()
opg4j> var snapshot2 = snapshot.createChangeSet().buildNewSnapshot();
opg4j> snapshot2.getVertexProperty("prop1").isPublished()
=> true
opg4j> snapshot2.getVertexProperty("prop2").isPublished()
=> true
opg4j> snapshot2.getEdgeProperty("cost").isPublished()
=> true
VertexProperty<Integer, Integer> prop1 = graph.createVertexProperty(PropertyType.INTEGER, "prop1");
prop1.fill(0);
VertexProperty<Integer, Integer> prop2 = graph.createVertexProperty(PropertyType.INTEGER, "prop2");
prop2.fill(0);
EdgeProperty<Double> cost = graph.createEdgeProperty(PropertyType.DOUBLE, "cost");
cost.fill(0d);
// the example intentionally avoids publishing prop2
graph.publishWithSnapshots(List.of(prop1), List.of(cost));
PgxGraph snapshot = graph.createChangeSet().buildNewSnapshot();
System.out.println(snapshot.getVertexProperty("prop1").isPublished()); // Returns true
System.out.println(snapshot.getVertexProperty("prop2").isPublished()); // Returns false
System.out.println(snapshot.getEdgeProperty("cost").isPublished()); // Returns true
// publish prop2 in snapshot, this will make it published in future snapshots too
// but not in the previous snapshots.
snapshot.getVertexProperty("prop2").publish();
PgxGraph snapshot2 = snapshot.createChangeSet().buildNewSnapshot();
System.out.println(snapshot2.getVertexProperty("prop1").isPublished()); // Returns true
System.out.println(snapshot2.getVertexProperty("prop2").isPublished()); // Returns true
System.out.println(snapshot2.getEdgeProperty("cost").isPublished()); // Returns true
単一のグラフ・スナップショットの公開
PgxGraph#publish()
メソッドを使用して、グラフの現在選択されているスナップショットを公開できます。公開操作により、グラフ名がセッション非公開のネームスペースからパブリック・ネームスペースに移動します。同じ名前を持つグラフがすでに公開されている場合、publish()
メソッドは失敗し、例外が発生します。スナップショットとともに公開されたグラフと、公開された単一のスナップショットは同じネームスペースを共有します。
表14-6に、グラフの公開に必要な権限を示します。
引数を指定せずにpublish()
メソッドをコールすると、スナップショットは永続プロパティのみとともに公開されます。ただし、特定の一時プロパティを公開する場合は、次のようにpublish()
コール内でそれらをリストする必要があります:
opg4j> var prop1 = graph.createVertexProperty(PropertyType.INTEGER, "prop1")
opg4j> prop1.fill(0)
opg4j> var cost = graph.createEdgeProperty(PropertyType.DOUBLE, "cost")
opg4j> cost.fill(0d)
opg4j> graph.publish(List.of(prop1), List.of(cost))
VertexProperty<Integer, Integer> prop1 = graph.createVertexProperty(PropertyType.INTEGER, "prop1");
prop1.fill(0);
EdgeProperty<Double> cost = graph.createEdgeProperty(PropertyType.DOUBLE, "cost");
cost.fill(0d);
Collection<VertexProperty<?, ?>> vertexProps = Arrays.asList(prop);
Collection<EdgeProperty<?>> edgeProps = Arrays.asList(cost);
graph.publish(vertexProps, edgeProps);
prop = graph.create_vertex_property("integer", "prop1")
prop1.fill(0)
cost = graph.create_edge_property("double", "cost")
cost.fill(float(0))
vertex_props = [prop]
edge_props = [cost]
graph.publish(vertex_props, edge_props)
別のセッションからの公開済グラフの参照
公開済グラフは、PgxSession#getGraph()
メソッドを使用して別のセッションで名前で参照できます。
次の例では、公開済グラフmyGraph
を新しいセッション(session2
)で参照します。
opg4j> var session2 = instance.createSession("session2")
opg4j> var graph2 = session2.getGraph(Namespace.PUBLIC, "myGraph")
PgxSession session2 = instance.createSession("session2");
PgxGraph graph2 = session2.getGraph(Namespace.PUBLIC, "myGraph");
session2 = pypgx.get_session("session2");
PgxGraph graph2 = session2.get_graph("myGraph")
session2
は、公開済スナップショットのみにアクセスできます。グラフがスナップショットなしで公開されている場合、getAvailableSnapshots()
メソッドのコールによって空のキューが返されます。
グラフ・スナップショットが公開されている場合は、getGraph()
へのコールによって使用可能な最新のスナップショットが返されます。session2
では、getAvailableSnapshots()
メソッドを使用して、使用可能なすべてのスナップショットを表示できます。その後、PgxSession#setSnapshot()
メソッドを使用して特定のスナップショットを設定できます。
ノート:
参照したグラフが不要になった場合は、グラフを解放することが重要です。詳細は、グラフの削除を参照してください。プロパティの公開
(単一のスナップショットまたは全スナップショットを)公開した後でも、一時プロパティを個々に公開できます。デフォルトでは、一時プロパティの公開状態は、それらが作成された特定のスナップショットに関連付けられているため、そのスナップショットでのみ表示されます。
opg4j> graph.getVertexProperty("prop1").publish()
opg4j> graph.getEdgeProperty("cost").publish()
graph.getVertexProperty("prop1").publish();
graph.getEdgeProperty("cost").publish();
graph.get_vertex_property("prop1").publish()
graph.get_edge_property("cost").publish()
別のセッションでの公開済プロパティの取得
公開済グラフを(スナップショットの有無に関係なく)参照するセッションは、PgxGraph#getVertexProperty
およびPgxGraph#getEdgeProperty
を介して公開済プロパティを参照できます。
opg4j> var session2 = instance.createSession("session2")
opg4j> var graph2 = session2.getGraph(Namespace.PUBLIC, "myGraph")
opg4j> var vertexProperty = graph2.getVertexProperty("prop1")
opg4j> var edgeProperty = graph2.getEdgeProperty("cost")
PgxSession session2 = instance.createSession("session2");
PgxGraph graph2 = session2.getGraph(Namespace.PUBLIC, "myGraph");
VertexProperty<Integer, Integer> vertexProperty = graph2.getVertexProperty("prop1");
EdgeProperty<Double> edgeProperty = graph2.getEdgeProperty("cost");
session2 = pypgx.get_session(session_name ="session2")
graph2 = session2.get_graph("myGraph")
vertex_property = graph2.get_vertex_property("prop1")
edge_property = graph2.get_edge_property("cost")
公開済グラフの固定
公開済グラフは、セッションで使用されない場合でも公開されたままになるように固定できます。
opg4j> graph.pin()
graph.pin();
>>> graph.pin()
公開済グラフの固定解除
以前に固定された公開済グラフの固定を解除できます。これにより、グラフとそのすべてのスナップショット(他のセッションでグラフのスナップショットを使用していない場合)を削除できます。
opg4j> var graph = session.getGraph("bank_graph_analytics")
graph ==> PgxGraph[name=bank_graph_analytics,N=999,E=4993,created=1660217577201]
opg4j> graph.unpin()
PgxGraph graph = session.getGraph("bank_graph_analytics");
graph.unpin();
>>> graph = session.get_graph("bank_graph_analytics")
>>> graph.unpin()
関連トピック
親トピック: グラフ・サーバー(PGX)でのグラフ管理