dsess

package
v0.40.4 Latest Latest
Warning

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

Go to latest
Published: May 19, 2022 License: Apache-2.0 Imports: 23 Imported by: 3

Documentation

Index

Constants

View Source
const (
	HeadKeySuffix          = "_head"
	HeadRefKeySuffix       = "_head_ref"
	WorkingKeySuffix       = "_working"
	StagedKeySuffix        = "_staged"
	DefaultBranchKeySuffix = "_default_branch"
)
View Source
const (
	DoltCommitOnTransactionCommit = "dolt_transaction_commit"
	TransactionsDisabledSysVar    = "dolt_transactions_disabled"
	ForceTransactionCommit        = "dolt_force_transaction_commit"
	CurrentBatchModeKey           = "batch_mode"
	AllowCommitConflicts          = "dolt_allow_commit_conflicts"
)
View Source
const (
	Batched batchMode
)
View Source
const TransactionMergeStompEnvKey = "DOLT_TRANSACTION_MERGE_STOMP"

Variables

View Source
var ErrRetryTransaction = errors.New("this transaction conflicts with a committed transaction from another client, please retry")
View Source
var ErrSessionNotPeristable = errors.New("session is not persistable")
View Source
var ErrUnresolvedConflictsCommit = errors.New("Merge conflict detected, transaction rolled back. Merge conflicts must be resolved using the dolt_conflicts tables before committing a transaction. To commit transactions with merge conflicts, set @@dolt_allow_commit_conflicts = 1")
View Source
var ErrUnresolvedConstraintViolationsCommit = errors.New("Constraint violation from merge detected, cannot commit transaction. Constraint violations from a merge must be resolved using the dolt_constraint_violations table before committing a transaction. To commit transactions with constraint violations set @@dolt_force_transaction_commit=1")
View Source
var ErrWorkingSetChanges = goerrors.NewKind("Cannot switch working set, session state is dirty. " +
	"Rollback or commit changes before changing working sets.")

Functions

func DefaultBranchKey

func DefaultBranchKey(dbName string) string

func HeadKey

func HeadKey(dbName string) string

func HeadRefKey

func HeadRefKey(dbName string) string

func InitPersistedSystemVars

func InitPersistedSystemVars(dEnv *env.DoltEnv) error

func IsDefaultBranchKey

func IsDefaultBranchKey(key string) (bool, string)

func IsHeadKey

func IsHeadKey(key string) (bool, string)

func IsHeadRefKey

func IsHeadRefKey(key string) (bool, string)

func IsReadOnlyVersionKey

func IsReadOnlyVersionKey(key string) bool

func IsWorkingKey

func IsWorkingKey(key string) (bool, string)

func StagedKey

func StagedKey(dbName string) string

func SystemVariablesInConfig

func SystemVariablesInConfig(conf config.ReadableConfig) ([]sql.SystemVariable, error)

SystemVariablesInConfig returns system variables from the persisted config

func TransactionsDisabled

func TransactionsDisabled(ctx *sql.Context) bool

func WorkingKey

func WorkingKey(dbName string) string

Types

type DatabaseSessionState

type DatabaseSessionState struct {
	WorkingSet *doltdb.WorkingSet

	WriteSession writer.WriteSession

	// Same as InitialDbState.Err, this signifies that this
	// DatabaseSessionState is invalid. LookupDbState returning a
	// DatabaseSessionState with Err != nil will return that err.
	Err error
	// contains filtered or unexported fields
}

func (DatabaseSessionState) EditOpts

func (d DatabaseSessionState) EditOpts() editor.Options

func (DatabaseSessionState) GetRoots

func (d DatabaseSessionState) GetRoots() doltdb.Roots

type DisabledTransaction

type DisabledTransaction struct{}

DisabledTransaction is a no-op transaction type that lets us feature-gate transaction logic changes

func (DisabledTransaction) IsReadOnly

func (d DisabledTransaction) IsReadOnly() bool

func (DisabledTransaction) String

func (d DisabledTransaction) String() string

type DoltSession

type DoltSession struct {
	*Session
	// contains filtered or unexported fields
}

func DSessFromSess

func DSessFromSess(sess sql.Session) *DoltSession

DSessFromSess retrieves a dolt session from a standard sql.Session

func NewDoltSession

