Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add go integrate test #1792

Merged
merged 26 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
259 changes: 138 additions & 121 deletions .github/workflows/pika.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,124 +11,129 @@ env:
BUILD_TYPE: RelWithDebInfo

jobs:
build_on_ubuntu:
# The CMake configure and build commands are platform-agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: cache dependencies
uses: actions/cache@v2
id: cache
with:
path: |
${{ github.workspace }}/${{ env.INSTALL_LOCATION }}
~/.cache/pip
key: ${{ runner.os }}-dependencies

- name: install Deps
if: ${{ steps.cache.output.cache-hit != 'true' }}
run: |
sudo apt-get install -y autoconf libprotobuf-dev protobuf-compiler
sudo apt-get install -y clang-tidy-12 python3-pip
python3 -m pip install --upgrade pip
python3 -m pip install redis

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B build -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DUSE_PIKA_TOOLS=ON -DCMAKE_CXX_FLAGS_DEBUG=-fsanitize=address

- name: Build
# Build your program with the given configuration
run: cmake --build build --config ${{ env.BUILD_TYPE }}

- name: Test
working-directory: ${{ github.workspace }}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C ${{ env.BUILD_TYPE }}

- name: Unit Test
working-directory: ${{ github.workspace }}
run: ./pikatests.sh all

# master on port 9221, slave on port 9231, all with 2 db
- name: Start pika master and slave
working-directory: ${{ github.workspace }}/build
run: |
chmod +x ../tests/integration/start_master_and_slave.sh
../tests/integration/start_master_and_slave.sh

- name: Run Python E2E Tests
working-directory: ${{ github.workspace }}/build
run: |
python3 ../tests/integration/pika_replication_test.py
python3 ../tests/unit/Blpop_Brpop_test.py

build_on_centos:
runs-on: ubuntu-latest
container:
image: centos:7

steps:
- name: Install deps
run: |
yum install -y wget git autoconf centos-release-scl
yum install -y devtoolset-10-gcc devtoolset-10-gcc-c++ devtoolset-10-make devtoolset-10-bin-util
yum install -y llvm-toolset-7 llvm-toolset-7-clang tcl which python3
python3 -m pip install --upgrade pip
python3 -m pip install redis

- name: Install cmake
run: |
wget https://github.com/Kitware/CMake/releases/download/v3.26.4/cmake-3.26.4-linux-x86_64.sh
bash ./cmake-3.26.4-linux-x86_64.sh --skip-license --prefix=/usr

- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Configure CMake
run: |
source /opt/rh/devtoolset-10/enable
cmake -B build -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DUSE_PIKA_TOOLS=ON -DCMAKE_CXX_FLAGS_DEBUG=-fsanitize=address

- name: Build
run: |
source /opt/rh/devtoolset-10/enable
cmake --build build --config ${{ env.BUILD_TYPE }}

- name: Test
working-directory: ${{ github.workspace }}/build
run: ctest -C ${{ env.BUILD_TYPE }}

- name: Unit Test
working-directory: ${{ github.workspace }}
run: ./pikatests.sh all

- name: Start pika master and slave
working-directory: ${{ github.workspace }}/build
run: |
chmod +x ../tests/integration/start_master_and_slave.sh
../tests/integration/start_master_and_slave.sh

