Repository navigation
Modify the binary format of tae strvec to be compatible with varlena - #5386
Conversation
| view.ApplyDeletes() | ||
| if view.GetData().Allocated() > 0 { | ||
| bat.Vecs[i] = containers.CopyToMoVector(view.GetData()) | ||
| bat.Vecs[i] = containers.CopyToMoVec(view.GetData()) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
- 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
- When TaeVec owns the memory, and we just want to execute some different read-only operation on the data, we can create a new
readerlike MoVec. For example, when we flush a column data, we can do this:moVec := taeVec.UnmarshalToVec(xxx) buf := moVec.Show() writer.Write(buf)
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
fengttt
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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 { |
…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
What type of PR is this?
Which issue(s) this PR fixes:
issue #
What this PR does / why we need it: