Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ require (
github.com/IBM-Cloud/bluemix-go v0.0.0-20220329045155-d2a8118ac5c7
github.com/aws/aws-sdk-go v1.40.39
github.com/codeskyblue/go-sh v0.0.0-20170112005953-b097669b1569
github.com/coreos/etcd v3.3.27+incompatible
github.com/golang/mock v1.4.4
github.com/google/uuid v1.1.2
github.com/hashicorp/go-version v1.2.1
github.com/libopenstorage/openstorage v8.0.1-0.20210603043922-faf638fed3e5+incompatible
github.com/libopenstorage/secrets v0.0.0-20210908194121-a1d19aa9713a
github.com/oracle/oci-go-sdk/v65 v65.13.1
github.com/pborman/uuid v1.2.0
github.com/portworx/kvdb v0.0.0-20230326003017-21a38cf82d4b
github.com/portworx/sched-ops v1.20.4-rc1.0.20211217234328-ead591c0f22d
github.com/prometheus/client_golang v1.9.0
github.com/sirupsen/logrus v1.8.1
Expand Down Expand Up @@ -74,6 +76,7 @@ require (
github.com/prometheus/procfs v0.2.0 // indirect
github.com/sony/gobreaker v0.5.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.2.0 // indirect
go.opencensus.io v0.22.4 // indirect
golang.org/x/crypto v0.6.0 // indirect
golang.org/x/net v0.6.0 // indirect
Expand Down
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ github.com/coreos/bbolt v1.3.3/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkE
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/etcd v3.3.12+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/etcd v3.3.27+incompatible h1:QIudLb9KeBsE5zyYxd1mjzRSkzLg9Wf9QlRwFgd6oTA=
github.com/coreos/etcd v3.3.27+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
github.com/coreos/go-oidc v2.0.0+incompatible/go.mod h1:CgnwVTmzoESiwO9qyAFEMiHoZ1nMCKZlZ9V6mm3/LKc=
github.com/coreos/go-oidc v2.1.0+incompatible/go.mod h1:CgnwVTmzoESiwO9qyAFEMiHoZ1nMCKZlZ9V6mm3/LKc=
Expand Down Expand Up @@ -1223,7 +1225,12 @@ github.com/portworx/kvdb v0.0.0-20190105022415-cccaa09abfc9/go.mod h1:Q8YyrNDvPp
github.com/portworx/kvdb v0.0.0-20191223203141-f42097b1fcd8/go.mod h1:Q8YyrNDvPp3DVF96BDcQuaC7fAYUCuUX+l58S7OnD2M=
github.com/portworx/kvdb v0.0.0-20200311180812-b2c72382d652/go.mod h1:Q8YyrNDvPp3DVF96BDcQuaC7fAYUCuUX+l58S7OnD2M=
github.com/portworx/kvdb v0.0.0-20200723230726-2734b7f40194/go.mod h1:Q8YyrNDvPp3DVF96BDcQuaC7fAYUCuUX+l58S7OnD2M=
github.com/portworx/kvdb v0.0.0-20200929023115-b312c7519467 h1:jkqzdbOnejgSN5HG/FLt4enNrozWT/K+nlmaRm3P1II=
github.com/portworx/kvdb v0.0.0-20200929023115-b312c7519467/go.mod h1:Q8YyrNDvPp3DVF96BDcQuaC7fAYUCuUX+l58S7OnD2M=
github.com/portworx/kvdb v0.0.0-20221027170939-f1680e5db6db h1:ycu2xaymWoDkRgIUadkX1XjlKs0RWHtkk5HI/JjF59g=
github.com/portworx/kvdb v0.0.0-20221027170939-f1680e5db6db/go.mod h1:Q8YyrNDvPp3DVF96BDcQuaC7fAYUCuUX+l58S7OnD2M=
github.com/portworx/kvdb v0.0.0-20230326003017-21a38cf82d4b h1:nP+m9tYQv2cWbN9wAwjlhJU9FZRs7GaYszhLJBLAg/I=
github.com/portworx/kvdb v0.0.0-20230326003017-21a38cf82d4b/go.mod h1:Q8YyrNDvPp3DVF96BDcQuaC7fAYUCuUX+l58S7OnD2M=
github.com/portworx/px-backup-api v1.0.1-0.20200915150042-274508e876ef/go.mod h1:puy7YVXeb6glot1vVCIePIiRLSwB//+rFtN2ZjvXeEw=
github.com/portworx/pxc v0.33.0/go.mod h1:Tl7hf4K2CDr0XtxzM08sr9H/KsMhscjf9ydb+MnT0U4=
github.com/portworx/sched-ops v0.0.0-20200123020607-b0799c4686f5/go.mod h1:yb1ypNIiZQAmM7xAWGzO6dydwl/+vNC0WjUm5IvHUEY=
Expand Down
126 changes: 126 additions & 0 deletions store/store.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package store

import (
"fmt"
"github.com/portworx/kvdb"
"time"
)

// PX specific scheduler constants
const (
// Kubernetes identifies kubernetes as the scheduler
Kubernetes = "kubernetes"
)

// Params is the parameters to use for the Store object
type Params struct {
// Kv is the bootstrap kvdb instance
Kv kvdb.Kvdb
// InternalKvdb indicates if PX is using internal kvdb or not
InternalKvdb bool
// SchedulerType indicates the platform pods are running on. e.g Kubernetes
SchedulerType string
}

// Lock identifies a lock taken over CloudDrive store
type Lock struct {
// Key is the name on which the lock is acquired.
// This is used by the callers for logging purpose. Hence public
Key string
// Name of the owner who acquired the lock
owner string
// true if this lock was acquired using LockWithKey() interface
lockedWithKey bool
// lock structure as returned from the KVDB interface
internalLock interface{}
}

// KeyDoesNotExist is error type when the key does not exist
type KeyDoesNotExist struct {
Key string
}

func (e *KeyDoesNotExist) Error() string {
return fmt.Sprintf("key %s does not exist", e.Key)
}

// KeyExists is error type when the key already exist in store
type KeyExists struct {
// Key that exists
Key string
// Message is an optional message to the user
Message string
}

func (e *KeyExists) Error() string {
errMsg := fmt.Sprintf("key %s already exists in store", e.Key)
if len(e.Message) > 0 {
errMsg += " " + e.Message
}
return errMsg
}

// Store provides a set of APIs to CloudDrive to store its metadata
// in a persistent store
type Store interface {
// Lock locks the cloud drive store for a node to perform operations
Lock(owner string) (*Lock, error)
// Unlock unlocks the cloud drive store
Unlock(storeLock *Lock) error
// LockWithKey locks the cloud drive store with an arbitrary key
LockWithKey(owner, key string) (*Lock, error)
// IsKeyLocked checks if the specified key is currently locked
IsKeyLocked(key string) (bool, string, error)
// CreateKey creates the given key with the value
CreateKey(key string, value []byte) error
// PutKey updates the given key with the value
PutKey(key string, value []byte) error
Comment thread
nrevanna marked this conversation as resolved.
// GetKey returns the value for the given key
GetKey(key string) ([]byte, error)
// DeleteKey deletes the given key
DeleteKey(key string) error
// EnumerateWithKeyPrefix enumerates all keys in the store that begin with the given key
EnumerateWithKeyPrefix(key string) ([]string, error)
}

// GetStoreWithParams returns instance for Store
// kv: bootstrap kvdb
// schedulerType: node scheduler type e.g Kubernetes
// internalKvdb: If the cluster is configured to have internal kvdb
// name: Name for the store
// lockTryDuration: Total time to try acquiring the lock for
// lockHoldTimeout: Once a lock is acquired, if it's held beyond this time, there will be panic
func GetStoreWithParams(
kv kvdb.Kvdb,
schedulerType string,
internalKvdb bool,
name string,
lockTryDuration time.Duration,
lockHoldTimeout time.Duration,
) (Store, error) {
if len(name) == 0 {
return nil, fmt.Errorf("name required to create Store")
}
var (
s Store
err error
)

if internalKvdb && schedulerType == Kubernetes {
s, _, err = newK8sStoreWithParams(name, lockTryDuration, lockHoldTimeout)
} else if internalKvdb && kv == nil {
return nil, fmt.Errorf("bootstrap kvdb cannot be empty")
} else {
// Two cases:
// internal kvdb && kv is not nil
// external kvdb
if !internalKvdb {
if kvdb.Instance() == nil {
return nil, fmt.Errorf("kvdb is not initialized")
}
kv = kvdb.Instance()
}
s, err = newKVStoreWithParams(kv, name, lockTryDuration, lockHoldTimeout)
}
return s, err
}
Loading