metadb

package
v0.3.0-beta0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoUpdate = errors.New("UpdateRecord doesn't need to commit the change")
)

Functions

This section is empty.

Types

type MetaDB

type MetaDB struct {
	// Datastore namespace for multi-tenancy
	Namespace string
	// contains filtered or unexported fields
}

MetaDB is a metadata database manager of Open Saves. The methods return gRPC error codes. Here are some common error codes returned. For additional details, please look at the method help. Common errors:

  • NotFound: entity or object is not found
  • Aborted: transaction is aborted
  • InvalidArgument: key or value provided is not valid
  • Internal: internal unrecoverable error

func NewMetaDB

func NewMetaDB(ctx context.Context, projectID string, opts ...option.ClientOption) (*MetaDB, error)

NewMetaDB creates a new MetaDB instance with an initialized database client.

func (*MetaDB) CreateStore

func (m *MetaDB) CreateStore(ctx context.Context, store *store.Store) (*store.Store, error)

CreateStore creates a new store.

func (*MetaDB) DeleteBlobRef

func (m *MetaDB) DeleteBlobRef(ctx context.Context, key uuid.UUID) error

DeleteBlobRef deletes the BlobRef object from the database. Returned errors:

  • NotFound: the blobref object is not found
  • FailedPrecondition: the blobref status is Ready and can't be deleted

func (*MetaDB) DeleteChunkRef

func (m *MetaDB) DeleteChunkRef(ctx context.Context, blobKey, key uuid.UUID) error

DeleteChunkRef deletes the ChunkRef object from the database. Returned errors:

  • NotFound: the chunkref object is not found.
  • FailedPrecondition: the chunkref status is Ready and can't be deleted.

func (*MetaDB) DeleteRecord

func (m *MetaDB) DeleteRecord(ctx context.Context, storeKey, key string) error

DeleteRecord deletes a record with key in store storeKey. It doesn't return error even if the key is not found in the database.

func (*MetaDB) DeleteStore

func (m *MetaDB) DeleteStore(ctx context.Context, key string) error

DeleteStore deletes the store with specified key. Returns error if the store has any child records.

func (*MetaDB) Disconnect

func (m *MetaDB) Disconnect(ctx context.Context) error

Disconnect terminates the database connection. Make sure to call this method to release resources (e.g. using defer). The MetaDB instance will not be available after Disconnect().

func (*MetaDB) FindChunkRefByNumber

func (m *MetaDB) FindChunkRefByNumber(ctx context.Context, storeKey, recordKey string, number int32) (*chunkref.ChunkRef, error)

FindChunkRefByNumber returns a ChunkRef object for the specified store, record, and number. The ChunkRef must be Ready and the chunk upload session must be committed.

func (*MetaDB) FindStoreByName

func (m *MetaDB) FindStoreByName(ctx context.Context, name string) (*store.Store, error)

FindStoreByName finds and fetch a store based on the name (complete match).

func (*MetaDB) GetBlobRef

func (m *MetaDB) GetBlobRef(ctx context.Context, key uuid.UUID) (*blobref.BlobRef, error)

GetBlobRef returns a BlobRef object specified by the key. Returns errors:

  • NotFound: the object is not found.

func (*MetaDB) GetChildChunkRefs

func (m *MetaDB) GetChildChunkRefs(ctx context.Context, blobKey uuid.UUID) *chunkref.ChunkRefCursor

GetChildChunkRefs returns a ChunkRef cursor that iterats over child ChunkRef entries of the BlobRef specified by blobkey.

func (*MetaDB) GetCurrentBlobRef

func (m *MetaDB) GetCurrentBlobRef(ctx context.Context, storeKey, recordKey string) (*blobref.BlobRef, error)

GetCurrentBlobRef gets a BlobRef object associated with a record. Returned errors:

  • NotFound: the record is not found.
  • FailedPrecondition: the record doesn't have a blob.

func (*MetaDB) GetRecord

func (m *MetaDB) GetRecord(ctx context.Context, storeKey, key string) (*record.Record, error)

GetRecord fetches and returns a record with key in store storeKey. Returns error if not found.

func (*MetaDB) GetRecords

func (m *MetaDB) GetRecords(ctx context.Context, storeKeys, recordKeys []string) ([]*record.Record, error)

GetRecords returns records by using the get multi request interface from datastore.

func (*MetaDB) GetStore

func (m *MetaDB) GetStore(ctx context.Context, key string) (*store.Store, error)

GetStore fetches a store based on the key provided. Returns error if the key is not found.

func (*MetaDB) InsertBlobRef

func (m *MetaDB) InsertBlobRef(ctx context.Context, blob *blobref.BlobRef) (*blobref.BlobRef, error)

InsertBlobRef inserts a new BlobRef object to the datastore.

func (*MetaDB) InsertChunkRef

func (m *MetaDB) InsertChunkRef(ctx context.Context, blob *blobref.BlobRef, chunk *chunkref.ChunkRef) error

InsertChunkRef inserts a new ChunkRef object to the datastore. If the current session has another chunk with the same Number, it will be marked for deletion.

func (*MetaDB) InsertRecord

func (m *MetaDB) InsertRecord(ctx context.Context, storeKey string, record *record.Record) (*record.Record, error)

InsertRecord creates a new Record in the store specified with storeKey. Returns error if there is already a record with the same key.

func (*MetaDB) ListBlobRefsByStatus

func (m *MetaDB) ListBlobRefsByStatus(ctx context.Context, status blobref.Status) (*blobref.BlobRefCursor, error)

ListBlobRefsByStatus returns a cursor that iterates over BlobRefs where Status = status.

func (*MetaDB) ListChunkRefsByStatus

func (m *MetaDB) ListChunkRefsByStatus(ctx context.Context, status blobref.Status) *chunkref.ChunkRefCursor

ListChunkRefsByStatus returns a cursor that iterates over ChunkRefs where Status = status.

func (*MetaDB) MarkUncommittedBlobForDeletion

func (m *MetaDB) MarkUncommittedBlobForDeletion(ctx context.Context, key uuid.UUID) error

MarkUncommittedBlobForDeletion marks the BlobRef specified by key for deletion if the current status is StatusInitializing. Returns FailedPrecondition is Status is not StatusInitializing.

func (*MetaDB) PromoteBlobRefToCurrent

func (m *MetaDB) PromoteBlobRefToCurrent(ctx context.Context, blob *blobref.BlobRef) (*record.Record, *blobref.BlobRef, error)

PromoteBlobRefToCurrent promotes the provided BlobRef object as a current external blob reference. Returned errors:

  • NotFound: the specified record or the blobref was not found
  • Internal: BlobRef status transition error

func (*MetaDB) PromoteBlobRefWithRecordUpdater

func (m *MetaDB) PromoteBlobRefWithRecordUpdater(ctx context.Context, blob *blobref.BlobRef, updateTo *record.Record, updater RecordUpdater) (*record.Record, *blobref.BlobRef, error)

PromoteBlobRefWithRecordUpdater promotes the provided BlobRef object as a current external blob reference and updates a record in one transaction. Returned errors:

  • NotFound: the specified record or the blobref was not found
  • Internal: BlobRef status transition error

func (*MetaDB) QueryRecords

func (m *MetaDB) QueryRecords(ctx context.Context, req *pb.QueryRecordsRequest) ([]*record.Record, error)

QueryRecords returns a list of records that match the given filters.

func (*MetaDB) RemoveBlobFromRecord

func (m *MetaDB) RemoveBlobFromRecord(ctx context.Context, storeKey string, recordKey string) (*record.Record, *blobref.BlobRef, error)

RemoveBlobFromRecord removes the ExternalBlob from the record specified by storeKey and recordKey. It also changes the status of the blob object to BlobRefStatusPendingDeletion. Returned errors:

  • NotFound: the specified record or the blobref was not found
  • FailedPrecondition: the record doesn't have an external blob
  • Internal: BlobRef status transition error

func (*MetaDB) UpdateBlobRef

func (m *MetaDB) UpdateBlobRef(ctx context.Context, blob *blobref.BlobRef) (*blobref.BlobRef, error)

UpdateBlobRef updates a BlobRef object with the new property values. Returns a NotFound error if the key is not found.

func (*MetaDB) UpdateChunkRef

func (m *MetaDB) UpdateChunkRef(ctx context.Context, chunk *chunkref.ChunkRef) error

UpdateChunkRef updates a ChunkRef object with the new property values. Returns a NotFound error if the key is not found.

func (*MetaDB) UpdateRecord

func (m *MetaDB) UpdateRecord(ctx context.Context, storeKey string, key string, updater RecordUpdater) (*record.Record, error)

UpdateRecord updates the record in the store specified with storeKey. Pass a callback function to updater and change values there. The callback will be protected by a transaction. Returns error if the store doesn't have a record with the key provided.

func (*MetaDB) ValidateChunkRefPreconditions

func (m *MetaDB) ValidateChunkRefPreconditions(ctx context.Context, chunk *chunkref.ChunkRef) (*blobref.BlobRef, error)

ValidateChunkRefPreconditions check if the parent blobref is chunked before attempting to upload any data

type RecordUpdater

type RecordUpdater func(record *record.Record) (*record.Record, error)

RecordUpdater is a callback function for record updates. Returning a non-nil error aborts the transaction.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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