Skip to content

Commit

Permalink
implement prototype of agent grpc server (#2492)
Browse files Browse the repository at this point in the history
* implement prototype of agent grpc server

* make format

---------

Co-authored-by: Hiroto Funakoshi <hiroto.funakoshi.hiroto@gmail.com>
  • Loading branch information
kmrmt and hlts2 committed May 23, 2024
1 parent 8a36249 commit 57c9376
Show file tree
Hide file tree
Showing 13 changed files with 563 additions and 12 deletions.
108 changes: 104 additions & 4 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions rust/bin/agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ edition = "2021"

[dependencies]
ngt = { version = "0.1.0", path = "../../libs/ngt" }
prost = "0.12.4"
proto = { version = "0.1.0", path = "../../libs/proto" }
tokio = { version = "1.37.0", features = ["full"] }
tokio-stream = { version = "0.1.15", features = ["full"] }
tonic = "0.11.0"
27 changes: 27 additions & 0 deletions rust/bin/agent/src/handler.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// Copyright (C) 2019-2024 vdaas.org vald team <vald@vdaas.org>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
mod common;
mod index;
mod insert;
mod remove;
mod search;
mod update;
mod upsert;

#[derive(Default, Debug)]
pub struct Agent {

}
21 changes: 21 additions & 0 deletions rust/bin/agent/src/handler/common.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Copyright (C) 2019-2024 vdaas.org vald team <vald@vdaas.org>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#[macro_export]
macro_rules! stream_type {
($t:ty) => {
std::pin::Pin<Box<dyn tokio_stream::Stream<Item = std::result::Result<$t, tonic::Status>> + Send>>
};
}
60 changes: 60 additions & 0 deletions rust/bin/agent/src/handler/index.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// Copyright (C) 2019-2024 vdaas.org vald team <vald@vdaas.org>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
use proto::{
core::v1::agent_server,
payload::v1::{control, info, object, Empty},
};

#[tonic::async_trait]
impl agent_server::Agent for super::Agent {
async fn create_index(
&self,
request: tonic::Request<control::CreateIndexRequest>,
) -> std::result::Result<tonic::Response<Empty>, tonic::Status> {
todo!()
}

async fn save_index(
&self,
request: tonic::Request<Empty>,
) -> std::result::Result<tonic::Response<Empty>, tonic::Status> {
todo!()
}

#[doc = " Represent the creating and saving index RPC.\n"]
async fn create_and_save_index(
&self,
request: tonic::Request<control::CreateIndexRequest>,
) -> std::result::Result<tonic::Response<Empty>, tonic::Status> {
todo!()
}

#[doc = " Represent the RPC to get the agent index information.\n"]
async fn index_info(
&self,
request: tonic::Request<Empty>,
) -> std::result::Result<tonic::Response<info::index::Count>, tonic::Status> {
todo!()
}

#[doc = " Represent the RPC to get the vector metadata. This RPC is mainly used for index correction process\n"]
async fn get_timestamp(
&self,
request: tonic::Request<object::GetTimestampRequest>,
) -> std::result::Result<tonic::Response<object::Timestamp>, tonic::Status> {
todo!()
}
}
47 changes: 47 additions & 0 deletions rust/bin/agent/src/handler/insert.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// Copyright (C) 2019-2024 vdaas.org vald team <vald@vdaas.org>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
use proto::{
payload::v1::{insert, object},
vald::v1::insert_server,
};
#[tonic::async_trait]
impl insert_server::Insert for super::Agent {
async fn insert(
&self,
request: tonic::Request<insert::Request>,
) -> std::result::Result<tonic::Response<object::Location>, tonic::Status> {
todo!()
}

#[doc = " Server streaming response type for the StreamInsert method."]
type StreamInsertStream = crate::stream_type!(object::StreamLocation);

#[doc = " A method to add new multiple vectors by bidirectional streaming.\n"]
async fn stream_insert(
&self,
request: tonic::Request<tonic::Streaming<insert::Request>>,
) -> std::result::Result<tonic::Response<Self::StreamInsertStream>, tonic::Status> {
todo!()
}

#[doc = " A method to add new multiple vectors in a single request.\n"]
async fn multi_insert(
&self,
request: tonic::Request<insert::MultiRequest>,
) -> std::result::Result<tonic::Response<object::Locations>, tonic::Status> {
todo!()
}
}
Loading

0 comments on commit 57c9376

Please sign in to comment.