datastore

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2023 License: MPL-2.0 Imports: 20 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Table is the name of the table in dynamoDB, could be modified in tests.
	Table = os.Getenv("TABLE_NAME")
)

Functions

func CreatePBSyncEntity

func CreatePBSyncEntity(entity *SyncEntity) (*sync_pb.SyncEntity, error)

CreatePBSyncEntity converts a DB sync item to a protobuf sync entity.

Types

type ClientItemCount

type ClientItemCount struct {
	ClientID  string
	ID        string
	ItemCount int
}

ClientItemCount is used to marshal and unmarshal ClientItemCount items in dynamoDB.

type ClientItemCountByClientID

type ClientItemCountByClientID []ClientItemCount

ClientItemCountByClientID implements sort.Interface for []ClientItemCount based on ClientID.

func (ClientItemCountByClientID) Len

func (ClientItemCountByClientID) Less

func (a ClientItemCountByClientID) Less(i, j int) bool

func (ClientItemCountByClientID) Swap

func (a ClientItemCountByClientID) Swap(i, j int)

type Datastore

type Datastore interface {
	// Insert a new sync entity.
	InsertSyncEntity(entity *SyncEntity) (bool, error)
	// Insert a series of sync entities in a write transaction.
	InsertSyncEntitiesWithServerTags(entities []*SyncEntity) error
	// Update an existing sync entity.
	UpdateSyncEntity(entity *SyncEntity, oldVersion int64) (conflict bool, delete bool, err error)
	// Get updates for a specific type which are modified after the time of
	// client token for a given client. Besides the array of sync entities, a
	// boolean value indicating whether there are more updates to query in the
	// next batch is returned.
	GetUpdatesForType(dataType int, clientToken int64, fetchFolders bool, clientID string, maxSize int64) (bool, []SyncEntity, error)
	// Check if a server-defined unique tag is in the datastore.
	HasServerDefinedUniqueTag(clientID string, tag string) (bool, error)
	// Get the count of sync items for a client.
	GetClientItemCount(clientID string) (int, error)
	// Update the count of sync items for a client.
	UpdateClientItemCount(clientID string, count int) error
	// ClearServerData deletes all items for a given clientID
	ClearServerData(clientID string) ([]SyncEntity, error)
	// DisableSyncChain marks a chain as disabled so no further updates or commits can happen
	DisableSyncChain(clientID string) error
	// IsSyncChainDisabled checks whether a given sync chain is deleted
	IsSyncChainDisabled(clientID string) (bool, error)
}

Datastore abstracts over the underlying datastore.

type DatastoreWithPrometheus

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

DatastoreWithPrometheus implements Datastore interface with all methods wrapped with Prometheus metrics

func NewDatastoreWithPrometheus

func NewDatastoreWithPrometheus(base Datastore, instanceName string) DatastoreWithPrometheus

NewDatastoreWithPrometheus returns an instance of the Datastore decorated with prometheus summary metric

func (DatastoreWithPrometheus) ClearServerData added in v0.1.20

func (_d DatastoreWithPrometheus) ClearServerData(clientID string) (sa1 []SyncEntity, err error)

ClearServerData implements Datastore

func (DatastoreWithPrometheus) DisableSyncChain added in v0.1.20

func (_d DatastoreWithPrometheus) DisableSyncChain(clientID string) (err error)

DisableSyncChain implements Datastore

func (DatastoreWithPrometheus) GetClientItemCount

func (_d DatastoreWithPrometheus) GetClientItemCount(clientID string) (i1 int, err error)

GetClientItemCount implements Datastore

func (DatastoreWithPrometheus) GetUpdatesForType

func (_d DatastoreWithPrometheus) GetUpdatesForType(dataType int, clientToken int64, fetchFolders bool, clientID string, maxSize int64) (b1 bool, sa1 []SyncEntity, err error)

GetUpdatesForType implements Datastore

func (DatastoreWithPrometheus) HasServerDefinedUniqueTag

func (_d DatastoreWithPrometheus) HasServerDefinedUniqueTag(clientID string, tag string) (b1 bool, err error)

HasServerDefinedUniqueTag implements Datastore

func (DatastoreWithPrometheus) InsertSyncEntitiesWithServerTags

func (_d DatastoreWithPrometheus) InsertSyncEntitiesWithServerTags(entities []*SyncEntity) (err error)

