Skip to content

Commit f41719b

Browse files
author
Adam Mitchell
authored
Add prefilling of various response methods (#27)
## What is the goal of this PR? Currently, the protocol only returns IDs for every answer. However, it is very rare to only require the ID for a concept e.g. for an attribute you are most likely interested in its value. The goal of this PR is to mitigate the case where hundreds of concept IDs are returned for Attributes from a query, and the client program is going to do a sync RPC to get the value of each. ## What are the changes implemented in this PR? By taking a selection of example queries run against protocol, we can determine that there are some common requests that are always bounded (if the returned result is a concept, pre-filling it wouldn't lead to recursion). In the case that the returned concept would cause this kind of explosion, or for some reason the results can't be pre-fetched, the `isPrefilled` field notifies a client that this concept wasn't pre-filled (as opposed to just missing various pre-filled parts). Currently there is no way to explicitly enable pre-filling. This is a static and simple variation on the "time travelling RPC" concept, where we are returning the results of another RPC call on the result of a first (see Cap'n Proto), although we are a long way from achieving this as a general pattern right now.
1 parent 9dacbd3 commit f41719b

File tree

2 files changed

+29
-44
lines changed

2 files changed

+29
-44
lines changed

session/Concept.proto

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -107,24 +107,14 @@ message Method {
107107
SchemaConcept.SetLabel.Res schemaConcept_setLabel_res = 202;
108108
SchemaConcept.GetSup.Res schemaConcept_getSup_res = 203;
109109
SchemaConcept.SetSup.Res schemaConcept_setSup_res = 204;
110-
SchemaConcept.Sups.Iter schemaConcept_sups_iter = 205;
111-
SchemaConcept.Subs.Iter schemaConcept_subs_iter = 206;
112110

113111
// Rule method responses
114112
Rule.When.Res rule_when_res = 300;
115113
Rule.Then.Res rule_then_res = 301;
116114

117-
// Role method responses
118-
Role.Relations.Iter role_relations_iter = 401;
119-
Role.Players.Iter role_players_iter = 402;
120-
121115
// Type method responses
122116
Type.IsAbstract.Res type_isAbstract_res = 500;
123117
Type.SetAbstract.Res type_setAbstract_res = 501;
124-
Type.Instances.Iter type_instances_iter = 502;
125-
Type.Keys.Iter type_keys_iter = 503;
126-
Type.Attributes.Iter type_attributes_iter = 504;
127-
Type.Playing.Iter type_playing_iter = 505;
128118
Type.Has.Res type_has_res = 506;
129119
Type.Key.Res type_key_res = 507;
130120
Type.Plays.Res type_plays_res = 508;
@@ -137,7 +127,6 @@ message Method {
137127

138128
// RelationType method responses
139129
RelationType.Create.Res relationType_create_res = 700;
140-
RelationType.Roles.Iter relationType_roles_iter = 701;
141130
RelationType.Relates.Res relationType_relates_res = 702;
142131
RelationType.Unrelate.Res relationType_unrelate_res = 703;
143132

@@ -151,22 +140,15 @@ message Method {
151140
// Thing method responses
152141
Thing.Type.Res thing_type_res = 900;
153142
Thing.IsInferred.Res thing_isInferred_res = 901;
154-
Thing.Keys.Iter thing_keys_iter = 902;
155-
Thing.Attributes.Iter thing_attributes_iter = 903;
156-
Thing.Relations.Iter thing_relations_iter = 904;
157-
Thing.Roles.Iter thing_roles_iter = 905;
158143
Thing.Relhas.Res thing_relhas_res = 906;
159144
Thing.Unhas.Res thing_unhas_res = 907;
160145

161146
// Relation method responses
162-
Relation.RolePlayersMap.Iter relation_rolePlayersMap_iter = 1000;
163-
Relation.RolePlayers.Iter relation_rolePlayers_iter = 1001;
164147
Relation.Assign.Res relation_assign_res = 1002;
165148
Relation.Unassign.Res relation_unassign_res = 1003;
166149

167150
// Attribute method responses
168151
Attribute.Value.Res attribute_value_res = 1100;
169-
Attribute.Owners.Iter attribute_owners_iter = 1101;
170152
}
171153
}
172154

@@ -213,6 +195,14 @@ message Concept {
213195
string id = 1;
214196
BASE_TYPE baseType = 2;
215197

198+
// Pre-filled responses:
199+
Thing.Type.Res type_res = 5;
200+
Thing.IsInferred.Res inferred_res = 6;
201+
Attribute.Value.Res value_res = 7;
202+
AttributeType.DataType.Res dataType_res = 8;
203+
SchemaConcept.GetLabel.Res label_res = 9;
204+
SchemaConcept.IsImplicit.Res isImplicit_res = 10;
205+
216206
enum BASE_TYPE {
217207
META_TYPE = 0;
218208
ENTITY_TYPE = 1;
@@ -276,7 +266,6 @@ message SchemaConcept {
276266
message Sups {
277267
message Req {}
278268
message Iter {
279-
int32 id = 1;
280269
message Res {
281270
Concept schemaConcept = 1;
282271
}
@@ -286,7 +275,6 @@ message SchemaConcept {
286275
message Subs {
287276
message Req {}
288277
message Iter {
289-
int32 id = 1;
290278
message Res {
291279
Concept schemaConcept = 1;
292280
}
@@ -328,7 +316,6 @@ message Role {
328316
message Relations {
329317
message Req {}
330318
message Iter {
331-
int32 id = 1;
332319
message Res {
333320
Concept relationType = 1;
334321
}
@@ -338,7 +325,6 @@ message Role {
338325
message Players {
339326
message Req {}
340327
message Iter {
341-
int32 id = 1;
342328
message Res {
343329
Concept type = 1;
344330
}
@@ -368,7 +354,6 @@ message Type {
368354
message Instances {
369355
message Req {}
370356
message Iter {
371-
int32 id = 1;
372357
message Res {
373358
Concept thing = 1;
374359
}
@@ -378,7 +363,6 @@ message Type {
378363
message Attributes {
379364
message Req {}
380365
message Iter {
381-
int32 id = 1;
382366
message Res {
383367
Concept attributeType = 1;
384368
}
@@ -388,7 +372,6 @@ message Type {
388372
message Keys {
389373
message Req {}
390374
message Iter {
391-
int32 id = 1;
392375
message Res {
393376
Concept attributeType = 1;
394377
}
@@ -398,7 +381,6 @@ message Type {
398381
message Playing {
399382
message Req {}
400383
message Iter {
401-
int32 id = 1;
402384
message Res {
403385
Concept role = 1;
404386
}
@@ -476,7 +458,6 @@ message RelationType {
476458
message Roles {
477459
message Req {}
478460
message Iter {
479-
int32 id = 1;
480461
message Res {
481462
Concept role = 1;
482463
}
@@ -583,7 +564,6 @@ message Thing {
583564
repeated Concept attributeTypes = 1;
584565
}
585566
message Iter {
586-
int32 id = 1;
587567
message Res {
588568
Concept attribute = 1;
589569
}
@@ -595,7 +575,6 @@ message Thing {
595575
repeated Concept attributeTypes = 1;
596576
}
597577
message Iter {
598-
int32 id = 1;
599578
message Res {
600579
Concept attribute = 1;
601580
}
@@ -607,7 +586,6 @@ message Thing {
607586
repeated Concept roles = 1;
608587
}
609588
message Iter {
610-
int32 id = 1;
611589
message Res {
612590
Concept relation = 1;
613591
}
@@ -617,7 +595,6 @@ message Thing {
617595
message Roles {
618596
message Req {}
619597
message Iter {
620-
int32 id = 1;
621598
message Res {
622599
Concept role = 1;
623600
}
@@ -649,7 +626,6 @@ message Relation {
649626
message RolePlayersMap {
650627
message Req {}
651628
message Iter {
652-
int32 id = 1;
653629
message Res {
654630
Concept role = 1;
655631
Concept player = 2;
@@ -662,7 +638,6 @@ message Relation {
662638
repeated Concept roles = 1;
663639
}
664640
message Iter {
665-
int32 id = 1;
666641
message Res {
667642
Concept thing = 1;
668643
}
@@ -700,7 +675,6 @@ message Attribute {
700675
message Owners {
701676
message Req {}
702677
message Iter {
703-
int32 id = 1;
704678
message Res {
705679
Concept thing = 1;
706680
}

session/Session.proto

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ message Transaction {
6565
Open.Req open_req = 1;
6666
Commit.Req commit_req = 2;
6767
Query.Req query_req = 3;
68-
Iter.Req iterate_req = 4;
68+
Batch.Req batch_req = 4;
6969
GetSchemaConcept.Req getSchemaConcept_req = 5;
7070
GetConcept.Req getConcept_req = 6;
7171
GetAttributes.Req getAttributes_req = 7;
@@ -82,11 +82,9 @@ message Transaction {
8282
oneof res {
8383
Open.Res open_res = 1;
8484
Commit.Res commit_res = 2;
85-
Query.Iter query_iter = 3;
8685
Iter.Res iterate_res = 4;
8786
GetSchemaConcept.Res getSchemaConcept_res = 5;
8887
GetConcept.Res getConcept_res = 6;
89-
GetAttributes.Iter getAttributes_iter = 7;
9088
PutEntityType.Res putEntityType_res = 8;
9189
PutAttributeType.Res putAttributeType_res = 9;
9290
PutRelationType.Res putRelationType_res = 10;
@@ -98,20 +96,34 @@ message Transaction {
9896
}
9997

10098
message Iter {
101-
message Req {
102-
int32 id = 1;
103-
bool all = 2;
104-
}
10599
message Res {
106100
oneof res {
107101
bool done = 1;
102+
Batch.Res batch_res = 5;
103+
108104
Query.Iter.Res query_iter_res = 2;
109105
GetAttributes.Iter.Res getAttributes_iter_res = 3;
110106
Method.Iter.Res conceptMethod_iter_res = 4;
111107
}
112108
}
113109
}
114110

111+
message Batch {
112+
message Options {
113+
oneof batch_size {
114+
int32 number = 1;
115+
bool all = 2;
116+
}
117+
}
118+
message Req {
119+
int32 id = 1;
120+
Options batch_options = 2;
121+
}
122+
message Res {
123+
int32 id = 1;
124+
}
125+
}
126+
115127
enum Type {
116128
READ = 0;
117129
WRITE = 1;
@@ -124,7 +136,6 @@ message Transaction {
124136
Type type = 2;
125137
}
126138
message Res {}
127-
128139
}
129140

130141
message Commit {
@@ -138,9 +149,10 @@ message Transaction {
138149
INFER infer = 2;
139150
// We cannot use bool for `infer` because GRPC's default value for bool is FALSE
140151
// We use enum INFER instead, because the default value is index 0 (TRUE)
152+
153+
Batch.Options batch_options = 3;
141154
}
142155
message Iter {
143-
int32 id = 1;
144156
message Res {
145157
Answer answer = 1;
146158
}
@@ -181,7 +193,6 @@ message Transaction {
181193
ValueObject value = 1;
182194
}
183195
message Iter {
184-
int32 id = 1;
185196
message Res {
186197
Concept attribute = 1;
187198
}

0 commit comments

Comments
 (0)