Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
picodata
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
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
core
picodata
Commits
a83d56d8
Commit
a83d56d8
authored
1 year ago
by
Georgy Moshkin
Browse files
Options
Downloads
Patches
Plain Diff
refactor: return Error from entrypoint instead of exit(1)
parent
dd17afb3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!893
feat: --config parameter to specify picodata configuration file
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/cli/run.rs
+4
-1
4 additions, 1 deletion
src/cli/run.rs
src/lib.rs
+42
-32
42 additions, 32 deletions
src/lib.rs
src/traft/error.rs
+9
-0
9 additions, 0 deletions
src/traft/error.rs
src/util.rs
+6
-5
6 additions, 5 deletions
src/util.rs
with
61 additions
and
38 deletions
src/cli/run.rs
+
4
−
1
View file @
a83d56d8
...
...
@@ -100,7 +100,10 @@ pub fn main(args: args::Run) -> ! {
});
std
::
mem
::
forget
(
fuse
.start
());
entrypoint
.exec
(
args
,
to_parent
)
if
let
Err
(
e
)
=
entrypoint
.exec
(
args
,
to_parent
)
{
tlog!
(
Critical
,
"{e}"
);
std
::
process
::
exit
(
1
);
}
}
);
std
::
process
::
exit
(
rc
);
...
...
This diff is collapsed.
Click to expand it.
src/lib.rs
+
42
−
32
View file @
a83d56d8
...
...
@@ -31,8 +31,9 @@ use crate::plugin::*;
use
crate
::
schema
::
ADMIN_ID
;
use
crate
::
schema
::
PICO_SERVICE_USER_NAME
;
use
crate
::
tier
::{
Tier
,
DEFAULT_TIER
};
use
crate
::
traft
::
error
::
Error
;
use
crate
::
traft
::
op
;
use
crate
::
util
::{
effective_user_id
,
listen_admin_console
,
unwrap_or_terminate
};
use
crate
::
util
::{
effective_user_id
,
listen_admin_console
};
mod
access_control
;
pub
mod
audit
;
...
...
@@ -503,20 +504,22 @@ pub enum Entrypoint {
}
impl
Entrypoint
{
pub
fn
exec
(
self
,
args
:
cli
::
args
::
Run
,
to_supervisor
:
ipc
::
Sender
<
IpcMessage
>
)
{
pub
fn
exec
(
self
,
args
:
cli
::
args
::
Run
,
to_supervisor
:
ipc
::
Sender
<
IpcMessage
>
,
)
->
Result
<
(),
Error
>
{
if
let
Some
(
filename
)
=
&
args
.service_password_file
{
let
res
=
pico_service
::
read_pico_service_password_from_file
(
filename
);
if
let
Err
(
e
)
=
res
{
tlog!
(
Error
,
"{e}"
);
std
::
process
::
exit
(
-
1
);
}
pico_service
::
read_pico_service_password_from_file
(
filename
)
?
;
}
match
self
{
Self
::
StartDiscover
=>
start_discover
(
&
args
,
to_supervisor
),
Self
::
StartBoot
=>
start_boot
(
&
args
),
Self
::
StartJoin
{
leader_address
}
=>
start_join
(
&
args
,
leader_address
),
Self
::
StartDiscover
=>
start_discover
(
&
args
,
to_supervisor
)
?
,
Self
::
StartBoot
=>
start_boot
(
&
args
)
?
,
Self
::
StartJoin
{
leader_address
}
=>
start_join
(
&
args
,
leader_address
)
?
,
}
Ok
(())
}
}
...
...
@@ -571,7 +574,7 @@ fn init_common(args: &args::Run, cfg: &tarantool::Cfg) -> (Clusterwide, RaftSpac
(
storage
.clone
(),
raft_storage
)
}
fn
start_discover
(
args
:
&
args
::
Run
,
to_supervisor
:
ipc
::
Sender
<
IpcMessage
>
)
{
fn
start_discover
(
args
:
&
args
::
Run
,
to_supervisor
:
ipc
::
Sender
<
IpcMessage
>
)
->
Result
<
(),
Error
>
{
tlog!
(
Info
,
">>>>> start_discover()"
);
tlog
::
set_log_level
(
args
.log_level
());
...
...
@@ -630,14 +633,14 @@ fn start_discover(args: &args::Run, to_supervisor: ipc::Sender<IpcMessage>) {
to_supervisor
.send
(
&
msg
);
std
::
process
::
exit
(
0
);
}
}
;
}
}
fn
start_boot
(
args
:
&
args
::
Run
)
{
fn
start_boot
(
args
:
&
args
::
Run
)
->
Result
<
(),
Error
>
{
tlog!
(
Info
,
">>>>> start_boot()"
);
let
init_cfg
=
match
&
args
.init_cfg
{
Some
(
path
)
=>
unwrap_or_terminate
(
InitCfg
::
try_from_yaml_file
(
path
)
)
,
Some
(
path
)
=>
InitCfg
::
try_from_yaml_file
(
path
)
.map_err
(
Error
::
other
)
?
,
None
=>
{
tlog!
(
Info
,
"init-cfg wasn't set"
);
tlog!
(
...
...
@@ -654,16 +657,13 @@ fn start_boot(args: &args::Run) {
let
tiers
=
init_cfg
.tier
;
let
current_instance_tier
=
unwrap_or_terminate
(
tiers
.iter
()
.find
(|
tier
|
tier
.name
==
args
.tier
)
.cloned
()
.ok_or
(
format!
(
"tier '{}' for current instance is not found in init-cfg"
,
args
.tier
)),
);
let
Some
(
current_instance_tier
)
=
tiers
.iter
()
.find
(|
tier
|
tier
.name
==
args
.tier
)
.cloned
()
else
{
return
Err
(
Error
::
other
(
format!
(
"tier '{}' for current instance is not found in init-cfg"
,
args
.tier
)));
};
let
instance
=
Instance
::
new
(
None
,
...
...
@@ -724,7 +724,7 @@ fn start_boot(args: &args::Run) {
})
.unwrap
();
postjoin
(
args
,
storage
,
raft_storage
);
postjoin
(
args
,
storage
,
raft_storage
)
?
;
let
db_name
=
&
args
.cluster_id
;
let
instance_id
=
instance
.instance_id
.as_ref
();
...
...
@@ -736,9 +736,11 @@ fn start_boot(args: &args::Run) {
instance_id
:
%
instance_id
,
raft_id
:
%
raft_id
,
);
Ok
(())
}
fn
start_join
(
args
:
&
args
::
Run
,
instance_address
:
String
)
{
fn
start_join
(
args
:
&
args
::
Run
,
instance_address
:
String
)
->
Result
<
(),
Error
>
{
tlog!
(
Info
,
">>>>> start_join({instance_address})"
);
let
req
=
join
::
Request
{
...
...
@@ -775,8 +777,9 @@ fn start_join(args: &args::Run, instance_address: String) {
continue
;
}
Err
(
e
)
=>
{
tlog!
(
Error
,
"join request failed: {e}, shutting down..."
);
std
::
process
::
exit
(
-
1
);
return
Err
(
Error
::
other
(
format!
(
"join request failed: {e}, shutting down..."
)));
}
}
};
...
...
@@ -826,7 +829,11 @@ fn start_join(args: &args::Run, instance_address: String) {
postjoin
(
args
,
storage
,
raft_storage
)
}
fn
postjoin
(
args
:
&
args
::
Run
,
storage
:
Clusterwide
,
raft_storage
:
RaftSpaceAccess
)
{
fn
postjoin
(
args
:
&
args
::
Run
,
storage
:
Clusterwide
,
raft_storage
:
RaftSpaceAccess
,
)
->
Result
<
(),
Error
>
{
tlog!
(
Info
,
">>>>> postjoin()"
);
if
let
Some
(
config
)
=
&
args
.audit
{
...
...
@@ -881,7 +888,7 @@ fn postjoin(args: &args::Run, storage: Clusterwide, raft_storage: RaftSpaceAcces
box_cfg
.listen
=
Some
(
format!
(
"{}:{}"
,
args
.listen.host
,
args
.listen.port
));
tarantool
::
set_cfg
(
&
box_cfg
);
unwrap_or_terminate
(
listen_admin_console
(
args
)
)
;
listen_admin_console
(
args
)
?
;
if
let
Err
(
e
)
=
tarantool
::
on_shutdown
(
move
||
fiber
::
block_on
(
on_shutdown
::
callback
(
PluginList
::
get
())))
...
...
@@ -954,8 +961,9 @@ fn postjoin(args: &args::Run, storage: Clusterwide, raft_storage: RaftSpaceAcces
continue
;
}
Err
(
e
)
=>
{
tlog!
(
Error
,
"failed to activate myself: {e}, shutting down..."
);
std
::
process
::
exit
(
-
1
);
return
Err
(
Error
::
other
(
format!
(
"failed to activate myself: {e}, shutting down..."
)));
}
}
}
...
...
@@ -992,4 +1000,6 @@ fn postjoin(args: &args::Run, storage: Clusterwide, raft_storage: RaftSpaceAcces
PluginList
::
get
()
.iter
()
.for_each
(|
plugin
|
{
plugin
.start
();
});
Ok
(())
}
This diff is collapsed.
Click to expand it.
src/traft/error.rs
+
9
−
0
View file @
a83d56d8
...
...
@@ -159,3 +159,12 @@ impl From<::tarantool::error::TarantoolError> for Error {
Self
::
Tarantool
(
err
.into
())
}
}
impl
<
V
>
From
<
tarantool
::
tlua
::
CallError
<
V
>>
for
Error
where
V
:
Into
<
tarantool
::
tlua
::
Void
>
,
{
fn
from
(
err
:
tarantool
::
tlua
::
CallError
<
V
>
)
->
Self
{
Self
::
Lua
(
err
.into
())
}
}
This diff is collapsed.
Click to expand it.
src/util.rs
+
6
−
5
View file @
a83d56d8
...
...
@@ -515,7 +515,7 @@ pub fn prompt_password(prompt: &str) -> Result<String, std::io::Error> {
///
/// Return None in case of incorrect path
/// Return Some(`value`) with `unix/:` and, probably, `./` prepended to `value`
pub
fn
validate_and_complete_unix_socket_path
(
socket_path
:
&
str
)
->
Result
<
String
,
String
>
{
pub
fn
validate_and_complete_unix_socket_path
(
socket_path
:
&
str
)
->
Result
<
String
,
Error
>
{
let
l
=
::
tarantool
::
lua_state
();
let
path
=
std
::
path
::
Path
::
new
(
socket_path
);
let
console_sock
=
match
path
.components
()
.next
()
{
...
...
@@ -530,7 +530,7 @@ pub fn validate_and_complete_unix_socket_path(socket_path: &str) -> Result<Strin
"local u = require('uri').parse(...); assert(u and u.unix)"
,
&
console_sock
,
)
.map_err
(|
_
|
format!
(
"invalid socket path: {socket_path}"
))
?
;
.map_err
(|
_
|
Error
::
other
(
format!
(
"invalid socket path: {socket_path}"
))
)
?
;
Ok
(
console_sock
)
}
...
...
@@ -539,13 +539,14 @@ pub fn validate_and_complete_unix_socket_path(socket_path: &str) -> Result<Strin
/// Starts admin console.
///
/// Returns Err in case of problems with socket path.
pub
fn
listen_admin_console
(
args
:
&
args
::
Run
)
->
Result
<
(),
String
>
{
pub
fn
listen_admin_console
(
args
:
&
args
::
Run
)
->
Result
<
(),
Error
>
{
let
lua
=
::
tarantool
::
lua_state
();
let
validated_path
=
validate_and_complete_unix_socket_path
(
&
args
.admin_sock
())
?
;
lua
.exec_with
(
r#"require('console').listen(...)"#
,
&
validated_path
)
.map_err
(|
err
|
err
.to_string
())
lua
.exec_with
(
r#"require('console').listen(...)"#
,
&
validated_path
)
?
;
Ok
(())
}
////////////////////////////////////////////////////////////////////////////////
...
...
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