Skip to content

Commit

Permalink
Rename src -> miniraft
Browse files Browse the repository at this point in the history
  • Loading branch information
resetius committed Dec 27, 2024
1 parent 5574c69 commit f02d204
Show file tree
Hide file tree
Showing 19 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ endif ()
enable_testing()

add_subdirectory(coroio/coroio)
add_subdirectory(src)
add_subdirectory(miniraft)
add_subdirectory(examples)
add_subdirectory(test)
4 changes: 2 additions & 2 deletions examples/client.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <coroio/ssl.hpp>
#include <coroio/socket.hpp>

#include <messages.h>
#include <server.h>
#include <miniraft/messages.h>
#include <miniraft/server.h>

#include <vector>
#include <queue>
Expand Down
4 changes: 2 additions & 2 deletions examples/kv.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <string_view>

#include <server.h>
#include <persist.h>
#include <miniraft/server.h>
#include <miniraft/persist.h>

#include "kv.h"

Expand Down
2 changes: 1 addition & 1 deletion examples/kv.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <unordered_map>
#include <string>

#include <raft.h>
#include <miniraft/raft.h>

class TKv: public IRsm {
public:
Expand Down
6 changes: 3 additions & 3 deletions examples/server.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <coroio/all.hpp>
#include <csignal>
#include <timesource.h>
#include <raft.h>
#include <server.h>
#include <miniraft/timesource.h>
#include <miniraft/raft.h>
#include <miniraft/server.h>

void usage(const char* prog) {
std::cerr << prog << " --id myid --node ip:port:id [--node ip:port:id ...]" << "\n";
Expand Down
18 changes: 9 additions & 9 deletions examples/sql.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include <sqlite3.h>
#include <iostream>

#include <raft.h>
#include <persist.h>
#include <server.h>
#include <miniraft/raft.h>
#include <miniraft/persist.h>
#include <miniraft/server.h>

struct TSqlEntry {
uint32_t QuerySize = 0;
Expand All @@ -18,7 +18,7 @@ struct TWriteSql: public TCommandRequest, public TSqlEntry
{
};

struct TReadSql: public TCommandRequest, public TSqlEntry
struct TReadSql: public TCommandRequest, public TSqlEntry
{
};

Expand Down Expand Up @@ -66,7 +66,7 @@ TSql::TSql(const std::string& path, int serverId)
{
std::string dbPath = path + "." + std::to_string(serverId);
if (sqlite3_open(dbPath.c_str(), &Db) != SQLITE_OK) {
std::cerr << "Cannot open db: `" << dbPath << "', "
std::cerr << "Cannot open db: `" << dbPath << "', "
<< "error: " << sqlite3_errmsg(Db)
<< std::endl;
throw std::runtime_error("Cannot open db");
Expand All @@ -83,7 +83,7 @@ TSql::~TSql()
{
if (Db) {
if (sqlite3_close(Db) != SQLITE_OK) {
std::cerr << "Failed to close db, error:" << sqlite3_errmsg(Db) << std::endl;
std::cerr << "Failed to close db, error:" << sqlite3_errmsg(Db) << std::endl;
}
}
}
Expand Down Expand Up @@ -121,7 +121,7 @@ bool TSql::Execute(const std::string& q) {
std::cerr << "OK" << std::endl;
return true;
}

TMessageHolder<TMessage> TSql::Read(TMessageHolder<TCommandRequest> message, uint64_t index) {
auto readSql = message.Cast<TReadSql>();
if (!Execute(std::string(readSql->Query, readSql->QuerySize))) {
Expand Down Expand Up @@ -214,7 +214,7 @@ NNet::TFuture<void> Client(TPoller& poller, TSocket socket) {
size_t pos = strLine.find(' ');
auto prefix = strLine.substr(0, pos);
TMessageHolder<TMessage> req;

int flags = 0;
if (!strcasecmp(prefix.data(), "create") || !strcasecmp(prefix.data(), "insert") || !strcasecmp(prefix.data(), "update")) {
auto mes = NewHoldedMessage<TWriteSql>(sizeof(TWriteSql) + strLine.size());
Expand Down Expand Up @@ -252,7 +252,7 @@ void usage(const char* prog) {
exit(0);
}

int main(int argc, char** argv)
int main(int argc, char** argv)
{
signal(SIGPIPE, SIG_IGN);
std::vector<THost> hosts;
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt → miniraft/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ add_library(miniraft
persist.cpp
)

target_include_directories(miniraft PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(miniraft PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/..)
target_link_libraries(miniraft PUBLIC coroio)
target_compile_features(miniraft PUBLIC cxx_std_20)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions test/test_raft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#include <memory>
#include <functional>

#include <messages.h>
#include <raft.h>
#include <timesource.h>
#include <persist.h>
#include <miniraft/messages.h>
#include <miniraft/raft.h>
#include <miniraft/timesource.h>
#include <miniraft/persist.h>
#include <coroio/all.hpp>

#include <stdarg.h>
Expand Down Expand Up @@ -718,7 +718,7 @@ void test_disk_state_restore1(void**) {
assert_int_equal(state->CurrentTerm, 1);
assert_int_equal(state->VotedFor, 0);
assert_int_equal(state->LastLogIndex, 1);

std::vector<TMessageHolder<TLogEntry>> log2;
for (int i = 0; i < state->LastLogIndex; i++) {
auto entry = state->Get(i);
Expand Down Expand Up @@ -752,7 +752,7 @@ void test_disk_state_restore(void**) {
assert_int_equal(state->CurrentTerm, 10);
assert_int_equal(state->VotedFor, 2);
assert_int_equal(state->LastLogIndex, 9);

std::vector<TMessageHolder<TLogEntry>> log2;
for (int i = 0; i < state->LastLogIndex; i++) {
auto entry = state->Get(i);
Expand Down
8 changes: 4 additions & 4 deletions test/test_read_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#include <memory>
#include <functional>

#include <messages.h>
#include <raft.h>
#include <server.h>
#include <timesource.h>
#include <miniraft/messages.h>
#include <miniraft/raft.h>
#include <miniraft/server.h>
#include <miniraft/timesource.h>
#include <coroio/all.hpp>

#include <stdarg.h>
Expand Down

0 comments on commit f02d204

Please sign in to comment.