-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
389 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#pragma once | ||
|
||
#include <google/protobuf/service.h> | ||
|
||
namespace pain { | ||
|
||
class Controller : public google::protobuf::RpcController { | ||
public: | ||
void Reset() override {} | ||
bool Failed() const override { | ||
return false; | ||
} | ||
std::string ErrorText() const override { | ||
return ""; | ||
} | ||
void StartCancel() override {} | ||
void SetFailed(const std::string& reason) override {} | ||
bool IsCanceled() const override { | ||
return false; | ||
} | ||
void NotifyOnCancel(google::protobuf::Closure* callback) override {} | ||
|
||
void set_timeout_us(int timeout_us) { | ||
_timeout_us = timeout_us; | ||
} | ||
|
||
int timeout_us() const { | ||
return _timeout_us; | ||
} | ||
|
||
void set_direct_io(bool direct_io) { | ||
_direct_io = direct_io; | ||
} | ||
|
||
bool direct_io() const { | ||
return _direct_io; | ||
} | ||
|
||
private: | ||
int _timeout_us = 1000000; | ||
bool _direct_io = false; | ||
}; | ||
|
||
} // namespace pain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
|
||
#include <google/protobuf/service.h> | ||
|
||
namespace pain { | ||
|
||
class FileStreamImpl; | ||
class FileStream : public google::protobuf::RpcChannel { | ||
public: | ||
virtual ~FileStream(); | ||
void CallMethod(const google::protobuf::MethodDescriptor* method, | ||
google::protobuf::RpcController* controller, | ||
const google::protobuf::Message* request, | ||
google::protobuf::Message* response, | ||
google::protobuf::Closure* done) override; | ||
|
||
private: | ||
FileStreamImpl* _impl = nullptr; | ||
friend class FileSystem; | ||
}; | ||
|
||
} // namespace pain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
|
||
/* | ||
* FileStream is a file stream abstraction that provides append, read and seal operations. | ||
* Example: | ||
#include "pain/pain.h" | ||
int main() { | ||
auto fs = pain::FileSystem::create("list://192.168.10.1:8001,192.168.10.2:8001,192.168.10.3:8001"); | ||
auto file = fs->open("/tmp/hello.txt", O_CREAT | O_WRONLY); | ||
pain::core::FileService::Stub stub(file.get()); | ||
pain::Controller cntl; | ||
pain::core::AppendRequest request; | ||
pain::core::AppendResponse response; | ||
stub.append(&cntl, &request, &response, nullptr); | ||
if (cntl.Failed()) { | ||
std::cerr << "append failed: " << cntl.ErrorText() << std::endl; | ||
return 1; | ||
} | ||
std::cout << "append success, offset: " << response.offset() << std::endl; | ||
return 0; | ||
} | ||
*/ | ||
|
||
namespace pain { | ||
|
||
class FileStream; | ||
class FileSystem { | ||
public: | ||
FileSystem() = default; | ||
FileSystem(const FileSystem&) = delete; | ||
FileSystem(FileSystem&&) = default; | ||
FileSystem& operator=(const FileSystem&) = delete; | ||
FileSystem& operator=(FileSystem&&) = default; | ||
|
||
static std::shared_ptr<FileSystem> create(const char* uri); | ||
std::shared_ptr<FileStream> open(const char* path, int flags); | ||
}; | ||
|
||
} // namespace pain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#pragma once | ||
|
||
#include <fcntl.h> | ||
#include "pain/controller.h" | ||
#include "pain/core/pain.pb.h" | ||
#include "pain/file_stream.h" | ||
#include "pain/file_system.h" |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
syntax = "proto3"; | ||
package pain.core.deva; | ||
|
||
import "pain/core/common.proto"; | ||
|
||
option cc_generic_services = true; | ||
|
||
service DevaService { | ||
rpc open(OpenRequest) returns (OpenResponse); | ||
rpc close(CloseRequest) returns (CloseResponse); | ||
rpc remove(RemoveRequest) returns (RemoveResponse); | ||
rpc seal(SealRequest) returns (SealResponse); | ||
|
||
rpc create_chunk(CreateChunkRequest) returns (CreateChunkResponse); | ||
rpc append_chunk(AppendChunkRequest) returns (AppendChunkResponse); | ||
rpc seal_chunk(SealChunkRequest) returns (SealChunkResponse); | ||
rpc seal_and_new_chunk(SealAndNewChunkRequest) | ||
returns (SealAndNewChunkResponse); | ||
} | ||
|
||
message OpenRequest { | ||
string path = 1; | ||
int32 flags = 2; | ||
} | ||
|
||
message OpenResponse { | ||
UUID uuid = 1; | ||
} | ||
|
||
message CloseRequest { | ||
UUID uuid = 1; | ||
} | ||
|
||
message CloseResponse {} | ||
|
||
message RemoveRequest { | ||
string path = 1; | ||
} | ||
|
||
message RemoveResponse {} | ||
|
||
message SealRequest { | ||
UUID uuid = 1; | ||
} | ||
|
||
message SealResponse {} | ||
|
||
message SealAndNewChunkRequest { | ||
UUID uuid = 1; | ||
} | ||
|
||
message SealAndNewChunkResponse { | ||
UUID uuid = 1; | ||
} | ||
|
||
message CreateChunkRequest {} | ||
|
||
message CreateChunkResponse { | ||
UUID uuid = 1; | ||
} | ||
|
||
message AppendChunkRequest { | ||
UUID uuid = 1; | ||
uint64 offset = 2; | ||
uint32 length = 3; | ||
uint32 digest = 4; | ||
} | ||
|
||
message AppendChunkResponse { | ||
uint64 offset = 1; | ||
} | ||
|
||
message SealChunkRequest { | ||
UUID uuid = 1; | ||
} | ||
|
||
message SealChunkResponse {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
syntax = "proto3"; | ||
package pain.core; | ||
import "pain/core/common.proto"; | ||
|
||
option cc_generic_services = true; | ||
|
||
message AppendRequest {} | ||
|
||
message AppendResponse { | ||
uint64 offset = 1; | ||
} | ||
|
||
message ReadRequest { | ||
uint64 offset = 1; | ||
uint32 length = 2; | ||
} | ||
|
||
message ReadResponse {} | ||
|
||
message SealRequest { | ||
UUID uuid = 1; | ||
} | ||
|
||
message SealResponse {} | ||
|
||
message CloseRequest { | ||
UUID uuid = 1; | ||
} | ||
|
||
message CloseResponse {} | ||
|
||
service FileService { | ||
rpc append(AppendRequest) returns (AppendResponse); | ||
rpc read(ReadRequest) returns (ReadResponse); | ||
rpc seal(SealRequest) returns (SealResponse); | ||
rpc close(CloseRequest) returns (CloseResponse); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
target("core") | ||
set_kind("static") | ||
add_files("*.proto", {proto_rootdir = "protocols", proto_public = true}) | ||
add_rules("protobuf.cpp") | ||
add_packages("protobuf-cpp", {public = true}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include "pain/file_stream.h" | ||
#include "pain/file_stream_impl.h" | ||
|
||
namespace pain { | ||
|
||
FileStream::~FileStream() { | ||
delete _impl; | ||
} | ||
|
||
void FileStream::CallMethod(const google::protobuf::MethodDescriptor* method, | ||
google::protobuf::RpcController* controller, | ||
const google::protobuf::Message* request, | ||
google::protobuf::Message* response, | ||
google::protobuf::Closure* done) { | ||
_impl->CallMethod(method, controller, request, response, done); | ||
} | ||
|
||
} // namespace pain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include "pain/file_stream_impl.h" | ||
#include <brpc/controller.h> | ||
#include "pain/controller.h" | ||
#include "base/plog.h" | ||
#include "brpc/closure_guard.h" | ||
|
||
namespace pain { | ||
|
||
void FileStreamImpl::append(::google::protobuf::RpcController* controller, | ||
const ::pain::core::AppendRequest* request, | ||
::pain::core::AppendResponse* response, | ||
::google::protobuf::Closure* done) { | ||
pain::Controller* cntl = static_cast<pain::Controller*>(controller); | ||
PLOG_DEBUG(("desc", __func__)); | ||
brpc::ClosureGuard done_guard(done); | ||
} | ||
|
||
void FileStreamImpl::read(::google::protobuf::RpcController* controller, | ||
const ::pain::core::ReadRequest* request, | ||
::pain::core::ReadResponse* response, | ||
::google::protobuf::Closure* done) { | ||
pain::Controller* cntl = static_cast<pain::Controller*>(controller); | ||
PLOG_DEBUG(("desc", __func__)); | ||
brpc::ClosureGuard done_guard(done); | ||
} | ||
|
||
void FileStreamImpl::seal(::google::protobuf::RpcController* controller, | ||
const ::pain::core::SealRequest* request, | ||
::pain::core::SealResponse* response, | ||
::google::protobuf::Closure* done) { | ||
pain::Controller* cntl = static_cast<pain::Controller*>(controller); | ||
PLOG_DEBUG(("desc", __func__)); | ||
brpc::ClosureGuard done_guard(done); | ||
} | ||
|
||
void FileStreamImpl::close(::google::protobuf::RpcController* controller, | ||
const ::pain::core::CloseRequest* request, | ||
::pain::core::CloseResponse* response, | ||
::google::protobuf::Closure* done) { | ||
pain::Controller* cntl = static_cast<pain::Controller*>(controller); | ||
PLOG_DEBUG(("desc", __func__)); | ||
brpc::ClosureGuard done_guard(done); | ||
} | ||
|
||
} // namespace pain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#pragma once | ||
#include "pain/core/pain.pb.h" | ||
#include "base/uuid.h" | ||
|
||
namespace pain { | ||
|
||
class Controller; | ||
class AppendRequest; | ||
class AppendResponse; | ||
class ReadRequest; | ||
class ReadResponse; | ||
class FileStreamImpl : public pain::core::FileService { | ||
public: | ||
void append(::google::protobuf::RpcController* controller, | ||
const ::pain::core::AppendRequest* request, | ||
::pain::core::AppendResponse* response, | ||
::google::protobuf::Closure* done) override; | ||
void read(::google::protobuf::RpcController* controller, | ||
const ::pain::core::ReadRequest* request, | ||
::pain::core::ReadResponse* response, | ||
::google::protobuf::Closure* done) override; | ||
void seal(::google::protobuf::RpcController* controller, | ||
const ::pain::core::SealRequest* request, | ||
::pain::core::SealResponse* response, | ||
::google::protobuf::Closure* done) override; | ||
void close(::google::protobuf::RpcController* controller, | ||
const ::pain::core::CloseRequest* request, | ||
::pain::core::CloseResponse* response, | ||
::google::protobuf::Closure* done) override; | ||
|
||
private: | ||
~FileStreamImpl() = default; | ||
UUID _uuid; | ||
|
||
friend class FileStream; | ||
}; | ||
|
||
} // namespace pain |
Oops, something went wrong.