From ed3844b71409d867a1e40431c226fd2443407a9d Mon Sep 17 00:00:00 2001 From: ashmrtn <3891298+ashmrtn@users.noreply.github.com> Date: Wed, 29 Jun 2022 10:35:41 -0700 Subject: [PATCH] API definition for model store (#249) Basic API definitions for model store CRUD operations --- src/internal/kopia/model_store.go | 67 ++++++++++++++++++++++++++ src/internal/kopia/modeltype_string.go | 26 ++++++++++ 2 files changed, 93 insertions(+) create mode 100644 src/internal/kopia/model_store.go create mode 100644 src/internal/kopia/modeltype_string.go diff --git a/src/internal/kopia/model_store.go b/src/internal/kopia/model_store.go new file mode 100644 index 000000000..a3814d29f --- /dev/null +++ b/src/internal/kopia/model_store.go @@ -0,0 +1,67 @@ +package kopia + +import ( + "context" +) + +// ID of the manifest in kopia. This is not guaranteed to be stable. +type ID string +type modelType int + +//go:generate stringer -type=modelType +const ( + UnknownModel = modelType(iota) + BackupOpModel + RestoreOpModel + RestorePointModel + + errStoreFlush = "flushing manifest store" +) + +type ModelStore struct{} + +// Put adds a model of the given type to the persistent model store. Any tags +// given to this function can later be used to help lookup the model. The +// returned ID can be used for subsequent Get, Update, or Delete calls. +func (ms *ModelStore) Put( + ctx context.Context, + t modelType, + tags map[string]string, + m any, +) (ID, error) { + return "", nil +} + +// GetIDsForType returns all IDs for models that match the given type and have +// the given tags. Returned IDs can be used in subsequent calls to Get, Update, +// or Delete. +func (ms *ModelStore) GetIDsForType( + ctx context.Context, + t modelType, + tags map[string]string, +) ([]ID, error) { + return nil, nil +} + +// Get deserializes the model with the given ID into data. +func (ms *ModelStore) Get(ctx context.Context, id ID, data any) error { + return nil +} + +// Update adds the new version of the model to the model store and deletes the +// version of the model with oldID if the old and new IDs do not match. The new +// ID of the model is returned. +func (ms *ModelStore) Update( + ctx context.Context, + t modelType, + oldID ID, + tags map[string]string, + m any, +) (ID, error) { + return "", nil +} + +// Delete deletes the model with the given ID from the model store. +func (ms *ModelStore) Delete(ctx context.Context, id ID) error { + return nil +} diff --git a/src/internal/kopia/modeltype_string.go b/src/internal/kopia/modeltype_string.go new file mode 100644 index 000000000..1acf5e7b5 --- /dev/null +++ b/src/internal/kopia/modeltype_string.go @@ -0,0 +1,26 @@ +// Code generated by "stringer -type=modelType"; DO NOT EDIT. + +package kopia + +import "strconv" + +func _() { + // An "invalid array index" compiler error signifies that the constant values have changed. + // Re-run the stringer command to generate them again. + var x [1]struct{} + _ = x[UnknownModel-0] + _ = x[BackupOpModel-1] + _ = x[RestoreOpModel-2] + _ = x[RestorePointModel-3] +} + +const _modelType_name = "UnknownModelBackupOpModelRestoreOpModelRestorePointModel" + +var _modelType_index = [...]uint8{0, 12, 25, 39, 56} + +func (i modelType) String() string { + if i < 0 || i >= modelType(len(_modelType_index)-1) { + return "modelType(" + strconv.FormatInt(int64(i), 10) + ")" + } + return _modelType_name[_modelType_index[i]:_modelType_index[i+1]] +}