func NewDoltSession(ctx *sql.Context, sqlSess *sql.BaseSession, pro RevisionDatabaseProvider, conf config.ReadWriteConfig, dbs ...InitialDbState) (*DoltSession, error)

NewDoltSession creates a DoltSession object from a standard sql.Session and 0 or more Database objects.

func (*DoltSession) GetPersistedValue

func (s *DoltSession) GetPersistedValue(k string) (interface{}, error)

RemoveAllPersistedGlobals implements sql.PersistableSession

func (*DoltSession) PersistGlobal

func (s *DoltSession) PersistGlobal(sysVarName string, value interface{}) error

PersistGlobal implements sql.PersistableSession

func (*DoltSession) RemoveAllPersistedGlobals

func (s *DoltSession) RemoveAllPersistedGlobals() error

RemoveAllPersistedGlobals implements sql.PersistableSession

func (*DoltSession) RemovePersistedGlobal

func (s *DoltSession) RemovePersistedGlobal(sysVarName string) error

RemovePersistedGlobal implements sql.PersistableSession

func (*DoltSession) SystemVariablesInConfig

func (s *DoltSession) SystemVariablesInConfig() ([]sql.SystemVariable, error)

SystemVariablesInConfig returns a list of System Variables associated with the session

type DoltTransaction

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

func NewDoltTransaction

func NewDoltTransaction(
	dbName string,
	startState *doltdb.WorkingSet,
	workingSet ref.WorkingSetRef,
	dbData env.DbData,
	mergeEditOpts editor.Options,
	tCharacteristic sql.TransactionCharacteristic,
) *DoltTransaction

func (*DoltTransaction) ClearSavepoint

func (tx *DoltTransaction) ClearSavepoint(name string) *doltdb.RootValue

ClearSavepoint removes the savepoint with the name given and returns the root value recorded there, or nil if no savepoint exists with that name.

func (*DoltTransaction) Commit

func (tx *DoltTransaction) Commit(ctx *sql.Context, workingSet *doltdb.WorkingSet) (*doltdb.WorkingSet, error)

Commit attempts to merge the working set given into the current working set. Uses the same algorithm as merge.Merger: |current working set working root| is the root |workingSet.workingRoot| is the mergeRoot |tx.startRoot| is ancRoot if workingSet.workingRoot == ancRoot, attempt a fast-forward merge TODO: Non-working roots aren't merged into the working set and just stomp any changes made there. We need merge

strategies for staged as well as merge state.

func (*DoltTransaction) CreateSavepoint

func (tx *DoltTransaction) CreateSavepoint(name string, root *doltdb.RootValue)

CreateSavepoint creates a new savepoint with the name and root value given. If a savepoint with the name given already exists, it's overwritten.

func (*DoltTransaction) DoltCommit

func (tx *DoltTransaction) DoltCommit(ctx *sql.Context, workingSet *doltdb.WorkingSet, commit *doltdb.PendingCommit) (*doltdb.WorkingSet, *doltdb.Commit, error)

DoltCommit commits the working set and creates a new DoltCommit as specified, in one atomic write

func (DoltTransaction) IsReadOnly

func (tx DoltTransaction) IsReadOnly() bool

func (*DoltTransaction) RollbackToSavepoint

func (tx *DoltTransaction) RollbackToSavepoint(name string) *doltdb.RootValue

RollbackToSavepoint returns the root value associated with the savepoint name given, or nil if no such savepoint can be found. All savepoints created after the one being rolled back to are no longer accessible.

func (DoltTransaction) String

func (tx DoltTransaction) String() string

type InitialDbState

type InitialDbState struct {
	Db          sql.Database
	HeadCommit  *doltdb.Commit
	ReadOnly    bool
	WorkingSet  *doltdb.WorkingSet
	DbData      env.DbData
	ReadReplica *env.Remote
	Remotes     map[string]env.Remote
	Branches    map[string]env.BranchConfig
	Backups     map[string]env.Remote

	// If err is set, this InitialDbState is partially invalid, but may be
	// usable to initialize a database at a revision specifier, for
	// example. Adding this InitialDbState to a session will return this
	// error.
	Err error
}

type RevisionDatabaseProvider

type RevisionDatabaseProvider interface {
	// RevisionDbState provides the InitialDbState for a revision database.
	RevisionDbState(ctx context.Context, revDB string) (InitialDbState, error)
}

RevisionDatabaseProvider provides revision databases. In Dolt, commits and branches can be accessed as discrete databases using a Dolt-specific syntax: `my_database/my_branch`. Revision databases corresponding to historical commits in the repository will be read-only databases. Revision databases for branches will be read/write.

func EmptyDatabaseProvider

func EmptyDatabaseProvider() RevisionDatabaseProvider

type Session

type Session struct {
	sql.Session
	// contains filtered or unexported fields
}

Session is the sql.Session implementation used by dolt. It is accessible through a *sql.Context instance

func DefaultSession

func DefaultSession() *Session

DefaultSession creates a Session object with default values

func NewSession

func NewSession(ctx *sql.Context, sqlSess *sql.BaseSession, pro RevisionDatabaseProvider, conf config.ReadableConfig, dbs ...InitialDbState) (*Session, error)

NewSession creates a Session object from a standard sql.Session and 0 or more Database objects.

func (*Session) AddDB

func (sess *Session) AddDB(ctx *sql.Context, dbState InitialDbState) error

AddDB adds the database given to this session. This establishes a starting root value for this session, as well as other state tracking metadata.

func (*Session) AddTemporaryTable

func (sess *Session) AddTemporaryTable(ctx *sql.Context, db string, tbl sql.Table)

func (*Session) BatchMode

func (sess *Session) BatchMode() batchMode

func (*Session) CWBHeadRef

func (sess *Session) CWBHeadRef(ctx *sql.Context, dbName string) (ref.DoltRef, error)

CWBHeadRef returns the branch ref for this session HEAD for the database named

func (*Session) CommitTransaction

func (sess *Session) CommitTransaction(ctx *sql.Context, dbName string, tx sql.Transaction) error

CommitTransaction commits the in-progress transaction for the database named. Depending on session settings, this may write only a new working set, or may additionally create a new dolt commit for the current HEAD.

func (*Session) CommitWorkingSet

func (sess *Session) CommitWorkingSet(ctx *sql.Context, dbName string, tx sql.Transaction) error

CommitWorkingSet commits the working set for the transaction given, without creating a new dolt commit. Clients should typically use CommitTransaction, which performs additional checks, instead of this method.

func (*Session) CreateSavepoint

func (sess *Session) CreateSavepoint(ctx *sql.Context, savepointName, dbName string, tx sql.Transaction) error

CreateSavepoint creates a new savepoint for this transaction with the name given. A previously created savepoint with the same name will be overwritten.

func (*Session) DoltCommit

func (sess *Session) DoltCommit(
	ctx *sql.Context,
	dbName string,
	tx sql.Transaction,
	commit *doltdb.PendingCommit,
) (*doltdb.Commit, error)

DoltCommit commits the working set and a new dolt commit with the properties given. Clients should typically use CommitTransaction, which performs additional checks, instead of this method.

func (*Session) DropTemporaryTable

func (sess *Session) DropTemporaryTable(ctx *sql.Context, db, name string)

func (*Session) Email

func (sess *Session) Email() string

func (*Session) EnableBatchedMode

func (sess *Session) EnableBatchedMode()

EnableBatchedMode enables batched mode for this session. This is only safe to do during initialization. Sessions operating in batched mode don't flush any edit buffers except when told to do so explicitly, or when a transaction commits. Disable @@autocommit to prevent edit buffers from being flushed prematurely in this mode.

func (*Session) Flush

func (sess *Session) Flush(ctx *sql.Context, dbName string) error

Flush flushes all changes sitting in edit sessions to the session root for the database named. This normally happens automatically as part of statement execution, and is only necessary when the session is manually batched (as for bulk SQL import)

func (*Session) GetAllTemporaryTables

func (sess *Session) GetAllTemporaryTables(ctx *sql.Context, db string) ([]sql.Table, error)

GetAllTemporaryTables returns all temp tables for this session.

func (*Session) GetDbData

func (sess *Session) GetDbData(ctx *sql.Context, dbName string) (env.DbData, bool)

func (*Session) GetDbStates

func (sess *Session) GetDbStates() map[string]*DatabaseSessionState

func (*Session) GetDoltDB

func (sess *Session) GetDoltDB(ctx *sql.Context, dbName string) (*doltdb.DoltDB, bool)

