├── .clang-format ├── .gitignore ├── .gitmodules ├── .travis.yml ├── Dockerfile ├── LICENSE ├── Makefile ├── README.md ├── README.zh_cn.md ├── build.sh ├── data └── clear_data.sh ├── docker-entrypoint.sh ├── etc ├── consumer_server.0.conf ├── consumer_server.1.conf ├── consumer_server.2.conf ├── consumerconfig.conf ├── globalconfig.conf ├── lock_server.0.conf ├── lock_server.1.conf ├── lock_server.2.conf ├── lockconfig.conf ├── scheduler_server.0.conf ├── scheduler_server.1.conf ├── scheduler_server.2.conf ├── schedulerconfig.conf ├── simpleconfig.conf ├── store_server.0.conf ├── store_server.1.conf ├── store_server.2.conf ├── storeconfig.conf └── topicconfig.conf ├── log └── clear_log.sh ├── makefile.mk ├── phxqueue ├── comm.h ├── comm │ ├── breakpoint.cpp │ ├── breakpoint.h │ ├── errdef.h │ ├── handler.h │ ├── logger.cpp │ ├── logger.h │ ├── masterclient.cpp │ ├── masterclient.h │ ├── multiproc.cpp │ ├── multiproc.h │ ├── notifierpool.cpp │ ├── notifierpool.h │ ├── proto │ │ └── comm.proto │ ├── resourcepool.h │ ├── utils.h │ └── utils │ │ ├── addr_util.cpp │ │ ├── addr_util.h │ │ ├── benchmark_util.cpp │ │ ├── benchmark_util.h │ │ ├── co_util.cpp │ │ ├── co_util.h │ │ ├── concurrent_util.h │ │ ├── file_util.cpp │ │ ├── file_util.h │ │ ├── hash_util.cpp │ │ ├── hash_util.h │ │ ├── load_util.cpp │ │ ├── load_util.h │ │ ├── memory_util.cpp │ │ ├── memory_util.h │ │ ├── other_util.cpp │ │ ├── other_util.h │ │ ├── string_util.cpp │ │ ├── string_util.h │ │ ├── time_util.cpp │ │ └── time_util.h ├── config.h ├── config │ ├── baseconfig.h │ ├── consumerconfig.cpp │ ├── consumerconfig.h │ ├── globalconfig.cpp │ ├── globalconfig.h │ ├── lockconfig.cpp │ ├── lockconfig.h │ ├── proto │ │ ├── consumerconfig.proto │ │ ├── globalconfig.proto │ │ ├── lockconfig.proto │ │ ├── schedulerconfig.proto │ │ ├── storeconfig.proto │ │ └── topicconfig.proto │ ├── schedulerconfig.cpp │ ├── schedulerconfig.h │ ├── storeconfig.cpp │ ├── storeconfig.h │ ├── topicconfig.cpp │ ├── topicconfig.h │ ├── utils.h │ └── utils │ │ ├── consumer_group_util.cpp │ │ ├── consumer_group_util.h │ │ ├── pub_util.cpp │ │ └── pub_util.h ├── consumer.h ├── consumer │ ├── consumer.cpp │ ├── consumer.h │ ├── consumeroption.h │ ├── freqman.cpp │ ├── freqman.h │ ├── hblock.cpp │ └── hblock.h ├── lock.h ├── lock │ ├── cleanthread.cpp │ ├── cleanthread.h │ ├── keepmasterthread.cpp │ ├── keepmasterthread.h │ ├── lock.cpp │ ├── lock.h │ ├── lockdb.cpp │ ├── lockdb.h │ ├── lockmasterclient.h │ ├── lockmgr.cpp │ ├── lockmgr.h │ ├── lockoption.h │ ├── locksm.cpp │ ├── locksm.h │ ├── lockutils.cpp │ ├── lockutils.h │ └── proto │ │ └── lock.proto ├── plugin.h ├── plugin │ ├── breakpointfactory.cpp │ ├── breakpointfactory.h │ ├── configfactory.cpp │ ├── configfactory.h │ ├── logger_google.cpp │ ├── logger_google.h │ ├── logger_sys.cpp │ └── logger_sys.h ├── producer.h ├── producer │ ├── batchhelper.cpp │ ├── batchhelper.h │ ├── producer.cpp │ ├── producer.h │ ├── produceroption.h │ ├── selector.cpp │ └── selector.h ├── scheduler.h ├── scheduler │ ├── keepmasterthread.cpp │ ├── keepmasterthread.h │ ├── loadbalancethread.cpp │ ├── loadbalancethread.h │ ├── scheduler.cpp │ ├── scheduler.h │ ├── schedulermasterclient.h │ ├── schedulermgr.cpp │ ├── schedulermgr.h │ └── scheduleroption.h ├── store.h ├── store │ ├── basemgr.cpp │ ├── basemgr.h │ ├── checkpointstat.cpp │ ├── checkpointstat.h │ ├── keepmasterthread.cpp │ ├── keepmasterthread.h │ ├── keepsyncthread.cpp │ ├── keepsyncthread.h │ ├── proto │ │ └── store.proto │ ├── store.cpp │ ├── store.h │ ├── storemasterclient.h │ ├── storemeta.cpp │ ├── storemeta.h │ ├── storeoption.h │ ├── storesm.cpp │ ├── storesm.h │ ├── syncctrl.cpp │ └── syncctrl.h └── test │ ├── check_config.cpp │ ├── check_config.h │ ├── simpleconsumer.cpp │ ├── simpleconsumer.h │ ├── simplehandler.cpp │ ├── simplehandler.h │ ├── simpleproducer.cpp │ ├── simpleproducer.h │ ├── simplescheduler.cpp │ ├── simplescheduler.h │ ├── test_config.cpp │ ├── test_config.h │ ├── test_config_main.cpp │ ├── test_configfactory.cpp │ ├── test_configfactory.h │ ├── test_consistent_hash_main.cpp │ ├── test_consumer_main.cpp │ ├── test_get_queues_by_pub_id_main.cpp │ ├── test_lock_main.cpp │ ├── test_log.cpp │ ├── test_log.h │ ├── test_log_main.cpp │ ├── test_main.cpp │ ├── test_notifierpool_main.cpp │ ├── test_plugin_main.cpp │ ├── test_producer.cpp │ ├── test_producer.h │ ├── test_producer_main.cpp │ ├── test_scheduler_main.cpp │ └── test_store_main.cpp ├── phxqueue_phxrpc ├── app │ ├── lock │ │ ├── Makefile │ │ ├── lock.proto │ │ ├── lock_client.conf │ │ ├── lock_client.cpp │ │ ├── lock_client.h │ │ ├── lock_client_uthread.cpp │ │ ├── lock_client_uthread.h │ │ ├── lock_main.cpp │ │ ├── lock_server.conf │ │ ├── lock_server_config.cpp │ │ ├── lock_server_config.h │ │ ├── lock_service_impl.cpp │ │ ├── lock_service_impl.h │ │ ├── lock_tool_impl.cpp │ │ ├── lock_tool_impl.h │ │ ├── lock_tool_main.cpp │ │ ├── phxrpc_lock_dispatcher.cpp │ │ ├── phxrpc_lock_dispatcher.h │ │ ├── phxrpc_lock_service.cpp │ │ ├── phxrpc_lock_service.h │ │ ├── phxrpc_lock_stub.cpp │ │ ├── phxrpc_lock_stub.h │ │ ├── phxrpc_lock_tool.cpp │ │ └── phxrpc_lock_tool.h │ ├── scheduler │ │ ├── Makefile │ │ ├── phxrpc_scheduler.cpp │ │ ├── phxrpc_scheduler.h │ │ ├── phxrpc_scheduler_dispatcher.cpp │ │ ├── phxrpc_scheduler_dispatcher.h │ │ ├── phxrpc_scheduler_service.cpp │ │ ├── phxrpc_scheduler_service.h │ │ ├── phxrpc_scheduler_stub.cpp │ │ ├── phxrpc_scheduler_stub.h │ │ ├── phxrpc_scheduler_tool.cpp │ │ ├── phxrpc_scheduler_tool.h │ │ ├── scheduler.proto │ │ ├── scheduler_client.conf │ │ ├── scheduler_client.cpp │ │ ├── scheduler_client.h │ │ ├── scheduler_client_uthread.cpp │ │ ├── scheduler_client_uthread.h │ │ ├── scheduler_main.cpp │ │ ├── scheduler_server.conf │ │ ├── scheduler_server_config.cpp │ │ ├── scheduler_server_config.h │ │ ├── scheduler_service_impl.cpp │ │ ├── scheduler_service_impl.h │ │ ├── scheduler_tool_impl.cpp │ │ ├── scheduler_tool_impl.h │ │ └── scheduler_tool_main.cpp │ └── store │ │ ├── Makefile │ │ ├── phxrpc_store_dispatcher.cpp │ │ ├── phxrpc_store_dispatcher.h │ │ ├── phxrpc_store_service.cpp │ │ ├── phxrpc_store_service.h │ │ ├── phxrpc_store_stub.cpp │ │ ├── phxrpc_store_stub.h │ │ ├── phxrpc_store_tool.cpp │ │ ├── phxrpc_store_tool.h │ │ ├── store.proto │ │ ├── store_client.conf │ │ ├── store_client.cpp │ │ ├── store_client.h │ │ ├── store_client_uthread.cpp │ │ ├── store_client_uthread.h │ │ ├── store_main.cpp │ │ ├── store_server.conf │ │ ├── store_server_config.cpp │ │ ├── store_server_config.h │ │ ├── store_service_impl.cpp │ │ ├── store_service_impl.h │ │ ├── store_tool_impl.cpp │ │ ├── store_tool_impl.h │ │ └── store_tool_main.cpp ├── comm.h ├── comm │ ├── fileconfig.cpp │ ├── fileconfig.h │ ├── fileloader.cpp │ ├── fileloader.h │ ├── ini2pb.cpp │ ├── ini2pb.h │ ├── iniparser.cpp │ └── iniparser.h ├── config.h ├── config │ ├── baseconfig.h │ ├── consumerconfig.h │ ├── globalconfig.h │ ├── lockconfig.h │ ├── schedulerconfig.h │ ├── storeconfig.h │ └── topicconfig.h ├── consumer.h ├── consumer │ ├── consumer.cpp │ ├── consumer.h │ ├── consumer_server.conf │ ├── consumerserverconfig.conf │ ├── consumerserverconfig.h │ └── proto │ │ └── consumerserverconfig.proto ├── plugin.h ├── plugin │ ├── configfactory.cpp │ └── configfactory.h ├── producer.h ├── producer │ ├── producer.cpp │ └── producer.h ├── scheduler.h ├── scheduler │ ├── scheduler.cpp │ └── scheduler.h └── test │ ├── config_check_main.cpp │ ├── consumer_main.cpp │ ├── echo_handler.cpp │ ├── echo_handler.h │ ├── etc │ ├── consumerconfig.conf │ ├── globalconfig.conf │ ├── lockconfig.conf │ ├── schedulerconfig.conf │ ├── simpleconfig.conf │ ├── storeconfig.conf │ └── topicconfig.conf │ ├── producer_benchmark.cpp │ ├── producer_benchmark.h │ ├── producer_benchmark_main.cpp │ ├── proto │ └── simpleconfig.proto │ ├── simpleconfig.h │ ├── test_get_main.cpp │ ├── test_load_config_main.cpp │ ├── test_producer_echo_main.cpp │ ├── test_rpc_config.cpp │ ├── test_rpc_config.h │ ├── test_rpc_config_main.cpp │ └── test_selector_main.cpp └── third_party └── autoinstall.sh /.gitignore: -------------------------------------------------------------------------------- 1 | # Directories 2 | bin/ 3 | lib/ 4 | build/ 5 | data/ 6 | log/ 7 | 8 | # Protocol Buffers 9 | *.pb.cc 10 | *.pb.h 11 | 12 | # Prerequisites 13 | *.d 14 | 15 | # Compiled Object files 16 | *.slo 17 | *.lo 18 | *.o 19 | *.obj 20 | 21 | # Precompiled Headers 22 | *.gch 23 | *.pch 24 | 25 | # Compiled Dynamic libraries 26 | *.so 27 | *.dylib 28 | *.dll 29 | 30 | # Fortran module files 31 | *.mod 32 | *.smod 33 | 34 | # Compiled Static libraries 35 | *.lai 36 | *.la 37 | *.a 38 | *.lib 39 | 40 | # Executables 41 | *.exe 42 | *.out 43 | *.app 44 | 45 | # gtags 46 | GPATH 47 | GRTAGS 48 | GTAGS -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "third_party/colib"] 2 | path = third_party/colib 3 | url = https://github.com/Tencent/libco 4 | [submodule "third_party/protobuf"] 5 | path = third_party/protobuf 6 | url = https://github.com/google/protobuf 7 | [submodule "third_party/gflags"] 8 | path = third_party/gflags 9 | url = https://github.com/gflags/gflags 10 | [submodule "third_party/glog"] 11 | path = third_party/glog 12 | url = https://github.com/google/glog 13 | [submodule "third_party/leveldb"] 14 | path = third_party/leveldb 15 | url = https://github.com/google/leveldb 16 | [submodule "third_party/phxpaxos"] 17 | path = third_party/phxpaxos 18 | url = https://github.com/Tencent/phxpaxos 19 | [submodule "third_party/phxrpc"] 20 | path = third_party/phxrpc 21 | url = https://github.com/Tencent/phxrpc 22 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | dist: trusty 3 | 4 | language: cpp 5 | compiler: g++ 6 | git: 7 | submodules: false 8 | script: 9 | - bash build.sh 10 | notifications: 11 | email: true 12 | branches: 13 | only: 14 | - /.*/ 15 | 16 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM buildpack-deps 2 | 3 | COPY . /phxqueue 4 | 5 | 6 | RUN apt-get update \ 7 | && apt-get install -y cmake --no-install-recommends \ 8 | && apt-get install -y python-pip \ 9 | && pip install protobuf \ 10 | && cd /phxqueue \ 11 | && ./build.sh \ 12 | && find . -name "*.o" | xargs rm 13 | 14 | ENV WORK_DIR=/phxqueue 15 | 16 | WORKDIR $WORK_DIR 17 | 18 | VOLUME $WORK_DIR/data 19 | 20 | ENV PATH="$WORK_DIR/bin:$PATH" 21 | 22 | #COPY docker-entrypoint.sh /usr/local/bin/ 23 | ENTRYPOINT ["docker-entrypoint.sh"] 24 | 25 | #EXPOSE 5100 5200 5300 26 | 27 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e # exit immediately on error 4 | set -x # display all commands 5 | 6 | git submodule update --init --recursive 7 | 8 | (cd third_party && bash ./autoinstall.sh) 9 | 10 | make 11 | 12 | -------------------------------------------------------------------------------- /data/clear_data.sh: -------------------------------------------------------------------------------- 1 | clear_store_dir () { 2 | cd $1/ 3 | rm -f sync 4 | rm -rf nodedb/ 5 | rm -rf cp/ 6 | ls -lhasp 7 | cd - 8 | } 9 | 10 | clear_lock_dir () { 11 | cd $1/ 12 | rm -rf nodedb/ 13 | rm -rf mirror/ 14 | ls -lhasp 15 | cd - 16 | } 17 | 18 | clear_store_dir 'store.0' 19 | clear_store_dir 'store.1' 20 | clear_store_dir 'store.2' 21 | 22 | clear_lock_dir 'lock.0' 23 | clear_lock_dir 'lock.1' 24 | clear_lock_dir 'lock.2' 25 | 26 | -------------------------------------------------------------------------------- /docker-entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -x 4 | ulimit -Sn 4096 5 | ulimit -n 4096 6 | 7 | cd /phxqueue/ 8 | bin/store_main -d -c etc/store_server.0.conf 9 | bin/store_main -d -c etc/store_server.1.conf 10 | bin/store_main -d -c etc/store_server.2.conf 11 | bin/consumer_main -d -c etc/consumer_server.0.conf 12 | bin/consumer_main -d -c etc/consumer_server.1.conf 13 | bin/consumer_main -d -c etc/consumer_server.2.conf 14 | bin/lock_main -d -c etc/lock_server.0.conf 15 | bin/lock_main -d -c etc/lock_server.1.conf 16 | bin/lock_main -d -c etc/lock_server.2.conf 17 | bin/scheduler_main -d -c etc/scheduler_server.0.conf 18 | bin/scheduler_main -d -c etc/scheduler_server.1.conf 19 | bin/scheduler_main -d -c etc/scheduler_server.2.conf 20 | 21 | #ps -ef | grep store_main 22 | #ps -ef | grep lock_main 23 | #ps -ef | grep scheduler_main 24 | #ps -ef | grep consumer_main 25 | 26 | exec tail -f /dev/null 27 | 28 | -------------------------------------------------------------------------------- /etc/consumer_server.0.conf: -------------------------------------------------------------------------------- 1 | { 2 | "consumer": 3 | { 4 | "ip": "127.0.0.1", 5 | "port": "8001", 6 | "topic": "test", 7 | "nproc": "2", 8 | "lock_path_base": "phxqueueconsumer.lock.", 9 | "phxqueue_global_config_path": "./etc/globalconfig.conf", 10 | "shm_key_base": "53460" 11 | }, 12 | "log": 13 | { 14 | "path": "./log/consumer.0", 15 | "level": "0" 16 | } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /etc/consumer_server.1.conf: -------------------------------------------------------------------------------- 1 | { 2 | "consumer": 3 | { 4 | "ip": "127.0.0.1", 5 | "port": "8002", 6 | "topic": "test", 7 | "nproc": "2", 8 | "lock_path_base": "phxqueueconsumer.lock.", 9 | "phxqueue_global_config_path": "./etc/globalconfig.conf", 10 | "shm_key_base": "53461" 11 | }, 12 | "log": 13 | { 14 | "path": "./log/consumer.1", 15 | "level": "0" 16 | } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /etc/consumer_server.2.conf: -------------------------------------------------------------------------------- 1 | { 2 | "consumer": 3 | { 4 | "ip": "127.0.0.1", 5 | "port": "8003", 6 | "topic": "test", 7 | "nproc": "2", 8 | "lock_path_base": "phxqueueconsumer.lock.", 9 | "phxqueue_global_config_path": "./etc/globalconfig.conf", 10 | "shm_key_base": "53462" 11 | }, 12 | "log": 13 | { 14 | "path": "./log/consumer.2", 15 | "level": "0" 16 | } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /etc/consumerconfig.conf: -------------------------------------------------------------------------------- 1 | { 2 | "consumers": 3 | [ 4 | { 5 | "addr": 6 | { 7 | "ip": "127.0.0.1", 8 | "port": "8001" 9 | }, 10 | "scale": "1000" 11 | }, 12 | { 13 | "addr": 14 | { 15 | "ip": "127.0.0.1", 16 | "port": "8002" 17 | }, 18 | "scale": "1000" 19 | }, 20 | { 21 | "addr": 22 | { 23 | "ip": "127.0.0.1", 24 | "port": "8003" 25 | }, 26 | "scale": "1000" 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /etc/globalconfig.conf: -------------------------------------------------------------------------------- 1 | { 2 | "topic_infos": 3 | [ 4 | { 5 | "topic_id": "1000", 6 | "topic_name": "test", 7 | "topic_config_path": "etc/topicconfig.conf", 8 | "consumer_config_path": "etc/consumerconfig.conf", 9 | "store_config_path": "etc/storeconfig.conf", 10 | "scheduler_config_path": "etc/schedulerconfig.conf", 11 | "lock_config_path": "etc/lockconfig.conf", 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /etc/lock_server.0.conf: -------------------------------------------------------------------------------- 1 | # lock_server.conf 2 | # 3 | # Generated by phxrpc_pb2server from lock.proto 4 | # 5 | # 6 | 7 | [Server] 8 | BindIP = 127.0.0.1 9 | Port = 7100 10 | MaxThreads = 10 11 | IOThreadCount = 1 12 | PackageName = phxqueue_phxrpc.lock 13 | MaxConnections = 800000 14 | MaxQueueLength = 20480 15 | FastRejectThresholdMS = 200 16 | FastRejectAdjustRate = 5 17 | 18 | [Log] 19 | LogDir = ./log/lock.0 20 | LogLevel = 0 21 | 22 | [ServerTimeout] 23 | SocketTimeoutMS = 120000 24 | 25 | [Lock] 26 | Topic = test 27 | DataDirPath = ./data/lock.0 28 | PhxQueueGlobalConfigPath = ./etc/globalconfig.conf 29 | PaxosPort = 7101 30 | NrGroup = 1 31 | 32 | -------------------------------------------------------------------------------- /etc/lock_server.1.conf: -------------------------------------------------------------------------------- 1 | # lock_server.conf 2 | # 3 | # Generated by phxrpc_pb2server from lock.proto 4 | # 5 | # 6 | 7 | [Server] 8 | BindIP = 127.0.0.1 9 | Port = 7200 10 | MaxThreads = 10 11 | IOThreadCount = 1 12 | PackageName = phxqueue_phxrpc.lock 13 | MaxConnections = 800000 14 | MaxQueueLength = 20480 15 | FastRejectThresholdMS = 200 16 | FastRejectAdjustRate = 5 17 | 18 | [Log] 19 | LogDir = ./log/lock.1 20 | LogLevel = 0 21 | 22 | [ServerTimeout] 23 | SocketTimeoutMS = 120000 24 | 25 | [Lock] 26 | Topic = test 27 | DataDirPath = ./data/lock.1 28 | PhxQueueGlobalConfigPath = ./etc/globalconfig.conf 29 | PaxosPort = 7201 30 | NrGroup = 1 31 | 32 | -------------------------------------------------------------------------------- /etc/lock_server.2.conf: -------------------------------------------------------------------------------- 1 | # lock_server.conf 2 | # 3 | # Generated by phxrpc_pb2server from lock.proto 4 | # 5 | # 6 | 7 | [Server] 8 | BindIP = 127.0.0.1 9 | Port = 7300 10 | MaxThreads = 10 11 | IOThreadCount = 1 12 | PackageName = phxqueue_phxrpc.lock 13 | MaxConnections = 800000 14 | MaxQueueLength = 20480 15 | FastRejectThresholdMS = 200 16 | FastRejectAdjustRate = 5 17 | 18 | [Log] 19 | LogDir = ./log/lock.2 20 | LogLevel = 0 21 | 22 | [ServerTimeout] 23 | SocketTimeoutMS = 120000 24 | 25 | [Lock] 26 | Topic = test 27 | DataDirPath = ./data/lock.2 28 | PhxQueueGlobalConfigPath = ./etc/globalconfig.conf 29 | PaxosPort = 7301 30 | NrGroup = 1 31 | 32 | -------------------------------------------------------------------------------- /etc/lockconfig.conf: -------------------------------------------------------------------------------- 1 | { 2 | "locks": 3 | [ 4 | { 5 | "lock_id": "1", 6 | "addrs": 7 | [ 8 | { 9 | "ip": "127.0.0.1", 10 | "port": "7100", 11 | "paxos_port": "7101" 12 | }, 13 | { 14 | "ip": "127.0.0.1", 15 | "port": "7200", 16 | "paxos_port": "7201" 17 | }, 18 | { 19 | "ip": "127.0.0.1", 20 | "port": "7300", 21 | "paxos_port": "7301" 22 | } 23 | ], 24 | "scale": 100 25 | }, 26 | ] 27 | } -------------------------------------------------------------------------------- /etc/scheduler_server.0.conf: -------------------------------------------------------------------------------- 1 | # scheduler_server.conf 2 | # 3 | # Generated by phxrpc_pb2server from scheduler.proto 4 | # 5 | # 6 | 7 | [Server] 8 | BindIP = 127.0.0.1 9 | Port = 6100 10 | MaxThreads = 10 11 | WorkerUThreadCount = 50 12 | WorkerUThreadStackSize = 65536 13 | IOThreadCount = 3 14 | PackageName = phxqueue_phxrpc.scheduler 15 | MaxConnections = 800000 16 | MaxQueueLength = 20480 17 | FastRejectThresholdMS = 20 18 | FastRejectAdjustRate = 5 19 | 20 | [Log] 21 | LogDir = ./log/scheduler.0 22 | LogLevel = 0 23 | 24 | [ServerTimeout] 25 | SocketTimeoutMS = 120000 26 | 27 | [Scheduler] 28 | Topic = test 29 | PhxQueueGlobalConfigPath = ./etc/globalconfig.conf 30 | 31 | -------------------------------------------------------------------------------- /etc/scheduler_server.1.conf: -------------------------------------------------------------------------------- 1 | # scheduler_server.conf 2 | # 3 | # Generated by phxrpc_pb2server from scheduler.proto 4 | # 5 | # 6 | 7 | [Server] 8 | BindIP = 127.0.0.1 9 | Port = 6200 10 | MaxThreads = 10 11 | WorkerUThreadCount = 50 12 | WorkerUThreadStackSize = 65536 13 | IOThreadCount = 3 14 | PackageName = phxqueue_phxrpc.scheduler 15 | MaxConnections = 800000 16 | MaxQueueLength = 20480 17 | FastRejectThresholdMS = 20 18 | FastRejectAdjustRate = 5 19 | 20 | [Log] 21 | LogDir = ./log/scheduler.1 22 | LogLevel = 0 23 | 24 | [ServerTimeout] 25 | SocketTimeoutMS = 120000 26 | 27 | [Scheduler] 28 | Topic = test 29 | PhxQueueGlobalConfigPath = ./etc/globalconfig.conf 30 | 31 | -------------------------------------------------------------------------------- /etc/scheduler_server.2.conf: -------------------------------------------------------------------------------- 1 | # scheduler_server.conf 2 | # 3 | # Generated by phxrpc_pb2server from scheduler.proto 4 | # 5 | # 6 | 7 | [Server] 8 | BindIP = 127.0.0.1 9 | Port = 6300 10 | MaxThreads = 10 11 | WorkerUThreadCount = 50 12 | WorkerUThreadStackSize = 65536 13 | IOThreadCount = 3 14 | PackageName = phxqueue_phxrpc.scheduler 15 | MaxConnections = 800000 16 | MaxQueueLength = 20480 17 | FastRejectThresholdMS = 20 18 | FastRejectAdjustRate = 5 19 | 20 | [Log] 21 | LogDir = ./log/scheduler.2 22 | LogLevel = 0 23 | 24 | [ServerTimeout] 25 | SocketTimeoutMS = 120000 26 | 27 | [Scheduler] 28 | Topic = test 29 | PhxQueueGlobalConfigPath = ./etc/globalconfig.conf 30 | 31 | -------------------------------------------------------------------------------- /etc/schedulerconfig.conf: -------------------------------------------------------------------------------- 1 | { 2 | "scheduler": 3 | { 4 | "addrs": 5 | [ 6 | { 7 | "ip": "127.0.0.1", 8 | "port": "6100" 9 | }, 10 | { 11 | "ip": "127.0.0.1", 12 | "port": "6200" 13 | }, 14 | { 15 | "ip": "127.0.0.1", 16 | "port": "6300" 17 | } 18 | ] 19 | } 20 | } -------------------------------------------------------------------------------- /etc/simpleconfig.conf: -------------------------------------------------------------------------------- 1 | { 2 | "foo": 3 | { 4 | "f": "1" 5 | }, 6 | "bars": 7 | [ 8 | { 9 | "a": "1000", 10 | "foo": 11 | { 12 | "f": "1001" 13 | } 14 | }, 15 | { 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /etc/store_server.0.conf: -------------------------------------------------------------------------------- 1 | # store_server.conf 2 | # 3 | # Generated by phxrpc_pb2server from store.proto 4 | # 5 | # 6 | 7 | [Server] 8 | BindIP = 127.0.0.1 9 | Port = 5100 10 | MaxThreads = 10 11 | IOThreadCount = 1 12 | PackageName = phxqueue_phxrpc.store 13 | MaxConnections = 800000 14 | MaxQueueLength = 20480 15 | FastRejectThresholdMS = 2000 16 | FastRejectAdjustRate = 5 17 | 18 | [Log] 19 | LogDir = ./log/store.0 20 | LogLevel = 0 21 | 22 | [ServerTimeout] 23 | SocketTimeoutMS = 120000 24 | 25 | [Store] 26 | Topic = test 27 | DataDirPath = ./data/store.0 28 | PhxQueueGlobalConfigPath = ./etc/globalconfig.conf 29 | PaxosPort = 5101 30 | NPaxosIOThread = 3 31 | NGroup = 1 32 | 33 | -------------------------------------------------------------------------------- /etc/store_server.1.conf: -------------------------------------------------------------------------------- 1 | # store_server.conf 2 | # 3 | # Generated by phxrpc_pb2server from store.proto 4 | # 5 | # 6 | 7 | [Server] 8 | BindIP = 127.0.0.1 9 | Port = 5200 10 | MaxThreads = 10 11 | IOThreadCount = 1 12 | PackageName = phxqueue_phxrpc.store 13 | MaxConnections = 800000 14 | MaxQueueLength = 20480 15 | FastRejectThresholdMS = 2000 16 | FastRejectAdjustRate = 5 17 | 18 | [Log] 19 | LogDir = ./log/store.1 20 | LogLevel = 0 21 | 22 | [ServerTimeout] 23 | SocketTimeoutMS = 120000 24 | 25 | [Store] 26 | Topic = test 27 | DataDirPath = ./data/store.1 28 | PhxQueueGlobalConfigPath = ./etc/globalconfig.conf 29 | PaxosPort = 5201 30 | NPaxosIOThread = 3 31 | NGroup = 1 32 | 33 | -------------------------------------------------------------------------------- /etc/store_server.2.conf: -------------------------------------------------------------------------------- 1 | # store_server.conf 2 | # 3 | # Generated by phxrpc_pb2server from store.proto 4 | # 5 | # 6 | 7 | [Server] 8 | BindIP = 127.0.0.1 9 | Port = 5300 10 | MaxThreads = 10 11 | IOThreadCount = 1 12 | PackageName = phxqueue_phxrpc.store 13 | MaxConnections = 800000 14 | MaxQueueLength = 20480 15 | FastRejectThresholdMS = 2000 16 | FastRejectAdjustRate = 5 17 | 18 | [Log] 19 | LogDir = ./log/store.2 20 | LogLevel = 0 21 | 22 | [ServerTimeout] 23 | SocketTimeoutMS = 120000 24 | 25 | [Store] 26 | Topic = test 27 | DataDirPath = ./data/store.2 28 | PhxQueueGlobalConfigPath = ./etc/globalconfig.conf 29 | PaxosPort = 5301 30 | NPaxosIOThread = 3 31 | NGroup = 1 32 | 33 | -------------------------------------------------------------------------------- /etc/storeconfig.conf: -------------------------------------------------------------------------------- 1 | { 2 | "stores": 3 | [ 4 | { 5 | "store_id": "1", 6 | "addrs": 7 | [ 8 | { 9 | "ip": "127.0.0.1", 10 | "port": "5100", 11 | "paxos_port": "5101" 12 | }, 13 | { 14 | "ip": "127.0.0.1", 15 | "port": "5200", 16 | "paxos_port": "5201" 17 | }, 18 | { 19 | "ip": "127.0.0.1", 20 | "port": "5300", 21 | "paxos_port": "5301" 22 | } 23 | ], 24 | "scale": 100, 25 | "pub_ids": [1, 2] 26 | }, 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /etc/topicconfig.conf: -------------------------------------------------------------------------------- 1 | { 2 | "topic": 3 | { 4 | "topic_id": "1000", 5 | "handle_ids": ["1", "2"], 6 | "store_paxos_batch_count": "80", 7 | "store_paxos_batch_delay_time_ms": "30" 8 | }, 9 | "queue_infos": 10 | [ 11 | { 12 | "queue_info_id": "1", 13 | "ranges": ["0"] 14 | } 15 | ], 16 | "pubs": 17 | [ 18 | { 19 | "pub_id": "1", 20 | "consumer_group_ids": ["1"], 21 | "queue_info_ids": ["1"] 22 | } 23 | ], 24 | "consumer_groups": 25 | [ 26 | { 27 | "consumer_group_id": "1", 28 | "use_dynamic_scale": "0", 29 | "skip_lock": "1" 30 | } 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /log/clear_log.sh: -------------------------------------------------------------------------------- 1 | clear_dir () { 2 | cd $1/ 3 | rm -f *.INFO 4 | rm -f *.WARNING 5 | rm -f *.ERROR 6 | rm -f *.INFO.* 7 | rm -f *.WARNING.* 8 | rm -f *.ERROR.* 9 | ls -lhasp 10 | cd - 11 | } 12 | 13 | clear_dir 'store.0' 14 | clear_dir 'store.1' 15 | clear_dir 'store.2' 16 | 17 | clear_dir 'consumer.0' 18 | clear_dir 'consumer.1' 19 | clear_dir 'consumer.2' 20 | 21 | clear_dir 'lock.0' 22 | clear_dir 'lock.1' 23 | clear_dir 'lock.2' 24 | 25 | clear_dir 'scheduler.0' 26 | clear_dir 'scheduler.1' 27 | clear_dir 'scheduler.2' 28 | 29 | -------------------------------------------------------------------------------- /phxqueue/comm.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue/comm/errdef.h" 16 | #include "phxqueue/comm/logger.h" 17 | #include "phxqueue/comm/breakpoint.h" 18 | #include "phxqueue/comm/masterclient.h" 19 | #include "phxqueue/comm/multiproc.h" 20 | #include "phxqueue/comm/utils.h" 21 | #include "phxqueue/comm/handler.h" 22 | #include "phxqueue/comm/resourcepool.h" 23 | #include "phxqueue/comm/notifierpool.h" 24 | #include "phxqueue/comm/proto/comm.pb.h" 25 | 26 | -------------------------------------------------------------------------------- /phxqueue/comm/masterclient.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #include "phxqueue/comm/masterclient.h" 14 | 15 | #include "phxqueue/comm/utils.h" 16 | 17 | 18 | namespace phxqueue { 19 | 20 | namespace comm { 21 | 22 | 23 | using namespace std; 24 | 25 | 26 | thread_local map> MasterClientBase::addr_cache_; 27 | 28 | MasterClientBase::MasterClientBase() {} 29 | 30 | MasterClientBase::~MasterClientBase() {} 31 | 32 | 33 | void MasterClientBase::PutAddrToCache(const std::string &key, const proto::Addr &addr) { 34 | addr_cache_[key] = make_pair(addr, time(nullptr) + 3600 + utils::OtherUtils::FastRand() % 1800); 35 | } 36 | 37 | bool MasterClientBase::GetAddrFromCache(const std::string &key, proto::Addr &addr) { 38 | auto &&it(addr_cache_.find(key)); 39 | if (it != addr_cache_.end()) { 40 | if (static_cast(time(nullptr)) > it->second.second) return false; 41 | addr = it->second.first; 42 | return true; 43 | } 44 | return false; 45 | } 46 | 47 | void MasterClientBase::RemoveCache(const std::string &key) { 48 | addr_cache_.erase(key); 49 | } 50 | 51 | 52 | } // namespace comm 53 | 54 | } // namespace phxqueue 55 | 56 | -------------------------------------------------------------------------------- /phxqueue/comm/multiproc.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include "phxqueue/comm/errdef.h" 20 | 21 | 22 | namespace phxqueue { 23 | 24 | namespace comm { 25 | 26 | 27 | class MultiProc { 28 | public: 29 | MultiProc() {} 30 | virtual ~MultiProc() {} 31 | 32 | // watch and refork the child process if killed/aborted unexpectedly 33 | void ForkAndRun(const int procs); 34 | 35 | protected: 36 | virtual void ChildRun(const int vpid) = 0; 37 | 38 | private: 39 | std::vector children_; 40 | }; 41 | 42 | 43 | } // namespace comm 44 | 45 | } // namespace phxqueue 46 | 47 | -------------------------------------------------------------------------------- /phxqueue/comm/notifierpool.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include "phxqueue/comm/errdef.h" 23 | 24 | namespace phxqueue { 25 | 26 | namespace comm { 27 | 28 | class Notifier { 29 | public: 30 | Notifier(); 31 | ~Notifier(); 32 | 33 | bool Init(); 34 | void Notify(const comm::RetCode retcode); 35 | void Wait(comm::RetCode &retcode); 36 | 37 | private: 38 | class NotifierImpl; 39 | std::unique_ptr impl_; 40 | }; 41 | 42 | class NotifierPool { 43 | public: 44 | NotifierPool(); 45 | ~NotifierPool(); 46 | 47 | static NotifierPool *GetInstance(); 48 | 49 | std::unique_ptr Get(); 50 | void Put(std::unique_ptr ¬ifier); 51 | 52 | private: 53 | class NotifierPoolImpl; 54 | std::unique_ptr impl_; 55 | }; 56 | 57 | 58 | } // namespace comm 59 | 60 | } // namespace phxqueue 61 | 62 | -------------------------------------------------------------------------------- /phxqueue/comm/utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue/comm/utils/addr_util.h" 16 | #include "phxqueue/comm/utils/concurrent_util.h" 17 | #include "phxqueue/comm/utils/file_util.h" 18 | #include "phxqueue/comm/utils/load_util.h" 19 | #include "phxqueue/comm/utils/memory_util.h" 20 | #include "phxqueue/comm/utils/other_util.h" 21 | #include "phxqueue/comm/utils/string_util.h" 22 | #include "phxqueue/comm/utils/time_util.h" 23 | #include "phxqueue/comm/utils/benchmark_util.h" 24 | #include "phxqueue/comm/utils/co_util.h" 25 | #include "phxqueue/comm/utils/hash_util.h" 26 | 27 | 28 | namespace phxqueue { 29 | 30 | namespace comm { 31 | 32 | 33 | } // namespace comm 34 | 35 | } // namespace phxqueue 36 | 37 | -------------------------------------------------------------------------------- /phxqueue/comm/utils/addr_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | 18 | 19 | #include "phxqueue/comm/proto/comm.pb.h" 20 | 21 | 22 | namespace phxqueue { 23 | 24 | namespace comm { 25 | 26 | namespace utils { 27 | 28 | 29 | uint64_t EncodeAddr(const proto::Addr &addr); 30 | void DecodeAddr(const uint64_t encoded_addr, proto::Addr &addr); 31 | std::string EncodedAddrToIPString(const uint64_t encoded_addr); 32 | std::string AddrToString(const proto::Addr &addr); 33 | std::string AddrScaleToString(const proto::AddrScale &addr_scale); 34 | std::string AddrScalesToString(const google::protobuf::RepeatedPtrField 35 | &addr_scales); 36 | 37 | 38 | } // namespace utils 39 | 40 | } // namespace comm 41 | 42 | } // namespace phxqueue 43 | 44 | -------------------------------------------------------------------------------- /phxqueue/comm/utils/benchmark_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | 22 | namespace phxqueue { 23 | 24 | namespace comm { 25 | 26 | namespace utils { 27 | 28 | 29 | class BenchMark { 30 | public: 31 | BenchMark(const int qps, const int nthread, const int nroutine); 32 | 33 | virtual ~BenchMark(); 34 | virtual int TaskFunc(const int vtid) = 0; 35 | virtual void BeforeThreadRun() {}; 36 | 37 | void Run(); 38 | int GetRoutineSleepTimeMS(); 39 | void ThreadRun(const int vtid); 40 | void Stat(const int vtid, const int ret, const uint64_t used_time_ms, const int sleep_ms); 41 | 42 | 43 | private: 44 | void ResStat(); 45 | 46 | private: 47 | class BenchMarkImpl; 48 | std::unique_ptr impl_; 49 | }; 50 | 51 | 52 | } // namespace utils 53 | 54 | } // namespace comm 55 | 56 | } // namespace phxqueue 57 | 58 | -------------------------------------------------------------------------------- /phxqueue/comm/utils/co_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include 16 | 17 | 18 | namespace phxqueue { 19 | 20 | namespace comm { 21 | 22 | namespace utils { 23 | 24 | 25 | bool CoWrite(const int fd, const char *buf, const int buf_len); 26 | 27 | bool CoRead(const int fd, char *buf, const int buf_len); 28 | 29 | 30 | } // namespace utils 31 | 32 | } // namespace comm 33 | 34 | } // namespace phxqueue 35 | 36 | -------------------------------------------------------------------------------- /phxqueue/comm/utils/file_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | 20 | namespace phxqueue { 21 | 22 | namespace comm { 23 | 24 | namespace utils { 25 | 26 | 27 | int ExtractFilePath(const std::string &file_path, std::string *dir, std::string *file_name); 28 | 29 | int RemoveFile(const std::string &file_path); 30 | 31 | int CopyFile(const std::string &src_file_path, const std::string &dst_file_path); 32 | 33 | int RemoveDir(const std::string &dir_path); 34 | 35 | int CopyDir(const std::string &src_dir_path, const std::string &dst_dir_path); 36 | 37 | int RecursiveListDir(const std::string &dir_path, std::vector *file_paths, std::vector *sub_dir_paths, 38 | const bool recursive = false); 39 | 40 | int RecursiveRemoveDir(const std::string &dir_path, 41 | const bool recursive, const bool remove_root = true); 42 | 43 | int RecursiveCopyDir(const std::string &src_dir_path, const std::string &dst_dir_path, 44 | const bool recursive, const bool copy_root = true); 45 | 46 | bool AccessDir(const std::string &dir_path); 47 | 48 | bool CreateDir(const std::string &dir_path); 49 | 50 | 51 | } // namespace utils 52 | 53 | } // namespace comm 54 | 55 | } //namespace phxqueue 56 | 57 | -------------------------------------------------------------------------------- /phxqueue/comm/utils/load_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #include 14 | 15 | 16 | namespace phxqueue { 17 | 18 | namespace comm { 19 | 20 | namespace utils { 21 | 22 | 23 | int GetCpu(); 24 | 25 | 26 | } // namespace utils 27 | 28 | } // namespace comm 29 | 30 | } // namespace phxqueue 31 | 32 | -------------------------------------------------------------------------------- /phxqueue/comm/utils/memory_util.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #include "phxqueue/comm/utils/memory_util.h" 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | 21 | namespace phxqueue { 22 | 23 | namespace comm { 24 | 25 | namespace utils { 26 | 27 | 28 | bool MemStat::Stat(pid_t pid) { 29 | char fileName[256]; 30 | if (pid == 0) { 31 | strcpy(fileName, "/proc/self/statm"); 32 | } else { 33 | snprintf(fileName, sizeof(fileName), "/proc/%d/statm", pid); 34 | } 35 | 36 | FILE *file = fopen(fileName, "r"); 37 | if (file) { 38 | if (0 == fscanf(file, "%lu %lu %lu %lu %lu %lu %lu", &size, &resident, &share, &text, &lib, &data, &dt)) { 39 | ; 40 | } 41 | fclose(file); 42 | return true; 43 | } 44 | return false; 45 | } 46 | 47 | 48 | } // namespace utils 49 | 50 | } // namespace comm 51 | 52 | } // namespace phxqueue 53 | 54 | -------------------------------------------------------------------------------- /phxqueue/comm/utils/memory_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #include 14 | 15 | 16 | namespace phxqueue { 17 | 18 | namespace comm { 19 | 20 | namespace utils { 21 | 22 | 23 | template 24 | std::unique_ptr make_unique(Ts&&... params) { 25 | return std::unique_ptr(new T(std::forward(params)...)); 26 | } 27 | 28 | 29 | class MemStat { 30 | public: 31 | MemStat() = default; 32 | virtual ~MemStat() = default; 33 | 34 | 35 | unsigned long size{0}; // total program size 36 | unsigned long resident{0}; // resident set size 37 | unsigned long share{0}; // shared pages 38 | unsigned long text{0}; // text (code) 39 | unsigned long lib{0}; // library 40 | unsigned long data{0}; // data/stack 41 | unsigned long dt{0}; // dirty pages 42 | 43 | bool Stat(pid_t pid = 0); 44 | }; 45 | 46 | 47 | } // namespace utils 48 | 49 | } // namespace comm 50 | 51 | } // namespace phxqueue 52 | 53 | -------------------------------------------------------------------------------- /phxqueue/comm/utils/other_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #include 14 | 15 | 16 | namespace phxqueue { 17 | 18 | namespace comm { 19 | 20 | namespace utils { 21 | 22 | 23 | class OtherUtils { 24 | public: 25 | static const uint32_t FastRand(); 26 | }; 27 | 28 | 29 | } // namespace utils 30 | 31 | } // namespace comm 32 | 33 | } // namespace phxqueue 34 | 35 | -------------------------------------------------------------------------------- /phxqueue/comm/utils/string_util.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #include 14 | 15 | #include "phxqueue/comm/utils/string_util.h" 16 | 17 | 18 | namespace phxqueue { 19 | 20 | namespace comm { 21 | 22 | namespace utils { 23 | 24 | 25 | using namespace std; 26 | 27 | 28 | void StrSplitList(const string &str, const string &delimiters, vector &results) { 29 | results.clear(); 30 | auto last = 0; 31 | auto found = str.find_first_of(delimiters); 32 | while (string::npos != found) { 33 | auto r = str.substr(last, found - last); 34 | last = found + 1; 35 | found = str.find_first_of(delimiters, last); 36 | if (!r.empty()) results.push_back(r); 37 | } 38 | auto r = str.substr(last); 39 | if (!r.empty()) results.push_back(r); 40 | } 41 | 42 | 43 | } // namespace utils 44 | 45 | } // namespace comm 46 | 47 | } // namespace phxqueue 48 | 49 | -------------------------------------------------------------------------------- /phxqueue/comm/utils/string_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | 18 | 19 | namespace phxqueue { 20 | 21 | namespace comm { 22 | 23 | namespace utils { 24 | 25 | 26 | void StrSplitList(const std::string &str, const std::string &delimiters, std::vector &results); 27 | 28 | 29 | } // namespace utils 30 | 31 | } // namespace comm 32 | 33 | } // namespace phxqueue 34 | 35 | -------------------------------------------------------------------------------- /phxqueue/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue/config/baseconfig.h" 16 | #include "phxqueue/config/consumerconfig.h" 17 | #include "phxqueue/config/globalconfig.h" 18 | #include "phxqueue/config/lockconfig.h" 19 | #include "phxqueue/config/schedulerconfig.h" 20 | #include "phxqueue/config/storeconfig.h" 21 | #include "phxqueue/config/topicconfig.h" 22 | #include "phxqueue/config/utils.h" 23 | 24 | -------------------------------------------------------------------------------- /phxqueue/config/consumerconfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include "phxqueue/comm.h" 20 | 21 | #include "phxqueue/config/baseconfig.h" 22 | #include "phxqueue/config/proto/consumerconfig.pb.h" 23 | 24 | 25 | namespace phxqueue { 26 | 27 | namespace config { 28 | 29 | 30 | class ConsumerConfig : public BaseConfig { 31 | public: 32 | ConsumerConfig(); 33 | 34 | virtual ~ConsumerConfig(); 35 | 36 | comm::RetCode GetAllConsumer(std::vector> &consumers) const; 37 | 38 | comm::RetCode GetConsumerByAddr(const comm::proto::Addr &addr, std::shared_ptr &consumer) const; 39 | 40 | protected: 41 | virtual comm::RetCode ReadConfig(proto::ConsumerConfig &proto); 42 | 43 | comm::RetCode Rebuild() override; 44 | 45 | private: 46 | class ConsumerConfigImpl; 47 | std::unique_ptr impl_; 48 | }; 49 | 50 | 51 | } // namespace config 52 | 53 | } // namespace phxqueue 54 | 55 | -------------------------------------------------------------------------------- /phxqueue/config/lockconfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include "phxqueue/comm.h" 20 | 21 | #include "phxqueue/config/baseconfig.h" 22 | #include "phxqueue/config/proto/lockconfig.pb.h" 23 | 24 | 25 | namespace phxqueue { 26 | 27 | namespace config { 28 | 29 | 30 | struct LockConfigImpl_t; 31 | 32 | class LockConfig : public BaseConfig { 33 | public: 34 | LockConfig(); 35 | 36 | virtual ~LockConfig(); 37 | 38 | comm::RetCode GetAllLock(std::vector > &locks) const; 39 | 40 | comm::RetCode GetAllLockID(std::set &lock_ids) const; 41 | 42 | comm::RetCode GetLockByLockID(const int lock_id, std::shared_ptr &lock) const; 43 | 44 | comm::RetCode GetLockIDByAddr(const comm::proto::Addr &addr, int &lock_id) const; 45 | 46 | comm::RetCode GetLockByAddr(const comm::proto::Addr &addr, std::shared_ptr &lock) const; 47 | 48 | protected: 49 | virtual comm::RetCode ReadConfig(proto::LockConfig &proto); 50 | 51 | comm::RetCode Rebuild() override; 52 | 53 | private: 54 | class LockConfigImpl; 55 | std::unique_ptr impl_; 56 | }; 57 | 58 | 59 | } // namespace config 60 | 61 | } // namespace phxqueue 62 | 63 | -------------------------------------------------------------------------------- /phxqueue/config/proto/consumerconfig.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package phxqueue.config.proto; 4 | import "phxqueue/comm/proto/comm.proto"; 5 | 6 | message ConsumerConfig { 7 | repeated Consumer consumers = 1; 8 | } 9 | 10 | message Consumer { 11 | optional comm.proto.Addr addr = 2; 12 | optional int32 scale = 3; 13 | repeated int32 consumer_group_ids = 20; 14 | } 15 | -------------------------------------------------------------------------------- /phxqueue/config/proto/globalconfig.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package phxqueue.config.proto; 4 | 5 | message GlobalConfig { 6 | repeated TopicInfo topic_infos = 1; 7 | } 8 | 9 | message TopicInfo { 10 | optional int32 topic_id = 1; 11 | optional string topic_name = 2; 12 | optional string topic_config_path = 3; 13 | optional string consumer_config_path = 4; 14 | optional string store_config_path = 5; 15 | optional string scheduler_config_path = 6; 16 | optional string lock_config_path = 7; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /phxqueue/config/proto/lockconfig.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package phxqueue.config.proto; 4 | import "phxqueue/comm/proto/comm.proto"; 5 | 6 | message LockConfig { 7 | repeated Lock locks = 1; 8 | } 9 | 10 | message Lock { 11 | optional int32 lock_id = 1; 12 | repeated comm.proto.Addr addrs = 2; 13 | optional int32 scale = 3; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /phxqueue/config/proto/schedulerconfig.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package phxqueue.config.proto; 4 | import "phxqueue/comm/proto/comm.proto"; 5 | 6 | message SchedulerConfig { 7 | optional Scheduler scheduler = 1; 8 | } 9 | 10 | message Scheduler { 11 | repeated comm.proto.Addr addrs = 2; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /phxqueue/config/proto/storeconfig.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package phxqueue.config.proto; 4 | import "phxqueue/comm/proto/comm.proto"; 5 | 6 | message StoreConfig { 7 | repeated Store stores = 1; 8 | } 9 | 10 | message Store { 11 | optional int32 store_id = 1; 12 | repeated comm.proto.Addr addrs = 2; 13 | optional int32 scale = 3; 14 | repeated int32 pub_ids = 20; 15 | } 16 | -------------------------------------------------------------------------------- /phxqueue/config/schedulerconfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include "phxqueue/comm.h" 20 | 21 | #include "phxqueue/config/baseconfig.h" 22 | #include "phxqueue/config/proto/schedulerconfig.pb.h" 23 | 24 | 25 | namespace phxqueue { 26 | 27 | namespace config { 28 | 29 | 30 | struct SchedulerConfigImpl_t; 31 | 32 | class SchedulerConfig : public BaseConfig { 33 | public: 34 | SchedulerConfig(); 35 | 36 | virtual ~SchedulerConfig(); 37 | 38 | comm::RetCode GetScheduler(std::shared_ptr &scheduler) const; 39 | 40 | protected: 41 | virtual comm::RetCode ReadConfig(proto::SchedulerConfig &proto); 42 | 43 | comm::RetCode Rebuild() override; 44 | 45 | private: 46 | class SchedulerConfigImpl; 47 | std::unique_ptr impl_; 48 | }; 49 | 50 | 51 | } // namespace config 52 | 53 | } // namespace phxqueue 54 | 55 | -------------------------------------------------------------------------------- /phxqueue/config/storeconfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include "phxqueue/comm.h" 20 | 21 | #include "phxqueue/config/baseconfig.h" 22 | #include "phxqueue/config/proto/storeconfig.pb.h" 23 | 24 | 25 | namespace phxqueue { 26 | 27 | namespace config { 28 | 29 | 30 | struct StoreConfigImpl_t; 31 | 32 | class StoreConfig : public BaseConfig { 33 | public: 34 | StoreConfig(); 35 | 36 | virtual ~StoreConfig(); 37 | 38 | comm::RetCode GetAllStore(std::vector> &stores) const; 39 | 40 | comm::RetCode GetAllStoreID(std::set &store_ids) const; 41 | 42 | comm::RetCode GetStoreByStoreID(const int store_id, std::shared_ptr &store) const; 43 | 44 | comm::RetCode GetStoreIDByAddr(const comm::proto::Addr &addr, int &store_id) const; 45 | 46 | comm::RetCode GetStoreByAddr(const comm::proto::Addr &addr, std::shared_ptr &store) const; 47 | 48 | protected: 49 | virtual comm::RetCode ReadConfig(proto::StoreConfig &proto); 50 | 51 | comm::RetCode Rebuild() override; 52 | 53 | private: 54 | class StoreConfigImpl; 55 | std::unique_ptr impl_; 56 | }; 57 | 58 | 59 | } // namespace config 60 | 61 | } // namespace phxqueue 62 | 63 | -------------------------------------------------------------------------------- /phxqueue/config/utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue/config/utils/pub_util.h" 16 | #include "phxqueue/config/utils/consumer_group_util.h" 17 | 18 | -------------------------------------------------------------------------------- /phxqueue/config/utils/consumer_group_util.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include 5 | #include 6 | 7 | 8 | namespace phxqueue { 9 | 10 | namespace config { 11 | 12 | namespace utils { 13 | 14 | 15 | comm::RetCode GetConsumerGroupIDsByConsumerAddr(const int topic_id, const comm::proto::Addr &addr, std::set &consumer_group_ids); 16 | 17 | 18 | } // namespace utils 19 | 20 | } // namespace config 21 | 22 | } // namespace phxqueue 23 | 24 | -------------------------------------------------------------------------------- /phxqueue/config/utils/pub_util.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "phxqueue/comm.h" 4 | 5 | #include "phxqueue/config/globalconfig.h" 6 | #include "phxqueue/config/storeconfig.h" 7 | #include "phxqueue/config/topicconfig.h" 8 | 9 | 10 | namespace phxqueue { 11 | 12 | namespace config { 13 | 14 | namespace utils { 15 | 16 | 17 | using namespace std; 18 | 19 | 20 | comm::RetCode GetPubIDsByStoreID(const int topic_id, const int store_id, set &pub_ids) { 21 | pub_ids.clear(); 22 | 23 | comm::RetCode ret; 24 | 25 | shared_ptr store_config; 26 | if (comm::RetCode::RET_OK != (ret = GlobalConfig::GetThreadInstance()->GetStoreConfig(topic_id, store_config))) { 27 | NLErr("GetStoreConfig ret %d topic_id %d", comm::as_integer(ret), topic_id); 28 | return ret; 29 | } 30 | 31 | shared_ptr store; 32 | if (comm::RetCode::RET_OK != (ret = store_config->GetStoreByStoreID(store_id, store))) { 33 | NLErr("GetStoreByStoreID ret %d", comm::as_integer(ret)); 34 | return ret; 35 | } 36 | 37 | shared_ptr topic_config; 38 | if (comm::RetCode::RET_OK != (ret = GlobalConfig::GetThreadInstance()->GetTopicConfigByTopicID(topic_id, topic_config))) { 39 | NLErr("GetTopicConfig ret %d topic_id %d", comm::as_integer(ret), topic_id); 40 | return ret; 41 | } 42 | 43 | if (store->pub_ids_size()) { 44 | for (int i{0}; i < store->pub_ids_size(); ++i) { 45 | auto &&pub_id = store->pub_ids(i); 46 | if (topic_config->IsValidPubID(pub_id)) { 47 | pub_ids.insert(store->pub_ids(i)); 48 | } 49 | } 50 | return comm::RetCode::RET_OK; 51 | } 52 | 53 | if (comm::RetCode::RET_OK != (ret = topic_config->GetAllPubID(pub_ids))) { 54 | NLErr("GetAllPubID ret %d", comm::as_integer(ret)); 55 | } 56 | 57 | return ret; 58 | } 59 | 60 | 61 | } // namespace utils 62 | 63 | } // namespace config 64 | 65 | } // namespace phxqueue 66 | 67 | 68 | -------------------------------------------------------------------------------- /phxqueue/config/utils/pub_util.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | 7 | namespace phxqueue { 8 | 9 | namespace config { 10 | 11 | namespace utils { 12 | 13 | 14 | comm::RetCode GetPubIDsByStoreID(const int topic_id, const int store_id, std::set &pub_ids); 15 | 16 | 17 | } // namespace utils 18 | 19 | } // namespace config 20 | 21 | } // namespace phxqueue 22 | 23 | -------------------------------------------------------------------------------- /phxqueue/consumer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue/consumer/consumer.h" 16 | #include "phxqueue/consumer/consumeroption.h" 17 | 18 | -------------------------------------------------------------------------------- /phxqueue/consumer/consumeroption.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue/comm.h" 16 | #include "phxqueue/plugin.h" 17 | 18 | 19 | namespace phxqueue { 20 | 21 | namespace consumer { 22 | 23 | 24 | class ConsumerOption { 25 | public: 26 | ConsumerOption() = default; 27 | virtual ~ConsumerOption() = default; 28 | 29 | std::string topic; 30 | 31 | std::string ip; 32 | int port{0}; 33 | int paxos_port{0}; 34 | 35 | int nprocs{1}; 36 | int nhandler{100}; 37 | int nbatch_handler{1}; 38 | //int nshare_stack{100}; 39 | int share_stack_size_kb{128}; 40 | 41 | int shm_key_base{14335}; 42 | std::string proc_pid_path; 43 | std::string lock_path_base; 44 | 45 | int use_store_master_client_on_get{0}; 46 | int use_store_master_client_on_add{0}; 47 | 48 | comm::LogFunc log_func{nullptr}; 49 | plugin::ConfigFactoryCreateFunc config_factory_create_func{nullptr}; 50 | plugin::BreakPointFactoryCreateFunc break_point_factory_create_func{nullptr}; 51 | }; 52 | 53 | 54 | } // namespace consumer 55 | 56 | } // namesapce phxqueue 57 | 58 | -------------------------------------------------------------------------------- /phxqueue/consumer/freqman.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | 18 | #include "phxqueue/consumer/consumer.h" 19 | 20 | 21 | namespace phxqueue { 22 | 23 | namespace consumer { 24 | 25 | 26 | class FreqMan { 27 | public: 28 | FreqMan(); 29 | virtual ~FreqMan(); 30 | comm::RetCode Init(const int topic_id, Consumer *consumer); 31 | void Run(); 32 | void UpdateConsumeStat(const int vpid, const comm::proto::ConsumerContext &cc, 33 | const std::vector> &items); 34 | void Judge(const int vpid, bool &need_block, bool &need_freqlimit, 35 | int &nrefill, int &sleep_ms_per_get_recommand); 36 | 37 | private: 38 | void ClearAllConsumeStat(); 39 | comm::RetCode UpdateLimitInfo(); 40 | 41 | class FreqManImpl; 42 | std::unique_ptr impl_; 43 | }; 44 | 45 | 46 | } // namespace consumer 47 | 48 | } // namespace phxqueue 49 | 50 | -------------------------------------------------------------------------------- /phxqueue/lock.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue/lock/lock.h" 16 | #include "phxqueue/lock/lockmasterclient.h" 17 | #include "phxqueue/lock/lockoption.h" 18 | 19 | -------------------------------------------------------------------------------- /phxqueue/lock/cleanthread.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxpaxos/node.h" 16 | 17 | #include "phxqueue/lock/proto/lock.pb.h" 18 | #include "phxqueue/lock/lockdb.h" 19 | #include "phxqueue/lock/lockmgr.h" 20 | 21 | 22 | namespace phxqueue { 23 | 24 | namespace lock { 25 | 26 | 27 | class CleanThread { 28 | public: 29 | CleanThread(Lock *const lock); 30 | virtual ~CleanThread(); 31 | 32 | void Run(); 33 | void Stop(); 34 | 35 | private: 36 | void DoRun(); 37 | 38 | void CleanRecord(const int paxos_group_id, const uint64_t now, 39 | int *const nr_group_key, int *const nr_group_clean_key); 40 | 41 | // if no request at all, we should write checkpoint sometimes 42 | // there are other paxos log need to be converted to mirror, such as 'try be master' paxos log 43 | void WriteRestartCheckpoint(const int paxos_group_id, const uint64_t now); 44 | 45 | //comm::RetCode ProposeCleanLock(const int paxos_group_id, 46 | // const std::vector &lock_key_infos); 47 | 48 | class CleanThreadImpl; 49 | std::unique_ptr impl_; 50 | uint64_t last_clean_lock_ms_{0}; 51 | uint64_t last_write_restart_checkpoint_ms_{0}; 52 | }; 53 | 54 | 55 | } // namespace lock 56 | 57 | } // namespace phxqueue 58 | 59 | -------------------------------------------------------------------------------- /phxqueue/lock/keepmasterthread.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue/lock/lock.h" 16 | 17 | 18 | namespace phxqueue { 19 | 20 | namespace lock { 21 | 22 | 23 | class KeepMasterThread { 24 | public: 25 | KeepMasterThread(Lock *lock); 26 | virtual ~KeepMasterThread(); 27 | 28 | void Run(); 29 | void Stop(); 30 | 31 | private: 32 | void DoRun(); 33 | comm::RetCode InitMasterRate(); 34 | comm::RetCode AdjustMasterRate(); 35 | comm::RetCode KeepMaster(); 36 | //comm::RetCode GetIdxInGroupAndGroupSize(int &idx_in_group, int &group_size); 37 | comm::RetCode ProposeMaster(const int paxos_group_id, const comm::proto::Addr addr); 38 | comm::RetCode UpdatePaxosArgs(); 39 | 40 | class KeepMasterThreadImpl; 41 | std::unique_ptr impl_; 42 | }; 43 | 44 | 45 | } // namespace lock 46 | 47 | } // namespace phxqueue 48 | 49 | -------------------------------------------------------------------------------- /phxqueue/lock/lockoption.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue/comm.h" 16 | #include "phxqueue/plugin.h" 17 | 18 | 19 | namespace phxqueue { 20 | 21 | namespace lock { 22 | 23 | 24 | class LockOption { 25 | public: 26 | LockOption() = default; 27 | virtual ~LockOption() = default; 28 | 29 | std::string topic; 30 | std::string data_dir_path; 31 | 32 | std::string ip; 33 | int port{0}; 34 | int paxos_port{0}; 35 | int nr_group{100}; 36 | int nr_paxos_io_thread{3}; 37 | 38 | int clean_interval_s{1}; 39 | int idle_write_checkpoint_interval_s{60}; 40 | int max_clean_lock_num{100}; 41 | int checkpoint_interval{100}; 42 | bool no_leveldb{false}; 43 | bool no_clean_thread{false}; 44 | 45 | comm::LogFunc log_func{nullptr}; 46 | plugin::ConfigFactoryCreateFunc config_factory_create_func{nullptr}; 47 | plugin::BreakPointFactoryCreateFunc break_point_factory_create_func{nullptr}; 48 | }; 49 | 50 | 51 | } // namespace lock 52 | 53 | } // namespace queue 54 | 55 | -------------------------------------------------------------------------------- /phxqueue/lock/proto/lock.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package phxqueue.lock.proto; 4 | import "phxqueue/comm/proto/comm.proto"; 5 | 6 | 7 | message LockPaxosArgs { 8 | optional comm.proto.AcquireLockRequest acquire_lock_req = 1; 9 | optional comm.proto.SetStringRequest set_string_req = 11; 10 | optional comm.proto.DeleteStringRequest delete_string_req = 12; 11 | optional comm.proto.Addr master_addr = 102; 12 | } 13 | 14 | message LocalRecordInfo { 15 | optional uint64 version = 1; 16 | optional bytes value = 2; 17 | optional uint64 lease_time_ms = 3; 18 | optional uint64 expire_time_ms = 4; 19 | } 20 | 21 | message RecordKeyInfo { 22 | optional uint64 version = 1; 23 | optional string key = 2; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /phxqueue/plugin.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue/plugin/breakpointfactory.h" 16 | #include "phxqueue/plugin/configfactory.h" 17 | #include "phxqueue/plugin/logger_google.h" 18 | #include "phxqueue/plugin/logger_sys.h" 19 | 20 | -------------------------------------------------------------------------------- /phxqueue/plugin/configfactory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #include "phxqueue/plugin/configfactory.h" 14 | 15 | #include 16 | 17 | 18 | namespace phxqueue { 19 | 20 | namespace plugin { 21 | 22 | 23 | using namespace std; 24 | 25 | 26 | ConfigFactoryCreateFunc ConfigFactory::config_factory_create_func_ = nullptr; 27 | 28 | 29 | } // namespace plugin 30 | 31 | } // namespace phxqueue 32 | 33 | -------------------------------------------------------------------------------- /phxqueue/plugin/logger_google.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | 18 | #include "phxqueue/comm.h" 19 | 20 | 21 | namespace phxqueue { 22 | 23 | namespace plugin { 24 | 25 | 26 | class LoggerGoogle { 27 | public: 28 | static int GetLogger(const std::string &module_name, const std::string &log_path, 29 | const int log_level, comm::LogFunc &log_func); 30 | 31 | static void Log(const int log_level, const char *format, va_list args); 32 | }; 33 | 34 | 35 | } // namespace plugin 36 | 37 | } // namespace phxqueue 38 | 39 | -------------------------------------------------------------------------------- /phxqueue/plugin/logger_sys.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | 18 | #include "phxqueue/comm.h" 19 | 20 | 21 | namespace phxqueue { 22 | 23 | namespace plugin { 24 | 25 | 26 | class LoggerSys { 27 | public: 28 | static int GetLogger(const std::string &module_name, const int sys_log_level, const bool daemonize, comm::LogFunc &pLogFunc); 29 | 30 | static void Log(const int log_level, const char *format, va_list args); 31 | }; 32 | 33 | 34 | } // namespace plugin 35 | 36 | } // namespace phxqueue 37 | 38 | -------------------------------------------------------------------------------- /phxqueue/producer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue/producer/producer.h" 16 | #include "phxqueue/producer/produceroption.h" 17 | #include "phxqueue/producer/selector.h" 18 | 19 | -------------------------------------------------------------------------------- /phxqueue/producer/batchhelper.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include "phxqueue/comm.h" 20 | #include "phxqueue/producer/producer.h" 21 | 22 | namespace phxqueue { 23 | 24 | namespace producer { 25 | 26 | class ProcessCtx_t; 27 | 28 | class BatchHelper { 29 | public: 30 | BatchHelper(producer::Producer *producer); 31 | ~BatchHelper(); 32 | 33 | void Init(); 34 | void Run(); 35 | void Stop(); 36 | 37 | comm::RetCode BatchRawAdd(const comm::proto::AddRequest &req); 38 | 39 | void DispatchBatchTask(int vtid); 40 | void Process(ProcessCtx_t *ctx); 41 | 42 | protected: 43 | void DaemonThreadRun(int vtid); 44 | 45 | private: 46 | class BatchHelperImpl; 47 | std::unique_ptr impl_; 48 | }; 49 | 50 | } // namespace producer 51 | 52 | } // namespace phxqueue 53 | 54 | -------------------------------------------------------------------------------- /phxqueue/producer/produceroption.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue/comm.h" 16 | #include "phxqueue/plugin.h" 17 | 18 | 19 | namespace phxqueue { 20 | 21 | namespace producer { 22 | 23 | 24 | class ProducerOption { 25 | public: 26 | ProducerOption() = default; 27 | virtual ~ProducerOption() = default; 28 | 29 | comm::LogFunc log_func{nullptr}; 30 | plugin::ConfigFactoryCreateFunc config_factory_create_func{nullptr}; 31 | plugin::BreakPointFactoryCreateFunc break_point_factory_create_func{nullptr}; 32 | 33 | int ndaemon_batch_thread{0}; 34 | int nprocess_routine{50}; 35 | int process_routine_share_stack_size_kb{128}; 36 | }; 37 | 38 | 39 | } // namespace producer 40 | 41 | } // namespace phxqueue 42 | 43 | -------------------------------------------------------------------------------- /phxqueue/scheduler.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue/scheduler/scheduler.h" 16 | #include "phxqueue/scheduler/schedulermasterclient.h" 17 | #include "phxqueue/scheduler/scheduleroption.h" 18 | 19 | -------------------------------------------------------------------------------- /phxqueue/scheduler/keepmasterthread.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue/scheduler/scheduler.h" 16 | 17 | 18 | namespace phxqueue { 19 | 20 | namespace scheduler { 21 | 22 | 23 | class KeepMasterThread { 24 | public: 25 | KeepMasterThread(Scheduler *const scheduler); 26 | virtual ~KeepMasterThread(); 27 | 28 | void Run(); 29 | void Stop(); 30 | 31 | comm::RetCode InitMasterRate(); 32 | comm::RetCode AdjustMasterRate(); 33 | comm::RetCode KeepMaster(); 34 | 35 | private: 36 | void DoRun(); 37 | comm::RetCode GetLockID(int &lock_id); 38 | 39 | class KeepMasterThreadImpl; 40 | std::unique_ptr impl_; 41 | }; 42 | 43 | 44 | } // namespace scheduler 45 | 46 | } // namespace phxqueue 47 | 48 | -------------------------------------------------------------------------------- /phxqueue/scheduler/loadbalancethread.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue/scheduler/scheduler.h" 16 | 17 | 18 | namespace phxqueue { 19 | 20 | namespace scheduler { 21 | 22 | 23 | class LoadBalanceThread { 24 | public: 25 | LoadBalanceThread(Scheduler *const scheduler); 26 | virtual ~LoadBalanceThread(); 27 | 28 | void Run(); 29 | void Stop(); 30 | 31 | private: 32 | void DoRun(); 33 | 34 | class LoadBalanceThreadImpl; 35 | std::unique_ptr impl_; 36 | }; 37 | 38 | 39 | } // namespace scheduler 40 | 41 | } // namespace phxqueue 42 | 43 | -------------------------------------------------------------------------------- /phxqueue/scheduler/scheduleroption.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue/comm.h" 16 | #include "phxqueue/plugin.h" 17 | 18 | 19 | namespace phxqueue { 20 | 21 | namespace scheduler { 22 | 23 | 24 | class SchedulerOption { 25 | public: 26 | SchedulerOption() = default; 27 | virtual ~SchedulerOption() = default; 28 | 29 | std::string topic; 30 | 31 | std::string ip; 32 | int port{0}; 33 | 34 | comm::LogFunc log_func{nullptr}; 35 | plugin::ConfigFactoryCreateFunc config_factory_create_func{nullptr}; 36 | plugin::BreakPointFactoryCreateFunc break_point_factory_create_func{nullptr}; 37 | }; 38 | 39 | 40 | } // namespace scheduler 41 | 42 | } // namespace phxqueue 43 | 44 | -------------------------------------------------------------------------------- /phxqueue/store.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue/store/store.h" 16 | #include "phxqueue/store/storemasterclient.h" 17 | #include "phxqueue/store/storeoption.h" 18 | 19 | -------------------------------------------------------------------------------- /phxqueue/store/basemgr.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | 18 | #include "phxqueue/comm.h" 19 | 20 | #include "phxqueue/store/store.h" 21 | 22 | 23 | namespace phxqueue { 24 | 25 | namespace store { 26 | 27 | 28 | class StoreMetaQueue; 29 | 30 | class BaseMgr { 31 | public: 32 | BaseMgr(Store *store); 33 | virtual ~BaseMgr(); 34 | 35 | comm::RetCode Init(); 36 | comm::RetCode Add(const uint64_t cursor_id, const comm::proto::AddRequest &req); 37 | bool NeedSkipAdd(const uint64_t cursor_id, const comm::proto::AddRequest &req); 38 | comm::RetCode Get(const comm::proto::GetRequest &req, comm::proto::GetResponse &resp); 39 | comm::RetCode GetItemsByCursorID(const int queue_id, const uint64_t cursor_id, 40 | std::vector &items); 41 | StoreMetaQueue *GetMetaQueue(const int queue_id); 42 | 43 | private: 44 | class BaseMgrImpl; 45 | std::unique_ptr impl_; 46 | }; 47 | 48 | 49 | } // namespace store 50 | 51 | } // namespace phxqueue 52 | 53 | -------------------------------------------------------------------------------- /phxqueue/store/checkpointstat.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include "phxqueue/store/store.h" 21 | 22 | 23 | namespace phxqueue { 24 | 25 | namespace store { 26 | 27 | 28 | class CheckPointStat { 29 | public: 30 | CheckPointStat(); 31 | virtual ~CheckPointStat(); 32 | 33 | comm::RetCode Init(const std::string &dir, const std::string &file); 34 | 35 | comm::RetCode GetCheckPoint(uint64_t &cp); 36 | 37 | comm::RetCode UpdateCheckPointAndFlush(const uint64_t cp); 38 | 39 | std::string GetDir() const; 40 | std::string GetFile() const; 41 | 42 | private: 43 | class CheckPointStatImpl; 44 | std::unique_ptr impl_; 45 | }; 46 | 47 | 48 | class CheckPointStatMgr { 49 | public: 50 | CheckPointStatMgr(Store *const store); 51 | virtual ~CheckPointStatMgr(); 52 | 53 | comm::RetCode Init(); 54 | 55 | CheckPointStat *GetCheckPointStat(const int paxos_group_id); 56 | 57 | private: 58 | class CheckPointStatMgrImpl; 59 | std::unique_ptr impl_; 60 | }; 61 | 62 | 63 | } // namespace store 64 | 65 | } // namespace phxqueue 66 | 67 | -------------------------------------------------------------------------------- /phxqueue/store/keepmasterthread.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | 18 | #include "phxqueue/store/store.h" 19 | 20 | 21 | namespace phxqueue { 22 | 23 | namespace store { 24 | 25 | 26 | class KeepMasterThread { 27 | public: 28 | KeepMasterThread(Store *const store); 29 | virtual ~KeepMasterThread(); 30 | 31 | void Run(); 32 | void Stop(); 33 | 34 | private: 35 | void DoRun(); 36 | void InitMasterRate(); 37 | void AdjustMasterRate(); 38 | void KeepMaster(); 39 | void UpdatePaxosArgs(); 40 | 41 | class KeepMasterThreadImpl; 42 | std::unique_ptr impl_; 43 | }; 44 | 45 | 46 | } // namespace store 47 | 48 | } // namespace phxqueue 49 | 50 | -------------------------------------------------------------------------------- /phxqueue/store/keepsyncthread.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include "phxqueue/config.h" 20 | #include "phxqueue/consumer.h" 21 | 22 | #include "phxqueue/store/store.h" 23 | 24 | 25 | namespace phxqueue { 26 | 27 | namespace store { 28 | 29 | 30 | class KeepSyncThread { 31 | public: 32 | KeepSyncThread(Store *const store); 33 | virtual ~KeepSyncThread(); 34 | 35 | void Run(); 36 | void Stop(); 37 | 38 | private: 39 | void DoRun(); 40 | void ClearSyncCtrl(); 41 | void MakeCheckPoint(); 42 | void SyncCursorID(); 43 | void Replay(); 44 | void ReportBacklog(); 45 | void ReportDelayStat(); 46 | 47 | void GetAllLocalQueue(std::vector &queues); 48 | bool QueueNeedReplay(const consumer::Queue_t &queue, const std::set &pub_ids, 49 | const std::vector> &replay_infos, 50 | int &replay_infos_idx); 51 | 52 | comm::RetCode DumpCheckPoint(const int paxos_group_id, const uint64_t cp); 53 | 54 | class KeepSyncThreadImpl; 55 | std::unique_ptr impl_; 56 | }; 57 | 58 | 59 | } // namespace store 60 | 61 | } // namespace phxqueue 62 | 63 | -------------------------------------------------------------------------------- /phxqueue/store/proto/store.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package phxqueue.store.proto; 4 | import "phxqueue/comm/proto/comm.proto"; 5 | 6 | message SyncCtrlInfo { 7 | message QueueDetail { 8 | optional int32 queue_id = 1; 9 | message ConsumerGroupDetail { 10 | optional int32 consumer_group_id = 1; 11 | optional uint64 prev_cursor_id = 2; 12 | } 13 | repeated ConsumerGroupDetail consumer_group_details = 2; 14 | } 15 | repeated QueueDetail queue_details = 1; 16 | } 17 | 18 | 19 | message StorePaxosArgs { 20 | optional comm.proto.AddRequest add_req = 1; 21 | optional SyncCtrlInfo sync_ctrl_info = 101; 22 | optional comm.proto.Addr master_addr = 102; 23 | optional uint64 timestamp = 201; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /phxqueue/store/storeoption.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue/comm.h" 16 | #include "phxqueue/plugin.h" 17 | 18 | 19 | namespace phxqueue { 20 | 21 | namespace store { 22 | 23 | 24 | class StoreOption { 25 | public: 26 | StoreOption() = default; 27 | virtual ~StoreOption() = default; 28 | 29 | std::string topic; 30 | 31 | std::string data_dir_path; 32 | 33 | std::string ip; 34 | int port{0}; 35 | int paxos_port{0}; 36 | 37 | int ngroup{100}; 38 | int nconsumer_group{64}; 39 | int nqueue{2000}; 40 | 41 | int npaxos_iothread{3}; 42 | 43 | comm::LogFunc log_func{nullptr}; 44 | plugin::ConfigFactoryCreateFunc config_factory_create_func{nullptr}; 45 | plugin::BreakPointFactoryCreateFunc break_point_factory_create_func{nullptr}; 46 | }; 47 | 48 | 49 | } // namespace store 50 | 51 | } // namespace phxqueue 52 | 53 | 54 | -------------------------------------------------------------------------------- /phxqueue/test/check_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue/config.h" 16 | 17 | 18 | namespace phxqueue { 19 | 20 | namespace test { 21 | 22 | 23 | class CheckConfig { 24 | public: 25 | void Process(); 26 | 27 | private: 28 | void CheckGlobalConfig(config::GlobalConfig *global_config); 29 | void CheckTopicConfig(const int topic_id, const config::TopicConfig *topic_config); 30 | void CheckConsumerConfig(const int topic_id, const config::ConsumerConfig *consumer_config); 31 | void CheckStoreConfig(const int topic_id, const config::StoreConfig *store_config); 32 | void CheckSchedulerConfig(const int topic_id, const config::SchedulerConfig *scheduler_config); 33 | void CheckLockConfig(const int topic_id, const config::LockConfig *lock_config); 34 | 35 | }; 36 | 37 | 38 | } // namespace test 39 | 40 | } // namespace phxqueue 41 | 42 | -------------------------------------------------------------------------------- /phxqueue/test/simplehandler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #include "phxqueue/test/simplehandler.h" 14 | 15 | #include 16 | #include 17 | 18 | #include "phxqueue/comm.h" 19 | 20 | 21 | namespace phxqueue { 22 | 23 | namespace test { 24 | 25 | 26 | using namespace std; 27 | 28 | 29 | comm::HandleResult SimpleHandler::Handle(const comm::proto::ConsumerContext &cc, 30 | comm::proto::QItem &item, string &uncompressed_buffer) { 31 | QLVerb("cc: consumer_group_id %d store_id %d queue_id %d. item uin %" PRIu64, 32 | cc.consumer_group_id(), cc.store_id(), cc.queue_id(), (uint64_t)item.meta().uin()); 33 | return comm::HandleResult::RES_OK; 34 | } 35 | 36 | 37 | } // namespace test 38 | 39 | } // namespace phxqueue 40 | 41 | -------------------------------------------------------------------------------- /phxqueue/test/simplehandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include 16 | 17 | #include "phxqueue/comm.h" 18 | 19 | 20 | namespace phxqueue { 21 | 22 | namespace test { 23 | 24 | 25 | class SimpleHandler : public comm::Handler { 26 | public: 27 | SimpleHandler() {} 28 | virtual ~SimpleHandler() override = default; 29 | 30 | virtual comm::HandleResult Handle(const comm::proto::ConsumerContext &cc, 31 | comm::proto::QItem &item, 32 | std::string &uncompressed_buffer) override; 33 | }; 34 | 35 | 36 | } // namespace test 37 | 38 | } // namespace phxqueue 39 | 40 | -------------------------------------------------------------------------------- /phxqueue/test/simpleproducer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include 16 | 17 | #include "phxqueue/producer.h" 18 | 19 | 20 | namespace phxqueue { 21 | 22 | namespace test { 23 | 24 | 25 | class SimpleProducer : public producer::Producer { 26 | public: 27 | SimpleProducer(const producer::ProducerOption &opt) : producer::Producer(opt) {} 28 | virtual ~SimpleProducer() override = default; 29 | 30 | virtual void CompressBuffer(const std::string &buffer, std::string &compress_buffer, 31 | int &buffer_type) override; 32 | 33 | protected: 34 | virtual comm::RetCode Add(const comm::proto::AddRequest &req, 35 | comm::proto::AddResponse &resp) override; 36 | 37 | }; 38 | 39 | 40 | } // namespace test 41 | 42 | } // namespace phxqueue 43 | 44 | -------------------------------------------------------------------------------- /phxqueue/test/simplescheduler.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include 16 | 17 | #include "phxqueue/scheduler.h" 18 | 19 | 20 | namespace phxqueue { 21 | 22 | namespace test { 23 | 24 | 25 | class SimpleScheduler : public scheduler::Scheduler { 26 | public: 27 | SimpleScheduler(const scheduler::SchedulerOption &opt) : scheduler::Scheduler(opt) {} 28 | virtual ~SimpleScheduler() override = default; 29 | 30 | protected: 31 | virtual comm::RetCode GetLockInfo(const comm::proto::GetLockInfoRequest &req, 32 | comm::proto::GetLockInfoResponse &resp) override; 33 | virtual comm::RetCode AcquireLock(const comm::proto::AcquireLockRequest &req, 34 | comm::proto::AcquireLockResponse &resp) override; 35 | }; 36 | 37 | 38 | } // namespace test 39 | 40 | } // namespace phxqueue 41 | 42 | -------------------------------------------------------------------------------- /phxqueue/test/test_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue/config.h" 16 | 17 | 18 | namespace phxqueue { 19 | 20 | namespace test { 21 | 22 | 23 | class TestConfig { 24 | public: 25 | static void TestGlobalConfig(config::GlobalConfig *global_config); 26 | static void TestTopicConfig(const config::TopicConfig *topic_config); 27 | static void TestConsumerConfig(const config::ConsumerConfig *consumer_config); 28 | static void TestStoreConfig(const config::StoreConfig *store_config); 29 | static void TestSchedulerConfig(const config::SchedulerConfig *scheduler_config); 30 | static void TestLockConfig(const config::LockConfig *lock_config); 31 | }; 32 | 33 | 34 | } // namespace test 35 | 36 | } // namespace phxqueue 37 | 38 | -------------------------------------------------------------------------------- /phxqueue/test/test_config_main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #include 14 | #include "phxqueue/test/test_config.h" 15 | 16 | #include "phxqueue/comm.h" 17 | #include "phxqueue/plugin.h" 18 | 19 | 20 | using namespace phxqueue; 21 | using namespace std; 22 | 23 | 24 | int main(int argc, char **argv) { 25 | comm::LogFunc log_func; 26 | plugin::LoggerGoogle::GetLogger("test_config", "/tmp/phxqueue/log", 3, log_func); 27 | comm::Logger::GetInstance()->SetLogFunc(log_func); 28 | 29 | config::GlobalConfig global_config; 30 | assert(comm::RetCode::RET_OK == global_config.Load()); 31 | test::TestConfig::TestGlobalConfig(&global_config); 32 | 33 | return 0; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /phxqueue/test/test_configfactory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #include "phxqueue/test/test_configfactory.h" 14 | 15 | #include 16 | 17 | #include "phxqueue/config.h" 18 | 19 | 20 | namespace phxqueue { 21 | 22 | namespace test { 23 | 24 | 25 | void TestConfigFactory::Process() { 26 | assert(plugin::ConfigFactory::GetInstance()->NewGlobalConfig()); 27 | assert(plugin::ConfigFactory::GetInstance()->NewTopicConfig(1000, "")); 28 | assert(plugin::ConfigFactory::GetInstance()->NewConsumerConfig(1000, "")); 29 | assert(plugin::ConfigFactory::GetInstance()->NewStoreConfig(1000, "")); 30 | } 31 | 32 | 33 | } // namespace test 34 | 35 | } // namespace phxqueue 36 | 37 | -------------------------------------------------------------------------------- /phxqueue/test/test_configfactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue/plugin.h" 16 | 17 | 18 | namespace phxqueue { 19 | 20 | namespace test { 21 | 22 | 23 | class TestConfigFactory { 24 | public: 25 | static void Process(); 26 | }; 27 | 28 | 29 | } // namespace test 30 | 31 | } // namespace phxqueue 32 | 33 | -------------------------------------------------------------------------------- /phxqueue/test/test_consumer_main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #include 14 | 15 | #include "phxqueue/test/simpleconsumer.h" 16 | #include "phxqueue/test/simplehandler.h" 17 | 18 | #include "phxqueue/comm.h" 19 | #include "phxqueue/plugin.h" 20 | 21 | 22 | using namespace phxqueue; 23 | using namespace std; 24 | 25 | 26 | int main(int argc, char **argv) { 27 | comm::LogFunc log_func; 28 | plugin::LoggerGoogle::GetLogger("test_consumer", "/tmp/phxqueue/log", 3, log_func); 29 | 30 | consumer::ConsumerOption opt; 31 | opt.topic = "test"; 32 | opt.ip = "127.0.0.1"; 33 | opt.port = 8001; 34 | opt.nprocs = 3; 35 | opt.proc_pid_path = "/tmp/phxqueue/"; 36 | opt.lock_path_base = "./phxqueueconsumer.lock."; 37 | opt.log_func = log_func; 38 | 39 | test::SimpleConsumer consumer(opt); 40 | consumer.AddHandlerFactory(1, new comm::DefaultHandlerFactory()); 41 | consumer.Run(); 42 | 43 | return 0; 44 | } 45 | 46 | -------------------------------------------------------------------------------- /phxqueue/test/test_log.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #include "phxqueue/test/test_log.h" 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include "phxqueue/comm.h" 20 | #include "phxqueue/plugin.h" 21 | 22 | 23 | namespace phxqueue { 24 | 25 | namespace test { 26 | 27 | 28 | using namespace std; 29 | 30 | 31 | void TestLog::Process() { 32 | comm::LogFunc log_func; 33 | plugin::LoggerGoogle::GetLogger("test_log", "./log/test", 2, log_func); // level: warn 34 | comm::Logger::GetInstance()->SetLogFunc(log_func); 35 | 36 | NLErr("error"); 37 | NLWarn("warn"); 38 | NLInfo("info"); 39 | } 40 | 41 | } // namespace test 42 | 43 | } // namespace phxqueue 44 | 45 | -------------------------------------------------------------------------------- /phxqueue/test/test_log.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | 16 | namespace phxqueue { 17 | 18 | namespace test { 19 | 20 | 21 | class TestLog { 22 | public: 23 | static void Process(); 24 | }; 25 | 26 | 27 | } // namespace test 28 | 29 | } // namespace phxqueue 30 | 31 | -------------------------------------------------------------------------------- /phxqueue/test/test_log_main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #include 14 | 15 | #include "phxqueue/test/test_log.h" 16 | 17 | int main(int argc, char **argv) { 18 | phxqueue::test::TestLog::Process(); 19 | return 0; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /phxqueue/test/test_main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #include 14 | 15 | int main(int argc, char **argv) { 16 | std::cout << "test" << std::endl; 17 | 18 | return 0; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /phxqueue/test/test_notifierpool_main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #include 14 | #include 15 | 16 | #include "phxqueue/comm.h" 17 | #include "phxqueue/producer.h" 18 | 19 | using namespace std; 20 | 21 | int main(int argc, char **argv) { 22 | unique_ptr notifier = move(phxqueue::comm::NotifierPool::GetInstance()->Get()); 23 | assert(notifier != nullptr); 24 | 25 | auto t = new thread([¬ifier]()->void { 26 | cout << "thread 2 begin wait notify ..." << endl; 27 | phxqueue::comm::RetCode retcode; 28 | notifier->Wait(retcode); 29 | cout << "thread 2 recv notify. retcode " << as_integer(retcode) << endl; 30 | }); 31 | 32 | sleep(1); 33 | 34 | phxqueue::comm::RetCode retcode = phxqueue::comm::RetCode::RET_OK; 35 | cout << "thread 1 send notify. retcode " << as_integer(retcode) << endl; 36 | notifier->Notify(retcode); 37 | 38 | sleep(1); 39 | 40 | return 0; 41 | } 42 | 43 | -------------------------------------------------------------------------------- /phxqueue/test/test_plugin_main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #include 14 | 15 | #include "phxqueue/test/test_configfactory.h" 16 | 17 | 18 | using namespace phxqueue; 19 | using namespace std; 20 | 21 | 22 | int main(int argc, char **argv) { 23 | test::TestConfigFactory::Process(); 24 | return 0; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /phxqueue/test/test_producer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #include "phxqueue/test/simpleproducer.h" 14 | #include "phxqueue/test/test_producer.h" 15 | 16 | #include 17 | #include 18 | 19 | 20 | namespace phxqueue { 21 | 22 | namespace test { 23 | 24 | 25 | using namespace std; 26 | 27 | 28 | void TestProducer::Process() { 29 | producer::ProducerOption opt; 30 | 31 | test::SimpleProducer producer(opt); 32 | producer.Enqueue(1000, 123, 1, "buffer", 1); 33 | } 34 | 35 | 36 | } // namespace test 37 | 38 | } // namespace phxqueue 39 | 40 | -------------------------------------------------------------------------------- /phxqueue/test/test_producer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue/producer.h" 16 | 17 | 18 | namespace phxqueue { 19 | 20 | namespace test { 21 | 22 | 23 | class TestProducer { 24 | public: 25 | static void Process(); 26 | }; 27 | 28 | 29 | } // namespace test 30 | 31 | } // namespace phxqueue 32 | 33 | -------------------------------------------------------------------------------- /phxqueue/test/test_producer_main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #include 14 | 15 | #include "phxqueue/comm.h" 16 | #include "phxqueue/plugin.h" 17 | 18 | #include "phxqueue/test/simpleproducer.h" 19 | 20 | 21 | using namespace phxqueue; 22 | using namespace std; 23 | 24 | 25 | int main(int argc, char ** argv) { 26 | comm::LogFunc log_func; 27 | plugin::LoggerGoogle::GetLogger("test_producer", "/tmp/phxqueue/log", 3, log_func); 28 | 29 | producer::ProducerOption opt; 30 | opt.log_func = log_func; 31 | 32 | test::SimpleProducer producer(opt); 33 | producer.Init(); 34 | producer.Enqueue(1000, 123, 1, "buffer", 1); 35 | 36 | return 0; 37 | } 38 | 39 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/lock/lock.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package phxqueue_phxrpc.lock; 4 | 5 | import "google/protobuf/empty.proto"; 6 | import "google/protobuf/wrappers.proto"; 7 | import "phxqueue/comm/proto/comm.proto"; 8 | import "phxrpc/rpc/phxrpc.proto"; 9 | 10 | service Lock { 11 | rpc GetString(phxqueue.comm.proto.GetStringRequest) returns(phxqueue.comm.proto.GetStringResponse) { 12 | option(phxrpc.CmdID) = 11; 13 | option(phxrpc.OptString) = "t:l:k:"; 14 | option(phxrpc.Usage) = "-t -l -k "; 15 | } 16 | 17 | rpc SetString(phxqueue.comm.proto.SetStringRequest) returns(phxqueue.comm.proto.SetStringResponse) { 18 | option(phxrpc.CmdID) = 12; 19 | option(phxrpc.OptString) = "t:l:k:r:s:T:"; 20 | option(phxrpc.Usage) = "-t -l -k -r -s -T "; 21 | } 22 | 23 | rpc DeleteString(phxqueue.comm.proto.DeleteStringRequest) returns(phxqueue.comm.proto.DeleteStringResponse) { 24 | option(phxrpc.CmdID) = 13; 25 | option(phxrpc.OptString) = "t:l:k:r:"; 26 | option(phxrpc.Usage) = "-t -l -k -r "; 27 | } 28 | 29 | rpc GetLockInfo(phxqueue.comm.proto.GetLockInfoRequest) returns(phxqueue.comm.proto.GetLockInfoResponse) { 30 | option(phxrpc.CmdID) = 21; 31 | option(phxrpc.OptString) = "t:l:k:"; 32 | option(phxrpc.Usage) = "-t -l -k "; 33 | } 34 | 35 | rpc AcquireLock(phxqueue.comm.proto.AcquireLockRequest) returns(phxqueue.comm.proto.AcquireLockResponse) { 36 | option(phxrpc.CmdID) = 22; 37 | option(phxrpc.OptString) = "t:l:k:r:s:T:"; 38 | option(phxrpc.Usage) = "-t -l -k -r -s -T "; 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/lock/lock_client.conf: -------------------------------------------------------------------------------- 1 | # lock_client.conf 2 | # 3 | # Generated by phxrpc_pb2server from lock.proto 4 | # 5 | # 6 | 7 | [ClientTimeout] 8 | ConnectTimeoutMS = 100 9 | SocketTimeoutMS = 5000 10 | 11 | [Server] 12 | ServerCount = 2 13 | PackageName=phxqueue_phxrpc.lock 14 | 15 | [Server0] 16 | IP = 127.0.0.1 17 | Port = 7300 18 | 19 | [Server1] 20 | IP = 127.0.0.1 21 | Port = 7300 22 | 23 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/lock/lock_server.conf: -------------------------------------------------------------------------------- 1 | # lock_server.conf 2 | # 3 | # Generated by phxrpc_pb2server from lock.proto 4 | # 5 | # 6 | 7 | [Server] 8 | BindIP = 127.0.0.1 9 | Port = 7100 10 | MaxThreads = 16 11 | IOThreadCount = 3 12 | PackageName = phxqueue_phxrpc.lock 13 | MaxConnections = 800000 14 | MaxQueueLength = 20480 15 | FastRejectThresholdMS = 20 16 | FastRejectAdjustRate = 5 17 | 18 | [Log] 19 | LogDir = /path/to/log 20 | LogLevel = 3 21 | 22 | [ServerTimeout] 23 | SocketTimeoutMS = 5000 24 | 25 | [Lock] 26 | Topic = test 27 | DataDirPath = /path/to/phxqueue/data/ 28 | PhxQueueGlobalConfigPath = /path/to/globalconfig.conf 29 | PaxosPort = 5101 30 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/lock/lock_server_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | /* lock_server_config.h 14 | 15 | Generated by phxrpc_pb2server from lock.proto 16 | 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "phxrpc/rpc.h" 22 | 23 | 24 | class LockServerConfig { 25 | public: 26 | LockServerConfig(); 27 | 28 | virtual ~LockServerConfig(); 29 | 30 | bool Read(const char *config_file); 31 | 32 | phxrpc::HshaServerConfig &GetHshaServerConfig(); 33 | 34 | const char *GetTopic() const; 35 | const char *GetDataDirPath() const; 36 | const char *GetPhxQueueGlobalConfigPath() const; 37 | int GetPaxosPort() const; 38 | int GetNrGroup() const; 39 | int GetNrPaxosIOThread() const; 40 | 41 | private: 42 | phxrpc::HshaServerConfig ep_server_config_; 43 | 44 | char topic_[128]; 45 | char data_dir_path_[128]; 46 | char phxqueue_global_config_path_[128]; 47 | int paxos_port_; 48 | int nr_group_{100}; 49 | int nr_paxos_io_thread_{3}; 50 | }; 51 | 52 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/lock/phxrpc_lock_dispatcher.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | /* phxrpc_lock_dispatcher.h 14 | 15 | Generated by phxrpc_pb2service from lock.proto 16 | 17 | Please DO NOT edit unless you know exactly what you are doing. 18 | 19 | */ 20 | 21 | #pragma once 22 | 23 | #include "phxrpc/http.h" 24 | #include "phxrpc/rpc.h" 25 | 26 | 27 | class LockService; 28 | 29 | 30 | class LockDispatcher { 31 | public: 32 | static const phxrpc::BaseDispatcher::URIFuncMap &GetURIFuncMap(); 33 | 34 | LockDispatcher(LockService &service, phxrpc::DispatcherArgs_t *dispatcher_args); 35 | 36 | virtual ~LockDispatcher(); 37 | 38 | int PHXEcho(const phxrpc::BaseRequest &req, phxrpc::BaseResponse *const resp); 39 | 40 | int GetString(const phxrpc::BaseRequest &req, phxrpc::BaseResponse *const resp); 41 | 42 | int SetString(const phxrpc::BaseRequest &req, phxrpc::BaseResponse *const resp); 43 | 44 | int DeleteString(const phxrpc::BaseRequest &req, phxrpc::BaseResponse *const resp); 45 | 46 | int GetLockInfo(const phxrpc::BaseRequest &req, phxrpc::BaseResponse *const resp); 47 | 48 | int AcquireLock(const phxrpc::BaseRequest &req, phxrpc::BaseResponse *const resp); 49 | 50 | private: 51 | LockService &service_; 52 | phxrpc::DispatcherArgs_t *dispatcher_args_; 53 | }; 54 | 55 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/scheduler/phxrpc_scheduler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #include "phxrpc_scheduler.h" 14 | 15 | #include "phxqueue_phxrpc/app/lock/lock_client.h" 16 | 17 | 18 | namespace phxqueue_phxrpc { 19 | 20 | namespace scheduler { 21 | 22 | 23 | PhxRpcScheduler::PhxRpcScheduler(const phxqueue::SchedulerOption &opt) 24 | : phxqueue::Scheduler(opt) {} 25 | 26 | PhxRpcScheduler::~PhxRpcScheduler() {} 27 | 28 | phxqueue::RetCode 29 | PhxRpcScheduler::GetLockInfo(const phxqueue_proto::GetLockInfoRequest &req, 30 | phxqueue_proto::GetLockInfoResponse &resp) { 31 | LockClient client; 32 | return client.ProtoGetLockInfo(req, resp); 33 | } 34 | 35 | phxqueue::RetCode 36 | PhxRpcScheduler::AcquireLock(const phxqueue_proto::AcquireLockRequest &req, 37 | phxqueue_proto::AcquireLockResponse &resp) { 38 | LockClient client; 39 | return client.ProtoAcquireLock(req, resp); 40 | } 41 | 42 | 43 | } 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/scheduler/phxrpc_scheduler.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue/scheduler.h" 16 | 17 | 18 | namespace phxqueue_phxrpc { 19 | 20 | namespace scheduler { 21 | 22 | 23 | class PhxRpcScheduler : public phxqueue::scheduler::Scheduler { 24 | public: 25 | PhxRpcScheduler(const phxqueue::scheduler::SchedulerOption &opt); 26 | virtual ~PhxRpcScheduler(); 27 | 28 | protected: 29 | virtual phxqueue::comm::RetCode GetLockInfo(const phxqueue::comm::proto::GetLockInfoRequest &req, 30 | phxqueue::comm::proto::GetLockInfoResponse &resp) override; 31 | virtual phxqueue::comm::RetCode AcquireLock(const phxqueue::comm::proto::AcquireLockRequest &req, 32 | phxqueue::comm::proto::AcquireLockResponse &resp) override; 33 | }; 34 | 35 | 36 | } 37 | 38 | } 39 | 40 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/scheduler/phxrpc_scheduler_dispatcher.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | /* phxrpc_scheduler_dispatcher.h 14 | 15 | Generated by phxrpc_pb2service from scheduler.proto 16 | 17 | Please DO NOT edit unless you know exactly what you are doing. 18 | 19 | */ 20 | 21 | #pragma once 22 | 23 | #include "phxrpc/http.h" 24 | #include "phxrpc/rpc.h" 25 | 26 | 27 | class SchedulerService; 28 | 29 | 30 | class SchedulerDispatcher { 31 | public: 32 | static const phxrpc::BaseDispatcher::URIFuncMap &GetURIFuncMap(); 33 | 34 | SchedulerDispatcher(SchedulerService &service, phxrpc::DispatcherArgs_t *dispatcher_args); 35 | 36 | virtual ~SchedulerDispatcher(); 37 | 38 | int PHXEcho(const phxrpc::BaseRequest &req, phxrpc::BaseResponse *const resp); 39 | 40 | int GetAddrScale(const phxrpc::BaseRequest &req, phxrpc::BaseResponse *const resp); 41 | 42 | private: 43 | SchedulerService &service_; 44 | phxrpc::DispatcherArgs_t *dispatcher_args_; 45 | }; 46 | 47 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/scheduler/phxrpc_scheduler_service.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | /* phxrpc_scheduler_service.cpp 14 | 15 | Generated by phxrpc_pb2service from scheduler.proto 16 | 17 | Please DO NOT edit unless you know exactly what you are doing. 18 | 19 | */ 20 | 21 | #include "phxrpc/file.h" 22 | 23 | #include "phxrpc_scheduler_service.h" 24 | #include "scheduler.pb.h" 25 | 26 | 27 | SchedulerService::SchedulerService() {} 28 | 29 | SchedulerService::~SchedulerService() {} 30 | 31 | int SchedulerService::PHXEcho(const google::protobuf::StringValue &/* req */, 32 | google::protobuf::StringValue */* resp */) { 33 | phxrpc::log(LOG_ERR, "ERROR: PHXEcho unimplemented"); 34 | return -1; 35 | } 36 | 37 | int SchedulerService::GetAddrScale(const phxqueue::comm::proto::GetAddrScaleRequest &/* req */, 38 | phxqueue::comm::proto::GetAddrScaleResponse */* resp */) { 39 | phxrpc::log(LOG_ERR, "ERROR: GetAddrScale unimplemented"); 40 | return -1; 41 | } 42 | 43 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/scheduler/phxrpc_scheduler_service.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | /* phxrpc_scheduler_service.h 14 | 15 | Generated by phxrpc_pb2service from scheduler.proto 16 | 17 | Please DO NOT edit unless you know exactly what you are doing. 18 | 19 | */ 20 | 21 | #pragma once 22 | 23 | #include "scheduler.pb.h" 24 | 25 | 26 | class SchedulerService { 27 | public: 28 | SchedulerService(); 29 | virtual ~SchedulerService(); 30 | 31 | virtual int PHXEcho(const google::protobuf::StringValue &req, 32 | google::protobuf::StringValue *resp); 33 | 34 | virtual int GetAddrScale(const phxqueue::comm::proto::GetAddrScaleRequest &req, 35 | phxqueue::comm::proto::GetAddrScaleResponse *resp); 36 | 37 | }; 38 | 39 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/scheduler/phxrpc_scheduler_stub.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | /* phxrpc_scheduler_stub.h 14 | 15 | Generated by phxrpc_pb2client from scheduler.proto 16 | 17 | Please DO NOT edit unless you know exactly what you are doing. 18 | 19 | */ 20 | 21 | #pragma once 22 | 23 | #include "scheduler.pb.h" 24 | 25 | 26 | namespace phxrpc { 27 | 28 | 29 | class BaseMessageHandlerFactory; 30 | class BaseTcpStream; 31 | class ClientMonitor; 32 | 33 | 34 | } 35 | 36 | 37 | class SchedulerStub { 38 | public: 39 | SchedulerStub(phxrpc::BaseTcpStream &socket, phxrpc::ClientMonitor &client_monitor, 40 | phxrpc::BaseMessageHandlerFactory &msg_handler_factory); 41 | ~SchedulerStub(); 42 | 43 | void set_keep_alive(const bool keep_alive); 44 | 45 | int PHXEcho(const google::protobuf::StringValue &req, 46 | google::protobuf::StringValue *resp); 47 | 48 | int GetAddrScale(const phxqueue::comm::proto::GetAddrScaleRequest &req, 49 | phxqueue::comm::proto::GetAddrScaleResponse *resp); 50 | 51 | private: 52 | phxrpc::BaseTcpStream &socket_; 53 | phxrpc::ClientMonitor &client_monitor_; 54 | bool keep_alive_{false}; 55 | phxrpc::BaseMessageHandlerFactory &msg_handler_factory_; 56 | }; 57 | 58 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/scheduler/phxrpc_scheduler_tool.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | /* phxrpc_scheduler_tool.cpp 14 | 15 | Generated by phxrpc_pb2tool from scheduler.proto 16 | 17 | Please DO NOT edit unless you know exactly what you are doing. 18 | 19 | */ 20 | 21 | #include "phxrpc_scheduler_tool.h" 22 | 23 | #include "phxrpc/file.h" 24 | 25 | #include "scheduler_client.h" 26 | 27 | 28 | using namespace phxrpc; 29 | 30 | 31 | SchedulerTool::SchedulerTool() {} 32 | 33 | SchedulerTool::~SchedulerTool() {} 34 | 35 | int SchedulerTool::PHXEcho(phxrpc::OptMap &/* opt_map */) { 36 | printf("\n *** PHXEcho unimplement ***\n"); 37 | 38 | return -1; 39 | } 40 | 41 | int SchedulerTool::GetAddrScale(phxrpc::OptMap &/* opt_map */) { 42 | printf("\n *** GetAddrScale unimplement ***\n"); 43 | 44 | return -1; 45 | } 46 | 47 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/scheduler/phxrpc_scheduler_tool.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | /* phxrpc_scheduler_tool.h 14 | 15 | Generated by phxrpc_pb2tool from scheduler.proto 16 | 17 | Please DO NOT edit unless you know exactly what you are doing. 18 | 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | 25 | 26 | namespace phxrpc { 27 | 28 | 29 | class OptMap; 30 | 31 | 32 | } 33 | 34 | 35 | class SchedulerTool { 36 | public: 37 | SchedulerTool(); 38 | virtual ~SchedulerTool(); 39 | 40 | virtual int PHXEcho(phxrpc::OptMap &bigmap); 41 | 42 | virtual int GetAddrScale(phxrpc::OptMap &bigmap); 43 | 44 | typedef int (SchedulerTool::*ToolFunc_t) (phxrpc::OptMap &); 45 | 46 | typedef struct tagName2Func { 47 | const char *name; 48 | SchedulerTool::ToolFunc_t func; 49 | const char *opt_string; 50 | const char *usage; 51 | } Name2Func_t; 52 | 53 | static Name2Func_t *GetName2Func() { 54 | static Name2Func_t name2func[]{ 55 | { "PHXEcho", &SchedulerTool::PHXEcho, "c:f:vs:", "-s " }, 56 | { nullptr, nullptr } 57 | }; 58 | 59 | return name2func; 60 | }; 61 | }; 62 | 63 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/scheduler/scheduler.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package phxqueue_phxrpc.scheduler; 4 | 5 | import "google/protobuf/empty.proto"; 6 | import "google/protobuf/wrappers.proto"; 7 | import "phxqueue/comm/proto/comm.proto"; 8 | import "phxrpc/rpc/phxrpc.proto"; 9 | 10 | service Scheduler { 11 | rpc GetAddrScale(phxqueue.comm.proto.GetAddrScaleRequest) returns(phxqueue.comm.proto.GetAddrScaleResponse) { 12 | option(phxrpc.CmdID) = 1; 13 | } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/scheduler/scheduler_client.conf: -------------------------------------------------------------------------------- 1 | # scheduler_client.conf 2 | # 3 | # Generated by phxrpc_pb2server from scheduler.proto 4 | # 5 | # 6 | 7 | [ClientTimeout] 8 | ConnectTimeoutMS = 100 9 | SocketTimeoutMS = 5000 10 | 11 | [Server] 12 | ServerCount = 2 13 | PackageName=phxqueue_phxrpc.scheduler 14 | 15 | [Server0] 16 | IP = 127.0.0.1 17 | Port = 6100 18 | 19 | [Server1] 20 | IP = 127.0.0.1 21 | Port = 6100 22 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/scheduler/scheduler_client.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | /* scheduler_client.h 14 | 15 | Generated by phxrpc_pb2client from scheduler.proto 16 | 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "phxqueue/comm.h" 22 | #include "phxrpc/rpc.h" 23 | 24 | #include "scheduler.pb.h" 25 | 26 | 27 | class SchedulerClient { 28 | public: 29 | static bool Init(const char *config_file); 30 | 31 | static const char *GetPackageName(); 32 | 33 | SchedulerClient(); 34 | virtual ~SchedulerClient(); 35 | 36 | int PHXEcho(const google::protobuf::StringValue &req, 37 | google::protobuf::StringValue *resp); 38 | 39 | int PHXBatchEcho(const google::protobuf::StringValue &req, 40 | google::protobuf::StringValue *resp); 41 | 42 | int GetAddrScale(const phxqueue::comm::proto::GetAddrScaleRequest &req, 43 | phxqueue::comm::proto::GetAddrScaleResponse *resp); 44 | 45 | phxqueue::comm::RetCode 46 | ProtoGetAddrScale(const phxqueue::comm::proto::GetAddrScaleRequest &req, 47 | phxqueue::comm::proto::GetAddrScaleResponse &resp); 48 | }; 49 | 50 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/scheduler/scheduler_client_uthread.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | /* scheduler_client.h 14 | 15 | Generated by phxrpc_pb2client from scheduler.proto 16 | 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "phxrpc/network.h" 22 | #include "phxrpc/rpc.h" 23 | 24 | #include "scheduler.pb.h" 25 | 26 | 27 | class SchedulerClientUThread { 28 | public: 29 | static bool Init(const char *config_file); 30 | 31 | static const char *GetPackageName(); 32 | 33 | SchedulerClientUThread(phxrpc::UThreadEpollScheduler *uthread_scheduler); 34 | virtual ~SchedulerClientUThread(); 35 | 36 | int PHXEcho(const google::protobuf::StringValue &req, 37 | google::protobuf::StringValue *resp); 38 | 39 | int PHXBatchEcho(const google::protobuf::StringValue &req, 40 | google::protobuf::StringValue *resp); 41 | 42 | int GetAddrScale(const phxqueue::comm::proto::GetAddrScaleRequest &req, 43 | phxqueue::comm::proto::GetAddrScaleResponse *resp); 44 | 45 | private: 46 | phxrpc::UThreadEpollScheduler *uthread_scheduler_; 47 | }; 48 | 49 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/scheduler/scheduler_server.conf: -------------------------------------------------------------------------------- 1 | # scheduler_server.conf 2 | # 3 | # Generated by phxrpc_pb2server from scheduler.proto 4 | # 5 | # 6 | 7 | [Server] 8 | BindIP = 127.0.0.1 9 | Port = 6100 10 | MaxThreads = 16 11 | WorkerUThreadCount = 50 12 | WorkerUThreadStackSize = 65536 13 | IOThreadCount = 3 14 | PackageName = phxqueue_phxrpc.scheduler 15 | MaxConnections = 800000 16 | MaxQueueLength = 20480 17 | FastRejectThresholdMS = 20 18 | FastRejectAdjustRate = 5 19 | 20 | [Log] 21 | LogDir = /path/to/log 22 | LogLevel = 3 23 | 24 | [ServerTimeout] 25 | SocketTimeoutMS = 5000 26 | 27 | [Scheduler] 28 | Topic = test 29 | PhxQueueGlobalConfigPath = /path/to/globalconfig.conf 30 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/scheduler/scheduler_server_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | /* scheduler_server_config.h 14 | 15 | Generated by phxrpc_pb2server from scheduler.proto 16 | 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "phxrpc/rpc.h" 22 | 23 | 24 | class SchedulerServerConfig { 25 | public: 26 | SchedulerServerConfig(); 27 | 28 | virtual ~SchedulerServerConfig(); 29 | 30 | bool Read(const char *config_file); 31 | 32 | phxrpc::HshaServerConfig &GetHshaServerConfig(); 33 | 34 | const char *GetTopic() const; 35 | const char *GetPhxQueueGlobalConfigPath() const; 36 | 37 | 38 | private: 39 | phxrpc::HshaServerConfig ep_server_config_; 40 | 41 | char topic_[128]; 42 | char phxqueue_global_config_path_[128]; 43 | }; 44 | 45 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/scheduler/scheduler_service_impl.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | /* scheduler_service_impl.cpp 14 | 15 | Generated by phxrpc_pb2service from scheduler.proto 16 | 17 | */ 18 | 19 | #include "scheduler_service_impl.h" 20 | 21 | #include "phxrpc/file.h" 22 | 23 | #include "scheduler_server_config.h" 24 | 25 | 26 | SchedulerServiceImpl::SchedulerServiceImpl(ServiceArgs_t &app_args) 27 | : args_(app_args), scheduler_(app_args.scheduler) {} 28 | 29 | SchedulerServiceImpl::~SchedulerServiceImpl() {} 30 | 31 | int SchedulerServiceImpl::PHXEcho(const google::protobuf::StringValue &req, 32 | google::protobuf::StringValue *resp) { 33 | resp->set_value(req.value()); 34 | return 0; 35 | } 36 | 37 | int SchedulerServiceImpl::GetAddrScale(const phxqueue::comm::proto::GetAddrScaleRequest &req, 38 | phxqueue::comm::proto::GetAddrScaleResponse *resp) { 39 | int ret{static_cast(scheduler_->GetAddrScale(req, *resp))}; 40 | 41 | if (0 != ret) { 42 | QLErr("Scheduler GetAddrScale err %d", ret); 43 | } 44 | 45 | return ret; 46 | } 47 | 48 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/scheduler/scheduler_service_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | /* scheduler_service_impl.h 14 | 15 | Generated by phxrpc_pb2service from scheduler.proto 16 | 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "phxrpc/network.h" 22 | 23 | #include "phxrpc_scheduler.h" 24 | #include "phxrpc_scheduler_service.h" 25 | #include "scheduler.pb.h" 26 | 27 | 28 | class SchedulerServerConfig; 29 | 30 | 31 | typedef struct tagServiceArgs { 32 | SchedulerServerConfig *config; 33 | phxqueue::scheduler::Scheduler *scheduler; 34 | } ServiceArgs_t; 35 | 36 | 37 | class SchedulerServiceImpl : public SchedulerService { 38 | public: 39 | SchedulerServiceImpl(ServiceArgs_t &app_args); 40 | virtual ~SchedulerServiceImpl(); 41 | 42 | virtual int PHXEcho(const google::protobuf::StringValue &req, 43 | google::protobuf::StringValue *resp) override; 44 | 45 | virtual int GetAddrScale(const phxqueue::comm::proto::GetAddrScaleRequest &req, 46 | phxqueue::comm::proto::GetAddrScaleResponse *resp) override; 47 | 48 | private: 49 | ServiceArgs_t &args_; 50 | phxqueue::scheduler::Scheduler *scheduler_{nullptr}; 51 | }; 52 | 53 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/scheduler/scheduler_tool_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | /* scheduler_tool_impl.h 14 | 15 | Generated by phxrpc_pb2tool from scheduler.proto 16 | 17 | */ 18 | 19 | #pragma once 20 | 21 | #include 22 | 23 | #include "phxrpc_scheduler_tool.h" 24 | 25 | 26 | namespace phxrpc { 27 | 28 | 29 | class OptMap; 30 | 31 | 32 | } 33 | 34 | 35 | class SchedulerToolImpl : public SchedulerTool { 36 | public: 37 | SchedulerToolImpl(); 38 | virtual ~SchedulerToolImpl(); 39 | 40 | virtual int PHXEcho(phxrpc::OptMap &opt_map) override; 41 | 42 | virtual int GetAddrScale(phxrpc::OptMap &opt_map) override; 43 | 44 | }; 45 | 46 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/store/phxrpc_store_dispatcher.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | /* phxrpc_store_dispatcher.h 14 | 15 | Generated by phxrpc_pb2service from store.proto 16 | 17 | Please DO NOT edit unless you know exactly what you are doing. 18 | 19 | */ 20 | 21 | #pragma once 22 | 23 | #include "phxrpc/http.h" 24 | #include "phxrpc/rpc.h" 25 | 26 | 27 | class StoreService; 28 | 29 | 30 | class StoreDispatcher { 31 | public: 32 | static const phxrpc::BaseDispatcher::URIFuncMap &GetURIFuncMap(); 33 | 34 | StoreDispatcher(StoreService &service, phxrpc::DispatcherArgs_t *dispatcher_args); 35 | 36 | virtual ~StoreDispatcher(); 37 | 38 | int PHXEcho(const phxrpc::BaseRequest &req, phxrpc::BaseResponse *const resp); 39 | 40 | int Add(const phxrpc::BaseRequest &req, phxrpc::BaseResponse *const resp); 41 | 42 | int Get(const phxrpc::BaseRequest &req, phxrpc::BaseResponse *const resp); 43 | 44 | private: 45 | StoreService &service_; 46 | phxrpc::DispatcherArgs_t *dispatcher_args_; 47 | }; 48 | 49 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/store/phxrpc_store_service.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | /* phxrpc_store_service.cpp 14 | 15 | Generated by phxrpc_pb2service from store.proto 16 | 17 | Please DO NOT edit unless you know exactly what you are doing. 18 | 19 | */ 20 | 21 | #include "phxrpc_store_service.h" 22 | 23 | #include "phxrpc/file.h" 24 | 25 | #include "store.pb.h" 26 | 27 | 28 | StoreService::StoreService() {} 29 | 30 | StoreService::~StoreService() {} 31 | 32 | int StoreService::PHXEcho(const google::protobuf::StringValue &/* req */, 33 | google::protobuf::StringValue */* resp */) { 34 | phxrpc::log(LOG_ERR, "ERROR: PHXEcho unimplemented"); 35 | return -1; 36 | } 37 | 38 | int StoreService::Add(const phxqueue::comm::proto::AddRequest &/* req */, 39 | phxqueue::comm::proto::AddResponse */* resp */) { 40 | phxrpc::log(LOG_ERR, "ERROR: Add unimplemented"); 41 | return -1; 42 | } 43 | 44 | int StoreService::Get(const phxqueue::comm::proto::GetRequest &/* req */, 45 | phxqueue::comm::proto::GetResponse */* resp */) { 46 | phxrpc::log(LOG_ERR, "ERROR: Get unimplemented"); 47 | return -1; 48 | } 49 | 50 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/store/phxrpc_store_service.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | /* phxrpc_store_service.h 14 | 15 | Generated by phxrpc_pb2service from store.proto 16 | 17 | Please DO NOT edit unless you know exactly what you are doing. 18 | 19 | */ 20 | 21 | #pragma once 22 | 23 | #include "store.pb.h" 24 | 25 | 26 | class StoreService { 27 | public: 28 | StoreService(); 29 | virtual ~StoreService(); 30 | 31 | virtual int PHXEcho(const google::protobuf::StringValue &req, 32 | google::protobuf::StringValue *resp); 33 | 34 | virtual int Add(const phxqueue::comm::proto::AddRequest &req, 35 | phxqueue::comm::proto::AddResponse *resp); 36 | 37 | virtual int Get(const phxqueue::comm::proto::GetRequest &req, 38 | phxqueue::comm::proto::GetResponse *resp); 39 | }; 40 | 41 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/store/phxrpc_store_stub.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | /* phxrpc_store_stub.h 14 | 15 | Generated by phxrpc_pb2client from store.proto 16 | 17 | Please DO NOT edit unless you know exactly what you are doing. 18 | 19 | */ 20 | 21 | #pragma once 22 | 23 | #include "store.pb.h" 24 | 25 | 26 | namespace phxrpc { 27 | 28 | 29 | class BaseMessageHandlerFactory; 30 | class BaseTcpStream; 31 | class ClientMonitor; 32 | 33 | 34 | } 35 | 36 | 37 | class StoreStub { 38 | public: 39 | StoreStub(phxrpc::BaseTcpStream &socket, phxrpc::ClientMonitor &client_monitor, 40 | phxrpc::BaseMessageHandlerFactory &msg_handler_factory); 41 | ~StoreStub(); 42 | 43 | void set_keep_alive(const bool keep_alive); 44 | 45 | int PHXEcho(const google::protobuf::StringValue &req, 46 | google::protobuf::StringValue *resp); 47 | 48 | int Add(const phxqueue::comm::proto::AddRequest &req, 49 | phxqueue::comm::proto::AddResponse *resp); 50 | 51 | int Get(const phxqueue::comm::proto::GetRequest &req, 52 | phxqueue::comm::proto::GetResponse *resp); 53 | 54 | private: 55 | phxrpc::BaseTcpStream &socket_; 56 | phxrpc::ClientMonitor &client_monitor_; 57 | bool keep_alive_{false}; 58 | phxrpc::BaseMessageHandlerFactory &msg_handler_factory_; 59 | }; 60 | 61 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/store/phxrpc_store_tool.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | /* phxrpc_store_tool.cpp 14 | 15 | Generated by phxrpc_pb2tool from store.proto 16 | 17 | Please DO NOT edit unless you know exactly what you are doing. 18 | 19 | */ 20 | 21 | #include "phxrpc_store_tool.h" 22 | 23 | #include "phxrpc/file.h" 24 | 25 | #include "store_client.h" 26 | 27 | 28 | using namespace phxrpc; 29 | 30 | 31 | StoreTool::StoreTool() {} 32 | 33 | StoreTool::~StoreTool() {} 34 | 35 | int StoreTool::PHXEcho(phxrpc::OptMap &/* opt_map */) { 36 | printf("\n *** PHXEcho unimplement ***\n"); 37 | 38 | return -1; 39 | } 40 | 41 | int StoreTool::Add(phxrpc::OptMap &/* opt_map */) { 42 | printf("\n *** Add unimplement ***\n"); 43 | 44 | return -1; 45 | } 46 | 47 | int StoreTool::Get(phxrpc::OptMap &/* opt_map */) { 48 | printf("\n *** Get unimplement ***\n"); 49 | 50 | return -1; 51 | } 52 | 53 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/store/phxrpc_store_tool.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | /* phxrpc_store_tool.h 14 | 15 | Generated by phxrpc_pb2tool from store.proto 16 | 17 | Please DO NOT edit unless you know exactly what you are doing. 18 | 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | 25 | 26 | namespace phxrpc { 27 | 28 | 29 | class OptMap; 30 | 31 | 32 | } 33 | 34 | 35 | class StoreTool { 36 | public: 37 | StoreTool(); 38 | virtual ~StoreTool(); 39 | 40 | virtual int PHXEcho(phxrpc::OptMap &bigmap); 41 | 42 | virtual int Add(phxrpc::OptMap &bigmap); 43 | 44 | virtual int Get(phxrpc::OptMap &bigmap); 45 | 46 | typedef int (StoreTool::*ToolFunc_t) (phxrpc::OptMap &); 47 | 48 | typedef struct tagName2Func { 49 | const char *name; 50 | StoreTool::ToolFunc_t func; 51 | const char *opt_string; 52 | const char *usage; 53 | } Name2Func_t; 54 | 55 | static Name2Func_t *GetName2Func() { 56 | static Name2Func_t name2func[]{ 57 | { "PHXEcho", &StoreTool::PHXEcho, "c:f:vs:", "-s " }, 58 | { nullptr, nullptr } 59 | }; 60 | 61 | return name2func; 62 | }; 63 | }; 64 | 65 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/store/store.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package phxqueue_phxrpc.store; 4 | 5 | import "google/protobuf/empty.proto"; 6 | import "google/protobuf/wrappers.proto"; 7 | import "phxqueue/comm/proto/comm.proto"; 8 | import "phxrpc/rpc/phxrpc.proto"; 9 | 10 | service Store { 11 | rpc Add(phxqueue.comm.proto.AddRequest) returns(phxqueue.comm.proto.AddResponse) { 12 | option(phxrpc.CmdID) = 1; 13 | } 14 | rpc Get(phxqueue.comm.proto.GetRequest) returns(phxqueue.comm.proto.GetResponse) { 15 | option(phxrpc.CmdID) = 2; 16 | } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/store/store_client.conf: -------------------------------------------------------------------------------- 1 | # store_client.conf 2 | # 3 | # Generated by phxrpc_pb2server from store.proto 4 | # 5 | # 6 | 7 | [ClientTimeout] 8 | ConnectTimeoutMS = 100 9 | SocketTimeoutMS = 5000 10 | 11 | [Server] 12 | ServerCount = 2 13 | PackageName=phxqueue_phxrpc.store 14 | 15 | [Server0] 16 | IP = 127.0.0.1 17 | Port = 5100 18 | 19 | [Server1] 20 | IP = 127.0.0.1 21 | Port = 5100 22 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/store/store_client.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | /* store_client.h 14 | 15 | Generated by phxrpc_pb2client from store.proto 16 | 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "phxqueue/comm.h" 22 | #include "phxrpc/rpc.h" 23 | 24 | #include "store.pb.h" 25 | 26 | class StoreClient { 27 | public: 28 | static bool Init(const char *config_file); 29 | 30 | static const char *GetPackageName(); 31 | 32 | StoreClient(); 33 | virtual ~StoreClient(); 34 | 35 | int PHXEcho(const google::protobuf::StringValue &req, 36 | google::protobuf::StringValue *resp); 37 | 38 | int PHXBatchEcho(const google::protobuf::StringValue &req, 39 | google::protobuf::StringValue *resp); 40 | 41 | int Add(const phxqueue::comm::proto::AddRequest &req, 42 | phxqueue::comm::proto::AddResponse *resp); 43 | 44 | int Get(const phxqueue::comm::proto::GetRequest &req, 45 | phxqueue::comm::proto::GetResponse *resp); 46 | 47 | phxqueue::comm::RetCode 48 | ProtoAdd(const phxqueue::comm::proto::AddRequest &req, phxqueue::comm::proto::AddResponse &resp); 49 | 50 | phxqueue::comm::RetCode 51 | ProtoGet(const phxqueue::comm::proto::GetRequest &req, phxqueue::comm::proto::GetResponse &resp); 52 | 53 | }; 54 | 55 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/store/store_client_uthread.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | /* store_client.h 14 | 15 | Generated by phxrpc_pb2client from store.proto 16 | 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "phxrpc/network.h" 22 | #include "phxrpc/rpc.h" 23 | 24 | #include "store.pb.h" 25 | 26 | 27 | class StoreClientUThread { 28 | public: 29 | static bool Init(const char *config_file); 30 | 31 | static const char *GetPackageName(); 32 | 33 | StoreClientUThread(phxrpc::UThreadEpollScheduler *uthread_scheduler); 34 | virtual ~StoreClientUThread(); 35 | 36 | int PHXEcho(const google::protobuf::StringValue &req, 37 | google::protobuf::StringValue *resp); 38 | 39 | int PHXBatchEcho(const google::protobuf::StringValue &req, 40 | google::protobuf::StringValue *resp); 41 | 42 | int Add(const phxqueue::comm::proto::AddRequest &req, 43 | phxqueue::comm::proto::AddResponse *resp); 44 | 45 | int Get(const phxqueue::comm::proto::GetRequest &req, 46 | phxqueue::comm::proto::GetResponse *resp); 47 | 48 | private: 49 | phxrpc::UThreadEpollScheduler *uthread_scheduler_; 50 | }; 51 | 52 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/store/store_server.conf: -------------------------------------------------------------------------------- 1 | # store_server.conf 2 | # 3 | # Generated by phxrpc_pb2server from store.proto 4 | # 5 | # 6 | 7 | [Server] 8 | BindIP = 127.0.0.1 9 | Port = 5100 10 | MaxThreads = 16 11 | IOThreadCount = 3 12 | PackageName = phxqueue_phxrpc.store 13 | MaxConnections = 800000 14 | MaxQueueLength = 20480 15 | FastRejectThresholdMS = 20 16 | FastRejectAdjustRate = 5 17 | 18 | [Log] 19 | LogDir = /path/to/log 20 | LogLevel = 3 21 | 22 | [ServerTimeout] 23 | SocketTimeoutMS = 5000 24 | 25 | [Store] 26 | Topic = test 27 | DataDirPath = /path/to/phxqueue/data/ 28 | PhxQueueGlobalConfigPath = /path/to/globalconfig.conf 29 | PaxosPort = 5101 30 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/store/store_server_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | /* store_server_config.h 14 | 15 | Generated by phxrpc_pb2server from store.proto 16 | 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "phxrpc/rpc.h" 22 | 23 | 24 | class StoreServerConfig { 25 | public: 26 | StoreServerConfig(); 27 | 28 | virtual ~StoreServerConfig(); 29 | 30 | bool Read(const char *config_file); 31 | 32 | phxrpc::HshaServerConfig &GetHshaServerConfig(); 33 | 34 | const char *GetTopic() const; 35 | const char *GetDataDirPath() const; 36 | const char *GetPhxQueueGlobalConfigPath() const; 37 | int GetPaxosPort() const; 38 | int GetNPaxosIOThread() const; 39 | int GetNGroup() const; 40 | 41 | private: 42 | phxrpc::HshaServerConfig ep_server_config_; 43 | 44 | char topic_[128]; 45 | char data_dir_path_[128]; 46 | char phxqueue_global_config_path_[128]; 47 | int paxos_port_; 48 | int npaxos_iothread_{3}; 49 | int ngroup_{100}; 50 | }; 51 | 52 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/store/store_service_impl.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | /* store_service_impl.cpp 14 | 15 | Generated by phxrpc_pb2service from store.proto 16 | 17 | */ 18 | 19 | #include "store_service_impl.h" 20 | 21 | #include "phxrpc/file.h" 22 | 23 | #include "store_server_config.h" 24 | 25 | 26 | StoreServiceImpl::StoreServiceImpl(ServiceArgs_t &app_args) : args_(app_args), store_(app_args.store) {} 27 | 28 | StoreServiceImpl::~StoreServiceImpl() {} 29 | 30 | int StoreServiceImpl::PHXEcho(const google::protobuf::StringValue &req, 31 | google::protobuf::StringValue *resp) { 32 | resp->set_value(req.value()); 33 | return 0; 34 | } 35 | 36 | int StoreServiceImpl::Add(const phxqueue::comm::proto::AddRequest &req, 37 | phxqueue::comm::proto::AddResponse *resp) { 38 | int ret{static_cast(store_->Add(req, *resp))}; 39 | 40 | if (0 > ret) { 41 | QLErr("Store Add err %d", ret); 42 | } 43 | 44 | return ret; 45 | } 46 | 47 | int StoreServiceImpl::Get(const phxqueue::comm::proto::GetRequest &req, 48 | phxqueue::comm::proto::GetResponse *resp) { 49 | int ret{static_cast(store_->Get(req, *resp))}; 50 | 51 | if (0 > ret) { 52 | QLErr("Store Get err %d", ret); 53 | } 54 | 55 | return ret; 56 | } 57 | 58 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/store/store_service_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | /* store_service_impl.h 14 | 15 | Generated by phxrpc_pb2service from store.proto 16 | 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "phxqueue/store.h" 22 | 23 | #include "phxrpc_store_service.h" 24 | #include "store.pb.h" 25 | 26 | 27 | class StoreServerConfig; 28 | 29 | 30 | typedef struct tagServiceArgs { 31 | StoreServerConfig *config; 32 | phxqueue::store::Store *store; 33 | } ServiceArgs_t; 34 | 35 | 36 | class StoreServiceImpl : public StoreService { 37 | public: 38 | StoreServiceImpl(ServiceArgs_t &app_args); 39 | virtual ~StoreServiceImpl(); 40 | 41 | virtual int PHXEcho(const google::protobuf::StringValue &req, 42 | google::protobuf::StringValue *resp) override; 43 | 44 | virtual int Add(const phxqueue::comm::proto::AddRequest &req, 45 | phxqueue::comm::proto::AddResponse *resp) override; 46 | 47 | virtual int Get(const phxqueue::comm::proto::GetRequest &req, 48 | phxqueue::comm::proto::GetResponse *resp) override; 49 | 50 | private: 51 | ServiceArgs_t &args_; 52 | phxqueue::store::Store *store_{nullptr}; 53 | }; 54 | 55 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/app/store/store_tool_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | /* store_tool_impl.h 14 | 15 | Generated by phxrpc_pb2tool from store.proto 16 | 17 | */ 18 | 19 | #pragma once 20 | 21 | #include 22 | 23 | #include "phxrpc_store_tool.h" 24 | 25 | 26 | namespace phxrpc { 27 | 28 | 29 | class OptMap; 30 | 31 | 32 | } 33 | 34 | 35 | class StoreToolImpl : public StoreTool { 36 | public: 37 | StoreToolImpl(); 38 | virtual ~StoreToolImpl(); 39 | 40 | virtual int PHXEcho(phxrpc::OptMap &opt_map); 41 | 42 | virtual int Add(phxrpc::OptMap &opt_map) override; 43 | 44 | virtual int Get(phxrpc::OptMap &opt_map) override; 45 | }; 46 | 47 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/comm.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue_phxrpc/comm/fileconfig.h" 16 | #include "phxqueue_phxrpc/comm/fileloader.h" 17 | #include "phxqueue_phxrpc/comm/ini2pb.h" 18 | #include "phxqueue_phxrpc/comm/iniparser.h" 19 | 20 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/comm/fileconfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | 18 | 19 | namespace phxqueue_phxrpc { 20 | 21 | namespace comm { 22 | 23 | 24 | class FileConfig { 25 | public: 26 | FileConfig(); 27 | FileConfig(const std::string &file); 28 | virtual ~FileConfig(); 29 | 30 | void SetFile(const std::string &file); 31 | bool Read(); 32 | bool GetContent(std::string &content); 33 | 34 | private: 35 | virtual void ParseContent(const std::string &content) {} 36 | 37 | class FileConfigImpl; 38 | std::unique_ptr impl_; 39 | }; 40 | 41 | 42 | } // namespace comm 43 | 44 | } // namespace phxqueue_phxrpc 45 | 46 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/comm/fileloader.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | 20 | namespace phxqueue_phxrpc { 21 | 22 | namespace comm { 23 | 24 | 25 | class FileLoader { 26 | public: 27 | FileLoader(); 28 | FileLoader(const std::string &file); 29 | virtual ~FileLoader(); 30 | 31 | void SetCheckInterval(const int check_interval_s); 32 | void SetRefreshDelay(const int refresh_delay_s); 33 | bool SetFileIfUnset(const std::string &file); 34 | 35 | void ResetTimeByInode(ino_t ino); 36 | bool LoadIfModified(); 37 | bool LoadIfModified(bool &is_modified); 38 | uint64_t GetLastModTime(); 39 | 40 | virtual bool LoadFile(const std::string &file, bool is_reload) = 0; 41 | 42 | private: 43 | class FileLoaderImpl; 44 | std::unique_ptr impl_; 45 | }; 46 | 47 | 48 | } // namespace comm 49 | 50 | } // namespace phxqueue_phxrpc 51 | 52 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/comm/ini2pb.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | 23 | namespace phxqueue_phxrpc { 24 | 25 | namespace comm { 26 | 27 | 28 | using INIReadFunc = std::function; 29 | 30 | 31 | class INI2Pb { 32 | public: 33 | INI2Pb(INIReadFunc); 34 | ~INI2Pb(); 35 | bool Parse(google::protobuf::Message *message, int idx = -1); 36 | 37 | private: 38 | bool ParseField(google::protobuf::Message *message, const std::string §ion_name, 39 | const google::protobuf::FieldDescriptor *field_descriptor); 40 | bool ParseMessage(google::protobuf::Message *message, const std::string §ion_name); 41 | 42 | INIReadFunc func_ = nullptr; 43 | }; 44 | 45 | 46 | } // namespace comm 47 | 48 | } // namespace phxqueeu_phxrpc 49 | 50 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/comm/iniparser.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | 20 | namespace phxqueue_phxrpc { 21 | 22 | namespace comm { 23 | 24 | 25 | class INIParser { 26 | public: 27 | INIParser(); 28 | virtual ~INIParser(); 29 | 30 | void ParseContent(const std::string &content); 31 | bool GetValue(const std::string §ion, const std::string &key, std::string &val); 32 | void SetDelAfterGet(bool del_after_get); 33 | void GetAllValue(std::vector> &vals); 34 | 35 | private: 36 | class INIParserImpl; 37 | std::unique_ptr impl_; 38 | }; 39 | 40 | 41 | } // namespace comm 42 | 43 | } // namespace phxqueue_phxrpc 44 | 45 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue_phxrpc/config/baseconfig.h" 16 | #include "phxqueue_phxrpc/config/consumerconfig.h" 17 | #include "phxqueue_phxrpc/config/globalconfig.h" 18 | #include "phxqueue_phxrpc/config/lockconfig.h" 19 | #include "phxqueue_phxrpc/config/schedulerconfig.h" 20 | #include "phxqueue_phxrpc/config/storeconfig.h" 21 | #include "phxqueue_phxrpc/config/topicconfig.h" 22 | 23 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/config/consumerconfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue_phxrpc/config/baseconfig.h" 16 | #include "phxqueue/config.h" 17 | 18 | 19 | namespace phxqueue_phxrpc { 20 | 21 | namespace config { 22 | 23 | 24 | class ConsumerConfig : public BaseConfig { 25 | public: 26 | ConsumerConfig() : BaseConfig() {} 27 | virtual ~ConsumerConfig() {} 28 | }; 29 | 30 | 31 | } // namespace config 32 | 33 | } // namespace phxqueue_phxrpc 34 | 35 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/config/globalconfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue_phxrpc/config/baseconfig.h" 16 | #include "phxqueue/config.h" 17 | 18 | 19 | namespace phxqueue_phxrpc { 20 | 21 | namespace config { 22 | 23 | 24 | class GlobalConfig : public BaseConfig { 25 | public: 26 | GlobalConfig() : BaseConfig() {} 27 | virtual ~GlobalConfig() {} 28 | }; 29 | 30 | 31 | } // namespace config 32 | 33 | } // namespace phxqueue_phxrpc 34 | 35 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/config/lockconfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue_phxrpc/config/baseconfig.h" 16 | #include "phxqueue/config.h" 17 | 18 | 19 | namespace phxqueue_phxrpc { 20 | 21 | namespace config { 22 | 23 | 24 | class LockConfig : public BaseConfig { 25 | public: 26 | LockConfig() : BaseConfig() {} 27 | virtual ~LockConfig() {} 28 | }; 29 | 30 | 31 | } // namespace config 32 | 33 | } // namespace phxqueue_phxrpc 34 | 35 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/config/schedulerconfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue_phxrpc/config/baseconfig.h" 16 | #include "phxqueue/config.h" 17 | 18 | 19 | namespace phxqueue_phxrpc { 20 | 21 | namespace config { 22 | 23 | 24 | class SchedulerConfig : public BaseConfig { 25 | public: 26 | SchedulerConfig() : BaseConfig() {} 27 | virtual ~SchedulerConfig() {} 28 | }; 29 | 30 | 31 | } // namespace config 32 | 33 | } // namespace phxqueue_phxrpc 34 | 35 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/config/storeconfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue_phxrpc/config/baseconfig.h" 16 | #include "phxqueue/config.h" 17 | 18 | 19 | namespace phxqueue_phxrpc { 20 | 21 | namespace config { 22 | 23 | 24 | class StoreConfig : public BaseConfig { 25 | public: 26 | StoreConfig() : BaseConfig() {} 27 | virtual ~StoreConfig() {} 28 | }; 29 | 30 | 31 | } // namespace config 32 | 33 | } // namespace phxqueue_phxrpc 34 | 35 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/config/topicconfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue_phxrpc/config/baseconfig.h" 16 | #include "phxqueue/config.h" 17 | 18 | 19 | namespace phxqueue_phxrpc { 20 | 21 | namespace config { 22 | 23 | 24 | class TopicConfig : public BaseConfig { 25 | public: 26 | TopicConfig() : BaseConfig() {} 27 | virtual ~TopicConfig() {} 28 | }; 29 | 30 | 31 | } // namespace config 32 | 33 | } // namespace phxqueue_phxrpc 34 | 35 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/consumer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue_phxrpc/consumer/consumer.h" 16 | #include "phxqueue_phxrpc/consumer/consumerserverconfig.h" 17 | 18 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/consumer/consumer_server.conf: -------------------------------------------------------------------------------- 1 | { 2 | "consumer": 3 | { 4 | "ip": "127.0.0.1", 5 | "port": "8001", 6 | "topic": "test", 7 | "nproc": "50", 8 | "lock_path_base": "./phxqueueconsumer.lock.", 9 | "phxqueue_global_config_path": "./etc/globalconfig.conf", 10 | "shm_key_base": "53452" 11 | }, 12 | "log": 13 | { 14 | "path": "./log", 15 | "level": "3" 16 | } 17 | } -------------------------------------------------------------------------------- /phxqueue_phxrpc/consumer/consumerserverconfig.conf: -------------------------------------------------------------------------------- 1 | [Log] 2 | log_dir = ./log 3 | log_level = 3 4 | 5 | 6 | [Consumer] 7 | ip = 127.0.0.1 8 | port = 8001 9 | topic = test 10 | nproc = 50 11 | phxqueue_global_config_path = ./etc/consumer_server.conf 12 | shm_key_base = 53452 13 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/consumer/proto/consumerserverconfig.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package phxqueue_phxrpc.consumer.proto; 4 | 5 | message ConsumerServerConfig { 6 | optional Consumer consumer = 1; 7 | optional Log log = 2; 8 | } 9 | 10 | message Consumer { 11 | optional string ip = 1; 12 | optional int32 port = 2; 13 | optional string topic = 3; 14 | optional int32 nproc = 4; 15 | optional string proc_pid_path = 5; 16 | optional string lock_path_base = 6; 17 | optional string phxqueue_global_config_path = 7; 18 | optional int32 shm_key_base = 8; 19 | } 20 | 21 | message Log { 22 | optional string path = 1; 23 | optional int32 level = 2; 24 | } 25 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/plugin.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue_phxrpc/plugin/configfactory.h" 16 | 17 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/producer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue_phxrpc/producer/producer.h" 16 | 17 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/producer/producer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #include "phxqueue_phxrpc/producer.h" 14 | 15 | #include "phxqueue_phxrpc/app/store/store_client.h" 16 | 17 | 18 | namespace phxqueue_phxrpc { 19 | 20 | namespace producer { 21 | 22 | 23 | using namespace std; 24 | 25 | 26 | Producer::Producer(const phxqueue::producer::ProducerOption &opt) 27 | : phxqueue::producer::Producer(opt) {} 28 | 29 | Producer::~Producer() {} 30 | 31 | void Producer::CompressBuffer(const string &buffer, string &compressed_buffer, int &buffer_type) { 32 | compressed_buffer = buffer; 33 | buffer_type = 0; 34 | } 35 | 36 | phxqueue::comm::RetCode Producer::Add(const phxqueue::comm::proto::AddRequest &req, 37 | phxqueue::comm::proto::AddResponse &resp) { 38 | StoreClient store_client; 39 | auto ret(store_client.ProtoAdd(req, resp)); 40 | 41 | if (phxqueue::comm::RetCode::RET_OK != ret) { 42 | QLErr("ProtoAdd ret %d", phxqueue::comm::as_integer(ret)); 43 | } 44 | return ret; 45 | } 46 | 47 | 48 | } // namespace producer 49 | 50 | } // namespace phxqueue_phxrpc 51 | 52 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/producer/producer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue/producer.h" 16 | 17 | 18 | namespace phxqueue_phxrpc { 19 | 20 | namespace producer { 21 | 22 | 23 | class Producer : public phxqueue::producer::Producer { 24 | public: 25 | Producer(const phxqueue::producer::ProducerOption &opt); 26 | virtual ~Producer() override; 27 | 28 | virtual void CompressBuffer(const std::string &buffer, std::string &compressed_buffer, 29 | int &buffer_type) override; 30 | 31 | protected: 32 | virtual phxqueue::comm::RetCode Add(const phxqueue::comm::proto::AddRequest &req, 33 | phxqueue::comm::proto::AddResponse &resp) override; 34 | }; 35 | 36 | 37 | } // namespace producer 38 | 39 | } // namespace phxqueue_phxrpc 40 | 41 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/scheduler.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue_phxrpc/scheduler/scheduler.h" 16 | 17 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/scheduler/scheduler.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue/comm.h" 16 | #include "phxqueue/scheduler.h" 17 | 18 | 19 | namespace phxqueue_phxrpc { 20 | 21 | namespace scheduler { 22 | 23 | 24 | class Scheduler : public phxqueue::scheduler::Scheduler { 25 | public: 26 | Scheduler(const phxqueue::scheduler::SchedulerOption &opt); 27 | virtual ~Scheduler() override; 28 | 29 | virtual phxqueue::comm::RetCode 30 | GetLockInfo(const phxqueue::comm::proto::GetLockInfoRequest &req, 31 | phxqueue::comm::proto::GetLockInfoResponse &resp) override; 32 | virtual phxqueue::comm::RetCode 33 | AcquireLock(const phxqueue::comm::proto::AcquireLockRequest &req, 34 | phxqueue::comm::proto::AcquireLockResponse &resp) override; 35 | }; 36 | 37 | 38 | } // namespace scheduler 39 | 40 | } // namespace phxqueue_phxrpc 41 | 42 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/test/echo_handler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #include "phxqueue_phxrpc/test/echo_handler.h" 14 | 15 | #include 16 | #include 17 | 18 | #include "phxqueue/comm.h" 19 | 20 | 21 | namespace phxqueue_phxrpc { 22 | 23 | namespace test { 24 | 25 | 26 | using namespace phxqueue; 27 | using namespace std; 28 | 29 | 30 | comm::HandleResult EchoHandler::Handle(const comm::proto::ConsumerContext &cc, 31 | comm::proto::QItem &item, string &uncompressed_buffer) { 32 | printf("consume echo \"%s\" succeeded! consumer_group_id %d store_id %d queue_id %d item_uin %" PRIu64 "\n", 33 | item.buffer().c_str(), cc.consumer_group_id(), cc.store_id(), cc.queue_id(), (uint64_t)item.meta().uin()); 34 | fflush(stdout); 35 | return comm::HandleResult::RES_OK; 36 | } 37 | 38 | 39 | } // namespace test 40 | 41 | } // namespace phxqueue_phxrpc 42 | 43 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/test/echo_handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include 16 | 17 | #include "phxqueue/comm.h" 18 | 19 | 20 | namespace phxqueue_phxrpc { 21 | 22 | namespace test { 23 | 24 | 25 | class EchoHandler : public phxqueue::comm::Handler { 26 | public: 27 | EchoHandler() {} 28 | virtual ~EchoHandler() override = default; 29 | 30 | virtual phxqueue::comm::HandleResult Handle(const phxqueue::comm::proto::ConsumerContext &cc, 31 | phxqueue::comm::proto::QItem &item, 32 | std::string &uncompressed_buffer) override; 33 | }; 34 | 35 | 36 | } // namespace test 37 | 38 | } // namespace phxqueue_phxrpc 39 | 40 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/test/etc/consumerconfig.conf: -------------------------------------------------------------------------------- 1 | { 2 | "consumers": 3 | [ 4 | { 5 | "addr": 6 | { 7 | "ip": "127.0.0.1", 8 | "port": "8001" 9 | }, 10 | "scale": "1000", 11 | "consumer_group_ids": [1, 2] 12 | }, 13 | { 14 | "addr": 15 | { 16 | "ip": "127.0.0.1", 17 | "port": "8002" 18 | }, 19 | "scale": "1000", 20 | "consumer_group_ids": [1, 2] 21 | }, 22 | { 23 | "addr": 24 | { 25 | "ip": "127.0.0.1", 26 | "port": "8003" 27 | }, 28 | "scale": "1000", 29 | "consumer_group_ids": [1, 2] 30 | } 31 | ] 32 | } -------------------------------------------------------------------------------- /phxqueue_phxrpc/test/etc/globalconfig.conf: -------------------------------------------------------------------------------- 1 | { 2 | "topic_infos": 3 | [ 4 | { 5 | "topic_id": "1000", 6 | "topic_name": "test", 7 | "topic_config_path": "etc/topicconfig.conf", 8 | "consumer_config_path": "etc/consumerconfig.conf", 9 | "store_config_path": "etc/storeconfig.conf", 10 | "scheduler_config_path": "etc/schedulerconfig.conf", 11 | "lock_config_path": "etc/lockconfig.conf", 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /phxqueue_phxrpc/test/etc/lockconfig.conf: -------------------------------------------------------------------------------- 1 | { 2 | "locks": 3 | [ 4 | { 5 | "lock_id": "1", 6 | "addrs": 7 | [ 8 | { 9 | "ip": "127.0.0.1", 10 | "port": "7100", 11 | "paxos_port": "7101" 12 | }, 13 | { 14 | "ip": "127.0.0.1", 15 | "port": "7200", 16 | "paxos_port": "7201" 17 | }, 18 | { 19 | "ip": "127.0.0.1", 20 | "port": "7300", 21 | "paxos_port": "7301" 22 | } 23 | ], 24 | "scale": 100 25 | }, 26 | ] 27 | } -------------------------------------------------------------------------------- /phxqueue_phxrpc/test/etc/schedulerconfig.conf: -------------------------------------------------------------------------------- 1 | { 2 | "scheduler": 3 | { 4 | "addrs": 5 | [ 6 | { 7 | "ip": "127.0.0.1", 8 | "port": "6100" 9 | }, 10 | { 11 | "ip": "127.0.0.1", 12 | "port": "6200" 13 | }, 14 | { 15 | "ip": "127.0.0.1", 16 | "port": "6300" 17 | } 18 | ] 19 | } 20 | } -------------------------------------------------------------------------------- /phxqueue_phxrpc/test/etc/simpleconfig.conf: -------------------------------------------------------------------------------- 1 | { 2 | "foo": 3 | { 4 | "f": "1" 5 | }, 6 | "bars": 7 | [ 8 | { 9 | "a": "1000", 10 | "foo": 11 | { 12 | "f": "1001" 13 | } 14 | }, 15 | { 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/test/etc/storeconfig.conf: -------------------------------------------------------------------------------- 1 | { 2 | "stores": 3 | [ 4 | { 5 | "store_id": "1", 6 | "addrs": 7 | [ 8 | { 9 | "ip": "127.0.0.1", 10 | "port": "5100", 11 | "paxos_port": "5101" 12 | }, 13 | { 14 | "ip": "127.0.0.1", 15 | "port": "5200", 16 | "paxos_port": "5201" 17 | }, 18 | { 19 | "ip": "127.0.0.1", 20 | "port": "5300", 21 | "paxos_port": "5301" 22 | } 23 | ], 24 | "scale": 100, 25 | "pub_ids": [1, 2] 26 | }, 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/test/etc/topicconfig.conf: -------------------------------------------------------------------------------- 1 | { 2 | "topic": 3 | { 4 | "topic_id": "1000" 5 | }, 6 | "queue_infos": 7 | [ 8 | { 9 | "queue_info_id": "1", 10 | "ranges": ["0-9"] 11 | }, 12 | { 13 | "queue_info_id": "2", 14 | "ranges": ["10-19"] 15 | }, 16 | { 17 | "queue_info_id": "3", 18 | "ranges": ["1000-1009"], 19 | "count": "100", 20 | "delay": "10" 21 | }, 22 | { 23 | "queue_info_id": "4", 24 | "ranges": ["1010-1019"], 25 | "count": "-1", 26 | "delay": "20" 27 | }, 28 | ], 29 | "pubs": 30 | [ 31 | { 32 | "pub_id": "1", 33 | "consumer_group_ids": ["1", "2"], 34 | "queue_info_ids": ["1", "3"] 35 | }, 36 | { 37 | "pub_id": "2", 38 | "consumer_group_ids": ["2"], 39 | "queue_info_ids": ["2", "4"] 40 | } 41 | ], 42 | "consumer_groups": 43 | [ 44 | { 45 | "consumer_group_id": "1", 46 | "use_dynamic_scale": "0", 47 | "skip_lock": "1" 48 | }, 49 | { 50 | "consumer_group_id": "2", 51 | "use_dynamic_scale": "0", 52 | "skip_lock": "1" 53 | } 54 | ] 55 | } -------------------------------------------------------------------------------- /phxqueue_phxrpc/test/producer_benchmark.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #include "phxqueue_phxrpc/test/producer_benchmark.h" 14 | 15 | 16 | namespace phxqueue_phxrpc { 17 | 18 | namespace test { 19 | 20 | 21 | using namespace std; 22 | 23 | 24 | ProducerBenchMark::ProducerBenchMark(const int qps, const int nthread, const int nroutine, 25 | const int buf_size, const int ndaemon_batch_thread) 26 | : phxqueue::comm::utils::BenchMark(qps, nthread, nroutine) { 27 | buf_ = string(buf_size ? buf_size : 1, 'a'); 28 | 29 | phxqueue::producer::ProducerOption opt; 30 | opt.ndaemon_batch_thread = ndaemon_batch_thread; 31 | producer_.reset(new phxqueue_phxrpc::producer::Producer(opt)); 32 | producer_->Init(); 33 | } 34 | 35 | int ProducerBenchMark::TaskFunc(const int vtid) { 36 | 37 | phxqueue::comm::RetCode ret; 38 | 39 | const int topic_id{1000}; 40 | const uint64_t uin{0}; 41 | const int handle_id{1}; 42 | const int pub_id{1}; 43 | 44 | ret = producer_->Enqueue(topic_id, uin, handle_id, buf_, pub_id); 45 | 46 | return phxqueue::comm::as_integer(ret); 47 | } 48 | 49 | 50 | } // namespace test 51 | 52 | } // namespace phxqueue_phxrpc 53 | 54 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/test/producer_benchmark.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | 18 | #include "phxqueue/comm.h" 19 | #include "phxqueue_phxrpc/producer.h" 20 | 21 | 22 | namespace phxqueue_phxrpc { 23 | 24 | namespace test { 25 | 26 | 27 | class ProducerBenchMark : public phxqueue::comm::utils::BenchMark { 28 | public: 29 | ProducerBenchMark(const int qps, const int nthread, const int nroutine, 30 | const int buf_size, const int ndaemon_batch_thread = 0); 31 | virtual ~ProducerBenchMark() override = default; 32 | int TaskFunc(const int vtid); 33 | 34 | private: 35 | std::string buf_; 36 | std::unique_ptr producer_; 37 | }; 38 | 39 | 40 | } // namespace test 41 | 42 | } // namespace phxqueue_phxrpc 43 | 44 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/test/proto/simpleconfig.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package phxqueue_phxrpc.test.proto; 4 | 5 | message Foo { 6 | optional int32 f = 1; 7 | } 8 | 9 | message Bar { 10 | optional int32 a = 1; 11 | optional uint64 b = 2 [default = 100]; 12 | optional string c = 3 [default = "101"]; 13 | repeated uint32 d = 4; 14 | optional Foo foo = 5; 15 | } 16 | 17 | message SimpleConfig { 18 | optional Foo foo = 1; 19 | repeated Bar bars = 2; 20 | } -------------------------------------------------------------------------------- /phxqueue_phxrpc/test/test_load_config_main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "phxqueue_phxrpc/test/simpleconfig.h" 28 | 29 | 30 | using namespace std; 31 | 32 | 33 | int main() { 34 | phxqueue_phxrpc::test::SimpleConfig simple_config("./etc/simpleconfig.conf"); 35 | 36 | while (1) { 37 | sleep(1); 38 | 39 | bool is_modified{false}; 40 | simple_config.LoadIfModified(is_modified); 41 | 42 | if (is_modified) cout << "modified" << endl; 43 | cout << simple_config.GetProto().DebugString() << endl; 44 | cout << simple_config.GetProto().bars_size() << endl; 45 | } 46 | 47 | return 0; 48 | } 49 | 50 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/test/test_rpc_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #pragma once 14 | 15 | #include "phxqueue/test/test_config.h" 16 | 17 | 18 | namespace phxqueue_phxrpc { 19 | 20 | namespace test { 21 | 22 | 23 | class TestConfig : public phxqueue::test::TestConfig { 24 | public: 25 | static void Process(); 26 | }; 27 | 28 | 29 | } // namespace test 30 | 31 | } // namespace phxqueue_phxrpc 32 | 33 | -------------------------------------------------------------------------------- /phxqueue_phxrpc/test/test_rpc_config_main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Tencent is pleased to support the open source community by making PhxQueue available. 3 | Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 5 | 6 | 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 9 | */ 10 | 11 | 12 | 13 | #include 14 | 15 | #include "phxqueue_phxrpc/test/test_rpc_config.h" 16 | 17 | #include "phxqueue/comm.h" 18 | #include "phxqueue/plugin.h" 19 | 20 | 21 | using namespace std; 22 | 23 | 24 | int main(int argc, char **argv) { 25 | phxqueue::comm::LogFunc log_func; 26 | phxqueue::plugin::LoggerGoogle::GetLogger("test_main", "/tmp/phxqueue/log", 3, log_func); 27 | phxqueue::comm::Logger::GetInstance()->SetLogFunc(log_func); 28 | 29 | phxqueue_phxrpc::test::TestConfig::Process(); 30 | 31 | return 0; 32 | } 33 | 34 | --------------------------------------------------------------------------------