Skip to content

Commit 1d507b6

Browse files
Add support for tunable write consistency (#123)
1 parent e5ae7ba commit 1d507b6

25 files changed

+586
-32
lines changed

batch/journey.test.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,10 @@ describe("batch importing", () => {
179179
},
180180
];
181181

182-
it("imports them", () => {
182+
it("imports them with consistency level", () => {
183183
client.batch
184184
.objectsBatcher()
185+
.withConsistencyLevel(weaviate.replication.ConsistencyLevel.ONE)
185186
.withObjects([toImport[0], toImport[1]])
186187
.do()
187188
.then()
@@ -215,7 +216,7 @@ describe("batch importing", () => {
215216
})
216217
});
217218

218-
it("imports the refs with raw objects", () => {
219+
it("imports the refs with raw objects and consistency level", () => {
219220
return client.batch
220221
.referencesBatcher()
221222
.withReference({
@@ -226,6 +227,7 @@ describe("batch importing", () => {
226227
from: `weaviate://localhost/${thingClassName}/${thingIds[1]}/refProp`,
227228
to: `weaviate://localhost/${otherThingClassName}/${otherThingIds[1]}`,
228229
})
230+
.withConsistencyLevel(weaviate.replication.ConsistencyLevel.ALL)
229231
.do()
230232
.then((res) => {
231233
res.forEach((elem) => {
@@ -429,7 +431,7 @@ describe("batch deleting", () => {
429431
})
430432
)
431433

432-
it("batch deletes with default dryRun", () => {
434+
it("batch deletes with default dryRun and consistency level", () => {
433435
const inAMinute = "" + (new Date().getTime() + 60 * 1000);
434436
return client.batch
435437
.objectsBatchDeleter()
@@ -440,6 +442,7 @@ describe("batch deleting", () => {
440442
path: ["_creationTimeUnix"]
441443
})
442444
.withOutput(weaviate.batch.DeleteOutput.VERBOSE)
445+
.withConsistencyLevel(weaviate.replication.ConsistencyLevel.QUORUM)
443446
.do()
444447
.then(result => {
445448
expect(result.dryRun).toBe(false);

batch/objectsBatchDeleter.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { isValidStringProperty } from "../validation/string";
2+
import { buildObjectsPath } from "./path"
23

34
export default class ObjectsBatchDeleter {
45
className;
@@ -31,6 +32,11 @@ export default class ObjectsBatchDeleter {
3132
return this;
3233
}
3334

35+
withConsistencyLevel = (cl) => {
36+
this.consistencyLevel = cl;
37+
return this;
38+
};
39+
3440
payload() {
3541
return {
3642
match: {
@@ -72,7 +78,11 @@ export default class ObjectsBatchDeleter {
7278
new Error("invalid usage: " + this.errors.join(", "))
7379
);
7480
}
75-
const path = `/batch/objects`;
81+
let params = new URLSearchParams()
82+
if (this.consistencyLevel) {
83+
params.set("consistency_level", this.consistencyLevel)
84+
}
85+
const path = buildObjectsPath(params);
7686
return this.client.delete(path, this.payload(), true);
7787
};
7888
}

batch/objectsBatcher.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { buildObjectsPath } from "./path"
2+
13
export default class ObjectsBatcher {
24
constructor(client) {
35
this.client = client;
@@ -25,6 +27,11 @@ export default class ObjectsBatcher {
2527
return this.withObjects(object);
2628
};
2729

30+
withConsistencyLevel = (cl) => {
31+
this.consistencyLevel = cl;
32+
return this;
33+
};
34+
2835
payload = () => ({
2936
objects: this.objects,
3037
});
@@ -50,7 +57,11 @@ export default class ObjectsBatcher {
5057
new Error("invalid usage: " + this.errors.join(", "))
5158
);
5259
}
53-
const path = `/batch/objects`;
60+
let params = new URLSearchParams()
61+
if (this.consistencyLevel) {
62+
params.set("consistency_level", this.consistencyLevel)
63+
}
64+
const path = buildObjectsPath(params);
5465
return this.client.post(path, this.payload());
5566
};
5667
}

batch/path.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export function buildObjectsPath(queryParams) {
2+
let path = "/batch/objects";
3+
return buildPath(path, queryParams)
4+
}
5+
6+
export function buildRefsPath(queryParams) {
7+
let path = "/batch/references";
8+
return buildPath(path, queryParams)
9+
}
10+
11+
function buildPath(path, queryParams) {
12+
if (queryParams && queryParams.toString() != "") {
13+
path = `${path}?${queryParams.toString()}`
14+
}
15+
return path
16+
}

batch/path.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { buildObjectsPath, buildRefsPath } from "./path"
2+
3+
describe("paths", () => {
4+
it("builds batch objects without params", () => {
5+
let path = buildObjectsPath(new URLSearchParams())
6+
expect(path).toEqual("/batch/objects")
7+
})
8+
9+
it("builds batch objects with params", () => {
10+
let path = buildObjectsPath(new URLSearchParams({
11+
consistency_level: "ONE"
12+
}))
13+
expect(path).toEqual("/batch/objects?consistency_level=ONE")
14+
})
15+
16+
it("builds batch references without params", () => {
17+
let path = buildRefsPath(new URLSearchParams())
18+
expect(path).toEqual("/batch/references")
19+
})
20+
21+
it("builds batch object with params", () => {
22+
let path = buildRefsPath(new URLSearchParams({
23+
consistency_level: "ONE"
24+
}))
25+
expect(path).toEqual("/batch/references?consistency_level=ONE")
26+
})
27+
})

batch/referencesBatcher.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { buildRefsPath } from "./path"
2+
13
export default class ReferencesBatcher {
24
constructor(client, beaconPath) {
35
this.client = client;
@@ -26,6 +28,11 @@ export default class ReferencesBatcher {
2628
return this.withReferences(reference);
2729
}
2830

31+
withConsistencyLevel = (cl) => {
32+
this.consistencyLevel = cl;
33+
return this;
34+
};
35+
2936
payload = () => this.references;
3037

3138
validateReferenceCount = () => {
@@ -49,7 +56,11 @@ export default class ReferencesBatcher {
4956
new Error("invalid usage: " + this.errors.join(", "))
5057
);
5158
}
52-
const path = `/batch/references`;
59+
let params = new URLSearchParams()
60+
if (this.consistencyLevel) {
61+
params.set("consistency_level", this.consistencyLevel)
62+
}
63+
const path = buildRefsPath(params);
5364
const payloadPromise = Promise.all(this.references.map(ref => this.rebuildReferencePromise(ref)));
5465

5566
return payloadPromise.then(payload => this.client.post(path, payload));

ci/docker-compose-azure-cc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ services:
1111
- --scheme
1212
- http
1313
- --write-timeout=600s
14-
image: semitechnologies/weaviate:preview-replace-shardingconfig-replicas-with-replication-factor-29e987d
14+
image: semitechnologies/weaviate:1.18.0-alpha.0-be532d2
1515
ports:
1616
- 8081:8081
1717
restart: on-failure:0

ci/docker-compose-okta-cc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ services:
1010
- --scheme
1111
- http
1212
- --write-timeout=600s
13-
image: semitechnologies/weaviate:1.15.4-b7811d4
13+
image: semitechnologies/weaviate:1.18.0-alpha.0-be532d2
1414
ports:
1515
- 8082:8082
1616
restart: on-failure:0

ci/docker-compose-okta-users.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ services:
1010
- --scheme
1111
- http
1212
- --write-timeout=600s
13-
image: semitechnologies/weaviate:1.17.0
13+
image: semitechnologies/weaviate:1.18.0-alpha.0-be532d2
1414
ports:
1515
- 8083:8083
1616
restart: on-failure:0

ci/docker-compose-wcs-noscope.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ services:
1010
- --scheme
1111
- http
1212
- --write-timeout=600s
13-
image: semitechnologies/weaviate:1.17.0
13+
image: semitechnologies/weaviate:1.18.0-alpha.0-be532d2
1414
ports:
1515
- 8086:8086
1616
restart: on-failure:0

0 commit comments

Comments
 (0)