InsertSyncEntitiesWithServerTags implements Datastore

func (DatastoreWithPrometheus) InsertSyncEntity

func (_d DatastoreWithPrometheus) InsertSyncEntity(entity *SyncEntity) (b1 bool, err error)

InsertSyncEntity implements Datastore

func (DatastoreWithPrometheus) IsSyncChainDisabled added in v0.1.20

func (_d DatastoreWithPrometheus) IsSyncChainDisabled(clientID string) (b1 bool, err error)

IsSyncChainDisabled implements Datastore

func (DatastoreWithPrometheus) UpdateClientItemCount

func (_d DatastoreWithPrometheus) UpdateClientItemCount(clientID string, count int) (err error)

UpdateClientItemCount implements Datastore

func (DatastoreWithPrometheus) UpdateSyncEntity

func (_d DatastoreWithPrometheus) UpdateSyncEntity(entity *SyncEntity, oldVersion int64) (conflict bool, delete bool, err error)

UpdateSyncEntity implements Datastore

type DisabledMarkerItem added in v0.1.20

type DisabledMarkerItem struct {
	ClientID string
	ID       string
	Reason   string
	Mtime    *int64
	Ctime    *int64
}

DisabledMarkerItem is used to mark sync chain as deleted in Dynamodb

type DisabledMarkerItemQuery added in v0.1.20

type DisabledMarkerItemQuery struct {
	ClientID string
	ID       string
}

DisabledMarkerItemQuery is used to query for disabled marker item in DynamoDB

type Dynamo

type Dynamo struct {
	*dynamodb.DynamoDB
}

Dynamo is a Datastore wrapper around a dynamoDB.

func NewDynamo

func NewDynamo() (*Dynamo, error)

NewDynamo returns a dynamoDB client to be used.

func (*Dynamo) ClearServerData added in v0.1.20

func (dynamo *Dynamo) ClearServerData(clientID string) ([]SyncEntity, error)

ClearServerData deletes all items for a given clientID

func (*Dynamo) DisableSyncChain added in v0.1.20

func (dynamo *Dynamo) DisableSyncChain(clientID string) error

DisableSyncChain marks a chain as disabled so no further updates or commits can happen

func (*Dynamo) GetClientItemCount

func (dynamo *Dynamo) GetClientItemCount(clientID string) (int, error)

GetClientItemCount returns the count of non-deleted sync items stored for a given client.

func (*Dynamo) GetUpdatesForType

func (dynamo *Dynamo) GetUpdatesForType(dataType int, clientToken int64, fetchFolders bool, clientID string, maxSize int64) (bool, []SyncEntity, error)

GetUpdatesForType returns sync entities of a data type where it's mtime is later than the client token. To do this in dynamoDB, we use (ClientID, DataType#Mtime) as GSI to get a list of (ClientID, ID) primary keys with the given condition, then read the actual sync item using the list of primary keys.

func (*Dynamo) HasServerDefinedUniqueTag

func (dynamo *Dynamo) HasServerDefinedUniqueTag(clientID string, tag string) (bool, error)

HasServerDefinedUniqueTag check the tag item to see if there is already a tag item exists with the tag value for a specific client.

func (*Dynamo) InsertSyncEntitiesWithServerTags

func (dynamo *Dynamo) InsertSyncEntitiesWithServerTags(entities []*SyncEntity) error

InsertSyncEntitiesWithServerTags is used to insert sync entities with server-defined unique tags. To ensure the uniqueness, for each sync entity, we will write a tag item and a sync item. Items for all the entities in the array would be written into DB in one transaction.

func (*Dynamo) InsertSyncEntity

func (dynamo *Dynamo) InsertSyncEntity(entity *SyncEntity) (bool, error)

InsertSyncEntity inserts a new sync entity into dynamoDB. If ClientDefinedUniqueTag is not null, we will use a write transaction to write a sync item along with a tag item to ensure the uniqueness of the client tag. Otherwise, only a sync item is written into DB without using transactions.

func (*Dynamo) IsSyncChainDisabled added in v0.1.20

func (dynamo *Dynamo) IsSyncChainDisabled(clientID string) (bool, error)

IsSyncChainDisabled checks whether a given sync chain has been deleted

func (*Dynamo) UpdateClientItemCount

func (dynamo *Dynamo) UpdateClientItemCount(clientID string, count int) error

