Skip to content

Commit 688403c

Browse files
Merge pull request #135 from dgraph-io/apoorv/txn-robust
chore: Sync api.proto & deprecate Slash endpoint method
2 parents 2259093 + 33dd410 commit 688403c

File tree

7 files changed

+88
-42
lines changed

7 files changed

+88
-42
lines changed

generated/api_pb.d.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ export class Request extends jspb.Message {
2929
getRespFormat(): Request.RespFormatMap[keyof Request.RespFormatMap];
3030
setRespFormat(value: Request.RespFormatMap[keyof Request.RespFormatMap]): void;
3131

32+
getHash(): string;
33+
setHash(value: string): void;
34+
3235
serializeBinary(): Uint8Array;
3336
toObject(includeInstance?: boolean): Request.AsObject;
3437
static toObject(includeInstance: boolean, msg: Request): Request.AsObject;
@@ -49,6 +52,7 @@ export namespace Request {
4952
mutationsList: Array<Mutation.AsObject>,
5053
commitNow: boolean,
5154
respFormat: Request.RespFormatMap[keyof Request.RespFormatMap],
55+
hash: string,
5256
}
5357

5458
export interface RespFormatMap {
@@ -307,6 +311,9 @@ export class TxnContext extends jspb.Message {
307311
setPredsList(value: Array<string>): void;
308312
addPreds(value: string, index?: number): string;
309313

314+
getHash(): string;
315+
setHash(value: string): void;
316+
310317
serializeBinary(): Uint8Array;
311318
toObject(includeInstance?: boolean): TxnContext.AsObject;
312319
static toObject(includeInstance: boolean, msg: TxnContext): TxnContext.AsObject;
@@ -324,6 +331,7 @@ export namespace TxnContext {
324331
aborted: boolean,
325332
keysList: Array<string>,
326333
predsList: Array<string>,
334+
hash: string,
327335
}
328336
}
329337

@@ -433,9 +441,6 @@ export class NQuad extends jspb.Message {
433441
getObjectValue(): Value | undefined;
434442
setObjectValue(value?: Value): void;
435443

436-
getLabel(): string;
437-
setLabel(value: string): void;
438-
439444
getLang(): string;
440445
setLang(value: string): void;
441446

@@ -463,7 +468,6 @@ export namespace NQuad {
463468
predicate: string,
464469
objectId: string,
465470
objectValue?: Value.AsObject,
466-
label: string,
467471
lang: string,
468472
facetsList: Array<Facet.AsObject>,
469473
namespace: number,

generated/api_pb.js

Lines changed: 62 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,8 @@ proto.api.Request.toObject = function(includeInstance, msg) {
439439
mutationsList: jspb.Message.toObjectList(msg.getMutationsList(),
440440
proto.api.Mutation.toObject, includeInstance),
441441
commitNow: jspb.Message.getBooleanFieldWithDefault(msg, 13, false),
442-
respFormat: jspb.Message.getFieldWithDefault(msg, 14, 0)
442+
respFormat: jspb.Message.getFieldWithDefault(msg, 14, 0),
443+
hash: jspb.Message.getFieldWithDefault(msg, 15, "")
443444
};
444445

445446
if (includeInstance) {
@@ -511,6 +512,10 @@ proto.api.Request.deserializeBinaryFromReader = function(msg, reader) {
511512
var value = /** @type {!proto.api.Request.RespFormat} */ (reader.readEnum());
512513
msg.setRespFormat(value);
513514
break;
515+
case 15:
516+
var value = /** @type {string} */ (reader.readString());
517+
msg.setHash(value);
518+
break;
514519
default:
515520
reader.skipField();
516521
break;
@@ -594,6 +599,13 @@ proto.api.Request.serializeBinaryToWriter = function(message, writer) {
594599
f
595600
);
596601
}
602+
f = message.getHash();
603+
if (f.length > 0) {
604+
writer.writeString(
605+
15,
606+
f
607+
);
608+
}
597609
};
598610

599611

@@ -773,6 +785,24 @@ proto.api.Request.prototype.setRespFormat = function(value) {
773785
};
774786

775787

788+
/**
789+
* optional string hash = 15;
790+
* @return {string}
791+
*/
792+
proto.api.Request.prototype.getHash = function() {
793+
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 15, ""));
794+
};
795+
796+
797+
/**
798+
* @param {string} value
799+
* @return {!proto.api.Request} returns this
800+
*/
801+
proto.api.Request.prototype.setHash = function(value) {
802+
return jspb.Message.setProto3StringField(this, 15, value);
803+
};
804+
805+
776806

777807
/**
778808
* List of repeated fields within this message type.
@@ -2489,7 +2519,8 @@ proto.api.TxnContext.toObject = function(includeInstance, msg) {
24892519
commitTs: jspb.Message.getFieldWithDefault(msg, 2, 0),
24902520
aborted: jspb.Message.getBooleanFieldWithDefault(msg, 3, false),
24912521
keysList: (f = jspb.Message.getRepeatedField(msg, 4)) == null ? undefined : f,
2492-
predsList: (f = jspb.Message.getRepeatedField(msg, 5)) == null ? undefined : f
2522+
predsList: (f = jspb.Message.getRepeatedField(msg, 5)) == null ? undefined : f,
2523+
hash: jspb.Message.getFieldWithDefault(msg, 6, "")
24932524
};
24942525

24952526
if (includeInstance) {
@@ -2546,6 +2577,10 @@ proto.api.TxnContext.deserializeBinaryFromReader = function(msg, reader) {
25462577
var value = /** @type {string} */ (reader.readString());
25472578
msg.addPreds(value);
25482579
break;
2580+
case 6:
2581+
var value = /** @type {string} */ (reader.readString());
2582+
msg.setHash(value);
2583+
break;
25492584
default:
25502585
reader.skipField();
25512586
break;
@@ -2610,6 +2645,13 @@ proto.api.TxnContext.serializeBinaryToWriter = function(message, writer) {
26102645
f
26112646
);
26122647
}
2648+
f = message.getHash();
2649+
if (f.length > 0) {
2650+
writer.writeString(
2651+
6,
2652+
f
2653+
);
2654+
}
26132655
};
26142656