- name: Run Python E2E Tests
working-directory: ${{ github.workspace }}/build
run: |
python3 ../tests/integration/pika_replication_test.py
python3 ../tests/unit/Blpop_Brpop_test.py
# build_on_ubuntu:
# # The CMake configure and build commands are platform-agnostic and should work equally well on Windows or Mac.
# # You can convert this to a matrix build if you need cross-platform coverage.
# # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
# runs-on: ubuntu-latest
#
# steps:
# - uses: actions/checkout@v3
#
# - name: cache dependencies
# uses: actions/cache@v2
# id: cache
# with:
# path: |
# ${{ github.workspace }}/${{ env.INSTALL_LOCATION }}
# ~/.cache/pip
# key: ${{ runner.os }}-dependencies
#
# - name: install Deps
# if: ${{ steps.cache.output.cache-hit != 'true' }}
# run: |
# sudo apt-get install -y autoconf libprotobuf-dev protobuf-compiler
# sudo apt-get install -y clang-tidy-12 python3-pip
# python3 -m pip install --upgrade pip
# python3 -m pip install redis
#
# - name: Configure CMake
# # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
# run: cmake -B build -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DUSE_PIKA_TOOLS=ON -DCMAKE_CXX_FLAGS_DEBUG=-fsanitize=address
#
# - name: Build
# # Build your program with the given configuration
# run: cmake --build build --config ${{ env.BUILD_TYPE }}
#
# - name: Test
# working-directory: ${{ github.workspace }}/build
# # Execute tests defined by the CMake configuration.
# # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
# run: ctest -C ${{ env.BUILD_TYPE }}
#
# - name: Unit Test
# working-directory: ${{ github.workspace }}
# run: ./pikatests.sh all
#
# # master on port 9221, slave on port 9231, all with 2 db
# - name: Start pika master and slave
# working-directory: ${{ github.workspace }}/build
# run: |
# chmod +x ../tests/integration/start_master_and_slave.sh
# ../tests/integration/start_master_and_slave.sh
#
# - name: Run Python E2E Tests
# working-directory: ${{ github.workspace }}/build
# run: |
# python3 ../tests/integration/pika_replication_test.py
# python3 ../tests/unit/Blpop_Brpop_test.py
#
# build_on_centos:
# runs-on: ubuntu-latest
# container:
# image: centos:7
#
# steps:
# - name: Install deps
# run: |
# yum install -y wget git autoconf centos-release-scl
# yum install -y devtoolset-10-gcc devtoolset-10-gcc-c++ devtoolset-10-make devtoolset-10-bin-util
# yum install -y llvm-toolset-7 llvm-toolset-7-clang tcl which python3
# python3 -m pip install --upgrade pip
# python3 -m pip install redis
#
# - name: Install cmake
# run: |
# wget https://github.com/Kitware/CMake/releases/download/v3.26.4/cmake-3.26.4-linux-x86_64.sh
# bash ./cmake-3.26.4-linux-x86_64.sh --skip-license --prefix=/usr
#
# - name: Checkout
# uses: actions/checkout@v3
# with:
# fetch-depth: 0
#
# - name: Configure CMake
# run: |
# source /opt/rh/devtoolset-10/enable
# cmake -B build -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DUSE_PIKA_TOOLS=ON -DCMAKE_CXX_FLAGS_DEBUG=-fsanitize=address
#
# - name: Build
# run: |
# source /opt/rh/devtoolset-10/enable
# cmake --build build --config ${{ env.BUILD_TYPE }}
#
# - name: Test
# working-directory: ${{ github.workspace }}/build
# run: ctest -C ${{ env.BUILD_TYPE }}
#
# - name: Unit Test
# working-directory: ${{ github.workspace }}
# run: ./pikatests.sh all
#
# - name: Start pika master and slave
# working-directory: ${{ github.workspace }}/build
# run: |
# chmod +x ../tests/integration/start_master_and_slave.sh
# ../tests/integration/start_master_and_slave.sh
#
# - name: Run Python E2E Tests
# working-directory: ${{ github.workspace }}/build
# run: |
# python3 ../tests/integration/pika_replication_test.py
# python3 ../tests/unit/Blpop_Brpop_test.py

build_on_macos:
runs-on: macos-latest

steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19

- name: cache dependencies
uses: actions/cache@v2
id: cache
Expand All @@ -147,6 +152,12 @@ jobs:
python3 -m pip install --upgrade pip
python3 -m pip install redis

- name: Run Go E2E Tests
working-directory: ${{ github.workspace }}/build
run: |
chmod +x ../tests/integration/integrate_test.sh
sh ../tests/integration/integrate_test.sh

- name: Configure CMake
run: |
export CC=/usr/local/opt/gcc@10/bin/gcc-10
Expand All @@ -156,15 +167,15 @@ jobs:
run: |
cmake --build build --config ${{ env.BUILD_TYPE }}

- name: Test
working-directory: ${{ github.workspace }}/build
run: ctest -C ${{ env.BUILD_TYPE }}

- name: Unit Test
working-directory: ${{ github.workspace }}
run: |
./pikatests.sh all

# - name: Test
# working-directory: ${{ github.workspace }}/build
# run: ctest -C ${{ env.BUILD_TYPE }}
#
# - name: Unit Test
# working-directory: ${{ github.workspace }}
# run: |
# ./pikatests.sh all
#
- name: Start pika master and slave
working-directory: ${{ github.workspace }}/build
run: |
Expand All @@ -175,4 +186,10 @@ jobs:
working-directory: ${{ github.workspace }}/build
run: |
python3 ../tests/integration/pika_replication_test.py
python3 ../tests/unit/Blpop_Brpop_test.py
python3 ../tests/unit/Blpop_Brpop_test.py

- name: Run Go E2E Tests
working-directory: ${{ github.workspace }}/build
run: |
chmod +x ../tests/integration/integrate_test.sh
sh ../tests/integration/integrate_test.sh
7 changes: 6 additions & 1 deletion src/net/src/thread_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ void ThreadPool::set_should_stop() { should_stop_.store(true); }

