Skip to content

Commit

Permalink
Merge stable/v8.x to stable/v9.x
Browse files Browse the repository at this point in the history
  • Loading branch information
szmyd committed Jan 10, 2024
2 parents 60e85b3 + 537e8de commit 9cdb752
Show file tree
Hide file tree
Showing 15 changed files with 353 additions and 116 deletions.
58 changes: 14 additions & 44 deletions .github/workflows/merge_conan_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,32 @@ on:
push:
branches:
- stable/v8.x
- stable/v9.x
- master

jobs:
Build:
strategy:
fail-fast: false
matrix:
platform: ["ubuntu-22.04", "ubuntu-20.04", "macos-13"]
platform: ["ubuntu-22.04"]
build-type: ["Debug", "Release"]
malloc-impl: ["libc", "tcmalloc", "jemalloc"]
malloc-impl: ["libc", "tcmalloc"]
prerelease: ["True", "False"]
tooling: ["Sanitize", "Coverage", "None"]
exclude:
- build-type: Debug
platform: ubuntu-20.04
- malloc-impl: tcmalloc
platform: ubuntu-20.04
- malloc-impl: jemalloc
platform: ubuntu-20.04
- build-type: Debug
platform: macos-13
- malloc-impl: tcmalloc
platform: macos-13
- malloc-impl: jemalloc
platform: macos-13
- malloc-impl: jemalloc
build-type: Debug
- malloc-impl: jemalloc
prerelease: "False"
- malloc-impl: libc
build-type: Release
platform: ubuntu-22.04
- prerelease: "True"
platform: ubuntu-20.04
- build-type: Debug
tooling: None
- build-type: Debug
malloc-impl: tcmalloc
- build-type: Release
malloc-impl: libc
- build-type: Release
tooling: Sanitize
- build-type: Release
tooling: Coverage
uses: ./.github/workflows/build_dependencies.yml
with:
platform: ${{ matrix.platform }}
Expand All @@ -46,26 +39,3 @@ jobs:
malloc-impl: ${{ matrix.malloc-impl }}
prerelease: ${{ matrix.prerelease }}
testing: 'True'
ChainBuild:
runs-on: "ubuntu-22.04"
steps:
- name: Start IOManager Build
run: |
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.CHAIN_BUILD_TOKEN }}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/eBay/iomanager/actions/workflows/merge_conan_build.yml/dispatches \
-d '{"ref":"master","inputs":{}}'
if: ${{ github.ref == 'refs/heads/master' }}
- name: Start NuraftMesg Build
run: |
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.CHAIN_BUILD_TOKEN }}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/eBay/nuraft_mesg/actions/workflows/merge_conan_build.yml/dispatches \
-d '{"ref":"main","inputs":{}}'
if: ${{ github.ref == 'refs/heads/master' }}
35 changes: 14 additions & 21 deletions .github/workflows/pr_conan_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,32 @@ on:
pull_request:
branches:
- stable/v8.x
- stable/v9.x
- master

