@@ -16,6 +16,10 @@ import (
1616 redis "github.com/redis/go-redis/v9"
1717)
1818
19+ const (
20+ storeFromContentLockTtlS = 5
21+ )
22+
1923type BlobCacheMetadata struct {
2024 rdb * RedisClient
2125 lock * RedisLock
@@ -368,17 +372,30 @@ func (m *BlobCacheMetadata) RemoveFsNodeChild(ctx context.Context, id string) er
368372 return nil
369373}
370374
375+ func (m * BlobCacheMetadata ) SetStoreFromContentLock (ctx context.Context , sourcePath string ) error {
376+ return m .lock .Acquire (ctx , MetadataKeys .MetadataStoreFromContentLock (sourcePath ), RedisLockOptions {TtlS : storeFromContentLockTtlS , Retries : 0 })
377+ }
378+
379+ func (m * BlobCacheMetadata ) RefreshStoreFromContentLock (ctx context.Context , sourcePath string ) error {
380+ return m .lock .Refresh (MetadataKeys .MetadataStoreFromContentLock (sourcePath ), RedisLockOptions {TtlS : storeFromContentLockTtlS , Retries : 0 })
381+ }
382+
383+ func (m * BlobCacheMetadata ) RemoveStoreFromContentLock (ctx context.Context , sourcePath string ) error {
384+ return m .lock .Release (MetadataKeys .MetadataStoreFromContentLock (sourcePath ))
385+ }
386+
371387// Metadata key storage format
372388var (
373- metadataPrefix string = "blobcache"
374- metadataHostIndex string = "blobcache:host_index"
375- metadataEntry string = "blobcache:entry:%s"
376- metadataClientLock string = "blobcache:client_lock:%s:%s"
377- metadataLocation string = "blobcache:location:%s"
378- metadataRef string = "blobcache:ref:%s"
379- metadataFsNode string = "blobcache:fs:node:%s"
380- metadataFsNodeChildren string = "blobcache:fs:node:%s:children"
381- metadataHostKeepAlive string = "blobcache:host:keepalive:%s"
389+ metadataPrefix string = "blobcache"
390+ metadataHostIndex string = "blobcache:host_index"
391+ metadataEntry string = "blobcache:entry:%s"
392+ metadataClientLock string = "blobcache:client_lock:%s:%s"
393+ metadataLocation string = "blobcache:location:%s"
394+ metadataRef string = "blobcache:ref:%s"
395+ metadataFsNode string = "blobcache:fs:node:%s"
396+ metadataFsNodeChildren string = "blobcache:fs:node:%s:children"
397+ metadataHostKeepAlive string = "blobcache:host:keepalive:%s"
398+ metadataStoreFromContentLock string = "blobcache:store_from_content_lock:%s"
382399)
383400
384401// Metadata keys
@@ -418,6 +435,11 @@ func (k *metadataKeys) MetadataClientLock(hostname, hash string) string {
418435 return fmt .Sprintf (metadataClientLock , hostname , hash )
419436}
420437
438+ func (k * metadataKeys ) MetadataStoreFromContentLock (sourcePath string ) string {
439+ sourcePath = strings .ReplaceAll (sourcePath , "/" , "_" )
440+ return fmt .Sprintf (metadataStoreFromContentLock , sourcePath )
441+ }
442+
421443var MetadataKeys = & metadataKeys {}
422444
423445type metadataKeys struct {}
0 commit comments