Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Bradley Matusiak
POD
Commits
d05a7b5d
Commit
d05a7b5d
authored
2 years ago
by
Aziz Berkay Yesilyurt
Browse files
Options
Download
Email Patches
Plain Diff
apply new changes related to pooling
parent
ae1b43b5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
libpod/src/db_connection_manager.rs
+26
-21
libpod/src/db_connection_manager.rs
pod/src/warp_api.rs
+3
-3
pod/src/warp_api.rs
pod/src/warp_endpoints.rs
+6
-6
pod/src/warp_endpoints.rs
with
35 additions
and
30 deletions
+35
-30
libpod/src/db_connection_manager.rs
+
26
-
21
View file @
d05a7b5d
...
...
@@ -15,28 +15,7 @@ pub type DBConnection = rusqlite::Connection;
pub
struct
DBConnectionManager
{
init_db
:
Arc
<
RwLock
<
HashMap
<
String
,
Arc
<
RwLock
<
PathBuf
>>>>>
,
}
pub
async
fn
remove_db
(
owner
:
&
str
,
init_db
:
&
InitDb
,
database_key
:
&
DatabaseKey
,)
->
Result
<
()
>
{
// gather write lock, so no other thread can access the the hashmap
let
mut
db
=
init_db
.write
()
.await
;
// NOTE: how do we verify owner-database_key pair is valid?
// remove the pool from the hashmap
// NOTE: readers will create a new pool as if it was never there
db
.remove
(
owner
);
let
database_path
=
format!
(
"{}{}"
,
&
owner
,
constants
::
DATABASE_SUFFIX
);
let
database_path_buf
=
PathBuf
::
from
(
constants
::
DATABASE_DIR
)
.join
(
database_path
);
let
database_path_str
=
database_path_buf
.to_str
()
.unwrap
();
info!
(
"Removing database at {:?}"
,
database_path_str
);
fs
::
remove_file
(
database_path_str
);
fs
::
remove_file
(
format!
(
"{}-wal"
,
database_path_str
));
fs
::
remove_file
(
format!
(
"{}-shm"
,
database_path_str
));
Ok
(())
}
impl
DBConnectionManager
{
pub
fn
new
()
->
Self
{
Self
{
...
...
@@ -172,6 +151,32 @@ impl DBConnectionManager {
Ok
(
conn
)
}
pub
async
fn
remove_db
(
&
self
,
owner
:
&
str
,
database_key
:
&
DatabaseKey
,)
->
Result
<
()
>
{
// gather write lock, so no other thread can access the the hashmap
let
mut
db
=
self
.init_db
.write
()
.await
;
let
database_path
=
format!
(
"{}{}"
,
&
owner
,
constants
::
DATABASE_SUFFIX
);
let
database_path
=
PathBuf
::
from
(
constants
::
DATABASE_DIR
)
.join
(
database_path
);
// Verify the ownership of the database
self
.make_connection
(
database_key
,
&*
database_path
)
?
;
// remove the pool from the hashmap
// NOTE: readers will create a new pool as if it was never there
db
.remove
(
owner
);
let
database_path
=
format!
(
"{}{}"
,
&
owner
,
constants
::
DATABASE_SUFFIX
);
let
database_path_buf
=
PathBuf
::
from
(
constants
::
DATABASE_DIR
)
.join
(
database_path
);
let
database_path_str
=
database_path_buf
.to_str
()
.unwrap
();
// info!("Removing database at {:?}", database_path_str);
fs
::
remove_file
(
database_path_str
);
fs
::
remove_file
(
format!
(
"{}-wal"
,
database_path_str
));
fs
::
remove_file
(
format!
(
"{}-shm"
,
database_path_str
));
Ok
(())
}
}
impl
Default
for
DBConnectionManager
{
...
...
This diff is collapsed.
Click to expand it.
pod/src/warp_api.rs
+
3
-
3
View file @
d05a7b5d
...
...
@@ -226,10 +226,10 @@ pub async fn run_server<S: 'static>(cli_options: CliOptions, trace_handle: Handl
.and
(
warp
::
path!
(
PodOwner
/
"delete_user"
))
.and
(
warp
::
path
::
end
())
.and
(
warp
::
body
::
bytes
())
.and
(
with_
init_
db
())
.and
(
with_db
())
.then
(
|
owner
:
PodOwner
,
body
:
Bytes
,
init_db
:
Arc
<
InitDb
>
|
async
move
{
warp_endpoints
::
delete_user
(
owner
,
init_db
.deref
()
,
body
)
.await
|
owner
:
PodOwner
,
body
:
Bytes
,
db
:
DBConnectionManager
|
async
move
{
warp_endpoints
::
delete_user
(
owner
,
db
,
body
)
.await
},
)
.boxed
();
...
...
This diff is collapsed.
Click to expand it.
pod/src/warp_endpoints.rs
+
6
-
6
View file @
d05a7b5d
...
...
@@ -300,18 +300,18 @@ async fn _delete_item(owner: PodOwner, db: DBConnectionManager, body: Bytes) ->
}
#[instrument(fields(uid=trace_uid(),
%
owner),
skip_all)]
pub
async
fn
delete_user
(
owner
:
PodOwner
,
init_db
:
&
InitDb
,
body
:
Bytes
)
->
Response
{
let
result
=
_delete_user
(
owner
,
init_
db
,
body
)
.await
;
pub
async
fn
delete_user
(
owner
:
PodOwner
,
db
:
DBConnectionManager
,
body
:
Bytes
)
->
Response
{
let
result
=
_delete_user
(
owner
,
db
,
body
)
.await
;
let
result
=
result
.map
(|()|
warp
::
reply
::
json
(
&
serde_json
::
json!
({})));
respond_with_result
(
result
)
}
async
fn
_delete_user
(
owner
:
PodOwner
,
init_db
:
&
InitDb
,
body
:
Bytes
)
->
Result
<
()
>
{
async
fn
_delete_user
(
owner
:
PodOwner
,
db
:
DBConnectionManager
,
body
:
Bytes
)
->
Result
<
()
>
{
let
body
=
&
mut
serde_json
::
Deserializer
::
from_slice
(
body
.deref
());
let
body
:
PayloadWrapper
<
String
>
=
serde_path_to_error
::
deserialize
(
body
)
?
;
let
auth
=
body
.auth
;
let
database_key
=
auth_to_database_key
(
auth
)
?
;
check_owner_and_delete_db
(
&
owner
,
init_
db
,
&
database_key
)
.await
?
;
check_owner_and_delete_db
(
&
owner
,
db
,
&
database_key
)
.await
?
;
Result
::
Ok
(())
}
...
...
@@ -665,11 +665,11 @@ async fn check_owner_and_initialize_db(
/// As additional failsafe to the fact that non-owners don't have the database key.
async
fn
check_owner_and_delete_db
(
owner
:
&
str
,
init_db
:
&
InitDb
,
db
:
DBConnectionManager
,
database_key
:
&
DatabaseKey
,
)
->
Result
<
()
>
{
check_owner
(
owner
)
?
;
remove_db
(
owner
,
init_db
,
database_key
)
.await
;
db
.
remove_db
(
owner
,
database_key
)
.await
;
Result
::
Ok
(())
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets