Skip to content

Architecture Refactor #302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Mar 17, 2021
Merged

Conversation

haikalpribadi
Copy link
Member

@haikalpribadi haikalpribadi commented Mar 15, 2021

What is the goal of this PR?

Over time, Client Java has been extended considerably to implement various features and optimisations. It has lead the architecture to a complex codebase which is not so easy to follow and replicate in other languages. We have now refactored Client Java considerably to come up with an architecture that is easy to understand, easy to extend, and easy to replicate in other languages that wish to implement a Grakn Client.

  1. Made the Transaction Bidirectional Stream architecture a first class citizen of the architecture, making it obvious and easier to understand and follow. The Bidirectional Stream now gets its own package at //stream.
  2. Made the two main responsibilities of the bidirectional stream - single response and streamed multipart response - to be explicitly enforced and expressed.
  3. Simplified the response parsing logic across the codebase from passing around lambdas to eventually be applied at the lowest level (at "ResponseIterator"), by reversing the logic such that every lower-level class returns the top-level response type and every top level class will unpack the response before returning upwards.
  4. Introducing the the "API" package in which all interfaces are aggregated into. This allows us to remove cycles across the classes that was complicated to follow in other language implementations of Grakn Client.
  5. Split the monolithic repository (there was only one "package" that compiled all source code) into multiple packages, enforcing and expressing a clear hierarchy.

The diagram below describes the new architecture of client-java, which should be able to be replicated across every other language implementation of Grakn Clients.

package-structure

haikalpribadi added a commit to typedb/typedb-protocol that referenced this pull request Mar 15, 2021
## What is the goal of this PR?

The previous definition of Grakn RPC protocol did not differentiate the fact that, for the Transaction Bidirectional Stream, some server responses are complete responses for their associated queries, and others are a partial list of a response which are streamed consecutively to make up a full response incrementally. This makes the protocol not explicitly clear to the developer implementing Grakn clients, without having the internal knowledge of how Grakn server responses are designed. We have now refined the Transaction Bidirectional Stream protocol, to express the server behaviour more explicitly. The Transaction Bidirectional Stream now sends "client" messages and receives back "server" messages. "Server" messages are defined to either be a complete response or a partial response. Additionally, we have refined the variable names for some other message definitions.

This PR is followed by typedb/typedb-driver#302 in client-java, and another one in Grakn Core (to be created).
@haikalpribadi haikalpribadi merged commit 9fd221b into typedb:master Mar 17, 2021
@haikalpribadi haikalpribadi added this to the 2.0.0-alpha-13 milestone Mar 19, 2021
alexjpwalker pushed a commit to typedb/typedb-driver-python that referenced this pull request Mar 26, 2021
## What is the goal of this PR?

We have refactored Client Python considerably to come up with an architecture that is easy to understand, easy to extend, and easy to replicate in other languages that wish to implement a Grakn Client.

This is a **breaking change**. The updated APIs are:

#### Create a Grakn Core client
```py
client = Grakn.core_client(address="localhost:1729")
```
#### Create a Grakn Cluster client
```py
client = Grakn.cluster_client(addresses=["127.0.0.1:11729:11730", "127.0.0.1:21729:21730", "127.0.0.1:31729:31730"])
```
#### Open a schema-write transaction
```py
with session = client.session(GraknSession.Type.SCHEMA):
    with transaction = session.transaction(GraknTransaction.Type.WRITE):
```
#### Retrieve answer of Graql Match Aggregate query
```py
count = tx.query().match_aggregate(query).get()
```
For full details of this rework, please see typedb/typedb-driver#302 .

## What are the changes implemented in this PR?

New client architecture
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants