diff --git a/gnes/__init__.py b/gnes/__init__.py index 04f8f8ce..4b2911de 100644 --- a/gnes/__init__.py +++ b/gnes/__init__.py @@ -14,7 +14,10 @@ # limitations under the License. -# do not change this line -# this is managed by git tag and replaced on every release +# do not change this line manually +# this is managed by git tag and updated on every release __version__ = '0.0.38' -__proto_version__ = '20190905' + +# do not change this line manually +# this is managed by shell/make-proto.sh and updated on every execution +__proto_version__ = '0.0.4' diff --git a/gnes/cli/parser.py b/gnes/cli/parser.py index 6330ded5..6ccb008a 100644 --- a/gnes/cli/parser.py +++ b/gnes/cli/parser.py @@ -151,6 +151,9 @@ def set_service_parser(parser=None): parser.add_argument('--parallel_type', type=ParallelType.from_string, choices=list(ParallelType), default=ParallelType.PUSH_NONBLOCK, help='parallel type of the concurrent services') + parser.add_argument('--check_version', action='store_true', default=False, + help='comparing the GNES and proto version of incoming message with local setup, ' + 'mismatch raise an exception') return parser diff --git a/gnes/client/base.py b/gnes/client/base.py index 815c9e28..97bea1b7 100644 --- a/gnes/client/base.py +++ b/gnes/client/base.py @@ -55,6 +55,6 @@ def send_message(self, message: "gnes_pb2.Message", timeout: int = -1): send_message(self.sender, message, timeout=timeout) def recv_message(self, timeout: int = -1) -> gnes_pb2.Message: - r = recv_message(self.receiver, timeout=timeout) + r = recv_message(self.receiver, timeout=timeout, check_version=self.args.check_version) self.logger.info('recv a message: %s' % r.envelope) return r diff --git a/gnes/proto/__init__.py b/gnes/proto/__init__.py index 992b8482..5bc50809 100644 --- a/gnes/proto/__init__.py +++ b/gnes/proto/__init__.py @@ -133,7 +133,7 @@ def send_message(sock: 'zmq.Socket', msg: 'gnes_pb2.Message', timeout: int = -1) sock.setsockopt(zmq.SNDTIMEO, -1) -def recv_message(sock: 'zmq.Socket', timeout: int = -1) -> Optional['gnes_pb2.Message']: +def recv_message(sock: 'zmq.Socket', timeout: int = -1, check_version: bool = False) -> Optional['gnes_pb2.Message']: response = [] try: if timeout > 0: @@ -144,6 +144,21 @@ def recv_message(sock: 'zmq.Socket', timeout: int = -1) -> Optional['gnes_pb2.Me _, msg_data = sock.recv_multipart() msg = gnes_pb2.Message() msg.ParseFromString(msg_data) + + if check_version and msg.envelope: + from .. import __version__, __proto_version__ + if hasattr(msg.envelope, 'gnes_version') and __version__ != msg.envelope.gnes_version: + raise AttributeError('mismatched GNES version! ' + 'incoming message has GNES version %s, whereas local GNES version %s' % ( + msg.envelope.gnes_version, __version__)) + if hasattr(msg.envelope, 'proto_version') and __proto_version__ != msg.envelope.proto_version: + raise AttributeError('mismatched protobuf version! ' + 'incoming message has protobuf version %s, whereas local protobuf version %s' % ( + msg.envelope.proto_version, __proto_version__)) + if not hasattr(msg.envelope, 'proto_version') and not hasattr(msg.envelope, 'gnes_version'): + raise AttributeError('version_check=True locally, ' + 'but incoming message contains no version info in its envelope. ' + 'the message is probably sent from an outdated GNES service') return msg except ValueError: diff --git a/gnes/proto/gnes.proto b/gnes/proto/gnes.proto index 5758ec0b..4ff878c1 100644 --- a/gnes/proto/gnes.proto +++ b/gnes/proto/gnes.proto @@ -92,6 +92,10 @@ message Envelope { google.protobuf.Timestamp timestamp = 2; } repeated route routes = 6; + + string gnes_version = 7; + + string proto_version = 8; } message Message { diff --git a/gnes/proto/gnes_pb2.py b/gnes/proto/gnes_pb2.py index c6a644f1..20739f1b 100644 --- a/gnes/proto/gnes_pb2.py +++ b/gnes/proto/gnes_pb2.py @@ -21,7 +21,7 @@ package='gnes', syntax='proto3', serialized_options=None, - serialized_pb=_b('\n\ngnes.proto\x12\x04gnes\x1a\x1fgoogle/protobuf/timestamp.proto\"9\n\x07NdArray\x12\x0c\n\x04\x64\x61ta\x18\x01 \x01(\x0c\x12\x11\n\x05shape\x18\x02 \x03(\rB\x02\x10\x01\x12\r\n\x05\x64type\x18\x03 \x01(\t\"\xb9\x01\n\x05\x43hunk\x12\x0e\n\x06\x64oc_id\x18\x01 \x01(\x04\x12\x0e\n\x04text\x18\x02 \x01(\tH\x00\x12\x1d\n\x04\x62lob\x18\x03 \x01(\x0b\x32\r.gnes.NdArrayH\x00\x12\r\n\x03raw\x18\x07 \x01(\x0cH\x00\x12\x0e\n\x06offset\x18\x04 \x01(\r\x12\x15\n\toffset_nd\x18\x05 \x03(\rB\x02\x10\x01\x12\x0e\n\x06weight\x18\x06 \x01(\x02\x12 \n\tembedding\x18\x08 \x01(\x0b\x32\r.gnes.NdArrayB\t\n\x07\x63ontent\"\xc4\x02\n\x08\x44ocument\x12\x0e\n\x06\x64oc_id\x18\x01 \x01(\x04\x12\x1b\n\x06\x63hunks\x18\x02 \x03(\x0b\x32\x0b.gnes.Chunk\x12(\n\x08\x64oc_type\x18\x03 \x01(\x0e\x32\x16.gnes.Document.DocType\x12\x11\n\tmeta_info\x18\x04 \x01(\x0c\x12\x12\n\x08raw_text\x18\x05 \x01(\tH\x00\x12\"\n\traw_image\x18\x06 \x01(\x0b\x32\r.gnes.NdArrayH\x00\x12\"\n\traw_video\x18\x07 \x01(\x0b\x32\r.gnes.NdArrayH\x00\x12\x13\n\traw_bytes\x18\x08 \x01(\x0cH\x00\x12\x0e\n\x06weight\x18\n \x01(\x02\"A\n\x07\x44ocType\x12\x0b\n\x07UNKNOWN\x10\x00\x12\x08\n\x04TEXT\x10\x01\x12\t\n\x05IMAGE\x10\x02\x12\t\n\x05VIDEO\x10\x03\x12\t\n\x05\x41UDIO\x10\x04\x42\n\n\x08raw_data\"\xd4\x01\n\x08\x45nvelope\x12\x11\n\tclient_id\x18\x01 \x01(\t\x12\x12\n\nrequest_id\x18\x02 \x01(\r\x12\x0f\n\x07part_id\x18\x03 \x01(\r\x12\x10\n\x08num_part\x18\x04 \x03(\r\x12\x0f\n\x07timeout\x18\x05 \x01(\r\x12$\n\x06routes\x18\x06 \x03(\x0b\x32\x14.gnes.Envelope.route\x1aG\n\x05route\x12\x0f\n\x07service\x18\x01 \x01(\t\x12-\n\ttimestamp\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\"y\n\x07Message\x12 \n\x08\x65nvelope\x18\x01 \x01(\x0b\x32\x0e.gnes.Envelope\x12 \n\x07request\x18\x02 \x01(\x0b\x32\r.gnes.RequestH\x00\x12\"\n\x08response\x18\x03 \x01(\x0b\x32\x0e.gnes.ResponseH\x00\x42\x06\n\x04\x62ody\"\xf6\x03\n\x07Request\x12\x12\n\nrequest_id\x18\x01 \x01(\r\x12+\n\x05train\x18\x02 \x01(\x0b\x32\x1a.gnes.Request.TrainRequestH\x00\x12+\n\x05index\x18\x03 \x01(\x0b\x32\x1a.gnes.Request.IndexRequestH\x00\x12,\n\x06search\x18\x04 \x01(\x0b\x32\x1a.gnes.Request.QueryRequestH\x00\x12/\n\x07\x63ontrol\x18\x05 \x01(\x0b\x32\x1c.gnes.Request.ControlRequestH\x00\x1a;\n\x0cTrainRequest\x12\x1c\n\x04\x64ocs\x18\x01 \x03(\x0b\x32\x0e.gnes.Document\x12\r\n\x05\x66lush\x18\x02 \x01(\x08\x1a,\n\x0cIndexRequest\x12\x1c\n\x04\x64ocs\x18\x01 \x03(\x0b\x32\x0e.gnes.Document\x1a<\n\x0cQueryRequest\x12\x1d\n\x05query\x18\x01 \x01(\x0b\x32\x0e.gnes.Document\x12\r\n\x05top_k\x18\x02 \x01(\r\x1am\n\x0e\x43ontrolRequest\x12\x35\n\x07\x63ommand\x18\x01 \x01(\x0e\x32$.gnes.Request.ControlRequest.Command\"$\n\x07\x43ommand\x12\r\n\tTERMINATE\x10\x00\x12\n\n\x06STATUS\x10\x01\x42\x06\n\x04\x62ody\"\xbb\x06\n\x08Response\x12\x12\n\nrequest_id\x18\x01 \x01(\r\x12-\n\x05train\x18\x02 \x01(\x0b\x32\x1c.gnes.Response.TrainResponseH\x00\x12-\n\x05index\x18\x03 \x01(\x0b\x32\x1c.gnes.Response.IndexResponseH\x00\x12.\n\x06search\x18\x04 \x01(\x0b\x32\x1c.gnes.Response.QueryResponseH\x00\x12\x31\n\x07\x63ontrol\x18\x05 \x01(\x0b\x32\x1e.gnes.Response.ControlResponseH\x00\x1a\x36\n\rTrainResponse\x12%\n\x06status\x18\x01 \x01(\x0e\x32\x15.gnes.Response.Status\x1a\x36\n\rIndexResponse\x12%\n\x06status\x18\x01 \x01(\x0e\x32\x15.gnes.Response.Status\x1a\x38\n\x0f\x43ontrolResponse\x12%\n\x06status\x18\x01 \x01(\x0e\x32\x15.gnes.Response.Status\x1a\xf8\x02\n\rQueryResponse\x12%\n\x06status\x18\x01 \x01(\x0e\x32\x15.gnes.Response.Status\x12\r\n\x05top_k\x18\x02 \x01(\r\x12?\n\x0ctopk_results\x18\x03 \x03(\x0b\x32).gnes.Response.QueryResponse.ScoredResult\x12\x1c\n\x14is_big_score_similar\x18\x04 \x01(\x08\x12\x11\n\tis_sorted\x18\x05 \x01(\x08\x1a\xbe\x01\n\x0cScoredResult\x12\x1c\n\x05\x63hunk\x18\x01 \x01(\x0b\x32\x0b.gnes.ChunkH\x00\x12\x1d\n\x03\x64oc\x18\x02 \x01(\x0b\x32\x0e.gnes.DocumentH\x00\x12>\n\x05score\x18\x03 \x01(\x0b\x32/.gnes.Response.QueryResponse.ScoredResult.Score\x1a)\n\x05Score\x12\r\n\x05value\x18\x01 \x01(\x02\x12\x11\n\texplained\x18\x02 \x01(\tB\x06\n\x04\x62ody\"-\n\x06Status\x12\x0b\n\x07SUCCESS\x10\x00\x12\t\n\x05\x45RROR\x10\x01\x12\x0b\n\x07PENDING\x10\x02\x42\x06\n\x04\x62ody2\xe3\x01\n\x07GnesRPC\x12(\n\x05Train\x12\r.gnes.Request\x1a\x0e.gnes.Response\"\x00\x12(\n\x05Index\x12\r.gnes.Request\x1a\x0e.gnes.Response\"\x00\x12(\n\x05Query\x12\r.gnes.Request\x1a\x0e.gnes.Response\"\x00\x12\'\n\x04\x43\x61ll\x12\r.gnes.Request\x1a\x0e.gnes.Response\"\x00\x12\x31\n\nStreamCall\x12\r.gnes.Request\x1a\x0e.gnes.Response\"\x00(\x01\x30\x01\x62\x06proto3') + serialized_pb=_b('\n\ngnes.proto\x12\x04gnes\x1a\x1fgoogle/protobuf/timestamp.proto\"9\n\x07NdArray\x12\x0c\n\x04\x64\x61ta\x18\x01 \x01(\x0c\x12\x11\n\x05shape\x18\x02 \x03(\rB\x02\x10\x01\x12\r\n\x05\x64type\x18\x03 \x01(\t\"\xb9\x01\n\x05\x43hunk\x12\x0e\n\x06\x64oc_id\x18\x01 \x01(\x04\x12\x0e\n\x04text\x18\x02 \x01(\tH\x00\x12\x1d\n\x04\x62lob\x18\x03 \x01(\x0b\x32\r.gnes.NdArrayH\x00\x12\r\n\x03raw\x18\x07 \x01(\x0cH\x00\x12\x0e\n\x06offset\x18\x04 \x01(\r\x12\x15\n\toffset_nd\x18\x05 \x03(\rB\x02\x10\x01\x12\x0e\n\x06weight\x18\x06 \x01(\x02\x12 \n\tembedding\x18\x08 \x01(\x0b\x32\r.gnes.NdArrayB\t\n\x07\x63ontent\"\xc4\x02\n\x08\x44ocument\x12\x0e\n\x06\x64oc_id\x18\x01 \x01(\x04\x12\x1b\n\x06\x63hunks\x18\x02 \x03(\x0b\x32\x0b.gnes.Chunk\x12(\n\x08\x64oc_type\x18\x03 \x01(\x0e\x32\x16.gnes.Document.DocType\x12\x11\n\tmeta_info\x18\x04 \x01(\x0c\x12\x12\n\x08raw_text\x18\x05 \x01(\tH\x00\x12\"\n\traw_image\x18\x06 \x01(\x0b\x32\r.gnes.NdArrayH\x00\x12\"\n\traw_video\x18\x07 \x01(\x0b\x32\r.gnes.NdArrayH\x00\x12\x13\n\traw_bytes\x18\x08 \x01(\x0cH\x00\x12\x0e\n\x06weight\x18\n \x01(\x02\"A\n\x07\x44ocType\x12\x0b\n\x07UNKNOWN\x10\x00\x12\x08\n\x04TEXT\x10\x01\x12\t\n\x05IMAGE\x10\x02\x12\t\n\x05VIDEO\x10\x03\x12\t\n\x05\x41UDIO\x10\x04\x42\n\n\x08raw_data\"\x81\x02\n\x08\x45nvelope\x12\x11\n\tclient_id\x18\x01 \x01(\t\x12\x12\n\nrequest_id\x18\x02 \x01(\r\x12\x0f\n\x07part_id\x18\x03 \x01(\r\x12\x10\n\x08num_part\x18\x04 \x03(\r\x12\x0f\n\x07timeout\x18\x05 \x01(\r\x12$\n\x06routes\x18\x06 \x03(\x0b\x32\x14.gnes.Envelope.route\x12\x14\n\x0cgnes_version\x18\x07 \x01(\t\x12\x15\n\rproto_version\x18\x08 \x01(\t\x1aG\n\x05route\x12\x0f\n\x07service\x18\x01 \x01(\t\x12-\n\ttimestamp\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\"y\n\x07Message\x12 \n\x08\x65nvelope\x18\x01 \x01(\x0b\x32\x0e.gnes.Envelope\x12 \n\x07request\x18\x02 \x01(\x0b\x32\r.gnes.RequestH\x00\x12\"\n\x08response\x18\x03 \x01(\x0b\x32\x0e.gnes.ResponseH\x00\x42\x06\n\x04\x62ody\"\xf6\x03\n\x07Request\x12\x12\n\nrequest_id\x18\x01 \x01(\r\x12+\n\x05train\x18\x02 \x01(\x0b\x32\x1a.gnes.Request.TrainRequestH\x00\x12+\n\x05index\x18\x03 \x01(\x0b\x32\x1a.gnes.Request.IndexRequestH\x00\x12,\n\x06search\x18\x04 \x01(\x0b\x32\x1a.gnes.Request.QueryRequestH\x00\x12/\n\x07\x63ontrol\x18\x05 \x01(\x0b\x32\x1c.gnes.Request.ControlRequestH\x00\x1a;\n\x0cTrainRequest\x12\x1c\n\x04\x64ocs\x18\x01 \x03(\x0b\x32\x0e.gnes.Document\x12\r\n\x05\x66lush\x18\x02 \x01(\x08\x1a,\n\x0cIndexRequest\x12\x1c\n\x04\x64ocs\x18\x01 \x03(\x0b\x32\x0e.gnes.Document\x1a<\n\x0cQueryRequest\x12\x1d\n\x05query\x18\x01 \x01(\x0b\x32\x0e.gnes.Document\x12\r\n\x05top_k\x18\x02 \x01(\r\x1am\n\x0e\x43ontrolRequest\x12\x35\n\x07\x63ommand\x18\x01 \x01(\x0e\x32$.gnes.Request.ControlRequest.Command\"$\n\x07\x43ommand\x12\r\n\tTERMINATE\x10\x00\x12\n\n\x06STATUS\x10\x01\x42\x06\n\x04\x62ody\"\xbb\x06\n\x08Response\x12\x12\n\nrequest_id\x18\x01 \x01(\r\x12-\n\x05train\x18\x02 \x01(\x0b\x32\x1c.gnes.Response.TrainResponseH\x00\x12-\n\x05index\x18\x03 \x01(\x0b\x32\x1c.gnes.Response.IndexResponseH\x00\x12.\n\x06search\x18\x04 \x01(\x0b\x32\x1c.gnes.Response.QueryResponseH\x00\x12\x31\n\x07\x63ontrol\x18\x05 \x01(\x0b\x32\x1e.gnes.Response.ControlResponseH\x00\x1a\x36\n\rTrainResponse\x12%\n\x06status\x18\x01 \x01(\x0e\x32\x15.gnes.Response.Status\x1a\x36\n\rIndexResponse\x12%\n\x06status\x18\x01 \x01(\x0e\x32\x15.gnes.Response.Status\x1a\x38\n\x0f\x43ontrolResponse\x12%\n\x06status\x18\x01 \x01(\x0e\x32\x15.gnes.Response.Status\x1a\xf8\x02\n\rQueryResponse\x12%\n\x06status\x18\x01 \x01(\x0e\x32\x15.gnes.Response.Status\x12\r\n\x05top_k\x18\x02 \x01(\r\x12?\n\x0ctopk_results\x18\x03 \x03(\x0b\x32).gnes.Response.QueryResponse.ScoredResult\x12\x1c\n\x14is_big_score_similar\x18\x04 \x01(\x08\x12\x11\n\tis_sorted\x18\x05 \x01(\x08\x1a\xbe\x01\n\x0cScoredResult\x12\x1c\n\x05\x63hunk\x18\x01 \x01(\x0b\x32\x0b.gnes.ChunkH\x00\x12\x1d\n\x03\x64oc\x18\x02 \x01(\x0b\x32\x0e.gnes.DocumentH\x00\x12>\n\x05score\x18\x03 \x01(\x0b\x32/.gnes.Response.QueryResponse.ScoredResult.Score\x1a)\n\x05Score\x12\r\n\x05value\x18\x01 \x01(\x02\x12\x11\n\texplained\x18\x02 \x01(\tB\x06\n\x04\x62ody\"-\n\x06Status\x12\x0b\n\x07SUCCESS\x10\x00\x12\t\n\x05\x45RROR\x10\x01\x12\x0b\n\x07PENDING\x10\x02\x42\x06\n\x04\x62ody2\xe3\x01\n\x07GnesRPC\x12(\n\x05Train\x12\r.gnes.Request\x1a\x0e.gnes.Response\"\x00\x12(\n\x05Index\x12\r.gnes.Request\x1a\x0e.gnes.Response\"\x00\x12(\n\x05Query\x12\r.gnes.Request\x1a\x0e.gnes.Response\"\x00\x12\'\n\x04\x43\x61ll\x12\r.gnes.Request\x1a\x0e.gnes.Response\"\x00\x12\x31\n\nStreamCall\x12\r.gnes.Request\x1a\x0e.gnes.Response\"\x00(\x01\x30\x01\x62\x06proto3') , dependencies=[google_dot_protobuf_dot_timestamp__pb2.DESCRIPTOR,]) @@ -78,8 +78,8 @@ ], containing_type=None, serialized_options=None, - serialized_start=1424, - serialized_end=1460, + serialized_start=1469, + serialized_end=1505, ) _sym_db.RegisterEnumDescriptor(_REQUEST_CONTROLREQUEST_COMMAND) @@ -104,8 +104,8 @@ ], containing_type=None, serialized_options=None, - serialized_start=2245, - serialized_end=2290, + serialized_start=2290, + serialized_end=2335, ) _sym_db.RegisterEnumDescriptor(_RESPONSE_STATUS) @@ -362,8 +362,8 @@ extension_ranges=[], oneofs=[ ], - serialized_start=769, - serialized_end=840, + serialized_start=814, + serialized_end=885, ) _ENVELOPE = _descriptor.Descriptor( @@ -415,6 +415,20 @@ message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='gnes_version', full_name='gnes.Envelope.gnes_version', index=6, + number=7, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='proto_version', full_name='gnes.Envelope.proto_version', index=7, + number=8, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), ], extensions=[ ], @@ -428,7 +442,7 @@ oneofs=[ ], serialized_start=628, - serialized_end=840, + serialized_end=885, ) @@ -475,8 +489,8 @@ name='body', full_name='gnes.Message.body', index=0, containing_type=None, fields=[]), ], - serialized_start=842, - serialized_end=963, + serialized_start=887, + serialized_end=1008, ) @@ -513,8 +527,8 @@ extension_ranges=[], oneofs=[ ], - serialized_start=1182, - serialized_end=1241, + serialized_start=1227, + serialized_end=1286, ) _REQUEST_INDEXREQUEST = _descriptor.Descriptor( @@ -543,8 +557,8 @@ extension_ranges=[], oneofs=[ ], - serialized_start=1243, - serialized_end=1287, + serialized_start=1288, + serialized_end=1332, ) _REQUEST_QUERYREQUEST = _descriptor.Descriptor( @@ -580,8 +594,8 @@ extension_ranges=[], oneofs=[ ], - serialized_start=1289, - serialized_end=1349, + serialized_start=1334, + serialized_end=1394, ) _REQUEST_CONTROLREQUEST = _descriptor.Descriptor( @@ -611,8 +625,8 @@ extension_ranges=[], oneofs=[ ], - serialized_start=1351, - serialized_end=1460, + serialized_start=1396, + serialized_end=1505, ) _REQUEST = _descriptor.Descriptor( @@ -672,8 +686,8 @@ name='body', full_name='gnes.Request.body', index=0, containing_type=None, fields=[]), ], - serialized_start=966, - serialized_end=1468, + serialized_start=1011, + serialized_end=1513, ) @@ -703,8 +717,8 @@ extension_ranges=[], oneofs=[ ], - serialized_start=1696, - serialized_end=1750, + serialized_start=1741, + serialized_end=1795, ) _RESPONSE_INDEXRESPONSE = _descriptor.Descriptor( @@ -733,8 +747,8 @@ extension_ranges=[], oneofs=[ ], - serialized_start=1752, - serialized_end=1806, + serialized_start=1797, + serialized_end=1851, ) _RESPONSE_CONTROLRESPONSE = _descriptor.Descriptor( @@ -763,8 +777,8 @@ extension_ranges=[], oneofs=[ ], - serialized_start=1808, - serialized_end=1864, + serialized_start=1853, + serialized_end=1909, ) _RESPONSE_QUERYRESPONSE_SCOREDRESULT_SCORE = _descriptor.Descriptor( @@ -800,8 +814,8 @@ extension_ranges=[], oneofs=[ ], - serialized_start=2194, - serialized_end=2235, + serialized_start=2239, + serialized_end=2280, ) _RESPONSE_QUERYRESPONSE_SCOREDRESULT = _descriptor.Descriptor( @@ -847,8 +861,8 @@ name='body', full_name='gnes.Response.QueryResponse.ScoredResult.body', index=0, containing_type=None, fields=[]), ], - serialized_start=2053, - serialized_end=2243, + serialized_start=2098, + serialized_end=2288, ) _RESPONSE_QUERYRESPONSE = _descriptor.Descriptor( @@ -905,8 +919,8 @@ extension_ranges=[], oneofs=[ ], - serialized_start=1867, - serialized_end=2243, + serialized_start=1912, + serialized_end=2288, ) _RESPONSE = _descriptor.Descriptor( @@ -967,8 +981,8 @@ name='body', full_name='gnes.Response.body', index=0, containing_type=None, fields=[]), ], - serialized_start=1471, - serialized_end=2298, + serialized_start=1516, + serialized_end=2343, ) _CHUNK.fields_by_name['blob'].message_type = _NDARRAY @@ -1229,8 +1243,8 @@ file=DESCRIPTOR, index=0, serialized_options=None, - serialized_start=2301, - serialized_end=2528, + serialized_start=2346, + serialized_end=2573, methods=[ _descriptor.MethodDescriptor( name='Train', diff --git a/gnes/service/base.py b/gnes/service/base.py index 1371ae32..3384847f 100644 --- a/gnes/service/base.py +++ b/gnes/service/base.py @@ -394,7 +394,7 @@ def _run(self, ctx): self.is_handler_done.clear() # receive message - msg = recv_message(pull_sock) + msg = recv_message(pull_sock, check_version=self.args.check_version) # choose output sock if msg.request and msg.request.WhichOneof('body') and \ diff --git a/shell/make-proto.sh b/shell/make-proto.sh index 584c1305..0b6c1be4 100755 --- a/shell/make-proto.sh +++ b/shell/make-proto.sh @@ -1,7 +1,10 @@ #!/usr/bin/env bash +set -e + SRC_NAME=gnes.proto SRC_DIR=../gnes/proto/ +VER_FILE=../gnes/__init__.py # generating test proto @@ -11,7 +14,21 @@ SRC_DIR=../gnes/proto/ PLUGIN_PATH=/Volumes/TOSHIBA-4T/Documents/grpc/bins/opt/grpc_python_plugin #PLUGIN_PATH=/user/local/grpc/bins/opt/grpc_python_plugin +printf "\e[1;33mgenerating protobuf and grpc python interface\e[0m\n" + protoc -I ${SRC_DIR} --python_out=${SRC_DIR} --grpc_python_out=${SRC_DIR} --plugin=protoc-gen-grpc_python=${PLUGIN_PATH} ${SRC_DIR}${SRC_NAME} +printf "\e[1;33mfixing grpc import\e[0m\n" # fix import bug in google generator sed -i '' -e '4s/.*/from\ \.\ import\ gnes_pb2\ as\ gnes__pb2/' ${SRC_DIR}gnes_pb2_grpc.py + +# update protobuf version in gnes/__init__.py + +OLDVER=$(sed -n 's/^__proto_version__ = '\''\(.*\)'\''$/\1/p' $VER_FILE) +printf "current proto version:\t\e[1;33m$OLDVER\e[0m\n" + +NEWVER=$(echo $OLDVER | awk -F. -v OFS=. 'NF==1{print ++$NF}; NF>1{$NF=sprintf("%0*d", length($NF), ($NF+1)); print}') +printf "bump proto version to:\t\e[1;32m$NEWVER\e[0m\n" + +sed -i '' -e 's/^__proto_version__ = '\''\(.*\)'\''/__proto_version__ = '\'"$NEWVER"\''/' $VER_FILE +printf "\e[1;32mAll done!\e[0m\n" \ No newline at end of file