Search code examples
pythontransactionsdgraph

How to obtain start and commit timestamps of transactions?


How can I obtain start and commit timestamps of transactions in Dgraph from operation messages or database logs? I need to issue multiple transactions in each client session.

I use this Docker image:

docker pull dgraph/dgraph:latest # version:v23.1.0

And pydgraph-23.0.1 driver with Python v3.8.18. I use simple.py and changed localhost on line 10 to 175.27.241.31. 175.27.241.31 is publicly available (you can use it directly without pulling the Docker image). I added print(response) after line 78 but there is only start_ts for the transaction. I do not find commit_ts:

txn {
  start_ts: 260380056
  keys: ...
    ...
    preds: ...
    ...
}
latency {
    ...
}
metrics {
    ...
}
uids {
    ...
}
  • How to obtain commit_ts for transactions using pydgraph? Is there any official documentation or source code for this?
  • Does following code from simple.py mean client is issuing multiple transactions one by one?
  • Are there other ways of obtaining start and commit timestamps than using pydgraph? Code examples are appreciated.
def main():
    client_stub = create_client_stub()
    client = create_client(client_stub)
    drop_all(client)
    set_schema(client)
    create_data(client)
    query_alice(client)  # query for Alice
    query_bob(client)  # query for Bob
    delete_data(client)  # delete Bob
    query_alice(client)  # query for Alice
    query_bob(client)  # query for Bob

    # Close the client stub.
    client_stub.close()

Related.


Solution

  • Answer from Ruohao Zhang @ discuss.dgraph.io:

    I want to get the commit_ts by using pydgraph. However, the function commit() doesn't return the commit_ts. By modifying line 238 in txn.py, I return the result of the function self._dc.commit_or_abort.

    return self._dc.commit_or_abort(self._ctx, timeout=timeout,
                                         metadata=new_metadata,
                                         credentials=credentials)
    

    Like this, I could get the commit_ts from the function commit().

    The result is following: start_ts: 260380200 commit_ts: 260380201


    I have raised an issue on github.

    Updated: The corresponding PR has been accepted.