Skip to content

Commit

Permalink
cli: add logs for upload-bin
Browse files Browse the repository at this point in the history
Logs for testing purpose.Refs. https://github
.com//issues/3658#issuecomment-2468210667

Signed-off-by: Ekaterina Pavlova <[email protected]>
  • Loading branch information
AliceInHunterland committed Nov 11, 2024
1 parent 66fbcb2 commit 067af5b
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions cli/util/upload_bin.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,12 @@ func uploadBlocks(ctx *cli.Context, p *pool.Pool, rpc *rpcclient.Client, signer

objBytes := bw.Bytes()
errRetr := retry(func() error {
return uploadObj(ctx.Context, p, signer, acc.PrivateKey().GetScriptHash(), containerID, objBytes, attrs, homomorphicHashingDisabled)
resOid, errUpload := uploadObj(ctx.Context, p, signer, acc.PrivateKey().GetScriptHash(), containerID, objBytes, attrs, homomorphicHashingDisabled)
if errUpload != nil {
return errUpload
}
fmt.Fprintf(ctx.App.Writer, "Uploaded block %d with object ID: %s\n", blockIndex, resOid.String())
return errUpload

Check warning on line 303 in cli/util/upload_bin.go

View check run for this annotation

Codecov / codecov/patch

cli/util/upload_bin.go#L298-L303

Added lines #L298 - L303 were not covered by tests
}, maxRetries)
if errRetr != nil {
select {
Expand Down Expand Up @@ -460,7 +465,12 @@ func uploadIndexFiles(ctx *cli.Context, p *pool.Pool, containerID cid.ID, accoun
*object.NewAttribute("IndexSize", strconv.Itoa(int(indexFileSize))),
}
err := retry(func() error {
return uploadObj(ctx.Context, p, signer, account.PrivateKey().GetScriptHash(), containerID, buffer, attrs, homomorphicHashingDisabled)
resOid, errUpload := uploadObj(ctx.Context, p, signer, account.PrivateKey().GetScriptHash(), containerID, buffer, attrs, homomorphicHashingDisabled)
if errUpload != nil {
return errUpload
}
fmt.Fprintf(ctx.App.Writer, "Uploaded index file %d with object ID: %s\n", i, resOid.String())
return errUpload

Check warning on line 473 in cli/util/upload_bin.go

View check run for this annotation

Codecov / codecov/patch

cli/util/upload_bin.go#L468-L473

Added lines #L468 - L473 were not covered by tests
}, maxRetries)
if err != nil {
select {
Expand Down Expand Up @@ -541,14 +551,15 @@ func searchObjects(ctx context.Context, p *pool.Pool, containerID cid.ID, accoun
}

// uploadObj uploads object to the container using provided settings.
func uploadObj(ctx context.Context, p *pool.Pool, signer user.Signer, owner util.Uint160, containerID cid.ID, objData []byte, attrs []object.Attribute, homomorphicHashingDisabled bool) error {
func uploadObj(ctx context.Context, p *pool.Pool, signer user.Signer, owner util.Uint160, containerID cid.ID, objData []byte, attrs []object.Attribute, homomorphicHashingDisabled bool) (oid.ID, error) {

Check warning on line 554 in cli/util/upload_bin.go

View check run for this annotation

Codecov / codecov/patch

cli/util/upload_bin.go#L554

Added line #L554 was not covered by tests
var (
ownerID user.ID
hdr object.Object
chSHA256 checksum.Checksum
chHomomorphic checksum.Checksum
v = new(version.Version)
prmObjectPutInit client.PrmObjectPutInit
resOID = oid.ID{}

Check warning on line 562 in cli/util/upload_bin.go

View check run for this annotation

Codecov / codecov/patch

cli/util/upload_bin.go#L562

Added line #L562 was not covered by tests
)

ownerID.SetScriptHash(owner)
Expand All @@ -569,31 +580,32 @@ func uploadObj(ctx context.Context, p *pool.Pool, signer user.Signer, owner util

err := hdr.SetIDWithSignature(signer)
if err != nil {
return err
return resOID, err

Check warning on line 583 in cli/util/upload_bin.go

View check run for this annotation

Codecov / codecov/patch

cli/util/upload_bin.go#L583

Added line #L583 was not covered by tests
}
err = hdr.CheckHeaderVerificationFields()
if err != nil {
return err
return resOID, err

Check warning on line 587 in cli/util/upload_bin.go

View check run for this annotation

Codecov / codecov/patch

cli/util/upload_bin.go#L587

Added line #L587 was not covered by tests
}

writer, err := p.ObjectPutInit(ctx, hdr, signer, prmObjectPutInit)
if err != nil {
return fmt.Errorf("failed to initiate object upload: %w", err)
return resOID, fmt.Errorf("failed to initiate object upload: %w", err)

Check warning on line 592 in cli/util/upload_bin.go

View check run for this annotation

Codecov / codecov/patch

cli/util/upload_bin.go#L592

Added line #L592 was not covered by tests
}
_, err = writer.Write(objData)
if err != nil {
_ = writer.Close()
return fmt.Errorf("failed to write object data: %w", err)
return resOID, fmt.Errorf("failed to write object data: %w", err)

Check warning on line 597 in cli/util/upload_bin.go

View check run for this annotation

Codecov / codecov/patch

cli/util/upload_bin.go#L597

Added line #L597 was not covered by tests
}
err = writer.Close()
if err != nil {
return fmt.Errorf("failed to close object writer: %w", err)
return resOID, fmt.Errorf("failed to close object writer: %w", err)

Check warning on line 601 in cli/util/upload_bin.go

View check run for this annotation

Codecov / codecov/patch

cli/util/upload_bin.go#L601

Added line #L601 was not covered by tests
}
res := writer.GetResult()
if res.StoredObjectID().Equals(oid.ID{}) {
return fmt.Errorf("object ID is empty")
resOID = res.StoredObjectID()
if resOID.Equals(oid.ID{}) {
return resOID, fmt.Errorf("object ID is empty")

Check warning on line 606 in cli/util/upload_bin.go

View check run for this annotation

Codecov / codecov/patch

cli/util/upload_bin.go#L604-L606

Added lines #L604 - L606 were not covered by tests
}
return nil
return resOID, nil

Check warning on line 608 in cli/util/upload_bin.go

View check run for this annotation

Codecov / codecov/patch

cli/util/upload_bin.go#L608

Added line #L608 was not covered by tests
}

func getBlockIndex(header object.Object, attribute string) (int, error) {
Expand Down

0 comments on commit 067af5b

Please sign in to comment.