core

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyFile

func CopyFile(src, dst string, perm os.FileMode) error

CopyFile copies the contents from src to dst atomically. If dst does not exist, CopyFile creates it with permissions perm. If the copy fails, CopyFile aborts and dst is preserved.

func Evict

func Evict(filePath string) (err error)

func Fallocate

func Fallocate(fd int, size int64) error

func GetBoolProperty

func GetBoolProperty(properties Properties, key string, defaultValue bool) bool

func GetDurationProperty

func GetDurationProperty(properties Properties, key string, defaultValue time.Duration) time.Duration

func GetFloat64Property

func GetFloat64Property(properties Properties, key string, defaultValue float64) float64

func GetIntProperty

func GetIntProperty(properties Properties, key string, defaultValue int) int

func GetSortedTimeStamps

func GetSortedTimeStamps(destinationFolder string, prefix string, storageHandler StorageHandler) ([]int64, error)

func GetStringProperty

func GetStringProperty(properties Properties, key string, defaultValue string) string

func HasProperty

func HasProperty(properties Properties, key string) bool

func ListFetchedFiles

func ListFetchedFiles(destinationFolder string, basename string, timestamp string, storageHandler StorageHandler) []string

func ListTempFetchedFiles

func ListTempFetchedFiles(destinationFolder string, basename string, storageHandler StorageHandler) []string

func MMapOptions

func MMapOptions() int

func MemoryUnMapAndEvictFile

func MemoryUnMapAndEvictFile(mmapInfo *MMapInfo)

func RemoveLastDownloadedFilesAfterError

func RemoveLastDownloadedFilesAfterError(destinationFolder string, basename string, timestamp string, storageHandler StorageHandler) error

func RemoveOldFiles

func RemoveOldFiles(destinationFolder string, basename string, numRetainedDownloads int, callback func(string), storageHandler StorageHandler) error

func SerializeProperties

func SerializeProperties(properties Properties) string

func UpdateProperties

func UpdateProperties(properties Properties, arg string) error

func WriteDecompressedFileToDiskFromReader

func WriteDecompressedFileToDiskFromReader(f io.Reader, compressedPath string, compressionMethod string, checksumExtension string, remoteCksum string, uncompressedSize int64, extraWriter ExtraWriter, progressBarLabel string) (string, int64, error)

func WritePropertiesFile

func WritePropertiesFile(properties Properties, path string) error

func WriteStringToFile

func WriteStringToFile(path string, text string) error

Types

type CoreDownloader

type CoreDownloader interface {
	Get(url string) (*http.Response, error)
}

func MakeHttpClient

func MakeHttpClient(downloaderOptions *DownloaderOptions, baseUrls []string, useTimeout bool) (CoreDownloader, error)

type DevNullWriter

type DevNullWriter struct {
}

func (*DevNullWriter) GetTotalRows

func (d *DevNullWriter) GetTotalRows() int

func (*DevNullWriter) Write

func (d *DevNullWriter) Write(p []byte) (int, error)

type DownloadError

type DownloadError struct {
	Url string
	Err error
}

func (*DownloadError) Error

func (e *DownloadError) Error() string

type DownloadReason

type DownloadReason int

The String() function below needs to be updated when adding entries

const (
	UpToDate                      DownloadReason = iota // 0
	NoTimestamp                                         // 1
	MissingLatestTimestamp                              // 2
	MissingRemoteInputs                                 // 3
	MissingLocalInputs                                  // 4
	EmptyRemoteInputs                                   // 5
	EmptyLocalInputs                                    // 6
	SimilarRemoteAndLocalInputs                         // 7
	DifferentRemoteAndLocalInputs                       // 8
	NotEnoughFiles                                      // 9
)

func (DownloadReason) String

func (reason DownloadReason) String() string

type DownloadStats

type DownloadStats struct {
	Timestamp               string  `json:"timestamp"`
	Delay                   string  `json:"delay"`
	DownloadMethod          string  `json:"download_method"`
	Prefetch                string  `json:"pre_fetch"`
	Download                string  `json:"download"`
	DownloadSeconds         float64 `json:"download_seconds"`
	DownloadSpeed           string  `json:"download_speed"`
	DiskWrite               string  `json:"decompress_checksum_disk_write"`
	DiskWriteSeconds        float64 `json:"decompress_checksum_disk_write_seconds"`
	MMap                    string  `json:"mmap"`
	MMapSeconds             float64 `json:"mmap_seconds"`
	Total                   string  `json:"total"`
	TotalSeconds            float64 `json:"total_seconds"`
	CompressedSize          string  `json:"compressed_size"`
	CompressedPath          string  `json:"compressed_path"`
	DecompressedSize        string  `json:"decompressed_size"`
	DecompressedSizeInBytes int64   `json:"decompressed_size_bytes"`
	DecompressedPath        string  `json:"decompressed_path"`
	BaseUrl                 string  `json:"base_url"`
	TotalBytesDownloaded    int64   `json:"total_bytes_downloaded"`
	TotalBytesWrittenToDisk int64   `json:"total_bytes_written_to_disk"`
	TotalRows               int     `json:"total_rows"`

	SavedFiles []string `json:"saved_files"`
}