jobs:
Build:
strategy:
fail-fast: false
matrix:
platform: ["ubuntu-22.04", "ubuntu-20.04", "macos-13"]
platform: ["ubuntu-22.04"]
build-type: ["Debug", "Release"]
malloc-impl: ["libc", "tcmalloc", "jemalloc"]
malloc-impl: ["libc", "tcmalloc"]
prerelease: ["True", "False"]
tooling: ["Sanitize", "Coverage", "None"]
exclude:
- build-type: Debug
platform: ubuntu-20.04
- malloc-impl: tcmalloc
platform: ubuntu-20.04
- malloc-impl: jemalloc
platform: ubuntu-20.04
- build-type: Debug
platform: macos-13
- malloc-impl: tcmalloc
platform: macos-13
- malloc-impl: jemalloc
platform: macos-13
- malloc-impl: jemalloc
build-type: Debug
- malloc-impl: jemalloc
prerelease: "False"
- malloc-impl: libc
build-type: Release
platform: ubuntu-22.04
- prerelease: "True"
platform: ubuntu-20.04
- build-type: Debug
tooling: None
- build-type: Debug
malloc-impl: tcmalloc
- build-type: Release
malloc-impl: libc
- build-type: Release
tooling: Sanitize
- build-type: Release
tooling: Coverage
uses: ./.github/workflows/build_dependencies.yml
with:
platform: ${{ matrix.platform }}
Expand Down
11 changes: 3 additions & 8 deletions .jenkins/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,13 @@ pipeline {
steps {
script {
sh(script: "sed -Ei 's, version = .*\"([[:digit:]]+\\.[[:digit:]]+\\.[[:digit:]]+).*, version = \"\\1-${env.BUILD_NUMBER}\",' conanfile.py")
sh(script: "sed -Ei 's,#LIBCURLFIXTOKEN.*,self.requires(\"libcurl/7.86.0\"\\, override=True),' conanfile.py")
BUILD_MISSING = "--build missing"
}
}
}
stage('Adjust for Testing/Stable') {
when {
branch "${STABLE_BRANCH}"
}
stage('include build missing') {
steps {
script {
BUILD_MISSING = ""
BUILD_MISSING = "--build missing"
}
}
}
Expand Down Expand Up @@ -109,7 +104,7 @@ pipeline {
}
steps {
sh "conan user -r ebay-local -p ${ARTIFACTORY_PASS} _service_sds"
sh "conan upload ${PROJECT}/${TAG} -c --all -r ebay-local"
sh "conan upload ${PROJECT}/${TAG} --parallel -c --all -r ebay-local"
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class SISLConan(ConanFile):
name = "sisl"
version = "9.4.5"
version = "9.4.6"

homepage = "https://github.com/eBay/sisl"
description = "Library for fast data structures, utilities"
Expand Down Expand Up @@ -87,6 +87,7 @@ def requirements(self):
#LIBCURLFIXTOKEN
self.requires("libevent/2.1.12", override=True)
self.requires("openssl/1.1.1q", override=True)
self.requires("libcurl/7.86.0")
self.requires("xz_utils/5.2.5", override=True)
self.requires("zlib/1.2.12", override=True)

Expand Down
83 changes: 83 additions & 0 deletions include/sisl/auth_manager/LRUCache.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#pragma once

#include <functional>
#include <list>
#include <mutex>
#include <optional>
#include <shared_mutex>
#include <unordered_map>

namespace sisl {

/**
*
* written by @jiankun
*
* A high performance LRU cache implementation.
*
* The cache provides two atomic operations:
* put(key, value): put an object into the cache.
* get(key): returns a optional reference to the value found by key in cache
*
* Important notes:
* 1. The get() method returns a const reference, any change to the reference
* needs to be done by a Put call.
* 2. The put/get methods are thread safe.
*/
template < typename key_t, typename value_t >
class LRUCache {
public:
using kv_pair_t = std::pair< key_t, value_t >;
using list_iterator_t = typename std::list< kv_pair_t >::iterator;

explicit LRUCache(size_t capacity) : capacity_(capacity) {}

template < typename K, typename V >
void put(K&& key, V&& value) {
std::unique_lock< std::shared_mutex > l{mtx_};

auto it = items_map_.find(key);
if (it != items_map_.end()) {
items_list_.erase(it->second);
items_map_.erase(it);
}

items_list_.emplace_front(std::make_pair(std::forward< K >(key), std::forward< V >(value)));
items_map_[key] = items_list_.begin();

if (items_map_.size() > capacity_) {
auto last = items_list_.rbegin();
items_map_.erase(last->first);
items_list_.pop_back();
}
}

[[nodiscard]] std::optional< value_t > get(const key_t& key) {
// we need unique lock for the splice operation
std::unique_lock< std::shared_mutex > l{mtx_};

auto it = items_map_.find(key);
if (it == items_map_.end()) { return std::nullopt; }

items_list_.splice(items_list_.begin(), items_list_, it->second);
return std::optional(it->second->second);
}

bool exists(const key_t& key) const {
std::shared_lock< std::shared_mutex > l{mtx_};
return items_map_.find(key) != items_map_.end();
}

[[nodiscard]] size_t size() const {
std::shared_lock< std::shared_mutex > l{mtx_};
return items_map_.size();
}

private:
std::list< kv_pair_t > items_list_;
std::unordered_map< key_t, list_iterator_t > items_map_;
size_t capacity_;
mutable std::shared_mutex mtx_;
};

} // namespace sisl
36 changes: 35 additions & 1 deletion include/sisl/auth_manager/auth_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,54 @@

#include <sisl/utility/enum.hpp>
#include "security_config.hpp"
#include "LRUCache.h"

namespace sisl {

ENUM(AuthVerifyStatus, uint8_t, OK, UNAUTH, FORBIDDEN)

template < typename key_t, typename value_t >
class LRUCache;

/**
* This struct holds information of a token, that can be used as if
* they were extracted from decoded token.
*/
struct CachedToken {
AuthVerifyStatus response_status;
std::string msg;
bool valid;
std::chrono::system_clock::time_point expires_at;

inline void set_invalid(AuthVerifyStatus code, const std::string& reason) {
valid = false;
response_status = code;
msg = reason;
}

inline void set_valid() {
valid = true;
response_status = AuthVerifyStatus::OK;
}
};

class AuthManager {
public:
AuthManager() {}
AuthManager();
virtual ~AuthManager() = default;
AuthVerifyStatus verify(const std::string& token, std::string& msg) const;

private:
void verify_decoded(const jwt::decoded_jwt& decoded) const;
virtual std::string download_key(const std::string& key_url) const;
std::string get_app(const jwt::decoded_jwt& decoded) const;

// the verify method is declared const. We make this mutable
// as these caches are modified in the verify method. md5_sum(raw_token) ->
// DecodedToken
mutable LRUCache< std::string, CachedToken > m_cached_tokens;

// key_id -> signing public key
mutable LRUCache< std::string, std::string > m_cached_keys;
};
} // namespace sisl
2 changes: 2 additions & 0 deletions include/sisl/logging/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <string_view>
#include <unordered_set>
#include <vector>
#include <filesystem>

#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/control/if.hpp>
Expand Down Expand Up @@ -482,6 +483,7 @@ extern bool is_crash_handler_installed();
extern bool restore_signal_handler(const SignalType sig_num);
extern bool restore_signal_handlers();
extern bool send_thread_signal(const pthread_t thr, const SignalType sig_num);
extern std::filesystem::path get_base_dir();

template < typename... Args >
std::string format_log_msg(const char* const msg, Args&&... args) {
Expand Down
11 changes: 11 additions & 0 deletions src/auth_manager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,16 @@ if (DEFINED ENABLE_TESTING)
GTest::gmock
)
add_test(NAME AuthManager COMMAND test_auth_mgr)

add_executable(test_lru_cache)
target_sources(test_lru_cache PRIVATE
tests/LRUCacheTest.cpp
)
target_link_libraries(test_lru_cache
sisl
${COMMON_DEPS}
GTest::gmock
)
add_test(NAME LRUCache COMMAND test_lru_cache)
endif()
endif()
Loading

0 comments on commit 9cdb752

Please sign in to comment.