Skip to content

Modify the binary format of tae strvec to be compatible with varlena - #5386

Merged
mergify[bot] merged 27 commits into
matrixorigin:mainfrom
XuPeng-SH:strvec2
Oct 5, 2022
Merged

mergify[bot] merged 27 commits into
matrixorigin:mainfrom
XuPeng-SH:strvec2

Conversation

@XuPeng-SH

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #

What this PR does / why we need it:

  1. Modify the binary data to be compatible with varlena type
  2. Avoid vector copy overhead caused by vector conversion
  3. Small code refactor

@XuPeng-SH XuPeng-SH added this to the v0.6.0 milestone Oct 1, 2022
@XuPeng-SH
XuPeng-SH requested a review from fengttt October 1, 2022 13:43
@XuPeng-SH XuPeng-SH self-assigned this Oct 1, 2022
@XuPeng-SH
XuPeng-SH requested a review from nnsgmsone as a code owner October 1, 2022 13:43
@matrix-meow matrix-meow added the size/XL Denotes a PR that changes [1000, 1999] lines label Oct 1, 2022
@mergify mergify Bot added the kind/refactor Code refactor label Oct 1, 2022
Comment thread pkg/vm/engine/tae/containers/types.go Resolved
Comment thread pkg/vm/engine/tae/containers/utils.go Resolved
Comment thread pkg/vm/engine/tae/containers/utils.go Resolved
view.ApplyDeletes()
if view.GetData().Allocated() > 0 {
bat.Vecs[i] = containers.CopyToMoVector(view.GetData())
bat.Vecs[i] = containers.CopyToMoVec(view.GetData())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the different between CopyToMoVec and UnmarshalToMoVec? Which one does not copy? Which one share the underlying data?

How will bat.Vecs[i] know who manages the data? Ever need to free?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UbnarshalToMoVec shares the underlying memory and CopyToXXX does copy.

In this scenario, the application layer will pass a buffer in. When the data of the returned tae vector is on this buffer, and no additional memory is allocated, it can share memory. Once new additional memory is allocated, it will be copied to avoid memory life cycle management.

There are probably these use scenarios:

  1. The application layer provide a buffer and TaeVec data store the underlying data on the buffer. Both the TaeVec and MoVec share the underlying memory on the buffer. In this case, TaeVec and MoVec are only two different Readers and Writers, neither owns the memory. In the above use case, when TaeVec.Allocated() == 0, neither TaeVec nor the converted MoVec owns the memory, and neither needs to free the memory
  2. When TaeVec owns the memory, and we just want to execute some different read-only operation on the data, we can create a new reader like MoVec. For example, when we flush a column data, we can do this:
    moVec := taeVec.UnmarshalToVec(xxx)
    buf := moVec.Show()
    writer.Write(buf)
    

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how these work -- can both threads read and write at the same time?
Unless both cases they are read only.

func (vec *StrVector[T]) RangeDelete(offset, length int) {
for i := offset + length - 1; i >= offset; i-- {
vec.Delete(i)
if vec.area.Length() == 0 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just not do delete at all? Just don't touch the area and do not need to adjust offset len.

Does this range delete really help reduce memory? Why do it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is some tradeoff.

The current implementation is not efficient enough at point deletion, since we also adjust the area and need to adjust offset.
An optional implementation is not to touch the area and only change the data. In this case, when the vector is continuously updated, deleted, and inserted, the size of the area will continue to grow.

I prefer the optional implementation and change it in the next pr by @LeftHandCold. It should also be a local change

Comment thread pkg/vm/engine/tae/stl/types.go Resolved

@fengttt fengttt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My main questions is, who owns that memory ...

CopyToMoVecs, UnmarshalToMoVecs, and NewVectorWithSharedMemory
-- when is memory allocated
-- who owns it, and who will call free
-- how does memory accounting work

@fengttt fengttt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved this PR. However the memory ownership and accounting mechanism is broken.

The orig flag in container vector, is really not doing what it intends to do. The worst is the FreeOriginal method -- it almost feels like a fault inject ...

Will need to have another go of mpool with mo chen, maybe after your PR.

}

func (v *Varlena) byteSlice() []byte {
func (v *Varlena) ByteSlice() []byte {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why expose this

@mergify
mergify Bot merged commit b64fa56 into matrixorigin:main Oct 5, 2022
fengttt pushed a commit to fengttt/matrixone that referenced this pull request May 7, 2026
…atrixorigin#5386)

1. Modify the binary data to be compatible with varlena type
2. Avoid vector copy overhead caused by vector conversion
3. Small code refactor

Approved by: @fengttt, @nnsgmsone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/refactor Code refactor kind/tech-request New feature or request size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants