Skip to content

Commit 5a119ff

Browse files
Rdk 58255 main (rdkcentral#6307)
* RDKEMW-3216 : Resiliency improvements for Persistent Store (rdkcentral#6244) * RDKEMW-3216 : Resiliency improvements for Persistent Store Reason for change: Create or use backup on start. Test Procedure: Corrupt store and reboot. Risks: None Signed-off-by: Nikita Poltorapavlo <[email protected]> * combine copy-paste workflows --------- Signed-off-by: Nikita Poltorapavlo <[email protected]> * update changelog and api version --------- Signed-off-by: Nikita Poltorapavlo <[email protected]>
1 parent b261b21 commit 5a119ff

File tree

8 files changed

+102
-200
lines changed

8 files changed

+102
-200
lines changed

.github/workflows/L0-PersistentStore.yml

Lines changed: 0 additions & 48 deletions
This file was deleted.

.github/workflows/L1-PersistentStore-sqlite.yml

Lines changed: 0 additions & 48 deletions
This file was deleted.

.github/workflows/L1-PersistentStore.yml

Lines changed: 0 additions & 48 deletions
This file was deleted.

.github/workflows/L2-PersistentStore.yml

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: PersistentStore
2+
3+
on:
4+
push:
5+
paths:
6+
- PersistentStore/**
7+
- .github/workflows/*PersistentStore*.yml
8+
pull_request:
9+
paths:
10+
- PersistentStore/**
11+
- .github/workflows/*PersistentStore*.yml
12+
13+
jobs:
14+
tests:
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
include:
19+
- src: 'PersistentStore/sqlite/l1test'
20+
build: 'build/sqlitel1test'
21+
test: 'sqlitel1test'
22+
- src: 'PersistentStore/l0test'
23+
build: 'build/persistentstorel0test'
24+
test: 'persistentstorel0test'
25+
- src: 'PersistentStore/l1test'
26+
build: 'build/persistentstorel1test'
27+
test: 'persistentstorel1test'
28+
- src: 'PersistentStore'
29+
build: 'build/PersistentStore'
30+
steps:
31+
- uses: actions/checkout@v4
32+
with:
33+
path: ${{github.repository}}
34+
- run: |
35+
sudo apt update
36+
sudo apt install -y valgrind cmake libsqlite3-dev
37+
- run: sh +x ${GITHUB_REPOSITORY}/.github/workflows/BuildThunder.sh
38+
- run: |
39+
cmake \
40+
-S ${GITHUB_REPOSITORY}/${{ matrix.src }} \
41+
-B ${{ matrix.build }} \
42+
-DCMAKE_INSTALL_PREFIX="install" \
43+
-DCMAKE_CXX_FLAGS="-Wall -Werror"
44+
cmake --build ${{ matrix.build }} --target install
45+
- if: ${{ matrix.test }}
46+
run: |
47+
PATH=${PWD}/install/bin:${PATH} \
48+
LD_LIBRARY_PATH=${PWD}/install/lib:${LD_LIBRARY_PATH} \
49+
valgrind --tool=memcheck --log-file=valgrind_log \
50+
--leak-check=yes \
51+
--show-reachable=yes \
52+
--track-fds=yes \
53+
--fair-sched=try \
54+
${{ matrix.test }}
55+
- if: ${{ !env.ACT && matrix.test }}
56+
uses: actions/upload-artifact@v4
57+
with:
58+
name: artifacts-${{ matrix.test }}
59+
path: |
60+
valgrind_log
61+
if-no-files-found: warn

PersistentStore/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ All notable changes to this RDK Service will be documented in this file.
1616

1717
* For more details, refer to [versioning](https://github.com/rdkcentral/rdkservices#versioning) section under Main README.
1818

19+
## [2.0.5] - 2025-06-30
20+
### Fixed
21+
- Create or use backup on start
22+
1923
## [2.0.4] - 2025-04-28
2024
### Fixed
2125
- Handle file system corruption issue

PersistentStore/PersistentStore.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
#define API_VERSION_NUMBER_MAJOR 2
2424
#define API_VERSION_NUMBER_MINOR 0
25-
#define API_VERSION_NUMBER_PATCH 4
25+
#define API_VERSION_NUMBER_PATCH 5
2626

2727
namespace WPEFramework {
2828

PersistentStore/sqlite/Store2.h

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,11 @@ namespace Plugin {
8787
, _maxSize(maxSize)
8888
, _maxValue(maxValue)
8989
, _limit(limit)
90+
, _corrupt(false)
9091
{
9192
TempDirectoryCheck();
9293
IntegrityCheck();
94+
Backup();
9395
Open();
9496
}
9597
~Store2() override
@@ -115,23 +117,41 @@ namespace Plugin {
115117
void IntegrityCheck()
116118
{
117119
Core::File file(_path);
118-
Core::Directory(file.PathName().c_str()).CreatePath();
119-
auto rc = sqlite3_open(_path.c_str(), &_data);
120-
sqlite3_stmt* stmt;
121-
sqlite3_prepare_v2(_data, "pragma integrity_check;",
122-
-1, &stmt, nullptr);
123-
while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) {
124-
TRACE(Trace::Information,
125-
(_T("%s %s"), __FUNCTION__,
126-
(const char*)sqlite3_column_text(stmt, 0)));
127-
}
128-
sqlite3_finalize(stmt);
129-
sqlite3_close_v2(_data);
130-
if (rc != SQLITE_DONE) {
131-
OnError(__FUNCTION__, rc);
132-
if ((rc == SQLITE_MISUSE) || (rc == SQLITE_CORRUPT)) {
120+
if (file.Exists()) {
121+
sqlite3_open(file.Name().c_str(), &_data);
122+
auto rc = sqlite3_exec(_data,
123+
"pragma integrity_check;", 0, 0, 0);
124+
sqlite3_close_v2(_data);
125+
if ((rc == SQLITE_CORRUPT) || (rc == SQLITE_NOTADB)) {
126+
OnError(__FUNCTION__, rc);
133127
ASSERT(file.Destroy());
128+
_corrupt = true;
129+
}
130+
}
131+
}
132+
void Backup()
133+
{
134+
Core::File file(_path);
135+
Core::File fileB(_path + "-backup");
136+
if (_corrupt ? fileB.Exists() : file.Exists()) {
137+
sqlite3* bkp;
138+
sqlite3_open(file.Name().c_str(), &_data);
139+
sqlite3_open(fileB.Name().c_str(), &bkp);
140+
auto to = _corrupt ? _data : bkp,
141+
from = _corrupt ? bkp : _data;
142+
auto ptr = sqlite3_backup_init(
143+
to, "main", from, "main");
144+
if (ptr != nullptr) {
145+
sqlite3_backup_step(ptr, -1);
146+
auto rc = sqlite3_backup_finish(ptr);
147+
if (rc != SQLITE_OK) {
148+
OnError(__FUNCTION__, rc);
149+
}
150+
} else {
151+
OnError(__FUNCTION__, sqlite3_errcode(to));
134152
}
153+
sqlite3_close_v2(bkp);
154+
sqlite3_close_v2(_data);
135155
}
136156
}
137157
void Open()
@@ -631,6 +651,7 @@ namespace Plugin {
631651
sqlite3* _data;
632652
std::list<INotification*> _clients;
633653
Core::CriticalSection _clientLock;
654+
bool _corrupt;
634655
};
635656

636657
} // namespace Sqlite

0 commit comments

Comments
 (0)