GetDoltDB returns the *DoltDB for a given database by name

func (*Session) GetHeadCommit

func (sess *Session) GetHeadCommit(ctx *sql.Context, dbName string) (*doltdb.Commit, error)

GetHeadCommit returns the parent commit of the current session.

func (*Session) GetRoots

func (sess *Session) GetRoots(ctx *sql.Context, dbName string) (doltdb.Roots, bool)

GetRoots returns the current roots for a given database associated with the session

func (*Session) GetTemporaryTable

func (sess *Session) GetTemporaryTable(ctx *sql.Context, db, name string) (sql.Table, bool)

func (*Session) HasDB

func (sess *Session) HasDB(ctx *sql.Context, dbName string) bool

HasDB returns true if |sess| is tracking state for this database.

func (*Session) LookupDbState

func (sess *Session) LookupDbState(ctx *sql.Context, dbName string) (*DatabaseSessionState, bool, error)

func (*Session) NewDoltSession

func (sess *Session) NewDoltSession(conf config.ReadWriteConfig) *DoltSession

NewDoltSession creates a persistable DoltSession with the given config arg

func (*Session) NewPendingCommit

func (sess *Session) NewPendingCommit(ctx *sql.Context, dbName string, roots doltdb.Roots, props actions.CommitStagedProps) (*doltdb.PendingCommit, error)

NewPendingCommit returns a new |doltdb.PendingCommit| for the database named, using the roots given, adding any merge parent from an in progress merge as appropriate. The session working set is not updated with these new roots, but they are set in the returned |doltdb.PendingCommit|. If there are no changes staged, this method returns nil.

func (*Session) PendingCommitAllStaged

func (sess *Session) PendingCommitAllStaged(ctx *sql.Context, dbName string, props actions.CommitStagedProps) (*doltdb.PendingCommit, error)

PendingCommitAllStaged returns a pending commit with all tables staged. Returns nil if there are no changes to stage.

func (*Session) ReleaseSavepoint

func (sess *Session) ReleaseSavepoint(ctx *sql.Context, savepointName, dbName string, tx sql.Transaction) error

ReleaseSavepoint removes the savepoint name from the transaction. It's an error if no savepoint with that name exists.

func (*Session) RollbackToSavepoint

func (sess *Session) RollbackToSavepoint(ctx *sql.Context, savepointName, dbName string, tx sql.Transaction) error

RollbackToSavepoint sets this session's root to the one saved in the savepoint name. It's an error if no savepoint with that name exists.

func (*Session) RollbackTransaction

func (sess *Session) RollbackTransaction(ctx *sql.Context, dbName string, tx sql.Transaction) error

RollbackTransaction rolls the given transaction back

func (*Session) SetRoot

func (sess *Session) SetRoot(ctx *sql.Context, dbName string, newRoot *doltdb.RootValue) error

SetRoot sets a new root value for the session for the database named. This is the primary mechanism by which data changes are communicated to the engine and persisted back to disk. All data changes should be followed by a call to update the session's root value via this method. Data changes contained in the |newRoot| aren't persisted until this session is committed. TODO: rename to SetWorkingRoot

func (*Session) SetRoots

func (sess *Session) SetRoots(ctx *sql.Context, dbName string, roots doltdb.Roots) error

SetRoots sets new roots for the session for the database named. Typically clients should only set the working root, via setRoot. This method is for clients that need to update more of the session state, such as the dolt_ functions. Unlike setting the only the working root, this method always marks the database state dirty.

func (*Session) SetSessionVariable

func (sess *Session) SetSessionVariable(ctx *sql.Context, key string, value interface{}) error

SetSessionVariable is defined on sql.Session. We intercept it here to interpret the special semantics of the system vars that we define. Otherwise we pass it on to the base implementation.

func (*Session) SetWorkingSet

func (sess *Session) SetWorkingSet(ctx *sql.Context, dbName string, ws *doltdb.WorkingSet) error

SetWorkingSet sets the working set for this session. Unlike setting the working root alone, this method always marks the session dirty.

func (*Session) StartTransaction

func (sess *Session) StartTransaction(ctx *sql.Context, dbName string, tCharacteristic sql.TransactionCharacteristic) (sql.Transaction, error)

StartTransaction refreshes the state of this session and starts a new transaction.

