utils

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

utils

通用工具,包含 pool.go 的任务池和 durable.go 的本地持久化辅助函数, 可独立用于其他 Go 程序,仅依赖标准库。

导入路径:github.com/lfhy/compactfs/utils。

进程内有界任务池,供文件读写调度使用,只依赖 Go 标准库。独立算法进程由 codec/worker 管理。

  • NewPool(ctx, workers, queue) 创建固定并发数、有限队列容量的任务池。
  • SubmitContext 支持取消入队等待,已接收任务的所有权仍由池管理。
  • Wait 停止接收新任务并等待完成;Close 先取消任务上下文再等待。
  • 首个任务错误会取消池上下文,后续已入队任务仍会执行以释放资源。任务需要 处理取消并完成自己持有的缓冲区或其他资源的清理。
import "github.com/lfhy/compactfs/utils"

pool, err := utils.NewPool(ctx, 8, 128)
if err != nil {
    return err
}
defer pool.Close()
if err := pool.SubmitContext(ctx, func(jobCtx context.Context) error {
    return persist(jobCtx)
}); err != nil {
    return err
}
return pool.Wait()

本地持久化函数:

  • MkdirAll(path, mode):创建缺失目录,并同步新目录及第一个已有父目录, 保证完整目录链的目录项得到持久化。
  • SyncDir(path):同步目录项,供创建文件或原子重命名后建立持久化边界。

backend、元数据日志和原始写回缓存共享这两项工具;函数保留原有目录同步语义。

Documentation

Overview

Package utils provides reusable utilities independent of compactfs storage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MkdirAll

func MkdirAll(name string, mode os.FileMode) error

MkdirAll creates a directory tree and syncs every new directory plus the first existing ancestor. Syncing a data file alone cannot persist the links of newly created parent directories.

func SyncDir

func SyncDir(name string) error

SyncDir persists directory entries after creation or atomic rename.

Types

type Job

type Job func(context.Context) error

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

func NewPool

func NewPool(parent context.Context, workers, queue int) (*Pool, error)

func (*Pool) Close

func (p *Pool) Close() error

func (*Pool) Submit

func (p *Pool) Submit(job Job) error

func (*Pool) SubmitContext

func (p *Pool) SubmitContext(ctx context.Context, job Job) error

SubmitContext cancels queue admission without canceling jobs already owned by the pool. Local writeback must be able to cancel capacity backpressure.

func (*Pool) Wait

func (p *Pool) Wait() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL