Documentation
¶
Overview ¶
Package mongo implements database interfaces using MongoDB.
Index ¶
- Constants
- Variables
- func NewRegistryBuilder() *bson.Registry
- type ChangeRange
- type ChangeStore
- func (s *ChangeStore) ChangesInRange(from, to int64) []*database.ChangeInfo
- func (s *ChangeStore) EnsureChanges(from, to int64, fetcher func(from, to int64) ([]*database.ChangeInfo, error)) error
- func (s *ChangeStore) ExpandRange(r ChangeRange)
- func (s *ChangeStore) RemoveChangesByActor(actorID types.ID)
- func (s *ChangeStore) ReplaceOrInsert(changes []*database.ChangeInfo)
- type Client
- func (c *Client) ActivateClient(ctx context.Context, projectID types.ID, key string, ...) (*database.ClientInfo, error)
- func (c *Client) ChangeUserPassword(ctx context.Context, username, hashedNewPassword string) error
- func (c *Client) Close() error
- func (c *Client) CompactChangeInfos(ctx context.Context, docInfo *database.DocInfo, lastServerSeq int64, ...) error
- func (c *Client) CountActivatedClients(ctx context.Context, projectID types.ID) (int64, error)
- func (c *Client) CountAliveDocuments(ctx context.Context, projectID types.ID) (int64, error)
- func (c *Client) CreateChangeInfos(ctx context.Context, refKey types.DocRefKey, checkpoint change.Checkpoint, ...) (*database.DocInfo, change.Checkpoint, error)
- func (c *Client) CreateInviteInfo(ctx context.Context, projectID types.ID, token string, ...) (*database.InviteInfo, error)
- func (c *Client) CreateProjectInfo(ctx context.Context, name string, owner types.ID) (*database.ProjectInfo, error)
- func (c *Client) CreateRevisionInfo(ctx context.Context, docRefKey types.DocRefKey, label string, ...) (*database.RevisionInfo, error)
- func (c *Client) CreateSchemaInfo(ctx context.Context, projectID types.ID, name string, version int, body string, ...) (*database.SchemaInfo, error)
- func (c *Client) CreateSnapshotInfo(ctx context.Context, docRefKey types.DocRefKey, doc *document.InternalDocument) error
- func (c *Client) CreateUserInfo(ctx context.Context, username string, hashedPassword string) (*database.UserInfo, error)
- func (c *Client) DeactivateClient(ctx context.Context, refKey types.ClientRefKey) (*database.ClientInfo, error)
- func (c *Client) DeleteExpiredInviteInfos(ctx context.Context, now gotime.Time) (int64, error)
- func (c *Client) DeleteMemberInfo(ctx context.Context, projectID types.ID, userID types.ID) error
- func (c *Client) DeleteRevisionInfo(ctx context.Context, revisionID types.ID) error
- func (c *Client) DeleteUserInfoByName(ctx context.Context, username string) error
- func (c *Client) EnsureDefaultUserAndProject(ctx context.Context, username, password string) (*database.UserInfo, *database.ProjectInfo, error)
- func (c *Client) FindActiveClients(ctx context.Context, candidatesLimit int, lastClientID types.ID) ([]*database.ClientInfo, types.ID, error)
- func (c *Client) FindAttachedClientCountsByDocIDs(ctx context.Context, projectID types.ID, docIDs []types.ID) (map[types.ID]int, error)
- func (c *Client) FindAttachedClientInfosByRefKey(ctx context.Context, docRefKey types.DocRefKey) ([]*database.ClientInfo, error)
- func (c *Client) FindChangeInfosBetweenServerSeqs(ctx context.Context, docRefKey types.DocRefKey, from int64, to int64) ([]*database.ChangeInfo, error)
- func (c *Client) FindChangesBetweenServerSeqs(ctx context.Context, docRefKey types.DocRefKey, from int64, to int64) ([]*change.Change, error)
- func (c *Client) FindClientInfoByRefKey(ctx context.Context, refKey types.ClientRefKey, skipCache ...bool) (*database.ClientInfo, error)
- func (c *Client) FindClosestSnapshotInfo(ctx context.Context, docRefKey types.DocRefKey, serverSeq int64, ...) (*database.SnapshotInfo, error)
- func (c *Client) FindClusterNodes(ctx context.Context, window gotime.Duration) ([]*database.ClusterNodeInfo, error)
- func (c *Client) FindCompactionCandidates(ctx context.Context, candidatesLimit int, compactionMinChanges int, ...) ([]*database.DocInfo, int64, types.ID, error)
- func (c *Client) FindDocInfoByKey(ctx context.Context, projectID types.ID, docKey key.Key) (*database.DocInfo, error)
- func (c *Client) FindDocInfoByRefKey(ctx context.Context, refKey types.DocRefKey) (*database.DocInfo, error)
- func (c *Client) FindDocInfosByIDs(ctx context.Context, projectID types.ID, docIDs []types.ID) ([]*database.DocInfo, error)
- func (c *Client) FindDocInfosByKeys(ctx context.Context, projectID types.ID, docKeys []key.Key) ([]*database.DocInfo, error)
- func (c *Client) FindDocInfosByPaging(ctx context.Context, projectID types.ID, paging types.Paging[types.ID]) ([]*database.DocInfo, error)
- func (c *Client) FindDocInfosByQuery(ctx context.Context, projectID types.ID, query string, pageSize int) (*types.SearchResult[*database.DocInfo], error)
- func (c *Client) FindInviteInfoByToken(ctx context.Context, token string) (*database.InviteInfo, error)
- func (c *Client) FindLatestChangeInfoByActor(ctx context.Context, docRefKey types.DocRefKey, actorID types.ID, ...) (*database.ChangeInfo, error)
- func (c *Client) FindMemberInfo(ctx context.Context, projectID types.ID, userID types.ID) (*database.MemberInfo, error)
- func (c *Client) FindOrCreateDocInfo(ctx context.Context, clientRefKey types.ClientRefKey, docKey key.Key, ...) (*database.DocInfo, error)
- func (c *Client) FindProjectInfoByID(ctx context.Context, id types.ID) (*database.ProjectInfo, error)
- func (c *Client) FindProjectInfoByName(ctx context.Context, name string) (*database.ProjectInfo, error)
- func (c *Client) FindProjectInfoByPublicKey(ctx context.Context, publicKey string) (*database.ProjectInfo, error)
- func (c *Client) FindProjectInfoBySecretKey(ctx context.Context, secretKey string) (*database.ProjectInfo, error)
- func (c *Client) FindProjectInfosForRefresh(ctx context.Context, limit int, lastID types.ID) ([]*database.ProjectInfo, types.ID, error)
- func (c *Client) FindRevisionInfoByID(ctx context.Context, revisionID types.ID) (*database.RevisionInfo, error)
- func (c *Client) FindRevisionInfosByPaging(ctx context.Context, docRefKey types.DocRefKey, paging types.Paging[int], ...) ([]*database.RevisionInfo, error)
- func (c *Client) FindSnapshotInfo(ctx context.Context, docKey types.DocRefKey, serverSeq int64) (*database.SnapshotInfo, error)
- func (c *Client) FindUserInfoByID(ctx context.Context, userID types.ID) (*database.UserInfo, error)
- func (c *Client) FindUserInfoByName(ctx context.Context, username string) (*database.UserInfo, error)
- func (c *Client) GetMinVersionVector(ctx context.Context, docRefKey types.DocRefKey, vector time.VersionVector) (time.VersionVector, error)
- func (c *Client) GetOrCreateUserInfoByGitHubID(ctx context.Context, githubID string) (*database.UserInfo, error)
- func (c *Client) GetProjectStatsCounts(ctx context.Context, projectID types.ID) (*database.ProjectStatsCounts, error)
- func (c *Client) GetSchemaInfo(ctx context.Context, projectID types.ID, name string, version int) (*database.SchemaInfo, error)
- func (c *Client) GetSchemaInfos(ctx context.Context, projectID types.ID, name string) ([]*database.SchemaInfo, error)
- func (c *Client) InvalidateCache(cacheType types.CacheType, key string)
- func (c *Client) IsDocumentAttachedOrAttaching(ctx context.Context, docRefKey types.DocRefKey, excludeClientID types.ID) (bool, error)
- func (c *Client) IsSchemaAttached(ctx context.Context, projectID types.ID, schema string) (bool, error)
- func (c *Client) ListMemberInfos(ctx context.Context, projectID types.ID) ([]*database.MemberInfo, error)
- func (c *Client) ListProjectInfos(ctx context.Context, owner types.ID) ([]*database.ProjectInfo, error)
- func (c *Client) ListProjectInfosByMember(ctx context.Context, userID types.ID) ([]*database.ProjectInfo, error)
- func (c *Client) ListSchemaInfos(ctx context.Context, projectID types.ID) ([]*database.SchemaInfo, error)
- func (c *Client) ListUserInfos(ctx context.Context) ([]*database.UserInfo, error)
- func (c *Client) PurgeDocument(ctx context.Context, docRefKey types.DocRefKey) (map[string]int64, error)
- func (c *Client) RemoveClusterNode(ctx context.Context, rpcAddr string) error
- func (c *Client) RemoveClusterNodes(ctx context.Context) error
- func (c *Client) RemoveSchemaInfo(ctx context.Context, projectID types.ID, name string, version int) error
- func (c *Client) RotateProjectKeys(ctx context.Context, id types.ID, publicKey string, secretKey string) (*database.ProjectInfo, *database.ProjectInfo, error)
- func (c *Client) TryAttaching(ctx context.Context, refKey types.ClientRefKey, docID types.ID) (*database.ClientInfo, error)
- func (c *Client) TryLeadership(ctx context.Context, rpcAddr, leaseToken string, leaseDuration gotime.Duration) (*database.ClusterNodeInfo, error)
- func (c *Client) UpdateClientInfoAfterPushPull(ctx context.Context, info *database.ClientInfo, docInfo *database.DocInfo) error
- func (c *Client) UpdateDocInfoSchema(ctx context.Context, refKey types.DocRefKey, schemaKey string) error
- func (c *Client) UpdateDocInfoStatusToRemoved(ctx context.Context, refKey types.DocRefKey) error
- func (c *Client) UpdateMemberRole(ctx context.Context, projectID types.ID, userID types.ID, ...) (*database.MemberInfo, error)
- func (c *Client) UpdateMinVersionVector(ctx context.Context, clientInfo *database.ClientInfo, ...) (time.VersionVector, error)
- func (c *Client) UpdateProjectInfo(ctx context.Context, id types.ID, fields *types.UpdatableProjectFields) (*database.ProjectInfo, error)
- func (c *Client) UpdateProjectStats(ctx context.Context, projectID types.ID, clientsCount int64, ...) error
- func (c *Client) UpsertMemberInfo(ctx context.Context, projectID types.ID, userID types.ID, invitedBy types.ID, ...) (*database.MemberInfo, error)
- type Config
- func (c *Config) ParseCacheStatsInterval() time.Duration
- func (c *Config) ParseConnectionTimeout() time.Duration
- func (c *Config) ParseMonitoringConfig() *MonitorConfig
- func (c *Config) ParsePingTimeout() time.Duration
- func (c *Config) ParseProjectCacheSize() int
- func (c *Config) ParseProjectCacheTTL() (time.Duration, error)
- func (c *Config) RedactedConnectionURI() string
- func (c *Config) Validate() error
- type MonitorConfig
- type ProjectCache
- func (pc *ProjectCache) Add(info *database.ProjectInfo)
- func (pc *ProjectCache) GetByAPIKey(apiKey string) (*database.ProjectInfo, bool)
- func (pc *ProjectCache) GetByID(id types.ID) (*database.ProjectInfo, bool)
- func (pc *ProjectCache) GetBySecretKey(secretKey string) (*database.ProjectInfo, bool)
- func (pc *ProjectCache) Len() int
- func (pc *ProjectCache) Name() string
- func (pc *ProjectCache) Purge()
- func (pc *ProjectCache) Remove(id types.ID)
- func (pc *ProjectCache) Stats() *cache.Stats
- type QueryMonitor
Constants ¶
const ( // DefaultProjectCacheSize is the default size of the project metadata cache. DefaultProjectCacheSize = 256 // DefaultProjectCacheTTL is the default TTL of the project metadata cache. DefaultProjectCacheTTL = 10 * time.Minute // DefaultCacheStatsInterval is the default interval for logging cache statistics. DefaultCacheStatsInterval = 30 * time.Second )
Below are the default values applied when the matching fields are left empty, so that a Config built in code (not only one read from a config file) resolves to a usable value.
const ( // ColClusterNodes represents the cluster nodes collection in the database. ColClusterNodes = "clusternodes" // ColUsers represents the users collection in the database. ColUsers = "users" // ColProjects represents the projects collection in the database. ColProjects = "projects" // ColMembers represents the project members collection in the database. ColMembers = "members" // ColInvites represents the project invites collection in the database. ColInvites = "invites" // ColClients represents the clients collection in the database. ColClients = "clients" // ColDocuments represents the documents collection in the database. ColDocuments = "documents" // ColSchemas represents the schemas collection in the database. ColSchemas = "schemas" // ColChanges represents the changes collection in the database. ColChanges = "changes" // ColSnapshots represents the snapshots collection in the database. ColSnapshots = "snapshots" // ColVersionVectors represents the versionvector collection in the database. ColVersionVectors = "versionvectors" // ColSnapshotBodies represents the snapshot_bodies collection in the database. ColSnapshotBodies = "snapshot_bodies" // ColRevisions represents the revisions collection in the database. ColRevisions = "revisions" )
const (
// StatusKey is the key of the status field.
StatusKey = "status"
)
Variables ¶
var Collections = []string{ ColClusterNodes, ColProjects, ColUsers, ColMembers, ColInvites, ColClients, ColDocuments, ColSchemas, ColChanges, ColSnapshots, ColSnapshotBodies, ColVersionVectors, ColRevisions, }
Collections represents the list of all collections in the database.
var ( // ErrInvalidServerSeq is returned when the server sequence is invalid. ErrInvalidServerSeq = errors.Internal("invalid server sequence").WithCode("ErrInvalidServerSeq") )
Functions ¶
func NewRegistryBuilder ¶ added in v0.4.14
NewRegistryBuilder returns a new registry with the default encoder and decoder.
Types ¶
type ChangeRange ¶ added in v0.6.17
type ChangeRange struct {
From int64 // Starting server sequence
To int64 // Ending server sequence
}
ChangeRange represents a range of server sequences from start to end
type ChangeStore ¶ added in v0.6.17
type ChangeStore struct {
// contains filtered or unexported fields
}
ChangeStore manages individual document changes using B-tree. It allows efficient storage and retrieval of changes based on their server sequence numbers.
func NewChangeStore ¶ added in v0.6.17
func NewChangeStore() *ChangeStore
NewChangeStore creates a new instance of ChangeStore.
func (*ChangeStore) ChangesInRange ¶ added in v0.6.17
func (s *ChangeStore) ChangesInRange(from, to int64) []*database.ChangeInfo
ChangesInRange retrieves all changes within the specified range
func (*ChangeStore) EnsureChanges ¶ added in v0.6.17
func (s *ChangeStore) EnsureChanges( from, to int64, fetcher func(from, to int64) ([]*database.ChangeInfo, error), ) error
EnsureChanges ensures that all changes in the specified range are present in the store.
func (*ChangeStore) ExpandRange ¶ added in v0.6.32
func (s *ChangeStore) ExpandRange(r ChangeRange)
ExpandRange manually expands the fetched ranges with the given range.
func (*ChangeStore) RemoveChangesByActor ¶ added in v0.6.32
func (s *ChangeStore) RemoveChangesByActor(actorID types.ID)
RemoveChangesByActor removes presence changes for the given actor, keeping Clear changes so the final state remains cleared.
func (*ChangeStore) ReplaceOrInsert ¶ added in v0.6.32
func (s *ChangeStore) ReplaceOrInsert(changes []*database.ChangeInfo)
ReplaceOrInsert replaces or inserts the given changes into the store.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a client that connects to Mongo DB and reads or saves Yorkie data.
func (*Client) ActivateClient ¶
func (c *Client) ActivateClient( ctx context.Context, projectID types.ID, key string, metadata map[string]string, ) (*database.ClientInfo, error)
ActivateClient activates the client of the given key.
func (*Client) ChangeUserPassword ¶ added in v0.4.29
ChangeUserPassword changes to new password for user.
func (*Client) CompactChangeInfos ¶ added in v0.6.9
func (*Client) CountActivatedClients ¶ added in v0.7.10
CountActivatedClients counts clients with status = activated for the given project. Uses secondary read preference to keep load off the primary.
func (*Client) CountAliveDocuments ¶ added in v0.7.10
CountAliveDocuments counts non-removed documents for the given project. Uses secondary read preference to keep load off the primary.
func (*Client) CreateChangeInfos ¶
func (c *Client) CreateChangeInfos( ctx context.Context, refKey types.DocRefKey, checkpoint change.Checkpoint, changes []*database.ChangeInfo, isRemoved bool, ) (*database.DocInfo, change.Checkpoint, error)
CreateChangeInfos stores the given changes and doc info.
func (*Client) CreateInviteInfo ¶ added in v0.6.43
func (c *Client) CreateInviteInfo( ctx context.Context, projectID types.ID, token string, role database.MemberRole, createdBy types.ID, expiresAt *gotime.Time, ) (*database.InviteInfo, error)
CreateInviteInfo creates a new reusable invite link for the project.
func (*Client) CreateProjectInfo ¶
func (c *Client) CreateProjectInfo( ctx context.Context, name string, owner types.ID, ) (*database.ProjectInfo, error)
CreateProjectInfo creates a new project.
func (*Client) CreateRevisionInfo ¶ added in v0.6.39
func (c *Client) CreateRevisionInfo( ctx context.Context, docRefKey types.DocRefKey, label string, description string, snapshot []byte, ) (*database.RevisionInfo, error)
CreateRevisionInfo creates a new revision for the given document.
func (*Client) CreateSchemaInfo ¶ added in v0.6.18
func (c *Client) CreateSchemaInfo( ctx context.Context, projectID types.ID, name string, version int, body string, rules []types.Rule, ) (*database.SchemaInfo, error)
CreateSchemaInfo stores the schema of the given document.
func (*Client) CreateSnapshotInfo ¶
func (c *Client) CreateSnapshotInfo( ctx context.Context, docRefKey types.DocRefKey, doc *document.InternalDocument, ) error
CreateSnapshotInfo stores the snapshot of the given document.
func (*Client) CreateUserInfo ¶ added in v0.2.14
func (c *Client) CreateUserInfo( ctx context.Context, username string, hashedPassword string, ) (*database.UserInfo, error)
CreateUserInfo creates a new user.
func (*Client) DeactivateClient ¶
func (c *Client) DeactivateClient( ctx context.Context, refKey types.ClientRefKey, ) (*database.ClientInfo, error)
DeactivateClient deactivates the client of the given refKey.
func (*Client) DeleteExpiredInviteInfos ¶ added in v0.6.43
DeleteExpiredInviteInfos deletes expired invites and returns the number of deleted items.
func (*Client) DeleteMemberInfo ¶ added in v0.6.43
func (c *Client) DeleteMemberInfo( ctx context.Context, projectID types.ID, userID types.ID, ) error
DeleteMemberInfo deletes a member from the project.
func (*Client) DeleteRevisionInfo ¶ added in v0.6.39
DeleteRevisionInfo deletes a revision by its ID.
func (*Client) DeleteUserInfoByName ¶ added in v0.4.29
DeleteUserInfoByName deletes a user by name.
func (*Client) EnsureDefaultUserAndProject ¶ added in v0.2.14
func (c *Client) EnsureDefaultUserAndProject( ctx context.Context, username, password string, ) (*database.UserInfo, *database.ProjectInfo, error)
EnsureDefaultUserAndProject creates the default user and project if they do not exist.
func (*Client) FindActiveClients ¶ added in v0.6.30
func (c *Client) FindActiveClients( ctx context.Context, candidatesLimit int, lastClientID types.ID, ) ([]*database.ClientInfo, types.ID, error)
FindActiveClients finds active clients for deactivation checking.
func (*Client) FindAttachedClientCountsByDocIDs ¶ added in v0.6.27
func (c *Client) FindAttachedClientCountsByDocIDs( ctx context.Context, projectID types.ID, docIDs []types.ID, ) (map[types.ID]int, error)
FindAttachedClientCountsByDocIDs returns the number of attached clients of the given documents as a map.
func (*Client) FindAttachedClientInfosByRefKey ¶ added in v0.6.14
func (c *Client) FindAttachedClientInfosByRefKey( ctx context.Context, docRefKey types.DocRefKey, ) ([]*database.ClientInfo, error)
FindAttachedClientInfosByRefKey returns the attached client infos of the given document.
func (*Client) FindChangeInfosBetweenServerSeqs ¶
func (c *Client) FindChangeInfosBetweenServerSeqs( ctx context.Context, docRefKey types.DocRefKey, from int64, to int64, ) ([]*database.ChangeInfo, error)
FindChangeInfosBetweenServerSeqs returns the changeInfos between two server sequences.
func (*Client) FindChangesBetweenServerSeqs ¶
func (c *Client) FindChangesBetweenServerSeqs( ctx context.Context, docRefKey types.DocRefKey, from int64, to int64, ) ([]*change.Change, error)
FindChangesBetweenServerSeqs returns the changes between two server sequences.
func (*Client) FindClientInfoByRefKey ¶ added in v0.4.14
func (c *Client) FindClientInfoByRefKey( ctx context.Context, refKey types.ClientRefKey, skipCache ...bool, ) (*database.ClientInfo, error)
FindClientInfoByRefKey finds the client of the given refKey.
func (*Client) FindClosestSnapshotInfo ¶
func (c *Client) FindClosestSnapshotInfo( ctx context.Context, docRefKey types.DocRefKey, serverSeq int64, includeSnapshot bool, ) (*database.SnapshotInfo, error)
FindClosestSnapshotInfo finds the last snapshot of the given document.
func (*Client) FindClusterNodes ¶ added in v0.6.32
func (c *Client) FindClusterNodes( ctx context.Context, window gotime.Duration, ) ([]*database.ClusterNodeInfo, error)
FindClusterNodes returns all cluster nodes that have been updated within the given time window. Results are sorted with the leader first, then by updated_at descending.
func (*Client) FindCompactionCandidates ¶ added in v0.6.30
func (c *Client) FindCompactionCandidates( ctx context.Context, candidatesLimit int, compactionMinChanges int, lastServerSeq int64, lastDocID types.ID, ) ([]*database.DocInfo, int64, types.ID, error)
FindCompactionCandidates finds documents that need compaction.
func (*Client) FindDocInfoByKey ¶
func (c *Client) FindDocInfoByKey( ctx context.Context, projectID types.ID, docKey key.Key, ) (*database.DocInfo, error)
FindDocInfoByKey finds the document of the given key.
func (*Client) FindDocInfoByRefKey ¶ added in v0.4.14
func (c *Client) FindDocInfoByRefKey( ctx context.Context, refKey types.DocRefKey, ) (*database.DocInfo, error)
FindDocInfoByRefKey finds a docInfo of the given refKey.
func (*Client) FindDocInfosByIDs ¶ added in v0.6.27
func (c *Client) FindDocInfosByIDs( ctx context.Context, projectID types.ID, docIDs []types.ID, ) ([]*database.DocInfo, error)
FindDocInfosByIDs finds the documents of the given ids.
func (*Client) FindDocInfosByKeys ¶ added in v0.4.28
func (c *Client) FindDocInfosByKeys( ctx context.Context, projectID types.ID, docKeys []key.Key, ) ([]*database.DocInfo, error)
FindDocInfosByKeys finds the documents of the given keys.
func (*Client) FindDocInfosByPaging ¶
func (c *Client) FindDocInfosByPaging( ctx context.Context, projectID types.ID, paging types.Paging[types.ID], ) ([]*database.DocInfo, error)
FindDocInfosByPaging returns the docInfos of the given paging.
func (*Client) FindDocInfosByQuery ¶ added in v0.2.13
func (c *Client) FindDocInfosByQuery( ctx context.Context, projectID types.ID, query string, pageSize int, ) (*types.SearchResult[*database.DocInfo], error)
FindDocInfosByQuery returns the docInfos which match the given query.
func (*Client) FindInviteInfoByToken ¶ added in v0.6.43
func (c *Client) FindInviteInfoByToken(ctx context.Context, token string) (*database.InviteInfo, error)
FindInviteInfoByToken finds an invite by token.
func (*Client) FindLatestChangeInfoByActor ¶ added in v0.5.6
func (c *Client) FindLatestChangeInfoByActor( ctx context.Context, docRefKey types.DocRefKey, actorID types.ID, serverSeq int64, ) (*database.ChangeInfo, error)
FindLatestChangeInfoByActor returns the latest change created by given actorID.
func (*Client) FindMemberInfo ¶ added in v0.6.43
func (c *Client) FindMemberInfo( ctx context.Context, projectID types.ID, userID types.ID, ) (*database.MemberInfo, error)
FindMemberInfo finds a member of the project.
func (*Client) FindOrCreateDocInfo ¶ added in v0.6.14
func (c *Client) FindOrCreateDocInfo( ctx context.Context, clientRefKey types.ClientRefKey, docKey key.Key, disablePresence bool, ) (*database.DocInfo, error)
FindOrCreateDocInfo finds the document or creates it if it does not exist. The disablePresence flag is fixated via $setOnInsert at first attach and observed by later callers — the persisted value wins regardless of what they pass.
func (*Client) FindProjectInfoByID ¶ added in v0.2.8
func (c *Client) FindProjectInfoByID(ctx context.Context, id types.ID) (*database.ProjectInfo, error)
FindProjectInfoByID returns a project by the given id.
func (*Client) FindProjectInfoByName ¶ added in v0.2.6
func (c *Client) FindProjectInfoByName( ctx context.Context, name string, ) (*database.ProjectInfo, error)
FindProjectInfoByName returns a project by name.
func (*Client) FindProjectInfoByPublicKey ¶
func (c *Client) FindProjectInfoByPublicKey(ctx context.Context, publicKey string) (*database.ProjectInfo, error)
FindProjectInfoByPublicKey returns a project by public key.
func (*Client) FindProjectInfoBySecretKey ¶ added in v0.4.13
func (c *Client) FindProjectInfoBySecretKey(ctx context.Context, secretKey string) (*database.ProjectInfo, error)
FindProjectInfoBySecretKey returns a project by secret key.
func (*Client) FindProjectInfosForRefresh ¶ added in v0.7.10
func (c *Client) FindProjectInfosForRefresh( ctx context.Context, limit int, lastID types.ID, ) ([]*database.ProjectInfo, types.ID, error)
FindProjectInfosForRefresh returns up to `limit` project infos ordered by `_id` ascending. On the first cycle (lastID == ZeroID) the boundary is inclusive so the auto-created `default` project (whose `_id` equals ZeroID) is not skipped forever; on subsequent cycles `_id > lastID` is used to avoid re-processing the previous cursor position. Returns (nil, ZeroID, nil) when iteration is exhausted.
func (*Client) FindRevisionInfoByID ¶ added in v0.6.39
func (c *Client) FindRevisionInfoByID( ctx context.Context, revisionID types.ID, ) (*database.RevisionInfo, error)
FindRevisionInfoByID returns a revision by its ID.
func (*Client) FindRevisionInfosByPaging ¶ added in v0.6.39
func (c *Client) FindRevisionInfosByPaging( ctx context.Context, docRefKey types.DocRefKey, paging types.Paging[int], includeSnapshot bool, ) ([]*database.RevisionInfo, error)
FindRevisionInfosByPaging returns the revision summaries of the given paging.
func (*Client) FindSnapshotInfo ¶ added in v0.6.18
func (c *Client) FindSnapshotInfo( ctx context.Context, docKey types.DocRefKey, serverSeq int64, ) (*database.SnapshotInfo, error)
FindSnapshotInfo returns the snapshot info of the given DocRefKey and serverSeq.
func (*Client) FindUserInfoByID ¶ added in v0.4.13
FindUserInfoByID returns a user by ID.
func (*Client) FindUserInfoByName ¶ added in v0.4.14
func (c *Client) FindUserInfoByName(ctx context.Context, username string) (*database.UserInfo, error)
FindUserInfoByName returns a user by username.
func (*Client) GetMinVersionVector ¶ added in v0.6.13
func (c *Client) GetMinVersionVector( ctx context.Context, docRefKey types.DocRefKey, vector time.VersionVector, ) (time.VersionVector, error)
GetMinVersionVector returns the minimum version vector of the given document.
func (*Client) GetOrCreateUserInfoByGitHubID ¶ added in v0.6.3
func (c *Client) GetOrCreateUserInfoByGitHubID( ctx context.Context, githubID string, ) (*database.UserInfo, error)
GetOrCreateUserInfoByGitHubID returns a user by the given GitHub ID. It only matches users created by GitHub login: a username held by another auth provider is never returned.
func (*Client) GetProjectStatsCounts ¶ added in v0.7.10
func (c *Client) GetProjectStatsCounts( ctx context.Context, projectID types.ID, ) (*database.ProjectStatsCounts, error)
GetProjectStatsCounts returns the cached project counts via a projection-only FindOne. ProjectCache is intentionally bypassed to avoid compounding staleness.
func (*Client) GetSchemaInfo ¶ added in v0.6.18
func (c *Client) GetSchemaInfo( ctx context.Context, projectID types.ID, name string, version int, ) (*database.SchemaInfo, error)
GetSchemaInfo returns the schema of the given document.
func (*Client) GetSchemaInfos ¶ added in v0.6.18
func (c *Client) GetSchemaInfos( ctx context.Context, projectID types.ID, name string, ) ([]*database.SchemaInfo, error)
GetSchemaInfos returns all versions of the schema.
func (*Client) InvalidateCache ¶ added in v0.6.36
InvalidateCache invalidates the cache of the given type and key.
func (*Client) IsDocumentAttachedOrAttaching ¶ added in v0.6.43
func (c *Client) IsDocumentAttachedOrAttaching( ctx context.Context, docRefKey types.DocRefKey, excludeClientID types.ID, ) (bool, error)
IsDocumentAttachedOrAttaching returns whether the given document is attached or attaching to clients.
func (*Client) IsSchemaAttached ¶ added in v0.6.18
func (c *Client) IsSchemaAttached( ctx context.Context, projectID types.ID, schema string, ) (bool, error)
IsSchemaAttached returns true if the schema is being used by any documents.
func (*Client) ListMemberInfos ¶ added in v0.6.43
func (c *Client) ListMemberInfos( ctx context.Context, projectID types.ID, ) ([]*database.MemberInfo, error)
ListMemberInfos returns all members of the project.
func (*Client) ListProjectInfos ¶
func (c *Client) ListProjectInfos( ctx context.Context, owner types.ID, ) ([]*database.ProjectInfo, error)
ListProjectInfos returns all project infos owned by owner.
func (*Client) ListProjectInfosByMember ¶ added in v0.6.43
func (c *Client) ListProjectInfosByMember( ctx context.Context, userID types.ID, ) ([]*database.ProjectInfo, error)
ListProjectInfosByMember returns all projects that the user is a member of.
func (*Client) ListSchemaInfos ¶ added in v0.6.18
func (*Client) ListUserInfos ¶ added in v0.2.14
ListUserInfos returns all user infos.
func (*Client) PurgeDocument ¶ added in v0.6.12
func (c *Client) PurgeDocument( ctx context.Context, docRefKey types.DocRefKey, ) (map[string]int64, error)
PurgeDocument purges the given document and its metadata from the database.
func (*Client) RemoveClusterNode ¶ added in v0.6.32
RemoveClusterNode removes the cluster node with the given rpcAddr.
func (*Client) RemoveClusterNodes ¶ added in v0.6.32
RemoveClusterNodes removes all cluster nodes.
func (*Client) RemoveSchemaInfo ¶ added in v0.6.18
func (*Client) RotateProjectKeys ¶ added in v0.6.15
func (c *Client) RotateProjectKeys( ctx context.Context, id types.ID, publicKey string, secretKey string, ) (*database.ProjectInfo, *database.ProjectInfo, error)
RotateProjectKeys rotates the API keys of the project.
func (*Client) TryAttaching ¶ added in v0.6.23
func (c *Client) TryAttaching( ctx context.Context, refKey types.ClientRefKey, docID types.ID, ) (*database.ClientInfo, error)
TryAttaching updates the status of the document to Attaching to prevent deactivating the client while the document is being attached.
func (*Client) TryLeadership ¶ added in v0.6.23
func (c *Client) TryLeadership( ctx context.Context, rpcAddr, leaseToken string, leaseDuration gotime.Duration, ) (*database.ClusterNodeInfo, error)
TryLeadership attempts to acquire or renew leadership with the given lease duration. If leaseToken is empty, it attempts to acquire new leadership. If leaseToken is provided, it attempts to renew the existing lease.
func (*Client) UpdateClientInfoAfterPushPull ¶
func (c *Client) UpdateClientInfoAfterPushPull( ctx context.Context, info *database.ClientInfo, docInfo *database.DocInfo, ) error
UpdateClientInfoAfterPushPull updates the client from the given clientInfo after handling PushPull.
func (*Client) UpdateDocInfoSchema ¶ added in v0.6.18
func (c *Client) UpdateDocInfoSchema( ctx context.Context, refKey types.DocRefKey, schemaKey string, ) error
UpdateDocInfoSchema updates the document schema.
func (*Client) UpdateDocInfoStatusToRemoved ¶ added in v0.4.0
UpdateDocInfoStatusToRemoved updates the document status to removed.
func (*Client) UpdateMemberRole ¶ added in v0.6.43
func (c *Client) UpdateMemberRole( ctx context.Context, projectID types.ID, userID types.ID, role database.MemberRole, ) (*database.MemberInfo, error)
UpdateMemberRole updates the role of a project member.
func (*Client) UpdateMinVersionVector ¶ added in v0.6.13
func (c *Client) UpdateMinVersionVector( ctx context.Context, clientInfo *database.ClientInfo, docRefKey types.DocRefKey, vector time.VersionVector, ) (time.VersionVector, error)
UpdateMinVersionVector updates the version vector of the given client and returns the minimum version vector of all clients.
func (*Client) UpdateProjectInfo ¶
func (c *Client) UpdateProjectInfo( ctx context.Context, id types.ID, fields *types.UpdatableProjectFields, ) (*database.ProjectInfo, error)
UpdateProjectInfo updates the project info.
func (*Client) UpdateProjectStats ¶ added in v0.7.10
func (c *Client) UpdateProjectStats( ctx context.Context, projectID types.ID, clientsCount int64, documentsCount int64, updatedAt gotime.Time, ) error
UpdateProjectStats writes the cached stats fields on the project document.
func (*Client) UpsertMemberInfo ¶ added in v0.6.44
func (c *Client) UpsertMemberInfo( ctx context.Context, projectID types.ID, userID types.ID, invitedBy types.ID, role database.MemberRole, ) (*database.MemberInfo, error)
UpsertMemberInfo creates a new member or returns the existing member if already exists.
type Config ¶
type Config struct {
ConnectionTimeout string `yaml:"ConnectionTimeout"`
ConnectionURI string `yaml:"ConnectionURI"`
YorkieDatabase string `yaml:"YorkieDatabase"`
PingTimeout string `yaml:"PingTimeout"`
// MonitoringEnabled determines whether query monitoring is enabled.
MonitoringEnabled bool `yaml:"MonitoringEnabled"`
// MonitoringSlowQueryThreshold is the threshold in milliseconds to log slow queries.
// If a query takes longer than this threshold, it will be logged as a slow query.
MonitoringSlowQueryThreshold string `yaml:"MonitoringSlowQueryThreshold"`
// CacheStatsEnabled determines whether cache statistics logging is enabled.
CacheStatsEnabled bool `yaml:"CacheStatsEnabled"`
// CacheStatsInterval is the interval for logging cache statistics.
CacheStatsInterval string `yaml:"CacheStatsInterval"`
// ClientCacheSize is the size of the client cache. It works as LRU cache.
ClientCacheSize int `yaml:"ClientCacheSize"`
// DocCacheSize is the size of the document cache. It works as LRU cache.
DocCacheSize int `yaml:"DocCacheSize"`
// ChangeCacheSize is the size of the change cache. It works as LRU cache.
ChangeCacheSize int `yaml:"ChangeCacheSize"`
// ActorCacheSize is the size of the actor cache. It works as LRU cache.
VectorCacheSize int `yaml:"VectorCacheSize"`
// ProjectCacheSize is the size of the project metadata cache.
ProjectCacheSize int `yaml:"ProjectCacheSize"`
// ProjectCacheTTL is the TTL value for the project metadata cache.
ProjectCacheTTL string `yaml:"ProjectCacheTTL"`
}
Config is the configuration for creating a Client instance.
func (*Config) ParseCacheStatsInterval ¶ added in v0.6.28
ParseCacheStatsInterval returns cache stats interval duration, falling back to DefaultCacheStatsInterval when the value is unset. A Config built in code may leave it empty, and an unset value must not terminate the process.
func (*Config) ParseConnectionTimeout ¶
ParseConnectionTimeout returns connection timeout duration.
func (*Config) ParseMonitoringConfig ¶ added in v0.6.17
func (c *Config) ParseMonitoringConfig() *MonitorConfig
ParseMonitoringConfig returns the monitoring configuration for MongoDB query monitoring.
func (*Config) ParsePingTimeout ¶
ParsePingTimeout returns ping timeout duration.
func (*Config) ParseProjectCacheSize ¶ added in v0.7.24
ParseProjectCacheSize returns the size of the project cache, falling back to DefaultProjectCacheSize when the value is unset. A non-positive size is also defaulted, because the underlying LRU reads it as "unbounded" rather than as the misconfiguration it is; Validate rejects a negative value outright.
func (*Config) ParseProjectCacheTTL ¶ added in v0.6.36
ParseProjectCacheTTL returns the TTL duration for the project cache, falling back to DefaultProjectCacheTTL when the value is unset. Configs built in code may leave it empty, and neither an unset nor an invalid value terminates the process: an invalid one is returned as an error for the caller to surface.
func (*Config) RedactedConnectionURI ¶ added in v0.7.25
RedactedConnectionURI returns the connection URI with every credential it carries masked: the password of its userinfo and the value of any credential-bearing connection-string option, such as tlsCertificateKeyFilePassword, proxyPassword or authMechanismProperties. The URI carries the database user's password, so logging it verbatim publishes that credential to everyone who can read the server's stdout — a far weaker permission than the one guarding the secret it is deployed in. Scheme, username, hosts and the remaining options are kept, since those are what make the line worth logging.
A URI whose credentials cannot be located is reported as unparsable instead of in part: masking too much costs a log line, masking too little publishes the password.
type MonitorConfig ¶ added in v0.6.17
type MonitorConfig struct {
// Enabled determines whether query monitoring is enabled.
Enabled bool
// SlowQueryThreshold is the threshold in milliseconds to log slow queries.
// If a query takes longer than this threshold, it will be logged as a slow query.
SlowQueryThreshold time.Duration
}
MonitorConfig represents configuration for MongoDB query monitoring.
type ProjectCache ¶ added in v0.6.42
type ProjectCache struct {
// contains filtered or unexported fields
}
ProjectCache is a cache for project information with multiple access paths. It uses a single LRU cache with ID as the primary key and maintains a indices for API key and secret key lookups to minimize memory usage and ensure cache consistency.
func NewProjectCache ¶ added in v0.6.42
func NewProjectCache(size int, ttl time.Duration) (*ProjectCache, error)
NewProjectCache creates a new project cache with the given size and TTL.
func (*ProjectCache) Add ¶ added in v0.6.42
func (pc *ProjectCache) Add(info *database.ProjectInfo)
Add adds a project to the cache.
func (*ProjectCache) GetByAPIKey ¶ added in v0.6.42
func (pc *ProjectCache) GetByAPIKey(apiKey string) (*database.ProjectInfo, bool)
GetByAPIKey retrieves a project by API key.
func (*ProjectCache) GetByID ¶ added in v0.6.42
func (pc *ProjectCache) GetByID(id types.ID) (*database.ProjectInfo, bool)
GetByID retrieves a project by ID.
func (*ProjectCache) GetBySecretKey ¶ added in v0.6.43
func (pc *ProjectCache) GetBySecretKey(secretKey string) (*database.ProjectInfo, bool)
GetBySecretKey retrieves a project by secret key.
func (*ProjectCache) Len ¶ added in v0.6.42
func (pc *ProjectCache) Len() int
Len returns the number of items in the cache.
func (*ProjectCache) Name ¶ added in v0.6.42
func (pc *ProjectCache) Name() string
Name returns the cache name.
func (*ProjectCache) Purge ¶ added in v0.6.42
func (pc *ProjectCache) Purge()
Purge removes all entries from the cache.
func (*ProjectCache) Remove ¶ added in v0.6.42
func (pc *ProjectCache) Remove(id types.ID)
Remove removes a project from the cache using both API key and ID.
func (*ProjectCache) Stats ¶ added in v0.6.42
func (pc *ProjectCache) Stats() *cache.Stats
Stats returns the cache statistics.
type QueryMonitor ¶ added in v0.6.17
type QueryMonitor struct {
// contains filtered or unexported fields
}
QueryMonitor represents a MongoDB query monitor.
func NewQueryMonitor ¶ added in v0.6.17
func NewQueryMonitor(config *MonitorConfig) *QueryMonitor
NewQueryMonitor creates a new instance of QueryMonitor.
func (*QueryMonitor) CreateCommandMonitor ¶ added in v0.6.17
func (m *QueryMonitor) CreateCommandMonitor() *event.CommandMonitor
CreateCommandMonitor creates a new instance of event.CommandMonitor which can be used to monitor MongoDB commands.