Skip to content
This repository was archived by the owner on Oct 9, 2023. It is now read-only.

Commit c7e3c7e

Browse files
author
Alex Walker
authored
Encode request IDs as bytes and make is_inferred a Local Thing method (#221)
## What is the goal of this PR? Previously the ID of a transaction request was stored as a string, which is an inefficient representation of a UUID. We've changed it to bytes. Also, `is_inferred` is now a Local method on `Thing`. ## What are the changes implemented in this PR? Store request IDs as bytes, not strings Make isInferred a Local Thing method
1 parent 6c6b364 commit c7e3c7e

File tree

13 files changed

+79
-77
lines changed

13 files changed

+79
-77
lines changed

dependencies/graknlabs/artifacts.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def graknlabs_grakn_core_artifacts():
2727
artifact_name = "grakn-core-server-{platform}-{version}.{ext}",
2828
tag_source = deployment["artifact.release"],
2929
commit_source = deployment["artifact.snapshot"],
30-
commit = "a36868f1e8a34188eb371dee329ed499399cb40f",
30+
commit = "922f9e50d05fd24187c5f020a8fc720722d49a60",
3131
)
3232

3333
def graknlabs_grakn_cluster_artifacts():
@@ -37,5 +37,5 @@ def graknlabs_grakn_cluster_artifacts():
3737
artifact_name = "grakn-cluster-all-{platform}-{version}.{ext}",
3838
tag_source = deployment_private["artifact.release"],
3939
commit_source = deployment_private["artifact.snapshot"],
40-
commit = "f08e4d9e194ee7e1806995377c8b0a7bd56903ec"
40+
commit = "ff24c81c3ce821d25df802192db05d6084365161"
4141
)

grakn/api/concept/thing/thing.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ def get_iid(self) -> str:
3939
def get_type(self) -> "ThingType":
4040
pass
4141

42+
@abstractmethod
43+
def is_inferred(self) -> bool:
44+
pass
45+
4246
def is_thing(self) -> bool:
4347
return True
4448

@@ -57,10 +61,6 @@ def set_has(self, attribute: "Attribute") -> None:
5761
def unset_has(self, attribute: "Attribute") -> None:
5862
pass
5963

60-
@abstractmethod
61-
def is_inferred(self) -> bool:
62-
pass
63-
6464
@abstractmethod
6565
def get_has(self, attribute_type: "AttributeType" = None, attribute_types: List["AttributeType"] = None, only_key: bool = False) -> Iterator["Attribute"]:
6666
pass

grakn/cluster/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def databases(self) -> _ClusterDatabaseManager:
6767
def session(self, database: str, session_type: SessionType, options=None) -> _ClusterSession:
6868
if not options:
6969
options = GraknOptions.cluster()
70-
return self._session_any_replica(database, session_type, options) if options.read_any_replica else self._session_primary_replica(database, session_type, options)
70+
return self._session_any_replica(database, session_type, options) if getattr(options, "read_any_replica", False) else self._session_primary_replica(database, session_type, options)
7171

7272
def _session_primary_replica(self, database: str, session_type: SessionType, options=None) -> _ClusterSession:
7373
return _OpenSessionFailsafeTask(database, session_type, options, self).run_primary_replica()

