Skip to content
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

Experiment with sending chunks of binary payload #4512

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ func filenameForDownload(meta *datapb.BinaryMetadata) string {
}

// Replace reserved characters.
fileName = data.CaptureFilePathWithReplacedReservedChars(fileName)
fileName = data.FilePathWithReplacedReservedChars(fileName)

return fileName
}
Expand Down
34 changes: 23 additions & 11 deletions data/capture_buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ type CaptureBufferedWriter interface {

// CaptureBuffer is a persistent queue of SensorData backed by a series of *data.CaptureFile.
type CaptureBuffer struct {
Directory string
MetaData *v1.DataCaptureMetadata
nextFile *CaptureFile
directory string
metaData *v1.DataCaptureMetadata
nextFile *ProgFile
lock sync.Mutex
maxCaptureFileSize int64
}

// NewCaptureBuffer returns a new Buffer.
func NewCaptureBuffer(dir string, md *v1.DataCaptureMetadata, maxCaptureFileSize int64) *CaptureBuffer {
return &CaptureBuffer{
Directory: dir,
MetaData: md,
directory: dir,
metaData: md,
maxCaptureFileSize: maxCaptureFileSize,
}
}
Expand All @@ -36,12 +36,24 @@ func NewCaptureBuffer(dir string, md *v1.DataCaptureMetadata, maxCaptureFileSize
// are still being written to are indicated with the extension
// InProgressFileExt. Files that have finished being written to are indicated by
// FileExt.
func isBinary(item *v1.SensorData) bool {
if item == nil {
return false
}
switch item.Data.(type) {
case *v1.SensorData_Binary:
return true
default:
return false
}
}

func (b *CaptureBuffer) Write(item *v1.SensorData) error {
b.lock.Lock()
defer b.lock.Unlock()

if item.GetBinary() != nil {
binFile, err := NewCaptureFile(b.Directory, b.MetaData)
if isBinary(item) {
binFile, err := NewProgFile(b.directory, b.metaData)
if err != nil {
return err
}
Expand All @@ -55,19 +67,19 @@ func (b *CaptureBuffer) Write(item *v1.SensorData) error {
}

if b.nextFile == nil {
nextFile, err := NewCaptureFile(b.Directory, b.MetaData)
nextFile, err := NewProgFile(b.directory, b.metaData)
if err != nil {
return err
}
b.nextFile = nextFile
// We want to special case on "CaptureAllFromCamera" because it is sensor data that contains images
// and their corresponding annotations. We want each image and its annotations to be stored in a
// separate file.
} else if b.nextFile.Size() > b.maxCaptureFileSize || b.MetaData.MethodName == "CaptureAllFromCamera" {
} else if b.nextFile.Size() > b.maxCaptureFileSize || b.metaData.MethodName == "CaptureAllFromCamera" {
if err := b.nextFile.Close(); err != nil {
return err
}
nextFile, err := NewCaptureFile(b.Directory, b.MetaData)
nextFile, err := NewProgFile(b.directory, b.metaData)
if err != nil {
return err
}
Expand All @@ -93,5 +105,5 @@ func (b *CaptureBuffer) Flush() error {

// Path returns the path to the directory containing the backing data capture files.
func (b *CaptureBuffer) Path() string {
return b.Directory
return b.directory
}
Loading
Loading