UpdateClientItemCount updates the count of non-deleted sync items for a given client stored in the dynamoDB.

func (*Dynamo) UpdateSyncEntity

func (dynamo *Dynamo) UpdateSyncEntity(entity *SyncEntity, oldVersion int64) (bool, bool, error)

UpdateSyncEntity updates a sync item in dynamoDB.

type PrimaryKey

type PrimaryKey struct {
	ClientID string // Hash key
	ID       string // Range key
}

PrimaryKey struct is used to represent the primary key of our table.

type ServerClientUniqueTagItem

type ServerClientUniqueTagItem struct {
	ClientID string // Hash key
	ID       string // Range key
	Mtime    *int64
	Ctime    *int64
}

ServerClientUniqueTagItem is used to marshal and unmarshal tag items in dynamoDB.

func NewServerClientUniqueTagItem

func NewServerClientUniqueTagItem(clientID string, tag string, isServer bool) *ServerClientUniqueTagItem

NewServerClientUniqueTagItem creates a tag item which is used to ensure the uniqueness of server-defined or client-defined unique tags for a client.

type ServerClientUniqueTagItemQuery added in v0.1.20

type ServerClientUniqueTagItemQuery struct {
	ClientID string // Hash key
	ID       string // Range key
}

ServerClientUniqueTagItemQuery is used to query for unique tag items in dynamoDB.

func NewServerClientUniqueTagItemQuery added in v0.1.20

func NewServerClientUniqueTagItemQuery(clientID string, tag string, isServer bool) *ServerClientUniqueTagItemQuery

NewServerClientUniqueTagItemQuery creates a tag item query which is used to determine whether a sync entity has a unique tag item or not

type SyncEntity

type SyncEntity struct {
	ClientID               string
	ID                     string
	ParentID               *string `dynamodbav:",omitempty"`
	Version                *int64
	Mtime                  *int64
	Ctime                  *int64
	Name                   *string `dynamodbav:",omitempty"`
	NonUniqueName          *string `dynamodbav:",omitempty"`
	ServerDefinedUniqueTag *string `dynamodbav:",omitempty"`
	Deleted                *bool
	OriginatorCacheGUID    *string `dynamodbav:",omitempty"`
	OriginatorClientItemID *string `dynamodbav:",omitempty"`
	Specifics              []byte
	DataType               *int
	Folder                 *bool
	ClientDefinedUniqueTag *string `dynamodbav:",omitempty"`
	UniquePosition         []byte  `dynamodbav:",omitempty"`
	DataTypeMtime          *string
}

SyncEntity is used to marshal and unmarshal sync items in dynamoDB.

func CreateDBSyncEntity

func CreateDBSyncEntity(entity *sync_pb.SyncEntity, cacheGUID *string, clientID string) (*SyncEntity, error)

CreateDBSyncEntity converts a protobuf sync entity into a DB sync item.

type SyncEntityByClientIDID

type SyncEntityByClientIDID []SyncEntity

SyncEntityByClientIDID implements sort.Interface for []SyncEntity based on the string concatenation of ClientID and ID fields.

func (SyncEntityByClientIDID) Len

func (a SyncEntityByClientIDID) Len() int

func (SyncEntityByClientIDID) Less

func (a SyncEntityByClientIDID) Less(i, j int) bool

func (SyncEntityByClientIDID) Swap

func (a SyncEntityByClientIDID) Swap(i, j int)

type SyncEntityByMtime

type SyncEntityByMtime []SyncEntity

SyncEntityByMtime implements sort.Interface for []SyncEntity based on Mtime.

func (SyncEntityByMtime) Len

func (a SyncEntityByMtime) Len() int

func (SyncEntityByMtime) Less

func (a SyncEntityByMtime) Less(i, j int) bool

func (SyncEntityByMtime) Swap

func (a SyncEntityByMtime) Swap(i, j int)

type TagItemByClientIDID

type TagItemByClientIDID []ServerClientUniqueTagItem

TagItemByClientIDID implements sort.Interface for []ServerClientUniqueTagItem based on the string concatenation of ClientID and ID fields.

func (TagItemByClientIDID) Len

func (a TagItemByClientIDID) Len() int

func (TagItemByClientIDID) Less

func (a TagItemByClientIDID) Less(i, j int) bool

func (TagItemByClientIDID) Swap

func (a TagItemByClientIDID) Swap(i, j int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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