Skip to content

Commit

Permalink
first version change to pika
Browse files Browse the repository at this point in the history
  • Loading branch information
baotiao committed Mar 30, 2015
1 parent 1b6f59b commit 3a848f0
Show file tree
Hide file tree
Showing 29 changed files with 381 additions and 324 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CXX = g++
CXXFLAGS = -Wall -W -DDEBUG -g -O0 -D__XDEBUG__ -fPIC -Wno-unused-function
OBJECT = tick
OBJECT = pika
SRC_DIR = ./src
THIRD_PATH = ./third/
OUTPUT = ./output
Expand Down
8 changes: 4 additions & 4 deletions conf/pika.conf
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Tick port
# Pika port
port : 9221
# Thread Number
thread_num : 2
# Tick log path
# Pika log path
log_path : ./log/
# Tick glog level
# Pika glog level
log_level : 1
# Tick heartbeat port
# Pika heartbeat port
hb_port : 9222
# The seed node
seed :
Expand Down
8 changes: 4 additions & 4 deletions conf/pika1.conf
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Tick port
# Pika port
port : 9231
# Thread Number
thread_num : 2
# Tick log path
# Pika log path
log_path : ./log/
# Tick glog level
# Pika glog level
log_level : 1
# Tick heartbeat port
# Pika heartbeat port
hb_port : 9232
# The seed node
seed : 127.0.0.1
Expand Down
6 changes: 3 additions & 3 deletions include/base_conf.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef __BASE_CONF_H__
#define __BASE_CONF_H__

#include "tick_define.h"
#include "pika_define.h"
#include "stdlib.h"
#include "stdio.h"
#include "xdebug.h"
Expand All @@ -21,8 +21,8 @@ class BaseConf

private:
struct ConfItem {
char name[TICK_WORD_SIZE];
char value[TICK_WORD_SIZE];
char name[PIKA_WORD_SIZE];
char value[PIKA_WORD_SIZE];
};

ConfItem *item_;
Expand Down
8 changes: 4 additions & 4 deletions include/hb_context.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef __TICK_HB_CONTEXT_H__
#define __TICK_HB_CONTEXT_H_
#ifndef __PIKA_HB_CONTEXT_H__
#define __PIKA_HB_CONTEXT_H_

#include "tick_define.h"
#include "pika_define.h"
#include "fcntl.h"
#include "tick_define.h"
#include "pika_define.h"
#include "status.h"
#include "csapp.h"

Expand Down
18 changes: 15 additions & 3 deletions include/pika.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,31 @@
#define __PIKA_H__

#include <stdio.h>
#include <pthread.h>

class TickServer;
class TickHb;
class PikaWorker;
class PikaHb;

