Skip to content

Commit

Permalink
[fix] compile in gcc11
Browse files Browse the repository at this point in the history
  • Loading branch information
xiedao0yy committed Mar 20, 2024
1 parent 4c7af53 commit 08e64ad
Show file tree
Hide file tree
Showing 77 changed files with 12,172 additions and 39 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2623,3 +2623,5 @@ plugin/polarx_rpc/protobuf_lite/
extra/IS/consensus/bu/
extra/IS/consensus/output/
extra/IS/dependency/easy/src/bu/
build
.cache
21 changes: 10 additions & 11 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ elif [ x"$build_type" = x"Debug" ]; then
fi

if [ x"$mach_type" = x"x86_64" ]; then # X86
COMMON_FLAGS="$COMMON_FLAGS -fno-omit-frame-pointer -D_GLIBCXX_USE_CXX11_ABI=0"
COMMON_FLAGS="$COMMON_FLAGS -fno-omit-frame-pointer -D_GLIBCXX_USE_CXX11_ABI=1"
elif [ x"$mach_type" = x"aarch64" ]; then # ARM64
# ARM64 needn't more flags
COMMON_FLAGS="$COMMON_FLAGS" #"-static-libstdc++ -static-libgcc"
Expand Down Expand Up @@ -253,14 +253,8 @@ else
exit 1
fi

if [ x"$mach_type" = x"aarch64" ]; then # ARM64
CC=gcc
CXX=g++
else # X86
CC=/opt/rh/devtoolset-7/root/usr/bin/gcc
CXX=/opt/rh/devtoolset-7/root/usr/bin/g++
source /opt/rh/devtoolset-7/enable
fi
CC=gcc
CXX=g++

# Update choosed version
gcc_version=`$CC --version | awk 'NR==1 {print $3}'`
Expand Down Expand Up @@ -321,10 +315,15 @@ else
-DDOWNLOAD_BOOST=0 \
-DMYSQL_SERVER_SUFFIX="$server_suffix" \
-DENABLE_DOWNLOADS=0 \
-DWITH_UNIT_TESTS=0
-DWITH_UNIT_TESTS=0 \
-DWITHOUT_IS_UT=1 \
-DWITH_PROTOBUF3=1 \
-DBUILD_AS_EXTERNAL=1 \
-DMINIMAL_MAKE=1 \
-DWITH_POLARX=OFF
fi

make -j `getconf _NPROCESSORS_ONLN`
make -j$(nproc)


if [ $with_initialize -eq 1 ]; then
Expand Down
59 changes: 59 additions & 0 deletions cluster/consensus/client_service.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/************************************************************************
*
* Copyright (c) 2016 Alibaba.com, Inc. All Rights Reserved
* $Id: client_service.h,v 1.0 08/23/2016 10:02:33 AM yingqiang.zyq([email protected]) $
*
************************************************************************/

/**
* @file client_service.h
* @author yingqiang.zyq([email protected])
* @date 08/23/2016 10:02:33 AM
* @version 1.0
* @brief
*
**/

#ifndef client_service_INC
#define client_service_INC

#include <cstring>
#include <string>
#include <map>
#include "easyNet.h"

namespace alisql {

class Paxos;

/**
* @class ClientService
*
* @brief
*
**/
class ClientService {
public:
ClientService () {};
virtual ~ClientService () {};

const std::string &get(const std::string &key) {return map_[key];}
void set(const std::string &key, const std::string &val);
const std::string set(const char *strKeyVal, uint64_t len);
int serviceProcess(easy_request_t *r, void *args);

protected:
std::map<const std::string, const std::string> map_;


private:
ClientService ( const ClientService &other ); // copy constructor
const ClientService& operator = ( const ClientService &other ); // assignment operator

};/* end of class ClientService */



} //namespace alisql

#endif //#ifndef client_service_INC
91 changes: 91 additions & 0 deletions cluster/consensus/consensus.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/************************************************************************
*
* Copyright (c) 2016 Alibaba.com, Inc. All Rights Reserved
* $Id: consensus.h,v 1.0 07/27/2016 11:42:30 AM yingqiang.zyq([email protected]) $
*
************************************************************************/

/**
* @file consensus.h
* @author yingqiang.zyq([email protected])
* @date 07/27/2016 11:42:30 AM
* @version 1.0
* @brief the interface class of Consensus
*
**/

#ifndef cluster_consensus_INC
#define cluster_consensus_INC

#include "paxos.pb.h"
#include "service.h"

namespace alisql {


/**
* @class Consensus
*
* @brief interface of consensus algorithm module
*
**/
class Consensus {
public:
enum MsgType {
RequestVote= 0,
RequestVoteResponce,
AppendLog,
AppendLogResponce,
LeaderCommand,
LeaderCommandResponce,
ClusterIdNotMatch,
OptimisticHeartbeat,
PreCheckFailedResponce
};

typedef enum CCOpType {
CCNoOp= 0,
CCMemberOp= 1,
CCLearnerOp= 2,
CCAddNode= 3,
CCDelNode= 4,
CCConfigureNode= 5,
CCDowngradeNode= 6,
CCSyncLearnerAll= 7,
CCAddLearnerAutoChange= 8,
CCLeaderTransfer= 9
} CCOpTypeT;

Consensus () {};
virtual ~Consensus () {};

virtual int onRequestVote(PaxosMsg *msg, PaxosMsg *rsp) = 0;
virtual int onAppendLog(PaxosMsg *msg, PaxosMsg *rsp) = 0;
virtual int onRequestVoteResponce(PaxosMsg *msg) = 0;
virtual int onAppendLogSendFail(PaxosMsg *msg, uint64_t *newId) = 0;
virtual int onAppendLogResponce(PaxosMsg *msg) = 0;
virtual int requestVote(bool force) = 0;
virtual uint64_t replicateLog(LogEntry &entry) = 0;
virtual int appendLog(const bool needLock) = 0;
virtual int onLeaderCommand(PaxosMsg *msg, PaxosMsg *rsp) = 0;
virtual int onLeaderCommandResponce(PaxosMsg *msg) = 0;
virtual int onClusterIdNotMatch(PaxosMsg *msg) = 0;
virtual int onMsgPreCheck(PaxosMsg *msg, PaxosMsg *rsp) = 0;
virtual int onMsgPreCheckFailed(PaxosMsg *msg) = 0;
virtual uint64_t getClusterId() = 0;
virtual int setClusterId(uint64_t ci) = 0;
virtual bool isShutdown() = 0;

protected:

private:
Consensus ( const Consensus &other ); // copy constructor
const Consensus& operator = ( const Consensus &other ); // assignment operator

};/* end of class Consensus */



} //namespace alisql

