Skip to content

Commit

Permalink
Add a new Promote API to KeyValueCache (#1502)
Browse files Browse the repository at this point in the history
Change the PrefetchTiles behavior to promote existing data when it is
requested but available in cache.

Relates-To: OAM-2436

Signed-off-by: Mykhailo Kuchma <[email protected]>
  • Loading branch information
mykhailo-kuchma committed Apr 24, 2024
1 parent 66e88d7 commit ec3441a
Show file tree
Hide file tree
Showing 13 changed files with 240 additions and 144 deletions.
42 changes: 21 additions & 21 deletions .github/workflows/psv_pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
CXX: g++-7
steps:
- name: Check out repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: "C++ Lint checker script"
run: ./scripts/misc/cpplint_ci.sh
shell: bash
Expand All @@ -42,9 +42,9 @@ jobs:
CXX: g++-9
steps:
- name: Check out repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install Ubuntu dependencies
run: sudo apt-get update && sudo apt-get install -y libboost-all-dev ccache libssl-dev libcurl4-openssl-dev gcc-9 g++-9 --no-install-recommends
run: sudo rm /etc/apt/sources.list.d/microsoft-prod.list && sudo apt-get update && sudo apt-get install -y libboost-all-dev ccache libssl-dev libcurl4-openssl-dev gcc-9 g++-9 --no-install-recommends
shell: bash
- name: Compile project with cmake and ccache
run: gcc --version && ./scripts/linux/psv/build_psv.sh
Expand All @@ -63,7 +63,7 @@ jobs:
CXX: g++-7
steps:
- name: Check out repository
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Install Ubuntu dependencies
run: sudo apt-get update && sudo apt-get install -y libboost-all-dev libssl-dev libcurl4-openssl-dev gcc-7 g++-7 --no-install-recommends
shell: bash
Expand All @@ -78,9 +78,9 @@ jobs:
BUILD_TYPE: RelWithDebInfo
steps:
- name: Check out repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install Ubuntu dependencies
run: sudo apt-get update && sudo apt-get install -y libboost-all-dev ccache libssl-dev libcurl4-openssl-dev --no-install-recommends
run: sudo rm /etc/apt/sources.list.d/microsoft-prod.list && sudo apt-get update && sudo apt-get install -y libboost-all-dev ccache libssl-dev libcurl4-openssl-dev --no-install-recommends
shell: bash
- name: Compile project with cmake and ccache
run: gcc --version && ./scripts/linux/psv/build_psv.sh
Expand All @@ -95,9 +95,9 @@ jobs:
CXX: g++-13
steps:
- name: Check out repository
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Install Ubuntu dependencies
run: sudo add-apt-repository ppa:ubuntu-toolchain-r/test && sudo apt-get update && sudo apt-get install -y libboost-all-dev libssl-dev libcurl4-openssl-dev gcc-13 g++-13 --no-install-recommends
run: sudo rm /etc/apt/sources.list.d/microsoft-prod.list && sudo add-apt-repository ppa:ubuntu-toolchain-r/test && sudo apt-get update && sudo apt-get install -y libboost-all-dev libssl-dev libcurl4-openssl-dev gcc-13 g++-13 --no-install-recommends
shell: bash
- name: Compile project without cache
run: ./scripts/linux/psv/build_psv_no_cache.sh
Expand All @@ -112,9 +112,9 @@ jobs:
CXX: g++-13
steps:
- name: Check out repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install Ubuntu dependencies
run: sudo add-apt-repository ppa:ubuntu-toolchain-r/test && sudo apt-get update && sudo apt-get install -y libboost-all-dev ccache libssl-dev libcurl4-openssl-dev --no-install-recommends
run: sudo rm /etc/apt/sources.list.d/microsoft-prod.list && sudo add-apt-repository ppa:ubuntu-toolchain-r/test && sudo apt-get update && sudo apt-get install -y libboost-all-dev ccache libssl-dev libcurl4-openssl-dev --no-install-recommends
shell: bash
- name: Compile project with cmake and ccache
run: gcc --version && ./scripts/linux/psv/build_psv.sh
Expand All @@ -127,9 +127,9 @@ jobs:
BUILD_TYPE: RelWithDebInfo
steps:
- name: Check out repository
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Install Ubuntu dependencies
run: sudo apt-get update && sudo apt-get install -y libboost-all-dev libssl-dev libcurl4-openssl-dev --no-install-recommends
run: sudo rm /etc/apt/sources.list.d/microsoft-prod.list && sudo apt-get update && sudo apt-get install -y libboost-all-dev libssl-dev libcurl4-openssl-dev --no-install-recommends
shell: bash
- name: Compile project without cache
run: ./scripts/linux/psv/build_psv_no_cache.sh
Expand All @@ -145,7 +145,7 @@ jobs:
CXX: clang++-7
steps:
- name: Check out repository
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Install Ubuntu dependencies
run: sudo apt-get update -y && sudo apt-get install clang-7 ccache libcurl4-openssl-dev -y --no-install-recommends --fix-missing
shell: bash
Expand All @@ -161,7 +161,7 @@ jobs:
BUILD_TYPE: RelWithDebInfo
steps:
- name: Check out repository
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Verification of prerequisites
run: env && ls -la $ANDROID_HOME
shell: bash
Expand All @@ -174,7 +174,7 @@ jobs:
runs-on: macOS-11
steps:
- name: Check out repository
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: MacOS Build
run: scripts/macos/psv/azure_macos_build_psv.sh
shell: bash
Expand All @@ -184,7 +184,7 @@ jobs:
runs-on: macOS-12
steps:
- name: Check out repository
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: MacOS Build
run: scripts/macos/psv/azure_macos_build_psv.sh
shell: bash
Expand All @@ -194,7 +194,7 @@ jobs:
runs-on: macOS-11
steps:
- name: Check out repository
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: iOS Xcode 11-7 Build
run: scripts/ios/azure_ios_build_psv.sh
shell: bash
Expand All @@ -206,7 +206,7 @@ jobs:
runs-on: macOS-12
steps:
- name: Check out repository
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: iOS Xcode 14-2 Build
run: scripts/ios/azure_ios_build_psv.sh
shell: bash
Expand All @@ -216,7 +216,7 @@ jobs:
runs-on: macOS-13
steps:
- name: Check out repository
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: iOS Xcode 15 Build
run: scripts/ios/azure_ios_build_psv.sh
shell: bash
Expand All @@ -226,7 +226,7 @@ jobs:
runs-on: macOS-14
steps:
- name: Check out repository
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: iOS Xcode 15 Build
run: scripts/ios/azure_ios_build_psv.sh
shell: bash
Expand All @@ -236,7 +236,7 @@ jobs:
runs-on: ubuntu-20.04
if: github.ref_name != 'master'
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set tags env variables.
Expand Down
9 changes: 8 additions & 1 deletion olp-cpp-sdk-core/include/olp/core/cache/DefaultCache.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2021 HERE Europe B.V.
* Copyright (C) 2019-2024 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -254,6 +254,13 @@ class CORE_API DefaultCache : public KeyValueCache {
*/
bool IsProtected(const std::string& key) const override;

/**
* @brief Promotes a key in the cache LRU when applicable.
*
* @param key The key to promote in the cache LRU.
*/
void Promote(const std::string& key) override;

/**
* @brief Gets size of the corresponding cache.
*
Expand Down
11 changes: 9 additions & 2 deletions olp-cpp-sdk-core/include/olp/core/cache/KeyValueCache.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2021 HERE Europe B.V.
* Copyright (C) 2019-2024 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,7 +19,7 @@

#pragma once

#include <time.h>
#include <ctime>
#include <functional>
#include <limits>
#include <memory>
Expand Down Expand Up @@ -174,6 +174,13 @@ class CORE_API KeyValueCache {
OLP_SDK_CORE_UNUSED(key);
return false;
}

/**
* @brief Promotes a key in the cache LRU when applicable.
*
* @param key The key to promote in the cache LRU.
*/
virtual void Promote(const std::string& key) { OLP_SDK_CORE_UNUSED(key); }
};

} // namespace cache
Expand Down
7 changes: 4 additions & 3 deletions olp-cpp-sdk-core/src/cache/DefaultCache.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2020 HERE Europe B.V.
* Copyright (C) 2019-2024 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,9 +17,8 @@
* License-Filename: LICENSE
*/

