Skip to content

Commit

Permalink
Fix error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
reshke committed Aug 24, 2024
1 parent 546d37f commit 879a50a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
38 changes: 17 additions & 21 deletions pkg/proc/interaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,24 @@ func ProcessPutExtended(
ycl.SetExternalFilePath(name)

var w io.WriteCloser

r, w := io.Pipe()

err := s.PutFileToDest(name, r, settings)

if err != nil {
_ = ycl.ReplyError(err, "failed to upload")

return err
}

defer r.Close()
defer w.Close()

wg := sync.WaitGroup{}
wg.Add(1)

go func() {
defer wg.Done()

var ww io.WriteCloser = w
if encrypt {
Expand All @@ -54,13 +65,6 @@ func ProcessPutExtended(
ylogger.Zero.Debug().Str("path", name).Msg("omit encryption for upload chunks")
}

for _, set := range settings {
ylogger.Zero.Debug().Str("setting name", set.Name).Str("value", set.Value).Msg("setting for chunk")
}

defer w.Close()
defer wg.Done()

for {
tp, body, err := pr.ReadPacket()
if err != nil {
Expand Down Expand Up @@ -99,16 +103,8 @@ func ProcessPutExtended(
}
}()

err := s.PutFileToDest(name, r, settings)

wg.Wait()

if err != nil {
_ = ycl.ReplyError(err, "failed to upload")

return err
}

_, err = ycl.GetRW().Write(message.NewReadyForQueryMessage().Encode())

if err != nil {
Expand Down Expand Up @@ -224,7 +220,7 @@ func ProcConn(s storage.StorageInteractor, cr crypt.Crypter, ycl client.YproxyCl
if err != nil {
_ = ycl.ReplyError(err, "failed to upload")

return nil
return err
}

case message.MessageTypeCopy:
Expand Down Expand Up @@ -340,7 +336,7 @@ func ProcConn(s storage.StorageInteractor, cr crypt.Crypter, ycl client.YproxyCl

if _, err = ycl.GetRW().Write(message.NewReadyForQueryMessage().Encode()); err != nil {
_ = ycl.ReplyError(err, "failed to upload")
return nil
return err
}
fmt.Println("Copy finished successfully")
ylogger.Zero.Info().Msg("Copy finished successfully")
Expand All @@ -366,19 +362,19 @@ func ProcConn(s storage.StorageInteractor, cr crypt.Crypter, ycl client.YproxyCl
err = dh.HandleDeleteGarbage(msg)
if err != nil {
_ = ycl.ReplyError(err, "failed to finish operation")
return nil
return err
}
} else {
err = dh.HandleDeleteFile(msg)
if err != nil {
_ = ycl.ReplyError(err, "failed to finish operation")
return nil
return err
}
}

if _, err = ycl.GetRW().Write(message.NewReadyForQueryMessage().Encode()); err != nil {
_ = ycl.ReplyError(err, "failed to upload")
return nil
return err
}
ylogger.Zero.Info().Msg("Deleted garbage successfully")
if !msg.Confirm {
Expand Down
3 changes: 2 additions & 1 deletion pkg/storage/s3storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ func (s *S3StorageInteractor) PutFileToDest(name string, r io.Reader, settings [

bucket, ok := s.bucketMap[tableSpace]
if !ok {
ylogger.Zero.Err(err).Msg(fmt.Sprintf("failed to match tablespace %s to s3 bucket.", tableSpace))
err := fmt.Errorf("failed to match tablespace %s to s3 bucket.", tableSpace)
ylogger.Zero.Err(err)
return err
}

Expand Down

0 comments on commit 879a50a

Please sign in to comment.