Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow kv services implemented without list support #850

Merged
merged 1 commit into from
Oct 12, 2022
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
27 changes: 26 additions & 1 deletion src/adapters/kv/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ use std::fmt::Debug;
use std::io::Result;

use async_trait::async_trait;
use flagset::FlagSet;
use futures::Stream;

use crate::AccessorCapability;
use crate::AccessorMetadata;
use crate::Scheme;

/// KvAdapter is the adapter to underlying kv services.
Expand Down Expand Up @@ -58,14 +61,20 @@ pub const INODE_ROOT: u64 = 0;
pub struct Metadata {
scheme: Scheme,
name: String,
capabilities: FlagSet<AccessorCapability>,
}

impl Metadata {
/// Create a new KeyValueAccessorMetadata.
pub fn new(scheme: Scheme, name: &str) -> Self {
pub fn new(
scheme: Scheme,
name: &str,
capabilities: impl Into<FlagSet<AccessorCapability>>,
) -> Self {
Self {
scheme,
name: name.to_string(),
capabilities: capabilities.into(),
}
}

Expand All @@ -78,6 +87,22 @@ impl Metadata {
pub fn name(&self) -> &str {
&self.name
}

/// Get the capabilities.
pub fn capabilities(&self) -> FlagSet<AccessorCapability> {
self.capabilities
}
}

impl From<Metadata> for AccessorMetadata {
fn from(m: Metadata) -> AccessorMetadata {
let mut am = AccessorMetadata::default();
am.set_name(m.name());
am.set_scheme(m.scheme());
am.set_capabilities(m.capabilities());

am
}
}

/// KeyStream represents a stream of keys.
Expand Down
9 changes: 1 addition & 8 deletions src/adapters/kv/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ use crate::path::get_basename;
use crate::path::get_parent;
use crate::path::normalize_root;
use crate::Accessor;
use crate::AccessorCapability;
use crate::AccessorMetadata;
use crate::BytesReader;
use crate::ObjectEntry;
Expand Down Expand Up @@ -96,15 +95,9 @@ where
S: Adapter,
{
fn metadata(&self) -> AccessorMetadata {
let mut am = AccessorMetadata::default();
let mut am: AccessorMetadata = self.kv.metadata().into();
am.set_root(&self.root);
am.set_capabilities(
AccessorCapability::Read | AccessorCapability::Write | AccessorCapability::List,
);

let kvam = self.kv.metadata();
am.set_scheme(kvam.scheme());
am.set_name(kvam.name());
am
}

Expand Down
7 changes: 6 additions & 1 deletion src/services/memory/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use parking_lot::Mutex;
use crate::adapters::kv;
use crate::adapters::kv::next_prefix;
use crate::Accessor;
use crate::AccessorCapability;
use crate::Scheme;

/// Builder for memory backend
Expand Down Expand Up @@ -60,7 +61,11 @@ pub struct Adapter {
#[async_trait]
impl kv::Adapter for Adapter {
fn metadata(&self) -> kv::Metadata {
kv::Metadata::new(Scheme::Memory, &format!("{:?}", &self.inner as *const _))
kv::Metadata::new(
Scheme::Memory,
&format!("{:?}", &self.inner as *const _),
AccessorCapability::Read | AccessorCapability::Write | AccessorCapability::List,
)
}

async fn next_id(&self) -> Result<u64> {
Expand Down
2 changes: 2 additions & 0 deletions src/services/redis/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use crate::adapters::kv;
use crate::error::new_other_backend_error;
use crate::path::normalize_root;
use crate::Accessor;
use crate::AccessorCapability;
use crate::Scheme;

const DEFAULT_REDIS_ENDPOINT: &str = "tcp://127.0.0.1:6379";
Expand Down Expand Up @@ -280,6 +281,7 @@ impl kv::Adapter for Adapter {
kv::Metadata::new(
Scheme::Redis,
&self.client.get_connection_info().addr.to_string(),
AccessorCapability::Read | AccessorCapability::Write | AccessorCapability::List,
)
}

Expand Down