#endif //#ifndef cluster_consensus_INC
17 changes: 17 additions & 0 deletions cluster/consensus/crc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once
#include <stddef.h>
#include <stdint.h>

namespace alisql {

// Return the crc32c of concat(A, data[0,n-1]) where init_crc is the
// crc32c of some string A. Extend() is often used to maintain the
// crc32c of a stream of data.
extern uint32_t Extend(uint32_t init_crc, const char* data, size_t n);

// Return the crc32c of data[0,n-1]
inline uint32_t calculateCRC32(const char* data, size_t n) {
return Extend(0, data, n);
}

} // namespace alisql
118 changes: 118 additions & 0 deletions cluster/consensus/easyNet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/************************************************************************
*
* Copyright (c) 2016 Alibaba.com, Inc. All Rights Reserved
* $Id: easyNet.h,v 1.0 07/27/2016 03:51:26 PM yingqiang.zyq([email protected]) $
*
************************************************************************/

/**
* @file easyNet.h
* @author yingqiang.zyq([email protected])
* @date 07/27/2016 03:51:26 PM
* @version 1.0
* @brief
*
**/

#ifndef cluster_easynet_INC
#define cluster_easynet_INC

#include <map>
#include <memory>
#include <mutex>
#include <easy_io.h>
#include <easy_atomic.h>
#include "net.h"

namespace alisql {

typedef struct NetPacket {
uint type;
uint64_t packetId;
void *msg;
int len;
char *data;
char buffer[0];
} NetPacket;

const uint NetPacketTypeNet= 0;
const uint NetPacketTypeAsync= 1;

const uint64_t NetPacketHeaderSize= sizeof(uint64_t);

// global variable to count easy pool memory usage
extern easy_atomic_t easy_pool_alloc_byte;

/**
* @class EasyNet
*
* @brief
*
**/
class EasyNet : public Net{
public:
EasyNet (uint64_t num= 2, const uint64_t sessionTimeout= 300, bool memory_usage_count= false);
virtual ~EasyNet () {};

virtual int init(void *ptr= NULL);
virtual int start(int port);
virtual int shutdown();
virtual int stop();

/* TODO here we should use a general handler. */
virtual easy_addr_t createConnection(const std::string &addr, NetServerRef server, uint64_t timeout= 1000, uint64_t index= 0);
virtual void disableConnection(easy_addr_t addr);
virtual int sendPacket(easy_addr_t addr, const char *buf, uint64_t len, uint64_t id= 0);
virtual int sendPacket(easy_addr_t addr, const std::string& buf, uint64_t id= 0);
virtual int resendPacket(easy_addr_t addr, void *ptr, uint64_t id= 0);
virtual int setRecvPacketCallback(void *handler);

void setWorkPool(easy_thread_pool_t* tp) {std::lock_guard<std::mutex> lg(lock_); workPool_= tp;}
void incRecived() {__sync_fetch_and_add(&reciveCnt_, 1);}
uint64_t getReciveCnt() {return reciveCnt_;}
// bool isShutDown() {return isShutdown_;} /* not used now. */

uint64_t getAddrKey(easy_addr_t addr);
NetServerRef getConnData(easy_addr_t addr, bool locked = false);
void setConnData(easy_addr_t addr, NetServerRef server);
void delConnDataById(uint64_t id);
NetServerRef getConnDataAndSetFail(easy_connection_t *c, bool isFail);
uint64_t getConnCnt() {return connStatus_.size();}
void setSessionTimeout(uint64_t t) { sessionTimeout_= t; }

static void tryFreeMsg(NetPacket *np);

/* Handler functions. */
static int reciveProcess(easy_request_t *r);
static void *paxosDecode(easy_message_t *m);
static int paxosEncode(easy_request_t *r, void *data);
static int onConnected(easy_connection_t *c);
static int onDisconnected(easy_connection_t *c);
static int onClientCleanup(easy_request_t *r, void *apacket);
static uint64_t getPacketId(easy_connection_t *c, void *data);

protected:
/* libeasy member. */
easy_io_t *eio_;
easy_io_handler_pt clientHandler_;
easy_io_handler_pt serverHandler_;
easy_thread_pool_t *workPool_;

/*TODO we shoud use shared_ptr here. */
std::map<uint64_t, NetServerRef> connStatus_;
std::mutex lock_;

uint64_t reciveCnt_;
bool isShutdown_;
uint64_t sessionTimeout_;

private:
EasyNet ( const EasyNet &other ); // copy constructor
const EasyNet& operator = ( const EasyNet &other ); // assignment operator

};/* end of class EasyNet */



} //namespace alisql
#endif //#ifndef cluster_easynet_INC
Loading

0 comments on commit 08e64ad

Please sign in to comment.