func (*Session) SwitchWorkingSet

func (sess *Session) SwitchWorkingSet(
	ctx *sql.Context,
	dbName string,
	wsRef ref.WorkingSetRef,
) error

SwitchWorkingSet switches to a new working set for this session. Unlike SetWorkingSet, this method expresses no intention to eventually persist any uncommitted changes. Rather, this method only changes the in memory state of this session. It's equivalent to starting a new session with the working set reference provided. If the current session is dirty, this method returns an error. Clients can only switch branches with a clean working set, and so must either commit or rollback any changes before attempting to switch working sets.

func (*Session) Username

func (sess *Session) Username() string

func (*Session) WorkingSet

func (sess *Session) WorkingSet(ctx *sql.Context, dbName string) (*doltdb.WorkingSet, error)

type SessionStateAdapter

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

SessionStateAdapter is an adapter for env.RepoStateReader in SQL contexts, getting information about the repo state from the session.

func NewSessionStateAdapter

func NewSessionStateAdapter(session *Session, dbName string, remotes map[string]env.Remote, branches map[string]env.BranchConfig, backups map[string]env.Remote) SessionStateAdapter

func (SessionStateAdapter) AbortMerge

func (s SessionStateAdapter) AbortMerge(ctx context.Context) error

func (SessionStateAdapter) AddBackup

func (s SessionStateAdapter) AddBackup(name string, url string, fetchSpecs []string, params map[string]string) error

func (SessionStateAdapter) AddRemote

func (s SessionStateAdapter) AddRemote(name string, url string, fetchSpecs []string, params map[string]string) error

func (SessionStateAdapter) CWBHeadRef

func (s SessionStateAdapter) CWBHeadRef() ref.DoltRef

func (SessionStateAdapter) CWBHeadSpec

func (s SessionStateAdapter) CWBHeadSpec() *doltdb.CommitSpec

func (SessionStateAdapter) ClearMerge

func (s SessionStateAdapter) ClearMerge(ctx context.Context) error

func (SessionStateAdapter) GetBackups

func (s SessionStateAdapter) GetBackups() (map[string]env.Remote, error)

func (SessionStateAdapter) GetBranches

func (s SessionStateAdapter) GetBranches() (map[string]env.BranchConfig, error)

func (SessionStateAdapter) GetMergeCommit

func (s SessionStateAdapter) GetMergeCommit(ctx context.Context) (*doltdb.Commit, error)

func (SessionStateAdapter) GetPreMergeWorking

func (s SessionStateAdapter) GetPreMergeWorking(ctx context.Context) (*doltdb.RootValue, error)

func (SessionStateAdapter) GetRemotes

func (s SessionStateAdapter) GetRemotes() (map[string]env.Remote, error)

func (SessionStateAdapter) GetRoots

func (s SessionStateAdapter) GetRoots(ctx context.Context) (doltdb.Roots, error)

func (SessionStateAdapter) IsMergeActive

func (s SessionStateAdapter) IsMergeActive(ctx context.Context) (bool, error)

func (SessionStateAdapter) RemoveBackup

func (s SessionStateAdapter) RemoveBackup(ctx context.Context, name string) error

func (SessionStateAdapter) RemoveRemote

func (s SessionStateAdapter) RemoveRemote(ctx context.Context, name string) error

func (SessionStateAdapter) SetCWBHeadRef

func (s SessionStateAdapter) SetCWBHeadRef(ctx context.Context, marshalableRef ref.MarshalableRef) error

func (SessionStateAdapter) StartMerge

func (s SessionStateAdapter) StartMerge(ctx context.Context, commit *doltdb.Commit) error

func (SessionStateAdapter) TempTableFilesDir

func (s SessionStateAdapter) TempTableFilesDir() string

func (SessionStateAdapter) UpdateBranch

func (s SessionStateAdapter) UpdateBranch(name string, new env.BranchConfig) error

func (SessionStateAdapter) UpdateStagedRoot

func (s SessionStateAdapter) UpdateStagedRoot(ctx context.Context, newRoot *doltdb.RootValue) error

func (SessionStateAdapter) UpdateWorkingRoot

func (s SessionStateAdapter) UpdateWorkingRoot(ctx context.Context, newRoot *doltdb.RootValue) error

Jump to

Keyboard shortcuts

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