-
Notifications
You must be signed in to change notification settings - Fork 16
Reducing size #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
b6b993d
feat: add trunk compress for storedFields
hengfeiyang 7f1692a
feat: use zstd replace snappy
hengfeiyang a5cb202
feat: compress docValue
hengfeiyang c3633ed
feat: reback the docValue compress
hengfeiyang 4662783
feat: packed docNum and Offset for docValue
hengfeiyang 439e31a
doc: update go.mod
hengfeiyang 0753dc9
feat: packed numeric of posting list
hengfeiyang 3061032
feat: compress numeric of posting list
hengfeiyang b4acb45
feat: packed numeric of posting list
hengfeiyang 3442f5a
feat: compress intcoder
hengfeiyang 152a011
feat: run optimize on bitmap
hengfeiyang c8cc4b7
feat: optimize document values chunk
hengfeiyang 79196b6
doc: add author
hengfeiyang 9bed194
style: change implement
hengfeiyang 4f5e6c0
fix: tests
hengfeiyang 929ccaf
test: add test for document coder
hengfeiyang ace50a7
style: format code
hengfeiyang dd60c36
update trunk to chunk
hengfeiyang ab3514f
update sort of Authors
hengfeiyang 2f4d2fd
rename BufferSize to Size and remove Close method
hengfeiyang 5e1f80d
update version
hengfeiyang d802dbc
fix panic when search memory
hengfeiyang 1e2159e
rename variables
hengfeiyang c784da3
Merge branch 'master'
hengfeiyang a14a43c
Merge branch 'blugelabs-master'
hengfeiyang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,4 +7,5 @@ | |
| # | ||
| # Please keep the list sorted. | ||
|
|
||
| Hengfei Yang <[email protected]> | ||
| Marty Schoch <[email protected]> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| package ice | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "encoding/binary" | ||
| "io" | ||
| ) | ||
|
|
||
| const defaultDocumentChunkSize uint32 = 128 | ||
|
|
||
| type chunkedDocumentCoder struct { | ||
| chunkSize uint64 | ||
| w io.Writer | ||
| buf *bytes.Buffer | ||
| metaBuf []byte | ||
| n uint64 | ||
| bytes uint64 | ||
| compressed []byte | ||
| offsets []uint64 | ||
| } | ||
|
|
||
| func newChunkedDocumentCoder(chunkSize uint64, w io.Writer) *chunkedDocumentCoder { | ||
| c := &chunkedDocumentCoder{ | ||
| chunkSize: chunkSize, | ||
| w: w, | ||
| } | ||
| c.buf = bytes.NewBuffer(nil) | ||
| c.metaBuf = make([]byte, binary.MaxVarintLen64) | ||
| c.offsets = append(c.offsets, 0) | ||
| return c | ||
| } | ||
|
|
||
| func (c *chunkedDocumentCoder) Add(docNum uint64, meta, data []byte) (int, error) { | ||
| var wn, n int | ||
| var err error | ||
| n = binary.PutUvarint(c.metaBuf, uint64(len(meta))) | ||
| if n, err = c.writeToBuf(c.metaBuf[:n]); err != nil { | ||
| return 0, err | ||
| } | ||
| wn += n | ||
| n = binary.PutUvarint(c.metaBuf, uint64(len(data))) | ||
| if n, err = c.writeToBuf(c.metaBuf[:n]); err != nil { | ||
| return 0, err | ||
| } | ||
| wn += n | ||
| if n, err = c.writeToBuf(meta); err != nil { | ||
| return 0, err | ||
| } | ||
| wn += n | ||
| if n, err = c.writeToBuf(data); err != nil { | ||
| return 0, err | ||
| } | ||
| wn += n | ||
|
|
||
| return wn, c.newLine() | ||
| } | ||
|
|
||
| func (c *chunkedDocumentCoder) writeToBuf(data []byte) (int, error) { | ||
| return c.buf.Write(data) | ||
| } | ||
|
|
||
| func (c *chunkedDocumentCoder) newLine() error { | ||
| c.n++ | ||
| if c.n%c.chunkSize != 0 { | ||
| return nil | ||
| } | ||
| return c.flush() | ||
| } | ||
|
|
||
| func (c *chunkedDocumentCoder) flush() error { | ||
| if c.buf.Len() > 0 { | ||
| var err error | ||
| c.compressed, err = ZSTDCompress(c.compressed[:cap(c.compressed)], c.buf.Bytes(), ZSTDCompressionLevel) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| n, err := c.w.Write(c.compressed) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| c.bytes += uint64(n) | ||
| c.buf.Reset() | ||
| } | ||
| c.offsets = append(c.offsets, c.bytes) | ||
| return nil | ||
| } | ||
|
|
||
| func (c *chunkedDocumentCoder) Write() error { | ||
| // flush first | ||
| if err := c.flush(); err != nil { | ||
| return err | ||
| } | ||
| var err error | ||
| var wn, n int | ||
| // write chunk offsets | ||
| for _, offset := range c.offsets { | ||
| n = binary.PutUvarint(c.metaBuf, offset) | ||
| if _, err = c.w.Write(c.metaBuf[:n]); err != nil { | ||
| return err | ||
| } | ||
| wn += n | ||
| } | ||
| // write chunk offset length | ||
| err = binary.Write(c.w, binary.BigEndian, uint32(wn)) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| // write chunk num | ||
| err = binary.Write(c.w, binary.BigEndian, uint32(len(c.offsets))) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (c *chunkedDocumentCoder) Reset() { | ||
| c.compressed = c.compressed[:0] | ||
| c.offsets = c.offsets[:0] | ||
| c.n = 0 | ||
| c.bytes = 0 | ||
| c.buf.Reset() | ||
| } | ||
|
|
||
| // Size returns buffer size of current chunk | ||
| func (c *chunkedDocumentCoder) Size() uint64 { | ||
| return uint64(c.buf.Len()) | ||
| } | ||
|
|
||
| // Len returns chunks num | ||
| func (c *chunkedDocumentCoder) Len() int { | ||
| return len(c.offsets) | ||
| } | ||
|
|
||
| // Len returns chunks num | ||
| func (c *chunkedDocumentCoder) Offsets() []uint64 { | ||
| m := make([]uint64, 0, len(c.offsets)) | ||
| m = append(m, c.offsets...) | ||
| return m | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| package ice | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestChunkedDocumentCoder(t *testing.T) { | ||
| tests := []struct { | ||
| chunkSize uint64 | ||
| docNums []uint64 | ||
| metas [][]byte | ||
| datas [][]byte | ||
| expected []byte | ||
| expectedChunkNum int | ||
| }{ | ||
| { | ||
| chunkSize: 1, | ||
| docNums: []uint64{0}, | ||
| metas: [][]byte{{0}}, | ||
| datas: [][]byte{[]byte("bluge")}, | ||
| expected: []byte{ | ||
| 0x28, 0xb5, 0x2f, 0xfd, 0x4, 0x0, 0x41, | ||
| 0x0, 0x0, 0x1, 0x5, 0x0, 0x62, 0x6c, 0x75, 0x67, 0x65, 0x2b, 0x30, 0x97, 0x33, 0x0, 0x15, 0x15, | ||
| 0x0, 0x0, 0x0, 0x3, 0x0, 0x0, 0x0, 0x3, | ||
| }, | ||
| expectedChunkNum: 3, // left, chunk, right | ||
| }, | ||
| { | ||
| chunkSize: 1, | ||
| docNums: []uint64{0, 1}, | ||
| metas: [][]byte{{0}, {1}}, | ||
| datas: [][]byte{[]byte("upside"), []byte("scorch")}, | ||
| expected: []byte{ | ||
| 0x28, 0xb5, 0x2f, 0xfd, 0x4, 0x0, 0x49, | ||
| 0x0, 0x0, 0x1, 0x6, 0x0, 0x75, 0x70, 0x73, 0x69, 0x64, 0x65, | ||
| 0x36, 0x6e, 0x7e, 0x39, 0x28, 0xb5, 0x2f, 0xfd, 0x4, 0x0, 0x49, | ||
| 0x0, 0x0, 0x1, 0x6, 0x1, 0x73, 0x63, 0x6f, 0x72, 0x63, 0x68, | ||
| 0x8f, 0x83, 0xa3, 0x37, 0x0, 0x16, 0x2c, 0x2c, | ||
| 0x0, 0x0, 0x0, 0x4, 0x0, 0x0, 0x0, 0x4, | ||
| }, | ||
| expectedChunkNum: 4, // left, chunk, chunk, right | ||
| }, | ||
| } | ||
|
|
||
| for _, test := range tests { | ||
| var actual bytes.Buffer | ||
| cic := newChunkedDocumentCoder(test.chunkSize, &actual) | ||
| for i, docNum := range test.docNums { | ||
| _, err := cic.Add(docNum, test.metas[i], test.datas[i]) | ||
| if err != nil { | ||
| t.Fatalf("error adding to documentcoder: %v", err) | ||
| } | ||
| } | ||
| err := cic.Write() | ||
| if err != nil { | ||
| t.Fatalf("error writing: %v", err) | ||
| } | ||
| if !bytes.Equal(test.expected, actual.Bytes()) { | ||
| t.Errorf("got:%s, expected:%s", actual.String(), string(test.expected)) | ||
| } | ||
| if test.expectedChunkNum != cic.Len() { | ||
| t.Errorf("got:%d, expected:%d", cic.Len(), test.expectedChunkNum) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func TestChunkedDocumentCoders(t *testing.T) { | ||
| chunkSize := uint64(2) | ||
| docNums := []uint64{0, 1, 2, 3, 4, 5} | ||
| metas := [][]byte{ | ||
| {0}, | ||
| {1}, | ||
| {2}, | ||
| {3}, | ||
| {4}, | ||
| {5}, | ||
| } | ||
| datas := [][]byte{ | ||
| []byte("scorch"), | ||
| []byte("does"), | ||
| []byte("better"), | ||
| []byte("than"), | ||
| []byte("upside"), | ||
| []byte("down"), | ||
| } | ||
| chunkNum := 5 // left, chunk, chunk, chunk, right | ||
|
|
||
| var actual1, actual2 bytes.Buffer | ||
| // chunkedDocumentCoder that writes out at the end | ||
| cic1 := newChunkedDocumentCoder(chunkSize, &actual1) | ||
| // chunkedContentCoder that writes out in chunks | ||
| cic2 := newChunkedDocumentCoder(chunkSize, &actual2) | ||
|
|
||
| for i, docNum := range docNums { | ||
| _, err := cic1.Add(docNum, metas[i], datas[i]) | ||
| if err != nil { | ||
| t.Fatalf("error adding to documentcoder: %v", err) | ||
| } | ||
| _, err = cic2.Add(docNum, metas[i], datas[i]) | ||
| if err != nil { | ||
| t.Fatalf("error adding to documentcoder: %v", err) | ||
| } | ||
| } | ||
|
|
||
| err := cic1.Write() | ||
| if err != nil { | ||
| t.Fatalf("error writing: %v", err) | ||
| } | ||
| err = cic2.Write() | ||
| if err != nil { | ||
| t.Fatalf("error writing: %v", err) | ||
| } | ||
|
|
||
| if !bytes.Equal(actual1.Bytes(), actual2.Bytes()) { | ||
| t.Errorf("%s != %s", actual1.String(), actual2.String()) | ||
| } | ||
| if chunkNum != cic1.Len() { | ||
| t.Errorf("got:%d, expected:%d", cic1.Len(), chunkNum) | ||
| } | ||
| if chunkNum != cic2.Len() { | ||
| t.Errorf("got:%d, expected:%d", cic2.Len(), chunkNum) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.