Skip to content

Commit ec3441a

Browse files
Add a new Promote API to KeyValueCache (#1502)
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 <ext-mykhailo.kuchma@here.com>
1 parent 66e88d7 commit ec3441a

File tree

13 files changed

+240
-144
lines changed

13 files changed

+240
-144
lines changed

.github/workflows/psv_pipelines.yml

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
CXX: g++-7
2323
steps:
2424
- name: Check out repository
25-
uses: actions/checkout@v3
25+
uses: actions/checkout@v4
2626
- name: "C++ Lint checker script"
2727
run: ./scripts/misc/cpplint_ci.sh
2828
shell: bash
@@ -42,9 +42,9 @@ jobs:
4242
CXX: g++-9
4343
steps:
4444
- name: Check out repository
45-
uses: actions/checkout@v3
45+
uses: actions/checkout@v4
4646
- name: Install Ubuntu dependencies
47-
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
47+
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
4848
shell: bash
4949
- name: Compile project with cmake and ccache
5050
run: gcc --version && ./scripts/linux/psv/build_psv.sh
@@ -63,7 +63,7 @@ jobs:
6363
CXX: g++-7
6464
steps:
6565
- name: Check out repository
66-
uses: actions/checkout@v2
66+
uses: actions/checkout@v4
6767
- name: Install Ubuntu dependencies
6868
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
6969
shell: bash
@@ -78,9 +78,9 @@ jobs:
7878
BUILD_TYPE: RelWithDebInfo
7979
steps:
8080
- name: Check out repository
81-
uses: actions/checkout@v3
81+
uses: actions/checkout@v4
8282
- name: Install Ubuntu dependencies
83-
run: sudo apt-get update && sudo apt-get install -y libboost-all-dev ccache libssl-dev libcurl4-openssl-dev --no-install-recommends
83+
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
8484
shell: bash
8585
- name: Compile project with cmake and ccache
8686
run: gcc --version && ./scripts/linux/psv/build_psv.sh
@@ -95,9 +95,9 @@ jobs:
9595
CXX: g++-13
9696
steps:
9797
- name: Check out repository
98-
uses: actions/checkout@v2
98+
uses: actions/checkout@v4
9999
- name: Install Ubuntu dependencies
100-
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
100+
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
101101
shell: bash
102102
- name: Compile project without cache
103103
run: ./scripts/linux/psv/build_psv_no_cache.sh
@@ -112,9 +112,9 @@ jobs:
112112
CXX: g++-13
113113
steps:
114114
- name: Check out repository
115-
uses: actions/checkout@v3
115+
uses: actions/checkout@v4
116116
- name: Install Ubuntu dependencies
117-
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
117+
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
118118
shell: bash
119119
- name: Compile project with cmake and ccache
120120
run: gcc --version && ./scripts/linux/psv/build_psv.sh
@@ -127,9 +127,9 @@ jobs:
127127
BUILD_TYPE: RelWithDebInfo
128128
steps:
129129
- name: Check out repository
130-
uses: actions/checkout@v2
130+
uses: actions/checkout@v4
131131
- name: Install Ubuntu dependencies
132-
run: sudo apt-get update && sudo apt-get install -y libboost-all-dev libssl-dev libcurl4-openssl-dev --no-install-recommends
132+
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
133133
shell: bash
134134
- name: Compile project without cache
135135
run: ./scripts/linux/psv/build_psv_no_cache.sh
@@ -145,7 +145,7 @@ jobs:
145145
CXX: clang++-7
146146
steps:
147147
- name: Check out repository
148-
uses: actions/checkout@v2
148+
uses: actions/checkout@v4
149149
- name: Install Ubuntu dependencies
150150
run: sudo apt-get update -y && sudo apt-get install clang-7 ccache libcurl4-openssl-dev -y --no-install-recommends --fix-missing
151151
shell: bash
@@ -161,7 +161,7 @@ jobs:
161161
BUILD_TYPE: RelWithDebInfo
162162
steps:
163163
- name: Check out repository
164-
uses: actions/checkout@v2
164+
uses: actions/checkout@v4
165165
- name: Verification of prerequisites
166166
run: env && ls -la $ANDROID_HOME
167167
shell: bash
@@ -174,7 +174,7 @@ jobs:
174174
runs-on: macOS-11
175175
steps:
176176
- name: Check out repository
177-
uses: actions/checkout@v2
177+
uses: actions/checkout@v4
178178
- name: MacOS Build
179179
run: scripts/macos/psv/azure_macos_build_psv.sh
180180
shell: bash
@@ -184,7 +184,7 @@ jobs:
184184
runs-on: macOS-12
185185
steps:
186186
- name: Check out repository
187-
uses: actions/checkout@v2
187+
uses: actions/checkout@v4
188188
- name: MacOS Build
189189
run: scripts/macos/psv/azure_macos_build_psv.sh
190190
shell: bash
@@ -194,7 +194,7 @@ jobs:
194194
runs-on: macOS-11
195195
steps:
196196
- name: Check out repository
197-
uses: actions/checkout@v2
197+
uses: actions/checkout@v4
198198
- name: iOS Xcode 11-7 Build
199199
run: scripts/ios/azure_ios_build_psv.sh
200200
shell: bash
@@ -206,7 +206,7 @@ jobs:
206206
runs-on: macOS-12
207207
steps:
208208
- name: Check out repository
209-
uses: actions/checkout@v2
209+
uses: actions/checkout@v4
210210
- name: iOS Xcode 14-2 Build
211211
run: scripts/ios/azure_ios_build_psv.sh
212212
shell: bash
@@ -216,7 +216,7 @@ jobs:
216216
runs-on: macOS-13
217217
steps:
218218
- name: Check out repository
219-
uses: actions/checkout@v2
219+
uses: actions/checkout@v4
220220
- name: iOS Xcode 15 Build
221221
run: scripts/ios/azure_ios_build_psv.sh
222222
shell: bash
@@ -226,7 +226,7 @@ jobs:
226226
runs-on: macOS-14
227227
steps:
228228
- name: Check out repository
229-
uses: actions/checkout@v2
229+
uses: actions/checkout@v4
230230
- name: iOS Xcode 15 Build
231231
run: scripts/ios/azure_ios_build_psv.sh
232232
shell: bash
@@ -236,7 +236,7 @@ jobs:
236236
runs-on: ubuntu-20.04
237237
if: github.ref_name != 'master'
238238
steps:
239-
- uses: actions/checkout@v3
239+
- uses: actions/checkout@v4
240240
with:
241241
fetch-depth: 0
242242
- name: Set tags env variables.

olp-cpp-sdk-core/include/olp/core/cache/DefaultCache.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2021 HERE Europe B.V.
2+
* Copyright (C) 2019-2024 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -254,6 +254,13 @@ class CORE_API DefaultCache : public KeyValueCache {
254254
*/
255255
bool IsProtected(const std::string& key) const override;
256256

257+
/**
258+
* @brief Promotes a key in the cache LRU when applicable.
259+
*
260+
* @param key The key to promote in the cache LRU.
261+
*/
262+
void Promote(const std::string& key) override;
263+
257264
/**
258265
* @brief Gets size of the corresponding cache.
259266
*

olp-cpp-sdk-core/include/olp/core/cache/KeyValueCache.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2021 HERE Europe B.V.
2+
* Copyright (C) 2019-2024 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@
1919

2020
#pragma once
2121

22-
#include <time.h>
22+
#include <ctime>
2323
#include <functional>
2424
#include <limits>
2525
#include <memory>
@@ -174,6 +174,13 @@ class CORE_API KeyValueCache {
174174
OLP_SDK_CORE_UNUSED(key);
175175
return false;
176176
}
177+
178+
/**
179+
* @brief Promotes a key in the cache LRU when applicable.
180+
*
181+
* @param key The key to promote in the cache LRU.
182+
*/
183+
virtual void Promote(const std::string& key) { OLP_SDK_CORE_UNUSED(key); }
177184
};
178185

179186
} // namespace cache

