ytdlp
This commit is contained in:
parent
0d7aac068c
commit
974814c281
20 changed files with 1532 additions and 716 deletions
src/export/nfs
|
@ -9,6 +9,8 @@ import (
|
|||
|
||||
"git.kmsign.ru/royalcat/tstor/pkg/go-nfs"
|
||||
"git.kmsign.ru/royalcat/tstor/src/config"
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/royalcat/kv"
|
||||
|
@ -40,6 +42,8 @@ func bytesToPath(path []string) string {
|
|||
return strings.Join(path, sep)
|
||||
}
|
||||
|
||||
var kvhandlerMeter = otel.Meter("git.kmsign.ru/royalcat/tstor/src/export/nfs.kvhandler")
|
||||
|
||||
// NewKvHandler provides a basic to/from-file handle cache that can be tuned with a smaller cache of active directory listings.
|
||||
func NewKvHandler(h nfs.Handler, fs nfs.Filesystem) (nfs.Handler, error) {
|
||||
activeHandles, err := kv.NewBadgerKVMarhsler[uuid.UUID, handle](path.Join(config.Config.Mounts.NFS.CachePath, "handlers"))
|
||||
|
@ -54,12 +58,24 @@ func NewKvHandler(h nfs.Handler, fs nfs.Filesystem) (nfs.Handler, error) {
|
|||
return true
|
||||
})
|
||||
|
||||
return &CachingHandler{
|
||||
c := &CachingHandler{
|
||||
Handler: h,
|
||||
fs: fs,
|
||||
activeHandles: activeHandles,
|
||||
reverseCache: reverseCache,
|
||||
}, nil
|
||||
}
|
||||
|
||||
_, err = kvhandlerMeter.Int64ObservableGauge("nfs.activehandles",
|
||||
metric.WithInt64Callback(func(ctx context.Context, io metric.Int64Observer) error {
|
||||
io.Observe(int64(c.ActiveHandlers()))
|
||||
return nil
|
||||
}),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// CachingHandler implements to/from handle via an LRU cache.
|
||||
|
@ -135,11 +151,20 @@ func (c *CachingHandler) InvalidateHandle(fs nfs.Filesystem, handle []byte) erro
|
|||
return c.activeHandles.Delete(ctx, id)
|
||||
}
|
||||
|
||||
const maxInt = int(^uint(0) >> 1)
|
||||
// const maxInt = int(^uint(0) >> 1)
|
||||
const maxHandlers = 8129
|
||||
|
||||
// HandleLimit exports how many file handles can be safely stored by this cache.
|
||||
func (c *CachingHandler) HandleLimit() int {
|
||||
return maxInt
|
||||
return maxHandlers
|
||||
}
|
||||
|
||||
// HandleLimit exports how many file handles can be safely stored by this cache.
|
||||
func (c *CachingHandler) ActiveHandlers() int {
|
||||
c.mu.RLock()
|
||||
defer c.mu.RUnlock()
|
||||
|
||||
return len(c.reverseCache)
|
||||
}
|
||||
|
||||
// func hasPrefix(path, prefix []string) bool {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue