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

【WIP】feat: Pd init #47

Open
wants to merge 17 commits into
base: unstable
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat: init pd
  • Loading branch information
panlei-coder committed Jul 27, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 8504e6520dbd7573bbf5432e5cc88c496af124a6
41 changes: 41 additions & 0 deletions src/pd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright (c) 2024-present, Qihoo, Inc. All rights reserved.
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.

ADD_CUSTOM_COMMAND(
OUTPUT "${PROTO_OUTPUT_DIR}/pd.pb.cc"
DEPENDS protobuf
COMMAND ${PROTOBUF_PROTOC}
ARGS -I ${CMAKE_CURRENT_SOURCE_DIR}
--cpp_out ${PROTO_OUTPUT_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/pd.proto
)
ADD_LIBRARY(pd_pb STATIC "${PROTO_OUTPUT_DIR}/pd.pb.cc")
SET(LIBRARY_OUTPUT_PATH ${PLIB_INSTALL_DIR})
TARGET_INCLUDE_DIRECTORIES(pd_pb PRIVATE ${PROTOBUF_INCLUDE_DIR})

FILE(GLOB PD_SRC
"${CMAKE_CURRENT_SOURCE_DIR}/*.cc"
)

SET(LIBRARY_OUTPUT_PATH ${PLIB_INSTALL_DIR})

ADD_LIBRARY(pd ${PD_SRC})

TARGET_INCLUDE_DIRECTORIES(pd
PRIVATE ${PROJECT_SOURCE_DIR}/src
PRIVATE ${rocksdb_SOURCE_DIR}/include
PRIVATE ${BRAFT_INCLUDE_DIR}
PRIVATE ${BRPC_INCLUDE_DIR}
PRIVATE ${PROTO_OUTPUT_DIR}
)

IF (CMAKE_SYSTEM_NAME STREQUAL "Linux")
SET(PD_LIB ${PD_LIB} rt)
ENDIF ()

SET(LIBRARY_OUTPUT_PATH ${PLIB_INSTALL_DIR})
ADD_DEPENDENCIES(pd protobuf pd_pb)
TARGET_LINK_LIBRARIES(pd praft dl fmt storage pstd braft brpc ssl crypto zlib protobuf leveldb gflags rocksdb z ${PD_LIB})
SET_TARGET_PROPERTIES(pd PROPERTIES LINKER_LANGUAGE CXX)
98 changes: 98 additions & 0 deletions src/pd/pd.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
syntax="proto3";
package pikiwidb;
option cc_generic_services = true;

message GetClusterInfoRequest {
};

message GetClusterInfoResponse {
repeated Store store = 1;
};

message Store {
required int64 store_id = 1;
required string ip = 2;
required int32 port = 3;
required StoreState state = 4;
repeated Region region = 5;
};

message Region {
required int64 region_id = 1;
optional string start_key = 2;
optional string end_key = 3;
repeated RegionEpoch region_epoch = 4;
repeated Peer peers = 5;
};

message RegionEpoch {
required int64 conf_change_ver = 1; // conf change version
required int64 region_ver = 2; // region version (split or merge)
};

enum StoreState {
UP = 0;
OFFLINE = 1;
TOMBSTONE = 2;
};

message CreateAllRegionsRequest {
required int64 regions_count = 1;
required int32 region_peers_count = 2;
repeated RegionOptions regionOptions = 3;
};

message CreateAllRegionsResponse {
};

message DeleteAllRegionsRequest {
};

message DeleteAllRegionsResponse {
};

message AddStoreRequest {
required string ip = 1;
required int32 port = 2;
};

message AddStoreResponse {
required int64 store_id = 1;
};

message RemoveStoreRequest {
required int64 store_id = 1;
};

message AddStoreResponse {
};

message OpenPDSchedulingRequest {
};

message OpenPDSchedulingResponse {
required bool is_open = 1;
};

message ClosePDSchedulingRequest {
};

message ClosePDSchedulingResponse {
required bool is_close = 1;
};

service PDService {
rpc CreateAllRegions(CreateAllRegionsRequest) returns (CreateAllRegionsResponse);

rpc DeleteAllRegions(DeleteAllRegionsRequest) returns (DeleteAllRegionsResponse);

rpc AddStore(AddStoreRequest) returns (AddStoreResponse);

rpc RemoveStore(RemoveStoreRequest) returns (RemoveStoreResponse);

rpc GetClusterInfo(GetClusterInfoRequest) returns (GetClusterInfoResponse);

rpc OpenPDScheduling(OpenPDSchedulingRequest) returns (OpenPDSchedulingResponse);

rpc ClosePDScheduling(ClosePDSchedulingRequest) returns (ClosePDSchedulingResponse);
};
8 changes: 8 additions & 0 deletions src/pd/pd_server.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright (c) 2024-present, Qihoo, Inc. All rights reserved.
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

namespace pikiwidb {} // namespace pikiwidb
33 changes: 33 additions & 0 deletions src/pd/pd_server.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2024-present, Qihoo, Inc. All rights reserved.
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

#pragma once

#include <string>
#include <thread>
#include <vector>

namespace pikiwidb {

// PD options
class PlacementDriverOptions {
private:
bool fake_ = false; // Standalone or hybrid deployment
std::string pd_group_id_; // PD Raft Group ID
std::string initial_pd_sever_list; // the list of initial pd server
};

// PD
class PlacementDriverServer {
private:
PlacementDriverServiceImpl placementDriverService_; // pd rpc service
int db_id_; // pd region, store meta
std::vector<std::thread> threads_; // for exploration, information gathering functions
bool is_started_; // mark whether the fragment is started
};

} // namespace pikiwidb
8 changes: 8 additions & 0 deletions src/pd/pd_service.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright (c) 2024-present, Qihoo, Inc. All rights reserved.
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

namespace pikiwidb {} // namespace pikiwidb
19 changes: 19 additions & 0 deletions src/pd/pd_service.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2024-present, Qihoo, Inc. All rights reserved.
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

#pragma once

#include "praft.h"

namespace pikiwidb {

class PlacementDriverServiceImpl : public PDService {
private:
PRaft* praft_;
};

} // namespace pikiwidb