Skip to content
Closed
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ IndentGotoLabels: true
IndentPPDirectives: None
IndentWidth: 2
IndentWrappedFunctionNames: false
InsertNewlineAtEOF: true
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
Expand Down
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2818b101312ee94224fa06c266e7c0bce910e437 # ignore repository-wide reformat
15 changes: 2 additions & 13 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,6 @@ jobs:
sudo apt-get install -y clang-format clang-tidy cmake g++ make
bash scripts/install_dependency.sh

- name: Get changed C/C++ files
id: changed-files
uses: tj-actions/changed-files@v46.0.5
with:
files: |
**/*.c
**/*.h
**/*.cpp
**/*.cc
**/*.hpp

- name: Create log directory
run: mkdir -p logs

Expand All @@ -41,7 +30,7 @@ jobs:
echo "Running clang-format checks..."
FORMAT_ERRORS=0

for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
for file in $(find . -iname '*.h' -or -iname '*.c' -or -iname '*.cpp' -or -iname '*.hpp' -or -iname '*.cc'); do
echo "Checking formatting for $file"
if ! clang-format --dry-run --Werror "$file" >> logs/format.log 2>&1; then
echo "::error file=$file::Formatting issues in $file"
Expand Down Expand Up @@ -72,7 +61,7 @@ jobs:
echo "Running clang-tidy checks..."
FILES_WITH_ISSUES=0

for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
for file in $(find . -iname '*.h' -or -iname '*.c' -or -iname '*.cpp' -or -iname '*.hpp' -or -iname '*.cc'); do
echo "Checking $file with clang-tidy"
LOG_FILE="logs/tidy_$(basename "$file").log"

Expand Down
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
9 changes: 4 additions & 5 deletions example/cacheCluster/consistentHash.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,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 Expand Up @@ -217,4 +216,4 @@ void ch_ring_destroy_ring(ring_t *ring) {

#ifdef __cplusplus
}
#endif
#endif
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
25 changes: 12 additions & 13 deletions example/cacheCluster/include/md5.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

This code implements the MD5 Algorithm defined in RFC 1321, whose
text is available at
http://www.ietf.org/rfc/rfc1321.txt
http://www.ietf.org/rfc/rfc1321.txt
The code is derived from the text of the RFC, including the test suite
(section A.5) but excluding the rest of Appendix A. It does not include
any code or documentation that is identified in the RFC as being
Expand All @@ -38,17 +38,17 @@
that follows (in reverse chronological order):

2002-04-13 lpd Removed support for non-ANSI compilers; removed
references to Ghostscript; clarified derivation from RFC 1321;
now handles byte order either statically or dynamically.
references to Ghostscript; clarified derivation from RFC 1321;
now handles byte order either statically or dynamically.
1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
added conditionalization for C++ compilation from Martin
Purschke <purschke@bnl.gov>.
added conditionalization for C++ compilation from Martin
Purschke <purschke@bnl.gov>.
1999-05-03 lpd Original version.
*/

#ifndef md5_INCLUDED
# define md5_INCLUDED
#define md5_INCLUDED

/*
* This package supports both compile-time and run-time determination of CPU
Expand All @@ -61,18 +61,17 @@
*/

typedef unsigned char md5_byte_t; /* 8-bit byte */
typedef unsigned int md5_word_t; /* 32-bit word */
typedef unsigned int md5_word_t; /* 32-bit word */

/* Define the state of the MD5 Algorithm. */
typedef struct md5_state_s {
md5_word_t count[2]; /* message length in bits, lsw first */
md5_word_t abcd[4]; /* digest buffer */
md5_byte_t buf[64]; /* accumulate block */
md5_word_t count[2]; /* message length in bits, lsw first */
md5_word_t abcd[4]; /* digest buffer */
md5_byte_t buf[64]; /* accumulate block */
} md5_state_t;

#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif

/* Initialize the algorithm. */
Expand All @@ -95,7 +94,7 @@ _declspec(dllexport)
void md5_finish(md5_state_t *pms, md5_byte_t digest[16]);

#ifdef __cplusplus
} /* end extern "C" */
} /* end extern "C" */
#endif

#endif /* md5_INCLUDED */
140 changes: 67 additions & 73 deletions example/cacheCluster/libketama/include/ketama.h
Original file line number Diff line number Diff line change
@@ -1,60 +1,56 @@
/*
* Copyright (c) 2017, Emory University, All rights reserved.
* Juncheng Yang <jason.yang.china@outlook.com>
*
* Modify for libCacheSim based on original version
* also add const modifier for compiler optimizations
*
*/



/*
* Copyright (c) 2017, Emory University, All rights reserved.
* Juncheng Yang <jason.yang.china@outlook.com>
*
* Modify for libCacheSim based on original version
* also add const modifier for compiler optimizations
*
*/