type Downloader

type Downloader struct {
	Basename          string
	BasenameNoExt     string
	DestinationFolder string
	AllUrls           string
	DownloadMethod    string
	Log               *logrus.Entry
	MMapInfo          *MMapInfo
	RemoteSettings    RemoteSettings

	// Clients used to be *http.Client before GCS support
	HttpClient          CoreDownloader
	HttpClientNoTimeout CoreDownloader

	// Bail out after a certain amount of time.
	NoProgressTimeout int

	DefaultCompressionMethod string
	DefaultChecksumExtension string

	// Memory map a file after download, so that it is ready and fully loaded in memory for
	// servers to utilize it right away. We do this in process with ccache V2, so this is only
	// enabled for ccache V1 files
	MMapFileAfterDownload bool
}

func NewDownloader

func NewDownloader(downloaderOptions *DownloaderOptions) *Downloader

func (*Downloader) DownloadFile

func (d *Downloader) DownloadFile(filepath string, url string) error

DownloadFile will download a url to a local file. It's efficient because it will write as it downloads and not load the whole file into memory. We pass an io.TeeReader into Copy() to report progress on the download.

func (*Downloader) GetBaseUrlAndTimestamp

func (d *Downloader) GetBaseUrlAndTimestamp() (string, string, error)

func (*Downloader) Run

func (d *Downloader) Run() (DownloadStats, error)

type DownloaderOptions

type DownloaderOptions struct {
	Basename          string
	DestinationFolder string
	AllUrls           string
	Timeout           time.Duration
}

type ExtraWriter

type ExtraWriter interface {
	Write(p []byte) (int, error)
	GetTotalRows() int
}

type GCSClient

type GCSClient struct {
	Client     *storage.Client
	BucketName string
}

func NewGCSClient

func NewGCSClient(bucketName string) (*GCSClient, error)

func (*GCSClient) CopyFile

func (c *GCSClient) CopyFile(src, dst string, perm os.FileMode) error

func (*GCSClient) Get

func (c *GCSClient) Get(url string) (*http.Response, error)

We implement the HTTP GET interface to retrieve an object using the GCS APIs

func (*GCSClient) Glob

func (c *GCSClient) Glob(pattern string) ([]string, error)

func (*GCSClient) Remove

func (c *GCSClient) Remove(file string) error

type GCSStorageHandler

type GCSStorageHandler struct {
	BucketName string
	Client     *GCSClient
}

GCS

func (*GCSStorageHandler) CopyFile

func (g *GCSStorageHandler) CopyFile(src, dst string, perm os.FileMode) error

func (*GCSStorageHandler) Glob

func (g *GCSStorageHandler) Glob(pattern string) ([]string, error)

func (*GCSStorageHandler) Remove

func (g *GCSStorageHandler) Remove(file string) error

type InsertCounter

type InsertCounter struct {
	Label     string
	Start     time.Time
	Total     int64
	LastTotal int64
	Mutex     sync.Mutex
}

func (*InsertCounter) Incr

func (ic *InsertCounter) Incr()

func (*InsertCounter) SetLabel

func (ic *InsertCounter) SetLabel(label string)

type LocalFStorageHandler

type LocalFStorageHandler struct {
}

Local filesystem

func (*LocalFStorageHandler) CopyFile

func (l *LocalFStorageHandler) CopyFile(src, dst string, perm os.FileMode) error

func (*LocalFStorageHandler) Glob

func (l *LocalFStorageHandler) Glob(pattern string) ([]string, error)

func (*LocalFStorageHandler) Remove

func (l *LocalFStorageHandler) Remove(file string) error

type MMapInfo

type MMapInfo struct {
	ByteRange []byte
	Path      string
}

func MemoryMapFile

func MemoryMapFile(path string) (*MMapInfo, error)

func (*MMapInfo) Prefetch

func (m *MMapInfo) Prefetch(fd int) error

type Properties

type Properties = map[string]string

func LoadPropertiesFile

func LoadPropertiesFile(path string) (Properties, error)

type RemoteSettings

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

type StorageHandler

type StorageHandler interface {
	// Need to copy files over
	CopyFile(src, dst string, perm os.FileMode) error

	// Need to do directory listing remotely
	Glob(pattern string) ([]string, error)

	// So that we can remove some files (typically the old ones)
	Remove(file string) error
}

Those are the basic operations that are needed to manage files pushed to GCS (or a mirror).

func MakeStorageHandler

func MakeStorageHandler(path string) StorageHandler

Utility code to make a storage handler

type WriteCounter

type WriteCounter struct {
	Label         string
	Total         uint64
	ContentLength int64
	Name          string
	Start         time.Time
	LastTotal     uint64
}

WriteCounter counts the number of bytes written to it. It implements to the io.Writer interface and we can pass this into io.TeeReader() which will report progress on each write cycle.

func (*WriteCounter) Write

func (wc *WriteCounter) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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