Commit b6f5ef45 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 71564067
...@@ -528,7 +528,7 @@ class Application(ThreadedApplication): ...@@ -528,7 +528,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)
......
...@@ -658,7 +658,7 @@ class ImporterDatabaseManager(DatabaseManager): ...@@ -658,7 +658,7 @@ class ImporterDatabaseManager(DatabaseManager):
next_serial = db._getNextTID(db._getPartition(u_oid), u_oid, u_tid) next_serial = db._getNextTID(db._getPartition(u_oid), u_oid, u_tid)
if next_serial: if next_serial:
next_serial = p64(next_serial) next_serial = p64(next_serial)
return (serial, next_serial, 0, return (serial, next_serial, False,
util.makeChecksum(value), util.makeChecksum(value),
value, value,
zodb.getDataTid(z_oid, u_tid)) zodb.getDataTid(z_oid, u_tid))
......
...@@ -935,7 +935,7 @@ class DatabaseManager(object): ...@@ -935,7 +935,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)
...@@ -950,7 +950,7 @@ class DatabaseManager(object): ...@@ -950,7 +950,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
...@@ -973,7 +973,7 @@ class DatabaseManager(object): ...@@ -973,7 +973,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)
......
...@@ -120,8 +120,6 @@ class ClientOperationHandler(BaseHandler): ...@@ -120,8 +120,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