[VOL-5417] Add GetWithPrefix and GetWithPrefixKeysOnly functions for the kvclient Interface
Change-Id: I446f414d157d5794de4302450fc075073243b564
Signed-off-by: pnalmas <praneeth.nalmas@radisys.com>
diff --git a/pkg/db/backend.go b/pkg/db/backend.go
index dc24fe6..bb99970 100644
--- a/pkg/db/backend.go
+++ b/pkg/db/backend.go
@@ -87,6 +87,7 @@
func (b *Backend) makePath(ctx context.Context, key string) string {
path := fmt.Sprintf("%s/%s", b.PathPrefix, key)
+ logger.Debugw(ctx, "make-path", log.Fields{"key": key, "path": path})
return path
}
@@ -145,7 +146,7 @@
}
// Extract Alive status of Kvstore based on type of error
-func (b *Backend) isErrorIndicatingAliveKvstore(ctx context.Context, err error) bool {
+func (b *Backend) isErrorIndicatingAliveKvstore(err error) bool {
// Alive unless observed an error indicating so
alive := true
@@ -188,7 +189,7 @@
pair, err := b.Client.List(ctx, formattedPath)
- b.updateLiveness(ctx, b.isErrorIndicatingAliveKvstore(ctx, err))
+ b.updateLiveness(ctx, b.isErrorIndicatingAliveKvstore(err))
return pair, err
}
@@ -203,7 +204,37 @@
pair, err := b.Client.Get(ctx, formattedPath)
- b.updateLiveness(ctx, b.isErrorIndicatingAliveKvstore(ctx, err))
+ b.updateLiveness(ctx, b.isErrorIndicatingAliveKvstore(err))
+
+ return pair, err
+}
+
+// GetWithPrefix retrieves one or more items that match the specified key prefix
+func (b *Backend) GetWithPrefix(ctx context.Context, prefixKey string) (map[string]*kvstore.KVPair, error) {
+ span, ctx := log.CreateChildSpan(ctx, "kvs-get-with-prefix")
+ defer span.Finish()
+
+ formattedPath := b.makePath(ctx, prefixKey)
+ logger.Debugw(ctx, "get-entries-matching-prefix-key", log.Fields{"key": prefixKey, "path": formattedPath})
+
+ pair, err := b.Client.GetWithPrefix(ctx, formattedPath)
+
+ b.updateLiveness(ctx, b.isErrorIndicatingAliveKvstore(err))
+
+ return pair, err
+}
+
+// GetWithPrefixKeysOnly retrieves one or more keys that match the specified key prefix
+func (b *Backend) GetWithPrefixKeysOnly(ctx context.Context, prefixKey string) ([]string, error) {
+ span, ctx := log.CreateChildSpan(ctx, "kvs-get-with-prefix")
+ defer span.Finish()
+
+ formattedPath := b.makePath(ctx, prefixKey)
+ logger.Debugw(ctx, "get-keys-entries-matching-prefix-key", log.Fields{"key": prefixKey, "path": formattedPath})
+
+ pair, err := b.Client.GetWithPrefixKeysOnly(ctx, formattedPath)
+
+ b.updateLiveness(ctx, b.isErrorIndicatingAliveKvstore(err))
return pair, err
}
@@ -218,7 +249,7 @@
err := b.Client.Put(ctx, formattedPath, value)
- b.updateLiveness(ctx, b.isErrorIndicatingAliveKvstore(ctx, err))
+ b.updateLiveness(ctx, b.isErrorIndicatingAliveKvstore(err))
return err
}
@@ -233,7 +264,7 @@
err := b.Client.Delete(ctx, formattedPath)
- b.updateLiveness(ctx, b.isErrorIndicatingAliveKvstore(ctx, err))
+ b.updateLiveness(ctx, b.isErrorIndicatingAliveKvstore(err))
return err
}
@@ -247,7 +278,7 @@
err := b.Client.DeleteWithPrefix(ctx, formattedPath)
- b.updateLiveness(ctx, b.isErrorIndicatingAliveKvstore(ctx, err))
+ b.updateLiveness(ctx, b.isErrorIndicatingAliveKvstore(err))
return err
}