Skip to content

Commit

Permalink
Revert changes to insertionindex
Browse files Browse the repository at this point in the history
Revert changes to serialization of `insertionindex` postponed until the
streaming index work stream.
  • Loading branch information
masih committed Jul 6, 2022
1 parent 4bc6774 commit fb79485
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
42 changes: 33 additions & 9 deletions v2/blockstore/insertionindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package blockstore

import (
"bytes"
"encoding/binary"
"errors"
"fmt"
"io"
Expand All @@ -11,6 +12,7 @@ import (
"github.com/multiformats/go-multicodec"
"github.com/multiformats/go-multihash"
"github.com/petar/GoLLRB/llrb"
cbor "github.com/whyrusleeping/cbor/go"
)

// This index is intended to be efficient for random-access, in-memory lookups
Expand Down Expand Up @@ -106,7 +108,37 @@ func (ii *insertionIndex) GetAll(c cid.Cid, fn func(uint64) bool) error {
}

func (ii *insertionIndex) Marshal(w io.Writer) (uint64, error) {
return 0, fmt.Errorf("unimplemented, index type not intended for serialization")
l := uint64(0)
if err := binary.Write(w, binary.LittleEndian, int64(ii.items.Len())); err != nil {
return l, err
}
l += 8

var err error
iter := func(i llrb.Item) bool {
if err = cbor.Encode(w, i.(recordDigest).Record); err != nil {
return false
}
return true
}
ii.items.AscendGreaterOrEqual(ii.items.Min(), iter)
return l, err
}

func (ii *insertionIndex) Unmarshal(r io.Reader) error {
var length int64
if err := binary.Read(r, binary.LittleEndian, &length); err != nil {
return err
}
d := cbor.NewDecoder(r)
for i := int64(0); i < length; i++ {
var rec index.Record
if err := d.Decode(&rec); err != nil {
return err
}
ii.items.InsertNoReplace(newRecordDigest(rec))
}
return nil
}

func (ii *insertionIndex) ForEach(f func(multihash.Multihash, uint64) error) error {
Expand All @@ -123,14 +155,6 @@ func (ii *insertionIndex) ForEach(f func(multihash.Multihash, uint64) error) err
return errr
}

func (ii *insertionIndex) Unmarshal(r io.Reader) error {
return fmt.Errorf("unimplemented, index type not intended for deserialization")
}

func (ii *insertionIndex) UnmarshalLazyRead(r io.ReaderAt) (int64, error) {
return 0, fmt.Errorf("unimplemented, index type not intended for deserialization")
}

func (ii *insertionIndex) Codec() multicodec.Code {
return insertionIndexCodec
}
Expand Down
1 change: 1 addition & 0 deletions v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ require (
github.com/multiformats/go-varint v0.0.6
github.com/petar/GoLLRB v0.0.0-20210522233825-ae3b015fd3e9
github.com/stretchr/testify v1.7.0
github.com/whyrusleeping/cbor v0.0.0-20171005072247-63513f603b11
golang.org/x/exp v0.0.0-20210615023648-acb5c1269671
)

Expand Down
1 change: 1 addition & 0 deletions v2/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,7 @@ github.com/warpfork/go-testmark v0.3.0/go.mod h1:jhEf8FVxd+F17juRubpmut64NEG6I2r
github.com/warpfork/go-wish v0.0.0-20180510122957-5ad1f5abf436/go.mod h1:x6AKhvSSexNrVSrViXSHUEbICjmGXhtgABaHIySUSGw=
github.com/warpfork/go-wish v0.0.0-20200122115046-b9ea61034e4a h1:G++j5e0OC488te356JvdhaM8YS6nMsjLAYF7JxCv07w=
github.com/warpfork/go-wish v0.0.0-20200122115046-b9ea61034e4a/go.mod h1:x6AKhvSSexNrVSrViXSHUEbICjmGXhtgABaHIySUSGw=
github.com/whyrusleeping/cbor v0.0.0-20171005072247-63513f603b11 h1:5HZfQkwe0mIfyDmc1Em5GqlNRzcdtlv4HTNmdpt7XH0=
github.com/whyrusleeping/cbor v0.0.0-20171005072247-63513f603b11/go.mod h1:Wlo/SzPmxVp6vXpGt/zaXhHH0fn4IxgqZc82aKg6bpQ=
github.com/whyrusleeping/cbor-gen v0.0.0-20200123233031-1cdf64d27158 h1:WXhVOwj2USAXB5oMDwRl3piOux2XMV9TANaYxXHdkoE=
github.com/whyrusleeping/cbor-gen v0.0.0-20200123233031-1cdf64d27158/go.mod h1:Xj/M2wWU+QdTdRbu/L/1dIZY8/Wb2K9pAhtroQuxJJI=
Expand Down

0 comments on commit fb79485

Please sign in to comment.