Allow registry exporter to work with gRPC objects #142

Merged
fyrchik merged 1 commits from elebedeva/xk6-frostfs:fix/registry-export-grpc-obj into master 2024-06-04 12:17:23 +00:00
Collaborator

Close #139

Added CID and OID keys export if S3Bucket or S3Key is empty.

Signed-off-by: Ekaterina Lebedeva ekaterina.lebedeva@yadro.com

Close #139 Added `CID` and `OID` keys export if `S3Bucket` or `S3Key` is empty. Signed-off-by: Ekaterina Lebedeva <ekaterina.lebedeva@yadro.com>
elebedeva requested review from storage-core-committers 2024-05-31 18:32:16 +00:00
elebedeva requested review from storage-core-developers 2024-05-31 18:32:17 +00:00
fyrchik approved these changes 2024-05-31 18:48:27 +00:00
Dismissed
@ -69,3 +64,1 @@
comma = ""
for bucket := range bucketMap {
if _, err = f.WriteString(fmt.Sprintf(`%s"%s"`, comma, bucket)); err != nil {
if len(bucketMap) > 1 {

This is wrong: len(bucketMap) can happily be 1 if we have exactly 1 S3 bucket, and in this case we need to print it.

What we might do instead is to have 2 maps (bucketMap and containerMap) and add only nonzero keys to them.

This is wrong: `len(bucketMap)` can happily be 1 if we have exactly 1 S3 bucket, and in this case we need to print it. What we might do instead is to have 2 maps (`bucketMap` and `containerMap`) and add only nonzero keys to them.
Poster
Collaborator

fixed

fixed
fyrchik marked this conversation as resolved
@ -83,0 +85,4 @@
func writeObjectInfo(comma string, info *ObjectInfo, f *os.File) (err error) {
var res string
if info.S3Bucket != "" || info.S3Key != "" {
res += fmt.Sprintf(`%s{"bucket":"%s","object":"%s"}`, comma, info.S3Bucket, info.S3Key)

Why is it res += and not res = ?

Why is it `res += ` and not `res = `?
Poster
Collaborator

Didn't notice, fixed

Didn't notice, fixed
fyrchik marked this conversation as resolved
fyrchik dismissed fyrchik’s review 2024-05-31 18:48:57 +00:00
Reason:

Approved accidentally

elebedeva force-pushed fix/registry-export-grpc-obj from 91aa27972b to ba769db1e3 2024-06-03 20:16:22 +00:00 Compare
elebedeva requested review from storage-core-committers 2024-06-03 20:19:35 +00:00
acid-ant requested changes 2024-06-04 09:09:24 +00:00
@ -62,3 +67,3 @@
}
if _, err = f.WriteString(`],"buckets":[`); err != nil {
if len(bucketMap) > 0 {
Collaborator

Can be shortened to:

if len(bucketMap) > 0 {
  err = writeContainerInfo("buckets", bucketMap, f)
} else {
  err = writeContainerInfo("containers", containerMap, f)
}
return err
Can be shortened to: ``` if len(bucketMap) > 0 { err = writeContainerInfo("buckets", bucketMap, f) } else { err = writeContainerInfo("containers", containerMap, f) } return err ```
Poster
Collaborator

fixed

fixed
elebedeva force-pushed fix/registry-export-grpc-obj from ba769db1e3 to 84f698bbdf 2024-06-04 09:15:06 +00:00 Compare
dstepanov-yadro approved these changes 2024-06-04 09:15:55 +00:00
achuprov approved these changes 2024-06-04 09:45:02 +00:00
fyrchik reviewed 2024-06-04 11:05:03 +00:00
@ -65,0 +69,4 @@
if len(bucketMap) > 0 {
err = writeContainerInfo("buckets", bucketMap, f)
} else {
err = writeContainerInfo("containers", containerMap, f)

This is tricky: each object was either put via gRPC or via S3.
But both can be in the registry at the same time, so we should print both maps, I believe.

This is tricky: each object was either put via gRPC or via S3. But both can be in the registry at the same time, so we should print both maps, I believe.
Poster
Collaborator

fixed

fixed
fyrchik marked this conversation as resolved
fyrchik reviewed 2024-06-04 11:06:03 +00:00
@ -70,2 +94,2 @@
for bucket := range bucketMap {
if _, err = f.WriteString(fmt.Sprintf(`%s"%s"`, comma, bucket)); err != nil {
comma := ""
for cnr := range cnrMap {

This change seems unnecessary and pollutes diff (it was bucketMap, we could continue to accept bucketMap).

This change seems unnecessary and pollutes diff (it was `bucketMap`, we could continue to accept `bucketMap`).
fyrchik marked this conversation as resolved
elebedeva force-pushed fix/registry-export-grpc-obj from 84f698bbdf to ebdadf2868 2024-06-04 11:24:24 +00:00 Compare
fyrchik reviewed 2024-06-04 11:33:50 +00:00
@ -63,2 +69,3 @@
if _, err = f.WriteString(`],"buckets":[`); err != nil {
if len(bucketMap) > 0 {
err = errors.Join(err, writeContainerInfo("buckets", bucketMap, f))

Why do you use errors.Join?
Error on write most likely will result in corrupted file (invalid JSON), we should just return the error.

Why do you use `errors.Join`? Error on write most likely will result in corrupted file (invalid JSON), we should just return the error.
Poster
Collaborator

accidentally pushed, will fix

accidentally pushed, will fix
fyrchik marked this conversation as resolved
elebedeva force-pushed fix/registry-export-grpc-obj from ebdadf2868 to 5a547e6d58 2024-06-04 12:03:24 +00:00 Compare
elebedeva force-pushed fix/registry-export-grpc-obj from 5a547e6d58 to 3dd559a7b1 2024-06-04 12:06:16 +00:00 Compare
fyrchik approved these changes 2024-06-04 12:17:02 +00:00
fyrchik merged commit 3dd559a7b1 into master 2024-06-04 12:17:23 +00:00
Sign in to join this conversation.
There is no content yet.