/*
* Copyright (c) 2007, Last.fm, All rights reserved.
* Richard Jones <rj@last.fm>
* Christian Muehlhaeuser <muesli@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Last.fm Limited nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Last.fm ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Last.fm BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
* Copyright (c) 2007, Last.fm, All rights reserved.
* Richard Jones <rj@last.fm>
* Christian Muehlhaeuser <muesli@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Last.fm Limited nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Last.fm ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Last.fm BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef KETAMA_LIBKETAMA_KETAMA_H__
#define KETAMA_LIBKETAMA_KETAMA_H__

#include <sys/sem.h> /* semaphore functions and structs. */
#include <sys/sem.h> /* semaphore functions and structs. */

#define MC_SHMSIZE 524288 // 512KB should be ample.
#define MC_SHMSIZE 524288 // 512KB should be ample.

#ifdef __cplusplus /* If this is a C++ compiler, use C linkage */
extern "C" {
#endif

#ifndef __APPLE__
union semun
{
int val; /* used for SETVAL only */
struct semid_ds *buf; /* for IPC_STAT and IPC_SET */
ushort *array; /* used for GETALL and SETALL */
union semun {
int val; /* used for SETVAL only */
struct semid_ds *buf; /* for IPC_STAT and IPC_SET */
ushort *array; /* used for GETALL and SETALL */
};
#endif

Expand All @@ -67,64 +63,63 @@ typedef struct {

typedef struct {
char addr[22];
unsigned long memory; // in CDNSimulator, this is used as weight
unsigned long memory; // in CDNSimulator, this is used as weight
} serverinfo;

typedef struct {
int numpoints;
void *modtime;
void *array; //array of mcs structs
void *array; // array of mcs structs
} continuum;

typedef continuum *ketama_continuum;

/** build a consistent hashing ring
* given the number of servers and the weight of each server.
* if weight is NULL, then each server has equal weight.
* key_identifier is just a number for identifying shared memory */
* given the number of servers and the weight of each server.
* if weight is NULL, then each server has equal weight.
* key_identifier is just a number for identifying shared memory */
int ketama_build_hashring(ketama_continuum *const contptr,
const unsigned int num_servers,
const unsigned long *const weight,
const int key_identifier);

int ketama_get_server_index(
const ketama_continuum cont,
const char *const key);
int ketama_get_server_index(const ketama_continuum cont, const char *const key);

void ketama_get_server_indexes(
const ketama_continuum cont,
const char *const key,
unsigned int n, int *indexes);
void ketama_get_server_indexes(const ketama_continuum cont,
const char *const key, unsigned int n,
int *indexes);

/** \brief Get a continuum struct that contains a reference to the server list.
* \param contptr The value of this pointer will contain the retrieved continuum.
* \param filename The server-definition file which defines our continuum.
* \return 0 on failure, 1 on success. */
* \param contptr The value of this pointer will contain the retrieved
* continuum.
* \param filename The server-definition file which defines our continuum.
* \return 0 on failure, 1 on success. */
int ketama_roll(ketama_continuum *contptr, char *filename);

/** \brief Frees any allocated memory.
* \param contptr The continuum that you want to be destroy. */
* \param contptr The continuum that you want to be destroy. */
void ketama_smoke(ketama_continuum contptr);

/** \brief Maps a key onto a server in the continuum.
* \param key The key that you want to map to a specific server.
* \param cont Pointer to the continuum in which we will search.
* \return The mcs struct that the given key maps to. */
* \param key The key that you want to map to a specific server.
* \param cont Pointer to the continuum in which we will search.
* \return The mcs struct that the given key maps to. */
mcs *ketama_get_server(char *key, ketama_continuum cont);

/** \brief Print the server list of a continuum to stdout.
* \param c The continuum to print. */
* \param c The continuum to print. */
void ketama_print_continuum(ketama_continuum c);

/** \brief Compare two server entries in the circle.
* \param a The first entry.
* \param b The second entry.
* \return -1 if b greater a, +1 if a greater b or 0 if both are equal. */
* \param a The first entry.
* \param b The second entry.
* \return -1 if b greater a, +1 if a greater b or 0 if both are equal. */
int ketama_compare(mcs *a, mcs *b);

/** \brief Hashing function, converting a string to an unsigned int by using MD5.
* \param inString The string that you want to hash.
* \return The resulting hash. */
/** \brief Hashing function, converting a string to an unsigned int by using
* MD5.
* \param inString The string that you want to hash.
* \return The resulting hash. */
unsigned int ketama_hashi(const char *const inString);

/** \brief Hashing function to 16 bytes char array using MD5.
Expand All @@ -133,12 +128,11 @@ unsigned int ketama_hashi(const char *const inString);
void ketama_md5_digest(const char *const inString, unsigned char md5pword[16]);

/** \brief Error method for error checking.
* \return The latest error that occurred. */
* \return The latest error that occurred. */
char *ketama_error();

#ifdef __cplusplus /* If this is a C++ compiler, end C linkage */
}
#endif

#endif // KETAMA_LIBKETAMA_KETAMA_H__

#endif // KETAMA_LIBKETAMA_KETAMA_H__
Loading