Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
Signed-off-by: Yadong Ding <ding_yadong@foxmail.com>
  • Loading branch information
Desiki-high committed Aug 5, 2023
1 parent 5c6be5c commit ad02d1b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/content/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var (
bucketKeyObjectContent = []byte("content")
bucketKeyObjectBlob = []byte("blob")
bucketKeyObjectLeases = []byte("leases")
bucketKeyObjectLabels = []byte("labels")

bucketKeyVersion = []byte("v1")
bucketKeyNamespace = []byte(accelerationServiceNamespace)
Expand Down
23 changes: 22 additions & 1 deletion pkg/content/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func (content *Content) GC(ctx context.Context) error {
// cleanLeases use lease to manage content blob, delete lease of content which should be gc
func (content *Content) cleanLeases(ctx context.Context, size int64) error {
ls, err := content.lm.List(ctx)
fmt.Println(len(ls))
if err != nil {
return nil
}
Expand All @@ -136,6 +137,7 @@ func (content *Content) cleanLeases(ctx context.Context, size int64) error {
return err
}
size -= blobsize
fmt.Println(size)
return nil
}); err != nil {
return err
Expand All @@ -148,6 +150,7 @@ func (content *Content) cleanLeases(ctx context.Context, size int64) error {
}
}
ls, err = content.lm.List(ctx)
fmt.Println(len(ls))
if err != nil {
return nil
}
Expand Down Expand Up @@ -222,5 +225,23 @@ func (content *Content) Abort(ctx context.Context, ref string) error {
}

func (content *Content) Writer(ctx context.Context, opts ...content.WriterOpt) (content.Writer, error) {
return content.store.Writer(ctx, opts...)
writer, err := content.store.Writer(ctx, opts...)
if err := content.db.Update(func(tx *bolt.Tx) error {
bucket := getBlobsBucket(tx)
// if can't find blob bucket, it maens content store is empty
if bucket == nil {
return nil
}
return bucket.ForEach(func(key, value []byte) error {
if subBucket := bucket.Bucket(key); subBucket != nil {
if subBucket.Bucket(bucketKeyObjectLabels) != nil {
return subBucket.DeleteBucket(bucketKeyObjectLabels)
}
}
return nil
})
}); err != nil {
return nil, err
}
return writer, err
}

0 comments on commit ad02d1b

Please sign in to comment.