Commit 4414aa26 authored by Peter Rabbitson's avatar Peter Rabbitson

Address block/chunk logical mismatch, name things correctly

parent 5f9fd98c
...@@ -12,21 +12,16 @@ const ( ...@@ -12,21 +12,16 @@ const (
// DefaultBlockSize is the chunk size that splitters produce (or aim to). // DefaultBlockSize is the chunk size that splitters produce (or aim to).
DefaultBlockSize int64 = 1024 * 256 DefaultBlockSize int64 = 1024 * 256
// 1 MB, on-wire block size for "datablocks ( unixfs, etc )" // No leaf block should contain more than 1MiB of payload data ( wrapping overhead aside )
// copy of https://github.com/ipfs/go-unixfs/blob/v0.2.3/importer/helpers/helpers.go#L8 // This effectively mandates the maximum chunk size
BlockSizeLimit int = 1048576 // See discussion at https://github.com/ipfs/go-ipfs-chunker/pull/21#discussion_r369124879 for background
ChunkSizeLimit int = 1048576
// in case we are using raw-leaves: this would match BlockSizeLimit, but we can't assume that
// be conservative and substract the PB wraping size of a full DAG-PB+UnixFS node describing 1M
// (2b(type2/file)+4b(data-field:3-byte-len-delimited)+4b(size-field:3-byte-varint))+(4b(DAG-type-1:3-byte-len-delimited))
// FIXME - this calculation will need an update for CBOR
BlockPayloadLimit int = (BlockSizeLimit - (2 + 4 + 4 + 4))
) )
var ( var (
ErrRabinMin = errors.New("rabin min must be greater than 16") ErrRabinMin = errors.New("rabin min must be greater than 16")
ErrSize = errors.New("chunker size must be greater than 0") ErrSize = errors.New("chunker size must be greater than 0")
ErrSizeMax = fmt.Errorf("chunker parameters may not exceed the maximum block payload size of %d", BlockPayloadLimit) ErrSizeMax = fmt.Errorf("chunker parameters may not exceed the maximum chunk size of %d", ChunkSizeLimit)
) )
// FromString returns a Splitter depending on the given string: // FromString returns a Splitter depending on the given string:
...@@ -44,7 +39,7 @@ func FromString(r io.Reader, chunker string) (Splitter, error) { ...@@ -44,7 +39,7 @@ func FromString(r io.Reader, chunker string) (Splitter, error) {
return nil, err return nil, err
} else if size <= 0 { } else if size <= 0 {
return nil, ErrSize return nil, ErrSize
} else if size > BlockPayloadLimit { } else if size > ChunkSizeLimit {
return nil, ErrSizeMax return nil, ErrSizeMax
} }
return NewSizeSplitter(r, int64(size)), nil return NewSizeSplitter(r, int64(size)), nil
...@@ -69,7 +64,7 @@ func parseRabinString(r io.Reader, chunker string) (Splitter, error) { ...@@ -69,7 +64,7 @@ func parseRabinString(r io.Reader, chunker string) (Splitter, error) {
size, err := strconv.Atoi(parts[1]) size, err := strconv.Atoi(parts[1])
if err != nil { if err != nil {
return nil, err return nil, err
} else if int(float32(size)*1.5) > BlockPayloadLimit { // FIXME - there is probably a better way to bubble up this calculation from NewRabin() } else if int(float32(size)*1.5) > ChunkSizeLimit { // FIXME - this will be addressed in a subsequent PR
return nil, ErrSizeMax return nil, ErrSizeMax
} }
return NewRabin(r, uint64(size)), nil return NewRabin(r, uint64(size)), nil
...@@ -108,7 +103,7 @@ func parseRabinString(r io.Reader, chunker string) (Splitter, error) { ...@@ -108,7 +103,7 @@ func parseRabinString(r io.Reader, chunker string) (Splitter, error) {
return nil, errors.New("incorrect format: rabin-min must be smaller than rabin-avg") return nil, errors.New("incorrect format: rabin-min must be smaller than rabin-avg")
} else if avg >= max { } else if avg >= max {
return nil, errors.New("incorrect format: rabin-avg must be smaller than rabin-max") return nil, errors.New("incorrect format: rabin-avg must be smaller than rabin-max")
} else if max > BlockPayloadLimit { } else if max > ChunkSizeLimit {
return nil, ErrSizeMax return nil, ErrSizeMax
} }
......
...@@ -7,7 +7,7 @@ import ( ...@@ -7,7 +7,7 @@ import (
) )
const ( const (
testTwoThirdsOfBlockPayloadLimit = 2 * (float32(BlockPayloadLimit) / float32(3)) testTwoThirdsOfChunkLimit = 2 * (float32(ChunkSizeLimit) / float32(3))
) )
func TestParseRabin(t *testing.T) { func TestParseRabin(t *testing.T) {
...@@ -33,22 +33,22 @@ func TestParseRabin(t *testing.T) { ...@@ -33,22 +33,22 @@ func TestParseRabin(t *testing.T) {
t.Fatalf("Expected an arg-out-of-order error, got: %#v", err) t.Fatalf("Expected an arg-out-of-order error, got: %#v", err)
} }
_, err = FromString(r, fmt.Sprintf("rabin-19-21-%d", BlockPayloadLimit)) _, err = FromString(r, fmt.Sprintf("rabin-19-21-%d", ChunkSizeLimit))
if err != nil { if err != nil {
t.Fatalf("Expected success, got: %#v", err) t.Fatalf("Expected success, got: %#v", err)
} }
_, err = FromString(r, fmt.Sprintf("rabin-19-21-%d", 1+BlockPayloadLimit)) _, err = FromString(r, fmt.Sprintf("rabin-19-21-%d", 1+ChunkSizeLimit))
if err != ErrSizeMax { if err != ErrSizeMax {
t.Fatalf("Expected 'ErrSizeMax', got: %#v", err) t.Fatalf("Expected 'ErrSizeMax', got: %#v", err)
} }
_, err = FromString(r, fmt.Sprintf("rabin-%.0f", testTwoThirdsOfBlockPayloadLimit)) _, err = FromString(r, fmt.Sprintf("rabin-%.0f", testTwoThirdsOfChunkLimit))
if err != nil { if err != nil {
t.Fatalf("Expected success, got: %#v", err) t.Fatalf("Expected success, got: %#v", err)
} }
_, err = FromString(r, fmt.Sprintf("rabin-%.0f", 1+testTwoThirdsOfBlockPayloadLimit)) _, err = FromString(r, fmt.Sprintf("rabin-%.0f", 1+testTwoThirdsOfChunkLimit))
if err != ErrSizeMax { if err != ErrSizeMax {
t.Fatalf("Expected 'ErrSizeMax', got: %#v", err) t.Fatalf("Expected 'ErrSizeMax', got: %#v", err)
} }
...@@ -68,12 +68,12 @@ func TestParseSize(t *testing.T) { ...@@ -68,12 +68,12 @@ func TestParseSize(t *testing.T) {
t.Fatalf("Expected success, got: %#v", err) t.Fatalf("Expected success, got: %#v", err)
} }
_, err = FromString(r, fmt.Sprintf("size-%d", BlockPayloadLimit)) _, err = FromString(r, fmt.Sprintf("size-%d", ChunkSizeLimit))
if err != nil { if err != nil {
t.Fatalf("Expected success, got: %#v", err) t.Fatalf("Expected success, got: %#v", err)
} }
_, err = FromString(r, fmt.Sprintf("size-%d", 1+BlockPayloadLimit)) _, err = FromString(r, fmt.Sprintf("size-%d", 1+ChunkSizeLimit))
if err != ErrSizeMax { if err != ErrSizeMax {
t.Fatalf("Expected 'ErrSizeMax', got: %#v", err) t.Fatalf("Expected 'ErrSizeMax', got: %#v", err)
} }
......
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