class Pika
{
public:
Pika();
~Pika();

int RunHb();
static void* StartHb(void* args);
int RunWorker();
static void* StartWorker(void* args);

PikaWorker *PikaWorker_() { return pikaWorker_; }
PikaHb *PikaHb_() { return pikaHb_; }

private:

TickWork
pthread_t workerId_, hbId_;
PikaWorker *pikaWorker_;
PikaHb *pikaHb_;


// No copying allowed
Pika(const Pika&);
Expand Down
16 changes: 8 additions & 8 deletions include/pika_conf.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#ifndef __TICK_CONF_H__
#define __TICK_CONF_H__
#include "tick_define.h"
#ifndef __PIKA_CONF_H__
#define __PIKA_CONF_H__
#include "pika_define.h"
#include "stdlib.h"
#include "stdio.h"
#include "xdebug.h"
#include "status.h"
#include "base_conf.h"

class TickConf : public BaseConf
class PikaConf : public BaseConf
{
public:
TickConf(const char* path);
PikaConf(const char* path);

/*
* The repetion return variable warpper
Expand All @@ -29,11 +29,11 @@ class TickConf : public BaseConf
int port_;
int hb_port_;
int thread_num_;
char log_path_[TICK_WORD_SIZE];
char log_path_[PIKA_WORD_SIZE];
int log_level_;
char seed_[TICK_WORD_SIZE];
char seed_[PIKA_WORD_SIZE];
int seed_port_;
char data_path_[TICK_WORD_SIZE];
char data_path_[PIKA_WORD_SIZE];
};

#endif
30 changes: 15 additions & 15 deletions include/pika_conn.h
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
#ifndef __TICK_CONN_H__
#define __TICK_CONN_H__
#ifndef __PIKA_CONN_H__
#define __PIKA_CONN_H__

#include "status.h"
#include "csapp.h"
#include "tick_thread.h"
#include "tick_define.h"
#include "pika_thread.h"
#include "pika_define.h"

class TickConn
class PikaConn
{
public:
TickConn(int fd);
TickConn();
~TickConn();
PikaConn(int fd);
PikaConn();
~PikaConn();
/*
* Set the fd to nonblock && set the flag_ the the fd flag
*/
bool SetNonblock();
void InitPara();
Status TickReadBuf();
Status PikaReadBuf();
void DriveMachine();
int TickGetRequest();
int TickSendReply();
int PikaGetRequest();
int PikaSendReply();
void set_fd(int fd) { fd_ = fd; };
int flags() { return flags_; };

Expand All @@ -34,9 +34,9 @@ class TickConn
/*
* These functions parse the message from client
*/
Status TickReadHeader(rio_t *rio);
Status TickReadCode(rio_t *rio);
Status TickReadPacket(rio_t *rio);
Status PikaReadHeader(rio_t *rio);
Status PikaReadCode(rio_t *rio);
Status PikaReadPacket(rio_t *rio);


Status BuildObuf(int32_t opcode, const int packet_len);
Expand All @@ -55,7 +55,7 @@ class TickConn
char* wbuf_;
int32_t wbuf_len_;
int32_t wbuf_pos_;
TickThread *thread_;
PikaThread *thread_;
};

#endif
22 changes: 11 additions & 11 deletions src/pika_define.cc → include/pika_define.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#ifndef __TICK_DEFINE_H__
#define __TICK_DEFINE_H__
#ifndef __PIKA_DEFINE_H__
#define __PIKA_DEFINE_H__

#define TICK_MAX_CLIENTS 10240
#define TICK_MAX_MESSAGE 1024
#define TICK_THREAD_NUM 16
#define TICK_HEARTBEAT_THREAD 1
#define PIKA_MAX_CLIENTS 10240
#define PIKA_MAX_MESSAGE 1024
#define PIKA_THREAD_NUM 16
#define PIKA_HEARTBEAT_THREAD 1
#define HB_MAX_BUFFER 1024
#define TICK_NAME_LEN 1024
#define PIKA_NAME_LEN 1024

/*
* The pb head and code length
Expand Down Expand Up @@ -76,12 +76,12 @@ enum CommandCode {
kHbSendRet = 602,
};
/*
* define the macro in tick_conf
* define the macro in pika_conf
*/

#define TICK_WORD_SIZE 1024
#define TICK_LINE_SIZE 1024
#define TICK_CONF_MAX_NUM 1024
#define PIKA_WORD_SIZE 1024
#define PIKA_LINE_SIZE 1024
#define PIKA_CONF_MAX_NUM 1024


/*
Expand Down
26 changes: 13 additions & 13 deletions include/pika_epoll.h
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
#ifndef __TICK_EPOLL_H__
#define __TICK_EPOLL_H__
#ifndef __PIKA_EPOLL_H__
#define __PIKA_EPOLL_H__
#include "sys/epoll.h"
#include "status.h"

typedef struct TickFiredEvent {
typedef struct PikaFiredEvent {
int fd_;
int mask_;
}TickFiredEvent;
}PikaFiredEvent;

class TickEpoll
class PikaEpoll
{

public:
TickEpoll();
~TickEpoll();
Status TickAddEvent(int fd, int mask);
void TickDelEvent(int fd);
Status TickModEvent(int fd, int oMask, int mask);
PikaEpoll();
~PikaEpoll();
Status PikaAddEvent(int fd, int mask);
void PikaDelEvent(int fd);
Status PikaModEvent(int fd, int oMask, int mask);

int TickPoll();
int PikaPoll();

TickFiredEvent *firedevent() { return firedevent_; }
PikaFiredEvent *firedevent() { return firedevent_; }

private:

int epfd_;
struct epoll_event *events_;
int timeout_;
TickFiredEvent *firedevent_;
PikaFiredEvent *firedevent_;
};

#endif
36 changes: 18 additions & 18 deletions include/pika_hb.h
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
#ifndef __TICK_HB_H__
#define __TICK_HB_H__
#ifndef __PIKA_HB_H__
#define __PIKA_HB_H__

#include "status.h"
#include "csapp.h"
#include "tick_thread.h"
#include "tick_define.h"
#include "tick_epoll.h"
#include "pika_thread.h"
#include "pika_define.h"
#include "pika_epoll.h"

#include <vector>

class HbContext;
class TickConn;
class PikaConn;

class TickHb
class PikaHb
{
public:
TickHb();
~TickHb();
PikaHb();
~PikaHb();

/*
* run the main heartbeat process
*/
void RunHb();
void Start();


void CreatePulse();
Expand Down Expand Up @@ -62,7 +62,7 @@ class TickHb
*/
void DebugSrv();

TickEpoll *tickEpoll_;
PikaEpoll *pikaEpoll_;


/*
Expand All @@ -74,23 +74,23 @@ class TickHb
/*
* This is the thread that deal with heartbeat
*/
TickThread *hbThread_[TICK_HEARTBEAT_THREAD];
PikaThread *hbThread_[PIKA_HEARTBEAT_THREAD];

pthread_t thread_id_;

/*
* The server side of connect to other tick node
* The server side of connect to other pika node
*/
std::vector<TickConn *> hbConns_;
std::vector<PikaConn *> hbConns_;

/*
* The client side of context to other tick node
* The client side of context to other pika node
*/
std::vector<HbContext *> hbContexts_;

/*
* The heartbeat servaddr and port information
* get the servaddr_ from the tick_server
* get the servaddr_ from the pika_worker
* get the port from config file
*/
int sockfd_;
Expand All @@ -105,8 +105,8 @@ class TickHb
/*
* Don't allow copy construct and copy assign construct
*/
TickHb(const TickHb&);
void operator=(const TickHb&);
PikaHb(const PikaHb&);
void operator=(const PikaHb&);
};

#endif
Loading

0 comments on commit 3a848f0

Please sign in to comment.