Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions .clang-tidy-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
libCacheSim/dataStructure/robin_hood.h



47 changes: 24 additions & 23 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,32 +66,33 @@ jobs:
-DCMAKE_CXX_FLAGS="-Wall -Wextra -Werror -Wno-unused-variable -Wno-unused-function -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-pedantic -Wformat=2 -Wformat-security -Wshadow -Wwrite-strings -Wmissing-include-dirs" \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON

- name: Clang-tidy check
if: steps.changed-files.outputs.any_changed == 'true'
run: |
echo "Running clang-tidy checks..."
FILES_WITH_ISSUES=0
# TODO(jason): disable clang-tidy check for now, as it reports too many CXX header issues
# - name: Clang-tidy check
# if: steps.changed-files.outputs.any_changed == 'true'
# run: |
# echo "Running clang-tidy checks..."
# FILES_WITH_ISSUES=0

for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
echo "Checking $file with clang-tidy"
LOG_FILE="logs/tidy_$(basename "$file").log"
# for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
# echo "Checking $file with clang-tidy"
# LOG_FILE="logs/tidy_$(basename "$file").log"

# Run clang-tidy with selected checks (same as pre-commit hook)
if ! clang-tidy -p=build \
-checks='-*,bugprone-*,cert-*,clang-analyzer-*,cppcoreguidelines-*,performance-*,portability-*,readability-*,-readability-magic-numbers,-readability-braces-around-statements,-cppcoreguidelines-avoid-magic-numbers,-readability-identifier-length,-clang-diagnostic-unused-command-line-argument' \
"$file" > "$LOG_FILE" 2>&1; then
echo "::error file=$file::clang-tidy found issues in $file"
cat "$LOG_FILE"
FILES_WITH_ISSUES=$((FILES_WITH_ISSUES + 1))
fi
done
# # Run clang-tidy with selected checks (same as pre-commit hook)
# if ! clang-tidy -p=build \
# -checks='-*,bugprone-*,cert-*,clang-analyzer-*,cppcoreguidelines-*,performance-*,portability-*,readability-*,-readability-magic-numbers,-readability-braces-around-statements,-cppcoreguidelines-avoid-magic-numbers,-readability-identifier-length,-clang-diagnostic-unused-command-line-argument' \
# "$file" > "$LOG_FILE" 2>&1; then
# echo "::error file=$file::clang-tidy found issues in $file"
# cat "$LOG_FILE"
# FILES_WITH_ISSUES=$((FILES_WITH_ISSUES + 1))
# fi
# done

if [ $FILES_WITH_ISSUES -gt 0 ]; then
echo "clang-tidy found issues in $FILES_WITH_ISSUES files."
exit 1
else
echo "clang-tidy check passed successfully."
fi
# if [ $FILES_WITH_ISSUES -gt 0 ]; then
# echo "clang-tidy found issues in $FILES_WITH_ISSUES files."
# exit 1
# else
# echo "clang-tidy check passed successfully."
# fi

- name: Compilation check
if: steps.changed-files.outputs.any_changed == 'true'
Expand Down
29 changes: 15 additions & 14 deletions example/cacheCluster/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
cmake_minimum_required (VERSION 3.2)
project (cacheCluster)
# set(CMAKE_BUILD_TYPE Debug)
cmake_minimum_required(VERSION 3.10)
# Collect source files
project(cacheCluster)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)


# Find required packages
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/../../cmake/Modules/")
find_package(GLib "2.40" REQUIRED)
include_directories(${GLib_INCLUDE_DIRS})
message(STATUS "glib found? " ${GLib_FOUND} ", GLIB = " ${GLib_LIBRARY} ", header = " ${GLib_INCLUDE_DIRS})

find_package(GLib "2.40" REQUIRED)
message(STATUS "GLib found: ${GLib_LIBRARY}")

find_package(ZSTD)
# https://stackoverflow.com/questions/61377055/cannot-find-gflags-gflags-h-while-building-library-osx/61379123#61379123
include_directories(${ZSTD_INCLUDE_DIR})
if ("${ZSTD_LIBRARIES}" STREQUAL "")
message(FATAL_ERROR "zstd not found")
find_package(ZSTD REQUIRED)
if("${ZSTD_LIBRARIES}" STREQUAL "")
message(FATAL_ERROR "ZSTD not found")
endif()


