Skip to content

Commit 8f13481

Browse files
committed
Txn context robust
1 parent 2259093 commit 8f13481

File tree

7 files changed

+83
-2
lines changed

7 files changed

+83
-2
lines changed

generated/api_pb.d.ts

Lines changed: 8 additions & 0 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

generated/api_pb.js

Lines changed: 62 additions & 2 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

lib/clientStubFromSlash.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var Url = require("url-parse");
66
var clientStub_1 = require("./clientStub");
77
var PORT = "443";
88
function clientStubFromSlashGraphQLEndpoint(graphqlEndpoint, apiKey) {
9+
console.warn("This method is deprecated and will be removed in v21.07 release.");
910
var url = new Url(graphqlEndpoint);
1011
var urlParts = url.host.split(".");
1112
var firstHalf = urlParts[0];

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: 2 additions & 0 deletions
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 {}

src/clientStubFromSlash.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@ 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.
8+
*/
9+
610
export function clientStubFromSlashGraphQLEndpoint(
711
graphqlEndpoint: string,
812
apiKey: string,
913
) {
14+
console.warn("This method is deprecated and will be removed in v21.07 release.");
1015
const url = new Url(graphqlEndpoint);
1116
const urlParts = url.host.split(".");
1217
const firstHalf = urlParts[0];

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()) {

0 commit comments

Comments
 (0)