cmd/segment-reaper: Report zombie segment's size

Makes the detect command of the segments reaper to report the size of
each zombie segment.

Change-Id: Ibded5f4d1b53f6d2805dac96fd306452af7f2524
This commit is contained in:
Ivan Fraixedes 2020-05-18 20:05:22 +02:00 committed by Ivan Fraixedes
parent 08692aef90
commit 5ea82dfb2e
2 changed files with 11 additions and 6 deletions

View File

@ -65,7 +65,7 @@ func cmdDelete(cmd *cobra.Command, args []string) (err error) {
}()
csvReader := csv.NewReader(inputFile)
csvReader.FieldsPerRecord = 5
csvReader.FieldsPerRecord = 6
csvReader.ReuseRecord = true
segmentsDeleted := 0

View File

@ -43,6 +43,7 @@ func newObserver(db metainfo.PointerDB, w *csv.Writer, from, to *time.Time) (*ob
"Bucket",
"EncodedEncryptedPath",
"CreationDate",
"Size",
}
err := w.Write(headers)
if err != nil {
@ -270,7 +271,7 @@ func (obsvr *observer) printSegment(ctx context.Context, segmentIndex int, bucke
} else {
segmentIndexStr = "s" + strconv.Itoa(segmentIndex)
}
creationDate, err := pointerCreationDate(ctx, obsvr.db, obsvr.lastProjectID, segmentIndexStr, bucket, path)
creationDate, size, err := pointerCreationDateAndSize(ctx, obsvr.db, obsvr.lastProjectID, segmentIndexStr, bucket, path)
if err != nil {
return err
}
@ -281,6 +282,7 @@ func (obsvr *observer) printSegment(ctx context.Context, segmentIndex int, bucke
bucket,
encodedPath,
creationDate,
strconv.FormatInt(size, 10),
})
if err != nil {
return err
@ -289,19 +291,22 @@ func (obsvr *observer) printSegment(ctx context.Context, segmentIndex int, bucke
return nil
}
func pointerCreationDate(ctx context.Context, db metainfo.PointerDB, projectID, segmentIndex, bucket, path string) (string, error) {
func pointerCreationDateAndSize(
ctx context.Context, db metainfo.PointerDB, projectID, segmentIndex, bucket, path string,
) (creationDate string, size int64, _ error) {
key := []byte(storj.JoinPaths(projectID, segmentIndex, bucket, path))
pointerBytes, err := db.Get(ctx, key)
if err != nil {
return "", err
return "", 0, err
}
pointer := &pb.Pointer{}
err = pb.Unmarshal(pointerBytes, pointer)
if err != nil {
return "", err
return "", 0, err
}
return pointer.CreationDate.Format(time.RFC3339Nano), nil
return pointer.CreationDate.Format(time.RFC3339Nano), pointer.SegmentSize, nil
}
func (obsvr *observer) resetZombieBuffer() {