Report a Dgraph Client Bug
Keep getting the error Transaction has been aborted
with Javascript gRpc client. Dgraph reboot needed.
What Dgraph client (and version) are you using?
(put “x” in the box to select)
- Dgo
- PyDgraph
- Dgraph4J
- Dgraph-js
- Dgraph-js-http
- Dgraph.NET
Version: latest
What version of Dgraph are you using?
v2011.2
Have you tried reproducing the issue with the latest release?
Yes
What is the hardware spec (RAM, OS)?
MacBook Pro 16" / OSX / 16 Gb ram
Steps to reproduce the issue (command/config used to run Dgraph).
I have a simple schema like this:
user.username: string @index(exact) .
user.email: string .
user.follow: [uid] @count @reverse .
user.id: string @index(exact) .
type User {
user.id
user.username
user.email
user.follow
<~user.follow>
}
I’m trying to load a bunch of random users with the following script:
import dgraph from 'dgraph-js';
import faker from 'faker';
import _ from 'lodash';
import schema from './schema.mjs';
const clientStub = new dgraph.DgraphClientStub('localhost:9080');
const dgraphClient = new dgraph.DgraphClient(clientStub);
const NB_USERS = 3000;
class Fixtures {
constructor(client) {
this.client = client;
}
async load() {
// await this.cleanGraph();
// await this.loadSchema();
const users = await this.loadUsers();
}
async cleanGraph() {
const op = new dgraph.Operation();
op.setDropAll(true);
await this.client.alter(op);
}
async loadSchema() {
const op = new dgraph.Operation();
op.setSchema(schema);
await this.client.alter(op);
}
async loadUsers() {
const users = [];
const userIds = _.range(0, NB_USERS - 1);
for (let i = 0; i < NB_USERS; i += 1) {
users.push({
uid: `_:user${i}`,
'dgraph.type': 'User',
'user.id': faker.datatype.uuid(),
'user.username': faker.internet.userName(),
'user.name': faker.name.findName(),
'user.email': faker.internet.email(),
'user.follow': _.sampleSize(userIds, _.random(1, NB_USERS / 10)).map((userId) => ({ uid: `_:user${userId}` })),
});
}
await this.loadObjects(users);
}
async loadObjects(objects) {
const txn = this.client.newTxn();
const mutations = [];
for (let i = 0; i < objects.length; i += 1) {
const mu = new dgraph.Mutation();
mu.setSetJson(objects[i]);
mutations.push(mu);
}
const req = new dgraph.Request();
req.setCommitNow(true);
req.setMutationsList(mutations);
await txn.doRequest(req);
}
}
// dgraphClient.setDebugMode(true);
const fixtures = new Fixtures(dgraphClient);
fixtures.load();
I have a bunch of problems.
-
Load a lot of data.
First, when I load about 1000 users, it’s quite fast to load. But with, 5000 it takes a really long time and fails most of the time (No matter if I run Dgraph with or without Docker). -
Running transaction again
Also, after the initial load, I can no longer run my script and I keep getting the errorError: Transaction has been aborted. Please retry
. I have to completely reboot Dgraph in order to make it work again. -
Query ordered by count
Lastly, when it works, I’m trying to run a query to get users ordered by the number of followers with a query like this:
{
q(func: Type("User"), orderdesc: followers) {
uid
user.username
user.email
followers: count(~user.follow)
following: count(user.follow)
}
}
But Dgraph doesn’t accept it and fails with the error : Cannot sort by unknown attribute followers
.
Thank you for reading me guys. Dgraph seems really good.