void ThreadPool::Schedule(TaskFunc func, void* arg) {
std::unique_lock lock(mu_);
wsignal_.wait(lock, [this]() { return queue_.size() < max_queue_size_ || should_stop(); });
if (queue_.size() > max_queue_size_) {
std::cout << "queue size: " << queue_.size() << ", max queue size: " << max_queue_size_;
}
wsignal_.wait(lock, [this]() {
return queue_.size() < max_queue_size_ || should_stop(); });
// wsignal_.wait(lock, [this]() { return should_stop(); });

if (!should_stop()) {
queue_.emplace(func, arg);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's a brief review of the code patch you provided:

  1. The addition of logging the queue size and max queue size when it exceeds the limit is a good improvement for understanding the behavior of the program during execution.
  2. The condition queue_.size() > max_queue_size_ checks if the queue size has exceeded the maximum allowed size. However, it doesn't take any action to handle this situation. Depending on your requirements, you might consider adding logic to handle this case, such as discarding or rejecting new tasks when the queue is full.
  3. The commented line // wsignal_.wait(lock, [this]() { return should_stop(); }); indicates that it was removed from the code patch. If this behavior is intentional and you don't need to check the queue size before waiting, then it is fine. Otherwise, ensure that the removal was not accidental and the existing condition [this]() { return should_stop(); } is sufficient.
  4. It seems that there are no other visible issues or bugs in the provided code patch.

Overall, the reviewed code patch looks appropriate, but further improvements could be made depending on your specific requirements.

Expand Down
12 changes: 12 additions & 0 deletions src/pika_client_conn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,13 @@ void PikaClientConn::BatchExecRedisCmd(const std::vector<net::RedisCmdArgsType>&
}

void PikaClientConn::TryWriteResp() {
if (resp_array.empty()) {
// LOG(INFO) << "【SPEC】Write resp to client【empty】";
}
int expected = 0;
if (resp_num.compare_exchange_strong(expected, -1)) {
for (auto& resp : resp_array) {
// LOG(INFO) << "【SPEC】Write resp to client: " << *resp;
WriteResp(*resp);
}
if (write_completed_cb_) {
Expand All @@ -265,6 +269,13 @@ void PikaClientConn::TryWriteResp() {
}

void PikaClientConn::ExecRedisCmd(const PikaCmdArgsType& argv, const std::shared_ptr<std::string>& resp_ptr) {
std::string cmd_ptr11;
for (const auto& item : argv) {
cmd_ptr11 += item;
cmd_ptr11 += " ";
}
LOG(INFO) << "【SPEC】Get exec Redis Cmd: " << cmd_ptr11;

// get opt
std::string opt = argv[0];
pstd::StringToLower(opt);
Expand All @@ -279,6 +290,7 @@ void PikaClientConn::ExecRedisCmd(const PikaCmdArgsType& argv, const std::shared
// level == 0 or (cmd error) or (is_read)
if (g_pika_conf->consensus_level() == 0 || !cmd_ptr->res().ok() || !cmd_ptr->is_write()) {
*resp_ptr = std::move(cmd_ptr->res().message());
LOG(INFO) << "【SPEC】Exec Redis Cmd: 【" << cmd_ptr11 << "】, result: " << *resp_ptr;
resp_num--;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/pika_dispatch_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ bool PikaDispatchThread::Handles::AccessHandle(std::string& ip) const {
return false;
}

DLOG(INFO) << "new client comming, ip: " << ip;
DLOG(INFO) << "new client comming, ip: " << ip << ":" << g_pika_server->port();
g_pika_server->incr_accumulative_connections();
return true;
}
Expand Down
13 changes: 11 additions & 2 deletions src/pika_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ void BLPopCmd::Do(std::shared_ptr<Slot> slot) {
for (auto& this_key : keys_) {
std::vector<std::string> values;
rocksdb::Status s = slot->db()->LPop(this_key, 1, &values);
if (s.ok()) {
if (s.ok()) {
res_.AppendArrayLen(2);
res_.AppendString(this_key);
res_.AppendString(values[0]);
Expand Down Expand Up @@ -331,8 +331,17 @@ void LPopCmd::DoInitial() {
void LPopCmd::Do(std::shared_ptr<Slot> slot) {
std::vector<std::string> elements;
rocksdb::Status s = slot->db()->LPop(key_, count_, &elements);

std::string res;
for (const auto& item : elements) {
res.append(item);
res.append(" ");
}

LOG(INFO) << "LPopCmd::Do, key=" << key_ << ", count=" << count_ << ", res=" << res;

if (s.ok()) {
res_.AppendArrayLenUint64(elements.size());
res_.AppendArrayLen(elements.size());
for (const auto& element : elements) {
res_.AppendString(element);
}
Expand Down
Loading