Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cellframe-sdk
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Merge requests
17
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cellframe
cellframe-sdk
Commits
69a0290b
Commit
69a0290b
authored
4 years ago
by
Dmitriy A. Gerasimov
Browse files
Options
Downloads
Patches
Plain Diff
[*] Fixed locks for db initialization check
parent
fda6c214
No related branches found
No related tags found
No related merge requests found
Pipeline
#7246
passed with stage
in 12 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/global-db/dap_chain_global_db_driver_sqlite.c
+49
-32
49 additions, 32 deletions
modules/global-db/dap_chain_global_db_driver_sqlite.c
with
49 additions
and
32 deletions
modules/global-db/dap_chain_global_db_driver_sqlite.c
+
49
−
32
View file @
69a0290b
...
@@ -121,13 +121,15 @@ int dap_db_driver_sqlite_init(const char *a_filename_db, dap_db_driver_callbacks
...
@@ -121,13 +121,15 @@ int dap_db_driver_sqlite_init(const char *a_filename_db, dap_db_driver_callbacks
int
dap_db_driver_sqlite_deinit
(
void
)
int
dap_db_driver_sqlite_deinit
(
void
)
{
{
if
(
s_db
){
pthread_rwlock_wrlock
(
&
s_db_rwlock
);
pthread_rwlock_wrlock
(
&
s_db_rwlock
);
if
(
!
s_db
){
pthread_rwlock_unlock
(
&
s_db_rwlock
);
return
-
666
;
}
dap_db_driver_sqlite_close
(
s_db
);
dap_db_driver_sqlite_close
(
s_db
);
pthread_rwlock_unlock
(
&
s_db_rwlock
);
pthread_rwlock_unlock
(
&
s_db_rwlock
);
s_db
=
NULL
;
s_db
=
NULL
;
return
sqlite3_shutdown
();
return
sqlite3_shutdown
();
}
}
}
// additional function for sqlite to convert byte to number
// additional function for sqlite to convert byte to number
...
@@ -227,6 +229,10 @@ int dap_db_driver_sqlite_flush()
...
@@ -227,6 +229,10 @@ int dap_db_driver_sqlite_flush()
{
{
log_it
(
L_DEBUG
,
"Start flush sqlite data base."
);
log_it
(
L_DEBUG
,
"Start flush sqlite data base."
);
pthread_rwlock_wrlock
(
&
s_db_rwlock
);
pthread_rwlock_wrlock
(
&
s_db_rwlock
);
if
(
!
s_db
){
pthread_rwlock_unlock
(
&
s_db_rwlock
);
return
-
666
;
}
dap_db_driver_sqlite_close
(
s_db
);
dap_db_driver_sqlite_close
(
s_db
);
char
*
l_error_message
;
char
*
l_error_message
;
s_db
=
dap_db_driver_sqlite_open
(
s_filename_db
,
SQLITE_OPEN_READWRITE
,
&
l_error_message
);
s_db
=
dap_db_driver_sqlite_open
(
s_filename_db
,
SQLITE_OPEN_READWRITE
,
&
l_error_message
);
...
@@ -459,19 +465,19 @@ int dap_db_driver_sqlite_vacuum(sqlite3 *l_db)
...
@@ -459,19 +465,19 @@ int dap_db_driver_sqlite_vacuum(sqlite3 *l_db)
*/
*/
int
dap_db_driver_sqlite_start_transaction
(
void
)
int
dap_db_driver_sqlite_start_transaction
(
void
)
{
{
if
(
s_db
)
pthread_rwlock_wrlock
(
&
s_db_rwlock
);
{
if
(
!
s_db
){
pthread_rwlock_wrlock
(
&
s_db_rwlock
);
pthread_rwlock_unlock
(
&
s_db_rwlock
);
if
(
SQLITE_OK
==
dap_db_driver_sqlite_exec
(
s_db
,
"BEGIN"
,
NULL
)){
return
-
666
;
pthread_rwlock_unlock
(
&
s_db_rwlock
);
return
0
;
}
else
{
pthread_rwlock_unlock
(
&
s_db_rwlock
);
return
-
1
;
}
}
}
else
if
(
SQLITE_OK
==
dap_db_driver_sqlite_exec
(
s_db
,
"BEGIN"
,
NULL
)){
pthread_rwlock_unlock
(
&
s_db_rwlock
);
return
0
;
}
else
{
pthread_rwlock_unlock
(
&
s_db_rwlock
);
return
-
1
;
return
-
1
;
}
}
}
/**
/**
...
@@ -479,19 +485,18 @@ int dap_db_driver_sqlite_start_transaction(void)
...
@@ -479,19 +485,18 @@ int dap_db_driver_sqlite_start_transaction(void)
*/
*/
int
dap_db_driver_sqlite_end_transaction
(
void
)
int
dap_db_driver_sqlite_end_transaction
(
void
)
{
{
if
(
s_db
)
pthread_rwlock_wrlock
(
&
s_db_rwlock
);
{
if
(
!
s_db
){
pthread_rwlock_wrlock
(
&
s_db_rwlock
);
pthread_rwlock_unlock
(
&
s_db_rwlock
);
if
(
SQLITE_OK
==
dap_db_driver_sqlite_exec
(
s_db
,
"COMMIT"
,
NULL
)){
return
-
666
;
pthread_rwlock_unlock
(
&
s_db_rwlock
);
return
0
;
}
else
{
pthread_rwlock_unlock
(
&
s_db_rwlock
);
return
-
1
;
}
}
}
else
if
(
SQLITE_OK
==
dap_db_driver_sqlite_exec
(
s_db
,
"COMMIT"
,
NULL
)){
pthread_rwlock_unlock
(
&
s_db_rwlock
);
return
0
;
}
else
{
pthread_rwlock_unlock
(
&
s_db_rwlock
);
return
-
1
;
return
-
1
;
}
}
}
char
*
dap_db_driver_sqlite_make_table_name
(
const
char
*
a_group_name
)
char
*
dap_db_driver_sqlite_make_table_name
(
const
char
*
a_group_name
)
...
@@ -516,8 +521,6 @@ char *dap_db_driver_sqlite_make_table_name(const char *a_group_name)
...
@@ -516,8 +521,6 @@ char *dap_db_driver_sqlite_make_table_name(const char *a_group_name)
*/
*/
int
dap_db_driver_sqlite_apply_store_obj
(
dap_store_obj_t
*
a_store_obj
)
int
dap_db_driver_sqlite_apply_store_obj
(
dap_store_obj_t
*
a_store_obj
)
{
{
if
(
!
s_db
)
return
-
666
;
if
(
!
a_store_obj
||
!
a_store_obj
->
group
)
if
(
!
a_store_obj
||
!
a_store_obj
->
group
)
return
-
1
;
return
-
1
;
char
*
l_query
=
NULL
;
char
*
l_query
=
NULL
;
...
@@ -556,6 +559,11 @@ int dap_db_driver_sqlite_apply_store_obj(dap_store_obj_t *a_store_obj)
...
@@ -556,6 +559,11 @@ int dap_db_driver_sqlite_apply_store_obj(dap_store_obj_t *a_store_obj)
}
}
// execute request
// execute request
pthread_rwlock_wrlock
(
&
s_db_rwlock
);
pthread_rwlock_wrlock
(
&
s_db_rwlock
);
if
(
!
s_db
){
pthread_rwlock_unlock
(
&
s_db_rwlock
);
return
-
666
;
}
int
l_ret
=
dap_db_driver_sqlite_exec
(
s_db
,
l_query
,
&
l_error_message
);
int
l_ret
=
dap_db_driver_sqlite_exec
(
s_db
,
l_query
,
&
l_error_message
);
if
(
l_ret
==
SQLITE_ERROR
)
{
if
(
l_ret
==
SQLITE_ERROR
)
{
dap_db_driver_sqlite_free
(
l_error_message
);
dap_db_driver_sqlite_free
(
l_error_message
);
...
@@ -636,8 +644,6 @@ static void fill_one_item(const char *a_group, dap_store_obj_t *a_obj, SQLITE_RO
...
@@ -636,8 +644,6 @@ static void fill_one_item(const char *a_group, dap_store_obj_t *a_obj, SQLITE_RO
*/
*/
dap_store_obj_t
*
dap_db_driver_sqlite_read_last_store_obj
(
const
char
*
a_group
)
dap_store_obj_t
*
dap_db_driver_sqlite_read_last_store_obj
(
const
char
*
a_group
)
{
{
if
(
!
s_db
)
return
-
666
;
dap_store_obj_t
*
l_obj
=
NULL
;
dap_store_obj_t
*
l_obj
=
NULL
;
char
*
l_error_message
=
NULL
;
char
*
l_error_message
=
NULL
;
...
@@ -647,6 +653,11 @@ dap_store_obj_t* dap_db_driver_sqlite_read_last_store_obj(const char *a_group)
...
@@ -647,6 +653,11 @@ dap_store_obj_t* dap_db_driver_sqlite_read_last_store_obj(const char *a_group)
char
*
l_table_name
=
dap_db_driver_sqlite_make_table_name
(
a_group
);
char
*
l_table_name
=
dap_db_driver_sqlite_make_table_name
(
a_group
);
char
*
l_str_query
=
sqlite3_mprintf
(
"SELECT id,ts,key,value FROM '%s' ORDER BY id DESC LIMIT 1"
,
l_table_name
);
char
*
l_str_query
=
sqlite3_mprintf
(
"SELECT id,ts,key,value FROM '%s' ORDER BY id DESC LIMIT 1"
,
l_table_name
);
pthread_rwlock_rdlock
(
&
s_db_rwlock
);
pthread_rwlock_rdlock
(
&
s_db_rwlock
);
if
(
!
s_db
){
pthread_rwlock_unlock
(
&
s_db_rwlock
);
return
NULL
;
}
int
l_ret
=
dap_db_driver_sqlite_query
(
s_db
,
l_str_query
,
&
l_res
,
&
l_error_message
);
int
l_ret
=
dap_db_driver_sqlite_query
(
s_db
,
l_str_query
,
&
l_res
,
&
l_error_message
);
pthread_rwlock_unlock
(
&
s_db_rwlock
);
pthread_rwlock_unlock
(
&
s_db_rwlock
);
sqlite3_free
(
l_str_query
);
sqlite3_free
(
l_str_query
);
...
@@ -688,8 +699,6 @@ dap_store_obj_t* dap_db_driver_sqlite_read_cond_store_obj(const char *a_group, u
...
@@ -688,8 +699,6 @@ dap_store_obj_t* dap_db_driver_sqlite_read_cond_store_obj(const char *a_group, u
sqlite3_stmt
*
l_res
;
sqlite3_stmt
*
l_res
;
if
(
!
a_group
)
if
(
!
a_group
)
return
NULL
;
return
NULL
;
if
(
!
s_db
)
return
-
666
;
char
*
l_table_name
=
dap_db_driver_sqlite_make_table_name
(
a_group
);
char
*
l_table_name
=
dap_db_driver_sqlite_make_table_name
(
a_group
);
// no limit
// no limit
...
@@ -704,6 +713,11 @@ dap_store_obj_t* dap_db_driver_sqlite_read_cond_store_obj(const char *a_group, u
...
@@ -704,6 +713,11 @@ dap_store_obj_t* dap_db_driver_sqlite_read_cond_store_obj(const char *a_group, u
l_str_query
=
sqlite3_mprintf
(
"SELECT id,ts,key,value FROM '%s' WHERE id>'%lld' ORDER BY id ASC"
,
l_str_query
=
sqlite3_mprintf
(
"SELECT id,ts,key,value FROM '%s' WHERE id>'%lld' ORDER BY id ASC"
,
l_table_name
,
a_id
);
l_table_name
,
a_id
);
pthread_rwlock_rdlock
(
&
s_db_rwlock
);
pthread_rwlock_rdlock
(
&
s_db_rwlock
);
if
(
!
s_db
){
pthread_rwlock_unlock
(
&
s_db_rwlock
);
return
NULL
;
}
int
l_ret
=
dap_db_driver_sqlite_query
(
s_db
,
l_str_query
,
&
l_res
,
&
l_error_message
);
int
l_ret
=
dap_db_driver_sqlite_query
(
s_db
,
l_str_query
,
&
l_res
,
&
l_error_message
);
pthread_rwlock_unlock
(
&
s_db_rwlock
);
pthread_rwlock_unlock
(
&
s_db_rwlock
);
sqlite3_free
(
l_str_query
);
sqlite3_free
(
l_str_query
);
...
@@ -762,8 +776,6 @@ dap_store_obj_t* dap_db_driver_sqlite_read_store_obj(const char *a_group, const
...
@@ -762,8 +776,6 @@ dap_store_obj_t* dap_db_driver_sqlite_read_store_obj(const char *a_group, const
sqlite3_stmt
*
l_res
;
sqlite3_stmt
*
l_res
;
if
(
!
a_group
)
if
(
!
a_group
)
return
NULL
;
return
NULL
;
if
(
!
s_db
)
return
-
666
;
char
*
l_table_name
=
dap_db_driver_sqlite_make_table_name
(
a_group
);
char
*
l_table_name
=
dap_db_driver_sqlite_make_table_name
(
a_group
);
// no limit
// no limit
...
@@ -787,6 +799,11 @@ dap_store_obj_t* dap_db_driver_sqlite_read_store_obj(const char *a_group, const
...
@@ -787,6 +799,11 @@ dap_store_obj_t* dap_db_driver_sqlite_read_store_obj(const char *a_group, const
l_str_query
=
sqlite3_mprintf
(
"SELECT id,ts,key,value FROM '%s' ORDER BY id ASC"
,
l_table_name
);
l_str_query
=
sqlite3_mprintf
(
"SELECT id,ts,key,value FROM '%s' ORDER BY id ASC"
,
l_table_name
);
}
}
pthread_rwlock_rdlock
(
&
s_db_rwlock
);
pthread_rwlock_rdlock
(
&
s_db_rwlock
);
if
(
!
s_db
){
pthread_rwlock_unlock
(
&
s_db_rwlock
);
return
NULL
;
}
int
l_ret
=
dap_db_driver_sqlite_query
(
s_db
,
l_str_query
,
&
l_res
,
&
l_error_message
);
int
l_ret
=
dap_db_driver_sqlite_query
(
s_db
,
l_str_query
,
&
l_res
,
&
l_error_message
);
pthread_rwlock_unlock
(
&
s_db_rwlock
);
pthread_rwlock_unlock
(
&
s_db_rwlock
);
sqlite3_free
(
l_str_query
);
sqlite3_free
(
l_str_query
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment