You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ze...@apache.org on 2022/07/13 20:47:39 UTC

[arrow] branch master updated: ARROW-16002: [Go] fileBlock.NewMessage should use memory.Allocator (#13554)

This is an automated email from the ASF dual-hosted git repository.

zeroshade pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new e766828c69 ARROW-16002: [Go] fileBlock.NewMessage should use memory.Allocator (#13554)
e766828c69 is described below

commit e766828c699c6c74eba3b8c5de99e541017b8b9e
Author: Matt Topol <zo...@gmail.com>
AuthorDate: Wed Jul 13 16:47:31 2022 -0400

    ARROW-16002: [Go] fileBlock.NewMessage should use memory.Allocator (#13554)
    
    Share the `FileReader`'s allocator with the `fileBlock` objects so that the `NewMessage` can be allocated using the memory allocator. Allowing for re-use if the Allocator allows it
    
    Lead-authored-by: Matt Topol <zo...@gmail.com>
    Co-authored-by: Matthew Topol <mt...@factset.com>
    Signed-off-by: Matthew Topol <mt...@factset.com>
---
 go/arrow/ipc/file_reader.go |  2 ++
 go/arrow/ipc/metadata.go    | 27 +++++++++++++++++++--------
 2 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/go/arrow/ipc/file_reader.go b/go/arrow/ipc/file_reader.go
index 068d5ebbc9..ab6e7bf108 100644
--- a/go/arrow/ipc/file_reader.go
+++ b/go/arrow/ipc/file_reader.go
@@ -188,6 +188,7 @@ func (f *FileReader) block(i int) (fileBlock, error) {
 		Meta:   blk.MetaDataLength(),
 		Body:   blk.BodyLength(),
 		r:      f.r,
+		mem:    f.mem,
 	}, nil
 }
 
@@ -202,6 +203,7 @@ func (f *FileReader) dict(i int) (fileBlock, error) {
 		Meta:   blk.MetaDataLength(),
 		Body:   blk.BodyLength(),
 		r:      f.r,
+		mem:    f.mem,
 	}, nil
 }
 
diff --git a/go/arrow/ipc/metadata.go b/go/arrow/ipc/metadata.go
index 132dfb6976..eaf2228f37 100644
--- a/go/arrow/ipc/metadata.go
+++ b/go/arrow/ipc/metadata.go
@@ -65,7 +65,8 @@ type fileBlock struct {
 	Meta   int32
 	Body   int64
 
-	r io.ReaderAt
+	r   io.ReaderAt
+	mem memory.Allocator
 }
 
 func fileBlocksToFB(b *flatbuffers.Builder, blocks []fileBlock, start startVecFunc) flatbuffers.UOffsetT {
@@ -80,12 +81,18 @@ func fileBlocksToFB(b *flatbuffers.Builder, blocks []fileBlock, start startVecFu
 
 func (blk fileBlock) NewMessage() (*Message, error) {
 	var (
-		err error
-		buf []byte
-		r   = blk.section()
+		err  error
+		buf  []byte
+		body *memory.Buffer
+		meta *memory.Buffer
+		r    = blk.section()
 	)
 
-	buf = make([]byte, blk.Meta)
+	meta = memory.NewResizableBuffer(blk.mem)
+	meta.Resize(int(blk.Meta))
+	defer meta.Release()
+
+	buf = meta.Bytes()
 	_, err = io.ReadFull(r, buf)
 	if err != nil {
 		return nil, fmt.Errorf("arrow/ipc: could not read message metadata: %w", err)
@@ -102,14 +109,18 @@ func (blk fileBlock) NewMessage() (*Message, error) {
 		prefix = 4
 	}
 
-	meta := memory.NewBufferBytes(buf[prefix:]) // drop buf-size already known from blk.Meta
+	// drop buf-size already known from blk.Meta
+	meta = memory.SliceBuffer(meta, prefix, int(blk.Meta)-prefix)
+	defer meta.Release()
 
-	buf = make([]byte, blk.Body)
+	body = memory.NewResizableBuffer(blk.mem)
+	defer body.Release()
+	body.Resize(int(blk.Body))
+	buf = body.Bytes()
 	_, err = io.ReadFull(r, buf)
 	if err != nil {
 		return nil, fmt.Errorf("arrow/ipc: could not read message body: %w", err)
 	}
-	body := memory.NewBufferBytes(buf)
 
 	return NewMessage(meta, body), nil
 }