Commit 93f25df5 authored by Levin Zimmermann's avatar Levin Zimmermann

proto: Switch 'compress' type on the wire from Optional[int] to bool

This patch aims to switch the compression parameter to the same
data type that it had before the introduction of msgpack: boolean [1].

1. It’s a smaller size on the wire [2].
2. It simplifies NEO/go code (we don't need to re-implement pythons
   __bool__ in golang to cast Optional[int] into a boolean).
3. It doesn’t complicate NEO/py code: in fact it doesn’t even
   need a protocol change because __bool__ keeps the same.
4. It’s more coherent regarding the protocol: compression can really only
   be either True or False. A compression of any other value than 0 or 1
   is meaningless.

We now need to explicitly cast compression to bool and not forget this when
adding new packets / code, but this is the same what happened to other packet
arguments (last argument of AskStoreTransaction needs to be explicitly cast
to list after switch to msgpack [3]).

---

[1] https://lab.nexedi.com/nexedi/neoppod/-/blob/ee44a3b0/neo/lib/protocol.py#L1113
[2] See msgpack specification: https://github.com/msgpack/msgpack/blob/master/spec.md?plain=1#L166-L178
[3] nexedi/neoppod@9d0bf97a
parent ceb21ce2
...@@ -506,7 +506,7 @@ class Application(ThreadedApplication): ...@@ -506,7 +506,7 @@ class Application(ThreadedApplication):
checksum = makeChecksum(compressed_data) checksum = makeChecksum(compressed_data)
txn_context.data_size += size txn_context.data_size += size
# Store object in tmp cache # Store object in tmp cache
packet = Packets.AskStoreObject(oid, serial, compression, packet = Packets.AskStoreObject(oid, serial, bool(compression),
checksum, compressed_data, data_serial, ttid) checksum, compressed_data, data_serial, ttid)
txn_context.data_dict[oid] = data, serial, txn_context.write( txn_context.data_dict[oid] = data, serial, txn_context.write(
self, packet, oid, oid=oid, serial=serial) self, packet, oid, oid=oid, serial=serial)
......
...@@ -619,7 +619,7 @@ class ImporterDatabaseManager(DatabaseManager): ...@@ -619,7 +619,7 @@ class ImporterDatabaseManager(DatabaseManager):
if next_serial: if next_serial:
next_serial = p64(next_serial) next_serial = p64(next_serial)
return (serial, next_serial, return (serial, next_serial,
0, checksum, value, zodb.getDataTid(z_oid, u_tid)) False, checksum, value, zodb.getDataTid(z_oid, u_tid))
def getTransaction(self, tid, all=False): def getTransaction(self, tid, all=False):
u64 = util.u64 u64 = util.u64
......
...@@ -474,7 +474,7 @@ class DatabaseManager(object): ...@@ -474,7 +474,7 @@ class DatabaseManager(object):
6-tuple: Record content. 6-tuple: Record content.
- record serial (packed) - record serial (packed)
- serial or next record modifying object (packed, None) - serial or next record modifying object (packed, None)
- compression (boolean-ish, None) - compression (boolean)
- checksum (binary string, None) - checksum (binary string, None)
- data (binary string, None) - data (binary string, None)
- data_serial (packed, None) - data_serial (packed, None)
...@@ -489,7 +489,7 @@ class DatabaseManager(object): ...@@ -489,7 +489,7 @@ class DatabaseManager(object):
return (tid or before_tid) and self.getLastObjectTID(oid) and False return (tid or before_tid) and self.getLastObjectTID(oid) and False
return (util.p64(serial), return (util.p64(serial),
None if next_serial is None else util.p64(next_serial), None if next_serial is None else util.p64(next_serial),
compression, checksum, data, bool(compression), checksum, data,
None if data_serial is None else util.p64(data_serial)) None if data_serial is None else util.p64(data_serial))
@fallback @fallback
...@@ -511,7 +511,7 @@ class DatabaseManager(object): ...@@ -511,7 +511,7 @@ class DatabaseManager(object):
r = self._fetchObject(u64(oid), u64(tid)) r = self._fetchObject(u64(oid), u64(tid))
if r: if r:
serial, compression, checksum, data, data_serial = r serial, compression, checksum, data, data_serial = r
return (util.p64(serial), compression, checksum, data, return (util.p64(serial), bool(compression), checksum, data,
None if data_serial is None else util.p64(data_serial)) None if data_serial is None else util.p64(data_serial))
@requires(_getPartitionTable) @requires(_getPartitionTable)
......
...@@ -114,8 +114,6 @@ class ClientOperationHandler(BaseHandler): ...@@ -114,8 +114,6 @@ class ClientOperationHandler(BaseHandler):
def askStoreObject(self, conn, oid, serial, def askStoreObject(self, conn, oid, serial,
compression, checksum, data, data_serial, ttid): compression, checksum, data, data_serial, ttid):
if 1 < compression:
raise ProtocolError('invalid compression value')
# register the transaction # register the transaction
self.app.tm.register(conn, ttid) self.app.tm.register(conn, ttid)
if data or checksum != ZERO_HASH: if data or checksum != ZERO_HASH:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment