Skip to content
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

feat(GraphService): Add Dgraph implementation of GraphService #3261

Conversation

EnricoMi
Copy link
Contributor

@EnricoMi EnricoMi commented Sep 18, 2021

This implements the GraphService API for Dgraph (https://dgraph.io). This implementation passes all GraphService tests added in #3011. Integration of Dgraph into GMS factories and the Docker setup is happening in a follow-up PR.

Checklist

  • The PR conforms to DataHub's Contributing Guideline (particularly Commit Message Format)
  • Links to related issues (if applicable)
  • Tests for the changes have been added/updated (if applicable)
  • Docs related to the changes have been added/updated (if applicable)

Fixes #3084.

@EnricoMi EnricoMi marked this pull request as draft September 20, 2021 07:37
@EnricoMi
Copy link
Contributor Author

Tests in master are not flaky: https://github.com/linkedin/datahub/actions/runs/1253184869.

@EnricoMi EnricoMi force-pushed the branch-test-dgraph-graph-service-thoroughly branch 4 times, most recently from 1ee76b8 to 585ad18 Compare September 27, 2021 08:03
@EnricoMi EnricoMi force-pushed the branch-test-dgraph-graph-service-thoroughly branch 6 times, most recently from bbf53e8 to 891a451 Compare October 6, 2021 10:46
@@ -41,6 +41,7 @@ project.ext.externalDependency = [
'commonsLang': 'commons-lang:commons-lang:2.6',
'commonsCollections': 'commons-collections:commons-collections:3.2.2',
'data' : 'com.linkedin.pegasus:data:' + pegasusVersion,
'dgraph4j' : 'io.dgraph:dgraph4j:21.03.1',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have different DAOs in datahub-gma, for example, gmaNeo4jDao. How about adding DgraphDAO?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would the purpose be? Who would be using it other than the DgraphGraphService?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I don't see a need for a DAO at the moment. If we need to create a shared DAO later down the line, we can always refactor DgraphGraphService

@EnricoMi EnricoMi force-pushed the branch-test-dgraph-graph-service-thoroughly branch from 3735b48 to 12cbfc1 Compare October 6, 2021 20:12
@EnricoMi EnricoMi marked this pull request as ready for review October 7, 2021 19:40
@EnricoMi EnricoMi force-pushed the branch-test-dgraph-graph-service-thoroughly branch from e88e118 to 739b16f Compare October 7, 2021 20:15
)) {
try {
// wait 0.01s, 0.02s, 0.04s, 0.08s, ..., 10.24s
long time = (long) Math.pow(2, Math.min(retry, 10)) * 10;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe declare this as a named const?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, called Duration INITIAL_DURATION and double BACKOFF_MULTIPLIER.

synchronized (System.out) {
System.out.println(System.currentTimeMillis() + ": schema not available yet, waiting 10s");
}
TimeUnit.SECONDS.sleep(10);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10s seems like an aggressive wait time- how long does it usually take for this schema to become available? Will this block gms from starting up?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only happens rarely and only when you start a new Dgraph instance. The service is up but the schema is not yet initialized. For a production service or cluster the schema is always there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe all this is not really needed. There are two possible situations when no schema information are contained in the response (no schema info meaning not even saying the schema is empty):

  1. there is no schema on the Dgraph cluster
  2. there is a schema on the Dgraph cluster

In 1) we want to create un-seen types and relationship types, in 2) we don't want to create what is already there. But since creating those types in the Dgraph schema should be idempotent anyway, we do not get into an inconsistent state when we create those existing types again.

I will rework this and assume an empty schema when no schema information are returned.

)) {
try {
// wait 0.01s, 0.02s, 0.04s, 0.08s, ..., 10.24s
long time = (long) Math.pow(2, Math.min(retry, 10)) * 10;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this backoff method be shared with Dgraph executor? Seems like there are some opportunities to factor out some shared code here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method was meant to be moved into DgraphExecutor, looks like I forgot to delete it here. This method is not referenced any more, removing.

Comment on lines 23 to 53
// request options for all requests
private static final RequestOptions OPTIONS = RequestOptions.DEFAULT;

private interface ThrowingSupplier<T, E extends Exception> {
T get() throws E;
}

// We are retrying requests, otherwise concurrency tests will see exceptions like these:
// java.net.SocketTimeoutException: 30,000 milliseconds timeout on connection http-outgoing-1 [ACTIVE]
private static <T> T retry(ThrowingSupplier<T, Exception> func) {
int attempts = 3;
Exception exception = null;

while (attempts > 0) {
try {
attempts--;
return func.get();
} catch (Exception e) {
exception = e;
if (e instanceof SocketTimeoutException) {
continue;
}
break;
}
}

throw new RuntimeException(exception);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this change come in a separate PR? Is this a blocker for the dgraph changes? seems like it may be easier to debug in case something goes wrong by separating this change out

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, will move that out

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved into #3377, which uses Resilience4j library for retry logic. The exponential backoff retry logic in DgraphExecutor also moved to use Resilience4j.

@EnricoMi EnricoMi force-pushed the branch-test-dgraph-graph-service-thoroughly branch from 23a8aeb to 801d272 Compare October 12, 2021 19:38
@EnricoMi EnricoMi force-pushed the branch-test-dgraph-graph-service-thoroughly branch 2 times, most recently from 9e9e3c7 to 8cd23d1 Compare October 21, 2021 19:19
@EnricoMi EnricoMi force-pushed the branch-test-dgraph-graph-service-thoroughly branch 4 times, most recently from 043b4fe to 6c71d79 Compare October 26, 2021 16:58
@EnricoMi EnricoMi force-pushed the branch-test-dgraph-graph-service-thoroughly branch from 5d85c93 to 451be33 Compare November 4, 2021 09:22
@EnricoMi
Copy link
Contributor Author

EnricoMi commented Nov 4, 2021

@gabe-lyons any more comments? is this good to go?

@gabe-lyons
Copy link
Contributor

Hey @EnricoMi - this is good to go from my end!

@EnricoMi
Copy link
Contributor Author

EnricoMi commented Nov 4, 2021

Good to hear @gabe-lyons, this is ready to go into master from my side as well.

I think the failing smoke test is spurious as I cannot reproduce it locally. Maybe someone can rerun that workflow?

@gabe-lyons
Copy link
Contributor

I agree- that looks unrelated. I've seen this test to be flakey as well cc @jjoyce0510

@EnricoMi
Copy link
Contributor Author

EnricoMi commented Nov 4, 2021

All green, yay. Btw, these new test stats look awesome ;-)

grafik

Copy link
Contributor

@shirshanka shirshanka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@shirshanka shirshanka merged commit 031e0b9 into datahub-project:master Nov 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for Dgraph as the graph database backend
4 participants