Skip to content

Commit 4b88f4d

Browse files
Rdk58255 delia68355 25q3 (#6310)
* Rdk 58255 main (#6307) * RDKEMW-3216 : Resiliency improvements for Persistent Store (#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]> * Delia 68355 main (#6308) * RDKEMW-4795 : Account the case when ASSERT is no-op (#6256) Reason for change: Code in ASSERT seemingly did not run Test Procedure: Corrupt store is removed Risks: None Signed-off-by: Nikita Poltorapavlo <[email protected]> * update changelog and api version --------- Signed-off-by: Nikita Poltorapavlo <[email protected]> --------- Signed-off-by: Nikita Poltorapavlo <[email protected]>
1 parent 7a71f44 commit 4b88f4d

File tree

8 files changed

+108
-200
lines changed

8 files changed

+108
-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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ 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.6] - 2025-06-30
20+
### Fixed
21+
- Account the case when ASSERT is no-op
22+
23+
## [2.0.5] - 2025-06-30
24+
### Fixed
25+
- Create or use backup on start
26+
1927
## [2.0.4] - 2025-04-28
2028
### Fixed
2129
- 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 6
2626

2727
namespace WPEFramework {
2828

PersistentStore/sqlite/Store2.h

Lines changed: 38 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,43 @@ 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)));
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);
127+
if (!file.Destroy()) {
128+
perror("remove failed");
129+
}
130+
_corrupt = true;
131+
}
127132
}
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)) {
133-
ASSERT(file.Destroy());
133+
}
134+
void Backup()
135+
{
136+
Core::File file(_path);
137+
Core::File fileB(_path + "-backup");
138+
if (_corrupt ? fileB.Exists() : file.Exists()) {
139+
sqlite3* bkp;
140+
sqlite3_open(file.Name().c_str(), &_data);
141+
sqlite3_open(fileB.Name().c_str(), &bkp);
142+
auto to = _corrupt ? _data : bkp,
143+
from = _corrupt ? bkp : _data;
144+
auto ptr = sqlite3_backup_init(
145+
to, "main", from, "main");
146+
if (ptr != nullptr) {
147+
sqlite3_backup_step(ptr, -1);
148+
auto rc = sqlite3_backup_finish(ptr);
149+
if (rc != SQLITE_OK) {
150+
OnError(__FUNCTION__, rc);
151+
}
152+
} else {
153+
OnError(__FUNCTION__, sqlite3_errcode(to));
134154
}
155+
sqlite3_close_v2(bkp);
156+
sqlite3_close_v2(_data);
135157
}
136158
}
137159
void Open()
@@ -631,6 +653,7 @@ namespace Plugin {
631653
sqlite3* _data;
632654
std::list<INotification*> _clients;
633655
Core::CriticalSection _clientLock;
656+
bool _corrupt;
634657
};
635658

636659
} // namespace Sqlite

0 commit comments

Comments
 (0)