################ this mode compiles the external cache replacement algorithm together with the simulator ############
message(STATUS "project_source dir = " ${PROJECT_SOURCE_DIR})
file(GLOB ALL_CXX_SRC ${PROJECT_SOURCE_DIR}/*.cpp)
file(GLOB ALL_C_SRC ${PROJECT_SOURCE_DIR}/*.c)
target_include_directories(cacheCluster PRIVATE
${GLib_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/include
)

add_executable(cacheCluster ${ALL_CXX_SRC} ${ALL_C_SRC})
target_link_libraries(cacheCluster libCacheSim m ${GLib_LIBRARY} pthread dl ${ZSTD_LIBRARIES})

3 changes: 1 addition & 2 deletions example/cacheCluster/cacheCluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ namespace CDNSimulator {

bool CacheCluster::get(request_t *req) {
// find the server idx
uint64_t idx =
ch_ring_get_server_from_uint64(req->obj_id, this->_ring);
uint64_t idx = ch_ring_get_server_from_uint64(req->obj_id, this->_ring);

// find the server
CacheServer &server = this->_cache_servers_vec.at(idx);
Expand Down
64 changes: 35 additions & 29 deletions example/cacheCluster/consistentHash.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,27 @@
// modified from libketama
//

#include "include/consistentHash.h"
#include "consistentHash.h"

#include <inttypes.h>
#include <stdbool.h>

#include "include/md5.h"
#include "md5.h"

#ifdef __cplusplus
extern "C" {
#endif

int ch_ring_compare(const void *a, const void *b) {
vnode_t *node_a = (vnode_t *)a;
vnode_t *node_b = (vnode_t *)b;
return (node_a->point < node_b->point)
? -1
: ((node_a->point > node_b->point) ? 1 : 0);
int ch_ring_compare(const void *node_a_ptr, const void *node_b_ptr) {
vnode_t *node_a = (vnode_t *)node_a_ptr;
vnode_t *node_b = (vnode_t *)node_b_ptr;
if (node_a->point < node_b->point) {
return -1;
}
if (node_a->point > node_b->point) {
return 1;
}
return 0;
}

void md5_digest(const char *const inString, unsigned char md5pword[16]) {
Expand All @@ -38,7 +42,7 @@ unsigned int ketama_hash(const char *const inString) {
(digest[1] << 8) | digest[0]);
}

ring_t *ch_ring_create_ring(int n_server, double *weight) {
ring_t *ch_ring_create_ring(int n_server, const double *weight) {
vnode_t *vnodes =
(vnode_t *)malloc(sizeof(vnode_t) * n_server * N_VNODE_PER_SERVER);

Expand All @@ -47,35 +51,38 @@ ring_t *ch_ring_create_ring(int n_server, double *weight) {
ring->n_point = n_server * N_VNODE_PER_SERVER;
ring->vnodes = vnodes;

int i;
unsigned int k, cnt = 0;
int server_idx;
unsigned int key_idx;
unsigned int cnt = 0;

for (i = 0; i < n_server; i++) {
for (server_idx = 0; server_idx < n_server; server_idx++) {
// default all servers have the same weight
unsigned int ks = N_VNODE_PER_SERVER / 4;
unsigned int keys_per_server = N_VNODE_PER_SERVER / 4;
if (weight != NULL)
ks = (unsigned int)floorf(weight[i] * (float)n_server *
(N_VNODE_PER_SERVER / 4));
keys_per_server =
(unsigned int)floorf((float)(weight[server_idx] * (double)n_server *
(N_VNODE_PER_SERVER / 4)));

for (k = 0; k < ks; k++) {
for (key_idx = 0; key_idx < keys_per_server; key_idx++) {
/* 40 hashes, 4 numbers per hash = 160 points per server */
char ss[30];
char string_buf[30];
unsigned char digest[16];

sprintf(ss, "%u-%u", i, k);
md5_digest(ss, digest);
sprintf(string_buf, "%u-%u", server_idx, key_idx);
md5_digest(string_buf, digest);

/* Use successive 4-bytes from hash as numbers for the points on the
* circle: */
int h;
for (h = 0; h < 4; h++) {
int hash_idx;
for (hash_idx = 0; hash_idx < 4; hash_idx++) {
// printf("%d i %d k %d h %d %d %d\n", cnt, i, k, h, ring->n_server,
// ring->n_point);
vnodes[cnt].point = (digest[3 + h * 4] << 24) |
(digest[2 + h * 4] << 16) |
(digest[1 + h * 4] << 8) | digest[h * 4];
vnodes[cnt].point = (digest[3 + hash_idx * 4] << 24) |
(digest[2 + hash_idx * 4] << 16) |
(digest[1 + hash_idx * 4] << 8) |
digest[hash_idx * 4];

vnodes[cnt].server_id = i;
vnodes[cnt].server_id = server_idx;
cnt++;
}
}
Expand Down Expand Up @@ -136,10 +143,9 @@ int ch_ring_get_server(const char *const key, const ring_t *const ring) {
return (ring->vnodes + ch_ring_get_vnode_idx(key, ring))->server_id;
}

int ch_ring_get_server_from_uint64(uint64_t obj_id,
const ring_t *const ring) {
char key[8];
memcpy(key, (char *) &obj_id, 8);
int ch_ring_get_server_from_uint64(uint64_t obj_id, const ring_t *const ring) {
char key[8];
memcpy(key, (char *)&obj_id, 8);
key[7] = 0;
return (ring->vnodes + ch_ring_get_vnode_idx(key, ring))->server_id;
}
Expand Down
3 changes: 2 additions & 1 deletion example/cacheCluster/include/cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
#ifndef CDNSIMULATOR_CACHE_HPP
#define CDNSIMULATOR_CACHE_HPP

#include <inttypes.h>

#include <algorithm>
#include <iostream>
#include <inttypes.h>

#include "libCacheSim/cache.h"
#include "libCacheSim/evictionAlgo.h"
Expand Down
1 change: 0 additions & 1 deletion example/cacheCluster/include/cacheCluster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ namespace CDNSimulator {

class CacheCluster {
private:

// the consistent hash ring
ring_t *_ring = nullptr;

Expand Down
2 changes: 1 addition & 1 deletion example/cacheCluster/include/consistentHash.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
extern "C" {
#endif

#include <inttypes.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>

#define N_VNODE_PER_SERVER 160

Expand Down
Loading