olp-cpp-sdk-core/src/cache/DefaultCache.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2020 HERE Europe B.V.
2+
* Copyright (C) 2019-2024 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,9 +17,8 @@
1717
* License-Filename: LICENSE
1818
*/
1919

20-
#include "DefaultCacheImpl.h"
2120
#include "olp/core/cache/DefaultCache.h"
22-
#include "olp/core/porting/warning_disable.h"
21+
#include "DefaultCacheImpl.h"
2322

2423
namespace olp {
2524
namespace cache {
@@ -89,5 +88,7 @@ uint64_t DefaultCache::Size(CacheType cache_type) const {
8988

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

91+
void DefaultCache::Promote(const std::string& key) { impl_->Promote(key); }
92+
9293
} // namespace cache
9394
} // namespace olp

olp-cpp-sdk-core/src/cache/DefaultCacheImpl.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ bool DefaultCacheImpl::AddKeyLru(std::string key, const leveldb::Slice& value) {
508508
// end, this could cause exception in std::stoll. This is fixed by
509509
// constructing a string, (We rely on small string optimization here).
510510
std::string timestamp(value.data(), value.size());
511-
props.expiry = std::stoll(timestamp.c_str());
511+
props.expiry = std::stoll(timestamp);
512512
} else {
513513
props.size = value.size();
514514
}
@@ -1139,5 +1139,12 @@ uint64_t DefaultCacheImpl::Size(uint64_t new_size) {
11391139
return evicted;
11401140
}
11411141

1142+
void DefaultCacheImpl::Promote(const std::string& key) {
1143+
std::lock_guard<std::mutex> lock(cache_lock_);
1144+
if (mutable_cache_lru_) {
1145+
mutable_cache_lru_->Find(key);
1146+
}
1147+
}
1148+
11421149
} // namespace cache
11431150
} // namespace olp

olp-cpp-sdk-core/src/cache/DefaultCacheImpl.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2020 HERE Europe B.V.
2+
* Copyright (C) 2019-2024 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -66,6 +66,7 @@ class DefaultCacheImpl {
6666
bool Protect(const DefaultCache::KeyListType& keys);
6767
bool Release(const DefaultCache::KeyListType& keys);
6868
bool IsProtected(const std::string& key) const;
69+
void Promote(const std::string& key);
6970

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

172-
time_t GetExpiryForMemoryCache(const std::string& key, const time_t& expiry) const;
173+
time_t GetExpiryForMemoryCache(const std::string& key,
174+
const time_t& expiry) const;
173175

174176
CacheSettings settings_;
175177
bool is_open_;

0 commit comments

Comments
 (0)