Commit ea5c3318 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 b5e985fd
This diff is collapsed.
......@@ -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}
udata, err := xzlib.Decompress(buf.Data)
buf.Release()
......
......@@ -257,7 +257,7 @@ func _TestMasterStorage(t0 *tEnv) {
Oid: xid1.Oid,
Serial: serial1,
NextSerial: proto.INVALID_TID,
Compression: false,
Compression: 0,
Data: buf1,
DataSerial: 0, // XXX
Checksum: sha1.Sum(buf1.Data),
......@@ -292,7 +292,7 @@ func _TestMasterStorage(t0 *tEnv) {
Oid: xid1prev.Oid,
Serial: serial1prev,
NextSerial: serial1,
Compression: false,
Compression: 0,
Data: buf1prev,
DataSerial: 0, // XXX
Checksum: sha1.Sum(buf1prev.Data),
......
......@@ -336,6 +336,11 @@ func (a *Address) neoDecodeN(b []byte) (uint64, bool) {
// Checksum is a SHA1 hash.
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.
//
// Zero value means "invalid id" (<-> None in py.PPTID, nil in msgpack)
......@@ -715,7 +720,7 @@ type AnswerRebaseObject struct {
Serial zodb.Tid
ConflictSerial zodb.Tid
// FIXME POption('data')
Compression bool
Compression Compression
Checksum Checksum
Data *mem.Buf
}
......@@ -729,7 +734,7 @@ type AnswerRebaseObject struct {
type StoreObject struct {
Oid zodb.Oid
Serial zodb.Tid
Compression bool
Compression Compression
Checksum Checksum
Data []byte // TODO -> msg.Buf, separately (for writev)
DataSerial zodb.Tid
......@@ -784,7 +789,7 @@ type AnswerObject struct {
Oid zodb.Oid
Serial zodb.Tid
NextSerial zodb.Tid
Compression bool
Compression Compression
Checksum Checksum
Data *mem.Buf // TODO encode -> separately (for writev)
DataSerial zodb.Tid
......@@ -1219,7 +1224,7 @@ type AddTransaction struct {
type AddObject struct {
Oid zodb.Oid
Serial zodb.Tid
Compression bool
Compression Compression
Checksum Checksum
Data *mem.Buf
DataSerial zodb.Tid
......
This diff is collapsed.
......@@ -87,7 +87,7 @@ func (f *Backend) Load(ctx context.Context, xid zodb.Xid) (*proto.AnswerObject,
Serial: serial,
NextSerial: nextSerial,
Compression: false,
Compression: 0,
Data: buf,
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