github.com/dolthub/dolt/go@v0.40.5-0.20240520175717-68db7794bea6/libraries/doltcore/sqle/statspro/interface.go (about)

     1  // Copyright 2024 Dolthub, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package statspro
    16  
    17  import (
    18  	"context"
    19  
    20  	"github.com/dolthub/go-mysql-server/sql"
    21  
    22  	"github.com/dolthub/dolt/go/libraries/doltcore/env"
    23  	"github.com/dolthub/dolt/go/libraries/doltcore/sqle"
    24  	"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess"
    25  	"github.com/dolthub/dolt/go/libraries/utils/filesys"
    26  	"github.com/dolthub/dolt/go/store/hash"
    27  )
    28  
    29  // Database is a backing store for a collection of DoltStats.
    30  // Each stats database tracks a user database, with multiple
    31  // branches potentially each having their own statistics.
    32  type Database interface {
    33  	// ListStatQuals returns the list of index statistics for a branch.
    34  	ListStatQuals(branch string) []sql.StatQualifier
    35  	// LoadBranchStats starts tracking a specific branch's statistics.
    36  	LoadBranchStats(ctx *sql.Context, branch string) error
    37  	// DeleteBranchStats removes references to in memory index statistics.
    38  	// If |flush| is true delete the data from storage.
    39  	DeleteBranchStats(ctx context.Context, branch string, flush bool) error
    40  	// GetStat returns a branch's index statistics.
    41  	GetStat(branch string, qual sql.StatQualifier) (*DoltStats, bool)
    42  	//SetStat bulk replaces the statistic, deleting any previous version
    43  	SetStat(ctx context.Context, branch string, qual sql.StatQualifier, stats *DoltStats) error
    44  	//DeleteStats deletes a list of index statistics.
    45  	DeleteStats(branch string, quals ...sql.StatQualifier)
    46  	// ReplaceChunks is an update interface that lets a stats implementation
    47  	// decide how to edit stats for a stats refresh.
    48  	ReplaceChunks(ctx context.Context, branch string, qual sql.StatQualifier, targetHashes []hash.Hash, dropChunks, newChunks []sql.HistogramBucket) error
    49  	// Flush instructs the database to sync any partial state to disk
    50  	Flush(ctx context.Context, branch string) error
    51  	// Close finalizes any file references.
    52  	Close() error
    53  
    54  	SetLatestHash(branch, tableName string, h hash.Hash)
    55  	GetLatestHash(branch, tableName string) hash.Hash
    56  }
    57  
    58  // StatsFactory instances construct statistic databases.
    59  type StatsFactory interface {
    60  	// Init gets a reference to the stats database for a dolt database
    61  	// rooted at the given filesystem. It will create the database if
    62  	// it does not exist.
    63  	Init(ctx *sql.Context, sourceDb dsess.SqlDatabase, prov *sqle.DoltDatabaseProvider, fs filesys.Filesys, hdp env.HomeDirProvider) (Database, error)
    64  }