Visitar URL original
Updated tx docs a little bit in preparation for release CTR · apache/tinkerpop@0eb5211 · GitHub
Skip to content

Commit 0eb5211

Browse files
committed
Updated tx docs a little bit in preparation for release CTR
1 parent d70aa4e commit 0eb5211

4 files changed

Lines changed: 104 additions & 55 deletions

File tree

‎docs/src/reference/gremlin-applications.asciidoc‎

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2578,32 +2578,6 @@ simply retry the request later. In the event a client detects a `ResponseStatusC
25782578
which is error code `596`, the client may choose to retry that request. Note that drivers do not have the ability to
25792579
automatically retry and that it is up to the application to provide such logic.
25802580
2581-
[[testing-remote-providers]]
2582-
==== Testing Remote Providers
2583-
2584-
As of 3.7.0, it is recommended to use TinkerTransactionGraph, the transactional TinkerGraph, for testing, as it provides
2585-
transactional capabilities on top of exiting TinkerGraph functionalities.
2586-
2587-
To use TinkerTransactionGraph remotely, start a Gremlin Server with the `gremlin-server-transaction.yaml` config file.
2588-
2589-
[source,java]
2590-
----
2591-
Cluster cluster = Cluster.build("localhost").port(8182).create();
2592-
Client client = cluster.connect();
2593-
GraphTraversalSource g = traversal().withRemote(DriverRemoteConnection.using(client, "g"));
2594-
GraphTraversalSource gtx = g.tx().begin();
2595-
2596-
try {
2597-
Vertex marko = gtx.addV("person").property("name","marko").property("age",29).next();
2598-
Vertex lop = gtx.addV("software").property("name","lop").property("lang","java").next();
2599-
gtx.addE("created").from(marko).to(lop).property("weight",0.6d).iterate();
2600-
2601-
gtx.tx().commit();
2602-
} catch (Exception ex) {
2603-
gtx.tx().rollback();
2604-
}
2605-
----
2606-
26072581
[[gremlin-server-docker-image]]
26082582
=== Docker Image
26092583

‎docs/src/reference/implementations-tinkergraph.asciidoc‎

Lines changed: 85 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ also be specified. If this value is not included (default), then the graph will
160160
loaded/persisted to disk.
161161
|=========================================================
162162
163+
NOTE: To use <<tinkergraph-gremlin-tx, transactions>>, configure `gremlin.graph` as
164+
`org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerTransactionGraph`.
165+
163166
The `IdManager` settings above refer to how TinkerGraph will control identifiers for vertices, edges and vertex
164167
properties. There are several options for each of these settings: `ANY`, `LONG`, `INTEGER`, `UUID`, or the fully
165168
qualified class name of an `IdManager` implementation on the classpath. When not specified, the default values
@@ -199,59 +202,124 @@ g.io("data/tinkerpop-crew.kryo").read().iterate()
199202
g.V().properties()
200203
----
201204
205+
[[tinkergraph-gremlin-tx]]
202206
=== Transactions
203207
204-
As of 3.7.0, `TinkerGraph` includes optional transaction support and thread-safety through the `TinkerTransactionGraph`
205-
class. The default configuration of TinkerGraph remains non-transactional.
208+
`TinkerGraph` includes optional transaction support and thread-safety through the `TinkerTransactionGraph` class.
209+
The default configuration of TinkerGraph remains non-transactional.
210+
211+
NOTE: This feature was first made available in TinkerPop 3.7.0.
206212
207213
==== Transaction Semantics
208214
209-
TinkerTransactionGraph only has support for ThreadLocal transactions, so embedded graph transactions may not be fully
215+
`TinkerTransactionGraph` only has support for `ThreadLocal` transactions, so embedded graph transactions may not be fully
210216
supported. You can think of the transaction as belonging to a thread, any traversals executed within the same thread
211217
will share the same transaction even if you attempt to start a new transaction.
212218
213-
TinkerTransactionGraph provides the `read committed` transaction isolation level. This means that it will always try to
219+
`TinkerTransactionGraph` provides the `read committed` transaction isolation level. This means that it will always try to
214220
guard against dirty reads. While you may notice stricter isolation semantics in some cases, you should not depend on
215221
this behavior as it may change in the future.
216222
217-
TinkerTransactionGraph employs optimistic locking as its locking strategy. This reduces complexity in the design as
223+
`TinkerTransactionGraph` employs optimistic locking as its locking strategy. This reduces complexity in the design as
218224
there are fewer timeouts that the user needs to manage. However, a consequence of this approach is that a transaction
219225
will throw a `TransactionException` if two different transactions attempt to lock the same element (see "Best Practices"
220226
below).
221227
222-
==== Use Cases
228+
[[testing-remote-providers]]
229+
==== Testing Remote Providers
223230
224231
These transaction semantics described above may not fit use cases for some production scenarios that require strict
225-
ACID-like transactions. Therefore, it is recommended that TinkerTransactionGraph be used as a Graph for test
226-
environments where you still require access to a Graph that supports transactions. TinkerTransactionGraph does fully
227-
support TinkerPop's `Transaction` interface which still makes it a useful Graph for exploring the Transaction API.
232+
ACID-like transactions. Therefore, it is recommended that `TinkerTransactionGraph` be used as a `Graph` for test
233+
environments where you still require access to a `Graph` that supports transactions. `TinkerTransactionGraph` does fully
234+
support TinkerPop's `Transaction` interface which still makes it a useful `Graph` for exploring the
235+
<<transactions,Transaction API>>.
228236
229-
Once you are ready to put your system into production then you can choose a Graph provider that has the
230-
transaction semantics that fit your application's needs.
237+
A common scenario where this sort of testing is helpful is with <<connecting-rgp, Remote Graph Providers>>, where
238+
developing unit tests might be hard against a graph service. Instead, configure `TinkerTransactionGraph`, either in an
239+
embedded style if using Java or with Gremlin Server for other cases.
240+
241+
[source,java]
242+
----
243+
// consider this class that returns the results of some Gremlin. by constructing the
244+
// GraphService in a way that takes a GraphTraversalSource it becomes possible to
245+
// execute getPersons() under any graph system.
246+
public class GraphService {
247+
private final GraphTraversalSource g;
248+
249+
public GraphService(GraphTraversalSource g) {
250+
this.g = g;
251+
}
252+
253+
public List<Vertex> getPersons() {
254+
return g.V().hasLabel("person").toList();
255+
}
256+
}
257+
258+
// when writing tests for the GraphService it becomes possible to configure the test
259+
// to run in a variety of scenarios. here we decide that TinkerTransactionGraph is a
260+
// suitable test graph replacement for our actual production graph.
261+
public class GraphServiceTest {
262+
private static final TinkerTransactionGraph graph = TinkerTransactionGraph().open();
263+
private static final GraphTraversalSource g = traversal.withEmbedded(graph);
264+
private static final GraphService service = new GraphService(g);
265+
266+
@Test
267+
public void shouldGetPersons() {
268+
final List<Vertex> persons = service.getPersons();
269+
assertEquals(6, persons.size());
270+
}
271+
}
272+
273+
// or perhaps, since we're using a remote graph provider, we feel it would be better to
274+
// start Gremlin Server with a TinkerTransactionGraph configured using a docker container,
275+
// embedding it directly in our tests or running it as a separate process like:
276+
//
277+
// bin/gremlin-server.sh conf/gremlin-server-transaction.yaml
278+
//
279+
// and then connect to it with a driver in more of an integration test style. obviously,
280+
// with this approach you could also configure your production graph directly or use custom
281+
// build options to trigger different test configurations for a more dynamic approach
282+
public class GraphServiceTest {
283+
private static final GraphTraversalSource g = traversal.withRemote(
284+
new DriverRemoteConnection('ws://localhost:8182/gremlin'));
285+
private static final GraphService service = new GraphService(g);
286+
287+
@Test
288+
public void shouldGetPersons() {
289+
final List<Vertex> persons = service.getPersons();
290+
assertEquals(6, persons.size());
291+
}
292+
}
293+
----
294+
295+
WARNING: There can be subtle behavioral differences between TinkerGraph and the graph ultimately intended for use.
296+
Be aware of the differences when writing tests to ensure that you are testing behaviors of your applications
297+
appropriately.
231298
232299
==== Best Practices
233300
234-
Errors can occur before a transaction gets committed. Specifically for TinkerTransactionGraph, you may encounter many
235-
`TransactionException`s in a highly concurrent environment due its optimistic approach to locking. Users should follow
236-
the try-catch-rollback pattern described in the
301+
Errors can occur before a transaction gets committed. Specifically for `TinkerTransactionGraph`, you may encounter many
302+
`TransactionException` errors in a highly concurrent environment due its optimistic approach to locking. Users should
303+
follow the try-catch-rollback pattern described in the
237304
link:https://tinkerpop.apache.org/docs/x.y.z/reference/#transactions[transactions] section in combination with
238305
exponential backoff based retries to mitigate this issue.
239306
240307
==== Performance Considerations
241308
242309
While transactions impose minimal impact for mutating workloads, users should expect performance degradation for
243310
read-only work relative to the non-transactional configuration. However, its approach to locking
244-
(write-only, optimistic) and its in-memory nature, TinkerTransactionGraph is likely faster than other Graph
311+
(write-only, optimistic) and its in-memory nature, TinkerTransactionGraph is likely faster than other `Graph`
245312
implementations that support transactions.
246313
247314
==== Examples
248315
249-
Constructing a simple graph using TinkerTransactionGraph in Java is presented below:
316+
Constructing a simple graph using `TinkerTransactionGraph` in Java is presented below:
250317
251318
[source,java]
252319
----
253320
Graph graph = TinkerTransactionGraph.open();
254-
GraphTraversalSource gtx = graph.tx().begin();
321+
g = traversal().withEmbedded(graph)
322+
GraphTraversalSource gtx = g.tx().begin();
255323
256324
try {
257325
Vertex marko = gtx.addV("person").property("name","marko").property("age",29).next();

‎docs/src/reference/intro.asciidoc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ the <<connecting-gremlin-server,previous section>> with the exact same caveats p
477477
478478
Despite leveraging TinkerPop protocols and drivers as being typical, RGPs are not required to do so to be considered
479479
TinkerPop-enabled. RGPs may well have their own drivers and protocols that may plug into
480-
<<gremlin-drivers-variants,Gremlin Language Variants> and may allow for more advanced options like better security,
480+
<<gremlin-drivers-variants,Gremlin Language Variants>> and may allow for more advanced options like better security,
481481
cluster awareness, batched requests or other features. The details of these different systems are outside the scope
482482
of this documentation, so be sure to consult their documentation for more information.
483483

‎docs/src/upgrade/release-3.7.x.asciidoc‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -162,23 +162,29 @@ See: link:https://issues.apache.org/jira/browse/TINKERPOP-2957[TINKERPOP-2957]
162162
163163
==== TinkerGraph Transactions
164164
165-
===== Introduction
166-
167165
Previously, there was no reference implementation provided for the `Transaction` API as this feature wasn't supported by
168166
TinkerGraph. Users were instead directed towards the Neo4jGraph provided in `neo4j-gremlin` if they wanted to get access
169167
to a `Graph` implementation that supported transactions. Unfortunately, the maintenance around this plugin has largely
170168
been abandoned and is only compatible with Neo4j version 3.4, which reached end of life in March 2020.
171169
172-
As of this version, we are introducing the transactional TinkerGraph, TinkerTransactionGraph, which is TinkerGraph with
173-
transaction capabilities. The TinkerTransactionGraph has `read committed` isolation level, which is the same as the
170+
As of this version, we are introducing the transactional TinkerGraph, `TinkerTransactionGraph`, which is TinkerGraph with
171+
transaction capabilities. The `TinkerTransactionGraph` has `read committed` isolation level, which is the same as the
174172
Neo4jGraph provided in `neo4j-gremlin`. Only `ThreadLocal` transactions are implemented, therefore embedded graph
175173
transactions may not be fully supported. These transaction semantics may not fit the use case for some production
176174
scenarios that require strict ACID-like transactions. Therefore, it is recommended that TinkerTransactionGraph be used
177175
as a Graph for test environments where you still require support for transactions.
178176
179177
===== Usage examples
180178
181-
To use TinkerTransactionGraph remotely, start a Gremlin Server with the `gremlin-server-transaction.yaml` config file.
179+
To use `TinkerTransactionGraph` remotely, start a Gremlin Server with the included `gremlin-server-transaction.yaml`
180+
config file.
181+
182+
[source,bash]
183+
----
184+
bin/gremlin-server.sh conf/gremlin-server-transaction.yaml
185+
----
186+
187+
Then to connect with Java:
182188
183189
[source,java]
184190
----
@@ -274,14 +280,15 @@ gremlin> g.V().valueMap()
274280
<4> Add a second vertex without committing
275281
<5> Rollback the change
276282
277-
Note that all embedded TinkerTransactionGraph remains ThreadLocal transactions, meaning that all traversal sources spawn
278-
from the graph will operate within the same transaction scope.
283+
Note that all embedded `TinkerTransactionGraph` remains `ThreadLocal` transactions, meaning that all traversal sources
284+
spawned from the graph will operate within the same transaction scope.
279285
280-
===== Limitations
281-
At this point, the transactional TinkerGraph comes with performance limitations and thus is only meant for testing
282-
and not for production use.
286+
IMPORTANT: `TinkerTransactionGraph` comes with performance and semantic limitations, where the former is expect to
287+
be resolved in future versions. Since its primary recommended use case is for testing these limitations should not be
288+
an impediment. Production use cases for TinkerGraph should generally prefer the non-transactional implementation.
283289
284-
Addition documentation can be found in <<transactions,Transactions>> section.
290+
See: link:https://issues.apache.org/jira/browse/TINKERPOP-2975[TINKERPOP-2975],
291+
link:https://tinkerpop.apache.org/docs/3.7.0/reference/#tinkergraph-gremlin-tx[Reference Documentation - TinkerGraph Transactions]
285292
286293
==== Properties on Elements
287294

0 commit comments

Comments
 (0)