grakn/cluster/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __init__(self, cluster_client: "_ClusterClient", server_address: str, databa
4242
def transaction(self, transaction_type: TransactionType, options: GraknClusterOptions = None) -> _CoreTransaction:
4343
if not options:
4444
options = GraknOptions.cluster()
45-
return self._transaction_any_replica(transaction_type, options) if options.read_any_replica else self._transaction_primary_replica(transaction_type, options)
45+
return self._transaction_any_replica(transaction_type, options) if getattr(options, "read_any_replica", False) else self._transaction_primary_replica(transaction_type, options)
4646

4747
def _transaction_primary_replica(self, transaction_type: TransactionType, options: GraknClusterOptions) -> _CoreTransaction:
4848
return _TransactionFailsafeTask(self, transaction_type, options).run_primary_replica()

grakn/common/rpc/request_builder.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
# specific language governing permissions and limitations
1717
# under the License.
1818
#
19-
import uuid
2019
from datetime import datetime
2120
from typing import List
21+
from uuid import UUID
2222

2323
import grakn_protocol.cluster.cluster_database_pb2 as cluster_database_proto
2424
import grakn_protocol.cluster.cluster_server_pb2 as cluster_server_proto
@@ -114,9 +114,9 @@ def transaction_client_msg(reqs: List[transaction_proto.Transaction.Req]):
114114
return req
115115

116116

117-
def transaction_stream_req(req_id: uuid):
117+
def transaction_stream_req(req_id: UUID):
118118
req = transaction_proto.Transaction.Req()
119-
req.req_id = str(req_id)
119+
req.req_id = req_id.bytes
120120
stream_req = transaction_proto.Transaction.Stream.Req()
121121
req.stream_req.CopyFrom(stream_req)
122122
return req
@@ -583,12 +583,6 @@ def thing_req(req: concept_proto.Thing.Req, iid: str):
583583
return tx_req
584584

585585

586-
def thing_is_inferred_req(iid: str):
587-
req = concept_proto.Thing.Req()
588-
req.thing_is_inferred_req.CopyFrom(concept_proto.Thing.IsInferred.Req())
589-
return thing_req(req, iid)
590-
591-
592586
def thing_get_has_req(iid: str, attribute_types: List[concept_proto.Type] = None, only_key: bool = False):
593587
if attribute_types and only_key:
594588
raise GraknClientException.of(GET_HAS_WITH_MULTIPLE_FILTERS)

grakn/concept/thing/attribute.py

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ def get_owners(self, owner_type: ThingType = None):
4545

4646
class _BooleanAttribute(BooleanAttribute, _Attribute):
4747

48-
def __init__(self, iid: str, type_: BooleanAttributeType, value: bool):
49-
super(_BooleanAttribute, self).__init__(iid)
48+
def __init__(self, iid: str, is_inferred: bool, type_: BooleanAttributeType, value: bool):
49+
super(_BooleanAttribute, self).__init__(iid, is_inferred)
5050
self._type = type_
5151
self._value = value
5252

5353
@staticmethod
5454
def of(thing_proto: concept_proto.Thing):
55-
return _BooleanAttribute(concept_proto_reader.iid(thing_proto.iid), concept_proto_reader.attribute_type(thing_proto.type), thing_proto.value.boolean)
55+
return _BooleanAttribute(concept_proto_reader.iid(thing_proto.iid), thing_proto.inferred, concept_proto_reader.attribute_type(thing_proto.type), thing_proto.value.boolean)
5656

5757
def get_type(self) -> "BooleanAttributeType":
5858
return self._type
@@ -61,13 +61,13 @@ def get_value(self):
6161
return self._value
6262

6363
def as_remote(self, transaction):
64-
return _RemoteBooleanAttribute(transaction, self.get_iid(), self.get_type(), self.get_value())
64+
return _RemoteBooleanAttribute(transaction, self.get_iid(), self.is_inferred(), self.get_type(), self.get_value())
6565

6666

6767
class _RemoteBooleanAttribute(RemoteBooleanAttribute, _RemoteAttribute):
6868

69-
def __init__(self, transaction, iid: str, type_, value: bool):
70-
super(_RemoteBooleanAttribute, self).__init__(transaction, iid)
69+
def __init__(self, transaction, iid: str, is_inferred: bool, type_, value: bool):
70+
super(_RemoteBooleanAttribute, self).__init__(transaction, iid, is_inferred)
7171
self._type = type_
7272
self._value = value
7373

@@ -78,19 +78,19 @@ def get_value(self):
7878
return self._value
7979

8080
def as_remote(self, transaction):
81-
return _RemoteBooleanAttribute(transaction, self.get_iid(), self.get_type(), self.get_value())
81+
return _RemoteBooleanAttribute(transaction, self.get_iid(), self.is_inferred(), self.get_type(), self.get_value())
8282

8383

8484
class _LongAttribute(LongAttribute, _Attribute):
8585

86-
def __init__(self, iid: str, type_: LongAttributeType, value: int):
87-
super(_LongAttribute, self).__init__(iid)
86+
def __init__(self, iid: str, is_inferred: bool, type_: LongAttributeType, value: int):
87+
super(_LongAttribute, self).__init__(iid, is_inferred)
8888
self._type = type_
8989
self._value = value
9090

9191
@staticmethod
9292
def of(thing_proto: concept_proto.Thing):
93-
return _LongAttribute(concept_proto_reader.iid(thing_proto.iid), concept_proto_reader.attribute_type(thing_proto.type), thing_proto.value.long)
93+
return _LongAttribute(concept_proto_reader.iid(thing_proto.iid), thing_proto.inferred, concept_proto_reader.attribute_type(thing_proto.type), thing_proto.value.long)
9494

9595
def get_type(self) -> "LongAttributeType":
9696
return self._type
@@ -99,13 +99,13 @@ def get_value(self):
9999
return self._value
100100

101101
def as_remote(self, transaction):
102-
return _RemoteLongAttribute(transaction, self.get_iid(), self.get_type(), self.get_value())
102+
return _RemoteLongAttribute(transaction, self.get_iid(), self.is_inferred(), self.get_type(), self.get_value())
103103

104104

105105
class _RemoteLongAttribute(RemoteLongAttribute, _RemoteAttribute):
106106

107-
def __init__(self, transaction, iid: str, type_, value: int):
108-
super(_RemoteLongAttribute, self).__init__(transaction, iid)
107+
def __init__(self, transaction, iid: str, is_inferred: bool, type_, value: int):
108+
super(_RemoteLongAttribute, self).__init__(transaction, iid, is_inferred)
109109
self._type = type_
110110
self._value = value
111111

@@ -116,19 +116,19 @@ def get_value(self):
116116
return self._value
117117

118118
def as_remote(self, transaction):
119-
return _RemoteLongAttribute(transaction, self.get_iid(), self.get_type(), self.get_value())
119+
return _RemoteLongAttribute(transaction, self.get_iid(), self.is_inferred(), self.get_type(), self.get_value())
120120

121121

122122
class _DoubleAttribute(DoubleAttribute, _Attribute):
123123

124-
def __init__(self, iid: str, type_: DoubleAttributeType, value: float):
125-
super(_DoubleAttribute, self).__init__(iid)
124+
def __init__(self, iid: str, is_inferred: bool, type_: DoubleAttributeType, value: float):
125+
super(_DoubleAttribute, self).__init__(iid, is_inferred)
126126
self._type = type_
127127
self._value = value
128128

129129
@staticmethod
130130
def of(thing_proto: concept_proto.Thing):
131-
return _DoubleAttribute(concept_proto_reader.iid(thing_proto.iid), concept_proto_reader.attribute_type(thing_proto.type), thing_proto.value.double)
131+
return _DoubleAttribute(concept_proto_reader.iid(thing_proto.iid), thing_proto.inferred, concept_proto_reader.attribute_type(thing_proto.type), thing_proto.value.double)
132132

133133
def get_type(self) -> "DoubleAttributeType":
134134
return self._type
@@ -137,13 +137,13 @@ def get_value(self):
137137
return self._value
138138

139139
def as_remote(self, transaction):
140-
return _RemoteDoubleAttribute(transaction, self.get_iid(), self.get_type(), self.get_value())
140+
return _RemoteDoubleAttribute(transaction, self.get_iid(), self.is_inferred(), self.get_type(), self.get_value())
141141

142142

143143
class _RemoteDoubleAttribute(RemoteDoubleAttribute, _RemoteAttribute):
144144

145-
def __init__(self, transaction, iid: str, type_: DoubleAttributeType, value: float):
146-
super(_RemoteDoubleAttribute, self).__init__(transaction, iid)
145+
def __init__(self, transaction, iid: str, is_inferred: bool, type_: DoubleAttributeType, value: float):
146+
super(_RemoteDoubleAttribute, self).__init__(transaction, iid, is_inferred)
147147
self._type = type_
148148
self._value = value
149149

@@ -154,19 +154,19 @@ def get_value(self):
154154
return self._value
155155

156156
def as_remote(self, transaction):
157-
return _RemoteDoubleAttribute(transaction, self.get_iid(), self.get_type(), self.get_value())
157+
return _RemoteDoubleAttribute(transaction, self.get_iid(), self.is_inferred(), self.get_type(), self.get_value())
158158

159159

160160
class _StringAttribute(StringAttribute, _Attribute):
161161

162-
def __init__(self, iid: str, type_: StringAttributeType, value: str):
163-
super(_StringAttribute, self).__init__(iid)
162+
def __init__(self, iid: str, is_inferred: bool, type_: StringAttributeType, value: str):
163+
super(_StringAttribute, self).__init__(iid, is_inferred)
164164
self._type = type_
165165
self._value = value
166166

167167
@staticmethod
168168
def of(thing_proto: concept_proto.Thing):
169-
return _StringAttribute(concept_proto_reader.iid(thing_proto.iid), concept_proto_reader.attribute_type(thing_proto.type), thing_proto.value.string)
169+
return _StringAttribute(concept_proto_reader.iid(thing_proto.iid), thing_proto.inferred, concept_proto_reader.attribute_type(thing_proto.type), thing_proto.value.string)
170170

171171
def get_type(self) -> "StringAttributeType":
172172
return self._type
@@ -175,13 +175,13 @@ def get_value(self):
175175
return self._value
176176

177177
def as_remote(self, transaction):
178-
return _RemoteStringAttribute(transaction, self.get_iid(), self.get_type(), self.get_value())
178+
return _RemoteStringAttribute(transaction, self.get_iid(), self.is_inferred(), self.get_type(), self.get_value())
179179

180180

181181
class _RemoteStringAttribute(RemoteStringAttribute, _RemoteAttribute):
182182

183-
def __init__(self, transaction, iid: str, type_: StringAttributeType, value: str):
184-
super(_RemoteStringAttribute, self).__init__(transaction, iid)
183+
def __init__(self, transaction, iid: str, is_inferred: bool, type_: StringAttributeType, value: str):
184+
super(_RemoteStringAttribute, self).__init__(transaction, iid, is_inferred)
185185
self._type = type_
186186
self._value = value
187187

@@ -192,19 +192,19 @@ def get_value(self):
192192
return self._value
193193

194194
def as_remote(self, transaction):
195-
return _RemoteStringAttribute(transaction, self.get_iid(), self.get_type(), self.get_value())
195+
return _RemoteStringAttribute(transaction, self.get_iid(), self.is_inferred(), self.get_type(), self.get_value())
196196

197197

198198
class _DateTimeAttribute(DateTimeAttribute, _Attribute):
199199

200-
def __init__(self, iid: str, type_: DateTimeAttributeType, value: datetime):
201-
super(_DateTimeAttribute, self).__init__(iid)
200+
def __init__(self, iid: str, is_inferred: bool, type_: DateTimeAttributeType, value: datetime):
201+
super(_DateTimeAttribute, self).__init__(iid, is_inferred)
202202
self._type = type_
203203
self._value = value
204204

205205
@staticmethod
206206
def of(thing_proto: concept_proto.Thing):
207-
return _DateTimeAttribute(concept_proto_reader.iid(thing_proto.iid), concept_proto_reader.attribute_type(thing_proto.type), datetime.fromtimestamp(float(thing_proto.value.date_time) / 1000.0))
207+
return _DateTimeAttribute(concept_proto_reader.iid(thing_proto.iid), thing_proto.inferred, concept_proto_reader.attribute_type(thing_proto.type), datetime.fromtimestamp(float(thing_proto.value.date_time) / 1000.0))
208208

209209
def get_type(self) -> "DateTimeAttributeType":
210210
return self._type
@@ -213,13 +213,13 @@ def get_value(self):
213213
return self._value
214214

215215
def as_remote(self, transaction):
216-
return _RemoteDateTimeAttribute(transaction, self.get_iid(), self.get_type(), self.get_value())
216+
return _RemoteDateTimeAttribute(transaction, self.get_iid(), self.is_inferred(), self.get_type(), self.get_value())
217217

218218

219219
class _RemoteDateTimeAttribute(RemoteDateTimeAttribute, _RemoteAttribute):
220220

221-
def __init__(self, transaction, iid: str, type_: DateTimeAttributeType, value: datetime):
222-
super(_RemoteDateTimeAttribute, self).__init__(transaction, iid)
221+
def __init__(self, transaction, iid: str, is_inferred: bool, type_: DateTimeAttributeType, value: datetime):
222+
super(_RemoteDateTimeAttribute, self).__init__(transaction, iid, is_inferred)
223223
self._type = type_
224224
self._value = value
225225

@@ -230,4 +230,4 @@ def get_value(self):
230230
return self._value
231231

232232
def as_remote(self, transaction):
233-
return _RemoteDateTimeAttribute(transaction, self.get_iid(), self.get_type(), self.get_value())
233+
return _RemoteDateTimeAttribute(transaction, self.get_iid(), self.is_inferred(), self.get_type(), self.get_value())

grakn/concept/thing/entity.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,29 @@
2727

2828
class _Entity(Entity, _Thing):
2929

30-
def __init__(self, iid: str, entity_type: EntityType):
31-
super(_Entity, self).__init__(iid)
30+
def __init__(self, iid: str, is_inferred: bool, entity_type: EntityType):
31+
super(_Entity, self).__init__(iid, is_inferred)
3232
self._type = entity_type
3333

3434
@staticmethod
3535
def of(thing_proto: concept_proto.Thing):
36-
return _Entity(concept_proto_reader.iid(thing_proto.iid), concept_proto_reader.type_(thing_proto.type))
36+
return _Entity(concept_proto_reader.iid(thing_proto.iid), thing_proto.inferred, concept_proto_reader.type_(thing_proto.type))
3737

3838
def get_type(self) -> "EntityType":
3939
return self._type
4040

4141
def as_remote(self, transaction):
42-
return _RemoteEntity(transaction, self._iid, self.get_type())
42+
return _RemoteEntity(transaction, self._iid, self.is_inferred(), self.get_type())
4343

4444

4545
class _RemoteEntity(_RemoteThing, RemoteEntity):
4646

47-
def __init__(self, transaction, iid: str, entity_type: EntityType):
48-
super(_RemoteEntity, self).__init__(transaction, iid)
47+
def __init__(self, transaction, iid: str, is_inferred: bool, entity_type: EntityType):
48+
super(_RemoteEntity, self).__init__(transaction, iid, is_inferred)
4949
self._type = entity_type
5050

5151
def as_remote(self, transaction):
52-
return _RemoteEntity(transaction, self._iid, self.get_type())
52+
return _RemoteEntity(transaction, self._iid, self.is_inferred(), self.get_type())
5353

5454
def get_type(self) -> "EntityType":
5555
return self._type

grakn/concept/thing/relation.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,29 +32,29 @@
3232

3333
class _Relation(Relation, _Thing):
3434

35-
def __init__(self, iid: str, relation_type: RelationType):
36-
super(_Relation, self).__init__(iid)
35+
def __init__(self, iid: str, is_inferred: bool, relation_type: RelationType):
36+
super(_Relation, self).__init__(iid, is_inferred)
3737
self._type = relation_type
3838

3939
@staticmethod
4040
def of(thing_proto: concept_proto.Thing):
41-
return _Relation(concept_proto_reader.iid(thing_proto.iid), concept_proto_reader.type_(thing_proto.type))
41+
return _Relation(concept_proto_reader.iid(thing_proto.iid), thing_proto.inferred, concept_proto_reader.type_(thing_proto.type))
4242

4343
def as_remote(self, transaction):
44-
return _RemoteRelation(transaction, self.get_iid(), self.get_type())
44+
return _RemoteRelation(transaction, self.get_iid(), self.is_inferred(), self.get_type())
4545

4646
def get_type(self) -> "RelationType":
4747
return self._type
4848

4949

5050
class _RemoteRelation(_RemoteThing, RemoteRelation):
5151

52-
def __init__(self, transaction, iid: str, relation_type: RelationType):
53-
super(_RemoteRelation, self).__init__(transaction, iid)
52+
def __init__(self, transaction, iid: str, is_inferred: bool, relation_type: RelationType):
53+
super(_RemoteRelation, self).__init__(transaction, iid, is_inferred)
5454
self._type = relation_type
5555

5656
def as_remote(self, transaction):
57-
return _RemoteRelation(transaction, self.get_iid(), self.get_type())
57+
return _RemoteRelation(transaction, self.get_iid(), self.is_inferred(), self.get_type())
5858

5959
def get_type(self) -> "RelationType":
6060
return self._type

0 commit comments

Comments
 (0)