Commit 34c4d915 authored by Levin Zimmermann's avatar Levin Zimmermann

proto: Update 'Compression' to int to support different compression algorithms

With nexedi/neoppod@fd80cc30 NEO/py added support to encode the compression
algorithm with the 'Compression' parameter. Before this, compression could
only be true (= with compression) or false (= without compression). Now
the absence of compression is encoded with 0. Any other number than 0
encodes a compression algorithm. The mapping is currently:

	1 = zlib

In the future, 2 could mean zstd [1].

[1] https://github.com/facebook/zstd/issues/1134
parent 33fab6e3
...@@ -381,7 +381,10 @@ func (c *Client) Load(ctx context.Context, xid zodb.Xid) (buf *mem.Buf, serial z ...@@ -381,7 +381,10 @@ func (c *Client) Load(ctx context.Context, xid zodb.Xid) (buf *mem.Buf, serial z
} }
} }
if resp.Compression { if resp.Compression != 0 {
if resp.Compression != 1 {
return nil, 0, fmt.Errorf("unsupported compression algorithm: %v", resp.Compression)
}
buf2 := &mem.Buf{Data: nil} buf2 := &mem.Buf{Data: nil}
udata, err := xzlib.Decompress(buf.Data) udata, err := xzlib.Decompress(buf.Data)
buf.Release() buf.Release()
......
...@@ -257,7 +257,7 @@ func _TestMasterStorage(t0 *tEnv) { ...@@ -257,7 +257,7 @@ func _TestMasterStorage(t0 *tEnv) {
Oid: xid1.Oid, Oid: xid1.Oid,
Serial: serial1, Serial: serial1,
NextSerial: proto.INVALID_TID, NextSerial: proto.INVALID_TID,
Compression: false, Compression: 0,
Data: buf1, Data: buf1,
DataSerial: 0, // XXX DataSerial: 0, // XXX
Checksum: sha1.Sum(buf1.Data), Checksum: sha1.Sum(buf1.Data),
...@@ -292,7 +292,7 @@ func _TestMasterStorage(t0 *tEnv) { ...@@ -292,7 +292,7 @@ func _TestMasterStorage(t0 *tEnv) {
Oid: xid1prev.Oid, Oid: xid1prev.Oid,
Serial: serial1prev, Serial: serial1prev,
NextSerial: serial1, NextSerial: serial1,
Compression: false, Compression: 0,
Data: buf1prev, Data: buf1prev,
DataSerial: 0, // XXX DataSerial: 0, // XXX
Checksum: sha1.Sum(buf1prev.Data), Checksum: sha1.Sum(buf1prev.Data),
......
...@@ -336,6 +336,11 @@ func (a *Address) neoDecodeN(b []byte) (uint64, bool) { ...@@ -336,6 +336,11 @@ func (a *Address) neoDecodeN(b []byte) (uint64, bool) {
// Checksum is a SHA1 hash. // Checksum is a SHA1 hash.
type Checksum [20]byte type Checksum [20]byte
// Compression is an integer that tells the compression algorithm:
// 0 = no compression algorithm is used
// 1 = zlib is used
type Compression uint64
// PTid is Partition Table identifier. // PTid is Partition Table identifier.
// //
// Zero value means "invalid id" (<-> None in py.PPTID, nil in msgpack) // Zero value means "invalid id" (<-> None in py.PPTID, nil in msgpack)
...@@ -715,7 +720,7 @@ type AnswerRebaseObject struct { ...@@ -715,7 +720,7 @@ type AnswerRebaseObject struct {
Serial zodb.Tid Serial zodb.Tid
ConflictSerial zodb.Tid ConflictSerial zodb.Tid
// FIXME POption('data') // FIXME POption('data')
Compression bool Compression Compression
Checksum Checksum Checksum Checksum
Data *mem.Buf Data *mem.Buf
} }
...@@ -729,7 +734,7 @@ type AnswerRebaseObject struct { ...@@ -729,7 +734,7 @@ type AnswerRebaseObject struct {
type StoreObject struct { type StoreObject struct {
Oid zodb.Oid Oid zodb.Oid
Serial zodb.Tid Serial zodb.Tid
Compression bool Compression Compression
Checksum Checksum Checksum Checksum
Data []byte // TODO -> msg.Buf, separately (for writev) Data []byte // TODO -> msg.Buf, separately (for writev)
DataSerial zodb.Tid DataSerial zodb.Tid
...@@ -784,7 +789,7 @@ type AnswerObject struct { ...@@ -784,7 +789,7 @@ type AnswerObject struct {
Oid zodb.Oid Oid zodb.Oid
Serial zodb.Tid Serial zodb.Tid
NextSerial zodb.Tid NextSerial zodb.Tid
Compression bool Compression Compression
Checksum Checksum Checksum Checksum
Data *mem.Buf // TODO encode -> separately (for writev) Data *mem.Buf // TODO encode -> separately (for writev)
DataSerial zodb.Tid DataSerial zodb.Tid
...@@ -1219,7 +1224,7 @@ type AddTransaction struct { ...@@ -1219,7 +1224,7 @@ type AddTransaction struct {
type AddObject struct { type AddObject struct {
Oid zodb.Oid Oid zodb.Oid
Serial zodb.Tid Serial zodb.Tid
Compression bool Compression Compression
Checksum Checksum Checksum Checksum
Data *mem.Buf Data *mem.Buf
DataSerial zodb.Tid DataSerial zodb.Tid
......
This diff is collapsed.
...@@ -87,7 +87,7 @@ func (f *Backend) Load(ctx context.Context, xid zodb.Xid) (*proto.AnswerObject, ...@@ -87,7 +87,7 @@ func (f *Backend) Load(ctx context.Context, xid zodb.Xid) (*proto.AnswerObject,
Serial: serial, Serial: serial,
NextSerial: nextSerial, NextSerial: nextSerial,
Compression: false, Compression: 0,
Data: buf, Data: buf,
Checksum: xsha1.NEOSum(buf.Data), // XXX computing every time Checksum: xsha1.NEOSum(buf.Data), // XXX computing every time
......
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