#include "DefaultCacheImpl.h"
#include "olp/core/cache/DefaultCache.h"
#include "olp/core/porting/warning_disable.h"
#include "DefaultCacheImpl.h"

namespace olp {
namespace cache {
Expand Down Expand Up @@ -89,5 +88,7 @@ uint64_t DefaultCache::Size(CacheType cache_type) const {

uint64_t DefaultCache::Size(uint64_t new_size) { return impl_->Size(new_size); }

void DefaultCache::Promote(const std::string& key) { impl_->Promote(key); }

} // namespace cache
} // namespace olp
9 changes: 8 additions & 1 deletion olp-cpp-sdk-core/src/cache/DefaultCacheImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ bool DefaultCacheImpl::AddKeyLru(std::string key, const leveldb::Slice& value) {
// end, this could cause exception in std::stoll. This is fixed by
// constructing a string, (We rely on small string optimization here).
std::string timestamp(value.data(), value.size());
props.expiry = std::stoll(timestamp.c_str());
props.expiry = std::stoll(timestamp);
} else {
props.size = value.size();
}
Expand Down Expand Up @@ -1139,5 +1139,12 @@ uint64_t DefaultCacheImpl::Size(uint64_t new_size) {
return evicted;
}

void DefaultCacheImpl::Promote(const std::string& key) {
std::lock_guard<std::mutex> lock(cache_lock_);
if (mutable_cache_lru_) {
mutable_cache_lru_->Find(key);
}
}

} // namespace cache
} // namespace olp
6 changes: 4 additions & 2 deletions olp-cpp-sdk-core/src/cache/DefaultCacheImpl.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2020 HERE Europe B.V.
* Copyright (C) 2019-2024 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -66,6 +66,7 @@ class DefaultCacheImpl {
bool Protect(const DefaultCache::KeyListType& keys);
bool Release(const DefaultCache::KeyListType& keys);
bool IsProtected(const std::string& key) const;
void Promote(const std::string& key);

uint64_t Size(DefaultCache::CacheType type) const;
uint64_t Size(uint64_t new_size);
Expand Down Expand Up @@ -169,7 +170,8 @@ class DefaultCacheImpl {
boost::optional<std::pair<std::string, time_t>> GetFromDiscCache(
const std::string& key);

time_t GetExpiryForMemoryCache(const std::string& key, const time_t& expiry) const;
time_t GetExpiryForMemoryCache(const std::string& key,
const time_t& expiry) const;

CacheSettings settings_;
bool is_open_;
Expand Down
Loading

0 comments on commit ec3441a

Please sign in to comment.