26152657

@@ -2741,6 +2783,24 @@ proto.api.TxnContext.prototype.clearPredsList = function() {
27412783
};
27422784

27432785

2786+
/**
2787+
* optional string hash = 6;
2788+
* @return {string}
2789+
*/
2790+
proto.api.TxnContext.prototype.getHash = function() {
2791+
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 6, ""));
2792+
};
2793+
2794+
2795+
/**
2796+
* @param {string} value
2797+
* @return {!proto.api.TxnContext} returns this
2798+
*/
2799+
proto.api.TxnContext.prototype.setHash = function(value) {
2800+
return jspb.Message.setProto3StringField(this, 6, value);
2801+
};
2802+
2803+
27442804

27452805

27462806

@@ -3398,7 +3458,6 @@ proto.api.NQuad.toObject = function(includeInstance, msg) {
33983458
predicate: jspb.Message.getFieldWithDefault(msg, 2, ""),
33993459
objectId: jspb.Message.getFieldWithDefault(msg, 3, ""),
34003460
objectValue: (f = msg.getObjectValue()) && proto.api.Value.toObject(includeInstance, f),
3401-
label: jspb.Message.getFieldWithDefault(msg, 5, ""),
34023461
lang: jspb.Message.getFieldWithDefault(msg, 6, ""),
34033462
facetsList: jspb.Message.toObjectList(msg.getFacetsList(),
34043463
proto.api.Facet.toObject, includeInstance),
@@ -3456,10 +3515,6 @@ proto.api.NQuad.deserializeBinaryFromReader = function(msg, reader) {
34563515
reader.readMessage(value,proto.api.Value.deserializeBinaryFromReader);
34573516
msg.setObjectValue(value);
34583517
break;
3459-
case 5:
3460-
var value = /** @type {string} */ (reader.readString());
3461-
msg.setLabel(value);
3462-
break;
34633518
case 6:
34643519
var value = /** @type {string} */ (reader.readString());
34653520
msg.setLang(value);
@@ -3531,13 +3586,6 @@ proto.api.NQuad.serializeBinaryToWriter = function(message, writer) {
35313586
proto.api.Value.serializeBinaryToWriter
35323587
);
35333588
}
3534-
f = message.getLabel();
3535-
if (f.length > 0) {
3536-
writer.writeString(
3537-
5,
3538-
f
3539-
);
3540-
}
35413589
f = message.getLang();
35423590
if (f.length > 0) {
35433591
writer.writeString(
@@ -3654,24 +3702,6 @@ proto.api.NQuad.prototype.hasObjectValue = function() {
36543702
};
36553703

36563704

3657-
/**
3658-
* optional string label = 5;
3659-
* @return {string}
3660-
*/
3661-
proto.api.NQuad.prototype.getLabel = function() {
3662-
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 5, ""));
3663-
};
3664-
3665-
3666-
/**
3667-
* @param {string} value
3668-
* @return {!proto.api.NQuad} returns this
3669-
*/
3670-
proto.api.NQuad.prototype.setLabel = function(value) {
3671-
return jspb.Message.setProto3StringField(this, 5, value);
3672-
};
3673-
3674-
36753705
/**
36763706
* optional string lang = 6;
36773707
* @return {string}

lib/txn.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ var Txn = (function () {
161161
this.mutated = true;
162162
}
163163
req.setStartTs(this.ctx.getStartTs());
164+
req.setHash(this.ctx.getHash());
164165
this.dc.debug("Do request:\n" + util_1.stringifyMessage(req));
165166
c = this.dc.anyClient();
166167
operation = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
@@ -296,6 +297,7 @@ var Txn = (function () {
296297
if (src === undefined) {
297298
return;
298299
}
300+
this.ctx.setHash(src.getHash());
299301
if (this.ctx.getStartTs() === 0) {
300302
this.ctx.setStartTs(src.getStartTs());
301303
}

protos/api.proto

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ message Request {
5757
RDF = 1;
5858
}
5959
RespFormat resp_format = 14;
60+
string hash = 15;
6061
}
6162

6263
message Uids {
@@ -128,6 +129,7 @@ message TxnContext {
128129
bool aborted = 3;
129130
repeated string keys = 4; // List of keys to be used for conflict detection.
130131
repeated string preds = 5; // List of predicates involved in this transaction.
132+
string hash = 6;
131133
}
132134

133135
message Check {}
@@ -150,11 +152,11 @@ message Metrics {
150152
}
151153

152154
message NQuad {
155+
reserved 5; // This was used for label.
153156
string subject = 1;
154157
string predicate = 2;
155158
string object_id = 3;
156159
Value object_value = 4;
157-
string label = 5;
158160
string lang = 6;
159161
repeated Facet facets = 7;
160162
uint64 namespace = 8;

src/clientStubFromSlash.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import * as Url from "url-parse";
33
import { DgraphClientStub } from "./clientStub";
44

55
const PORT = "443";
6+
/**
7+
* @deprecated since v21.3 and will be removed in v21.07 release. For more details, see:
8+
* https://discuss.dgraph.io/t/regarding-slash-cloud-dgraph-endpoints-in-the-clients/13492
9+
*/
10+
611
export function clientStubFromSlashGraphQLEndpoint(
712
graphqlEndpoint: string,
813
apiKey: string,

src/txn.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ export class Txn {
212212
}
213213

214214
req.setStartTs(this.ctx.getStartTs());
215+
req.setHash(this.ctx.getHash());
215216
this.dc.debug(`Do request:\n${stringifyMessage(req)}`);
216217

217218
let resp: types.Response;
@@ -332,6 +333,8 @@ export class Txn {
332333
return;
333334
}
334335

336+
this.ctx.setHash(src.getHash());
337+
335338
if (this.ctx.getStartTs() === 0) {
336339
this.ctx.setStartTs(src.getStartTs());
337340
} else if (this.ctx.getStartTs() !== src.getStartTs()) {

tests/integration/acl.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jest.setTimeout(JEST_TIMEOUT);
1212

1313
let client: dgraph.DgraphClient;
1414

15-
const GROOT_PWD = "password";
15+
const GUARDIAN_CREDS = "user=groot;password=password;namespace=0";
1616
const USERID = "alice";
1717
const USERPWD = "alicepassword";
1818
const PRED = "name";
@@ -71,22 +71,22 @@ async function aclSetup() {
7171
}
7272

7373
async function addUser() {
74-
const command = `dgraph acl -a ${SERVER_ADDR} add -u ${USERID} -p ${USERPWD} -x ${GROOT_PWD}`;
74+
const command = `dgraph acl -a \'${SERVER_ADDR}\' add -u \'${USERID}\' -p \'${USERPWD}\' --guardian-creds \'${GUARDIAN_CREDS}\'`;
7575
await cmd(command);
7676
}
7777

7878
async function addGroup() {
79-
const command = `dgraph acl -a ${SERVER_ADDR} add -g ${DEV_GROUP} -x ${GROOT_PWD}`;
79+
const command = `dgraph acl -a \'${SERVER_ADDR}\' add -g \'${DEV_GROUP}\' --guardian-creds \'${GUARDIAN_CREDS}\'`;
8080
await cmd(command);
8181
}
8282

8383
async function addUserToGroup() {
84-
const command = `dgraph acl -a ${SERVER_ADDR} mod -u ${USERID} -l ${DEV_GROUP} -x ${GROOT_PWD}`;
84+
const command = `dgraph acl -a \'${SERVER_ADDR}\' mod -u \'${USERID}\' -l \'${DEV_GROUP}\' --guardian-creds \'${GUARDIAN_CREDS}\'`;
8585
await cmd(command);
8686
}
8787

8888
async function changePermission(permission: number) {
89-
const command = `dgraph acl -a ${SERVER_ADDR} mod -g ${DEV_GROUP} -p ${PRED} -m ${permission} -x ${GROOT_PWD}`;
89+
const command = `dgraph acl -a \'${SERVER_ADDR}\' mod -g \'${DEV_GROUP}\' -p \'${PRED}\' -m \'${permission}\' --guardian-creds \'${GUARDIAN_CREDS}\'`;
9090
await cmd(command);
9191
await wait(WAIT_FOR_SIX_SECONDS);
9292
}

0 commit comments

Comments
 (0)