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
cf7951be
Unverified
Commit
cf7951be
authored
3 years ago
by
Sergey V
Browse files
Options
Downloads
Patches
Plain Diff
feat: rebootstrap initial implementation
parent
9934b325
No related branches found
No related tags found
1 merge request
!62
feat: rebootstrap tarantool
Pipeline
#3653
passed
3 years ago
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main.rs
+47
-0
47 additions, 0 deletions
src/main.rs
with
47 additions
and
0 deletions
src/main.rs
+
47
−
0
View file @
cf7951be
use
std
::
os
::
raw
::{
c_char
,
c_int
,
c_void
};
use
std
::
os
::
raw
::{
c_char
,
c_int
,
c_void
};
use
std
::
os
::
unix
::
process
::
CommandExt
;
use
std
::
process
::
Command
;
use
structopt
::
StructOpt
;
use
structopt
::
StructOpt
;
use
::
raft
::
prelude
as
raft
;
use
::
raft
::
prelude
as
raft
;
...
@@ -75,6 +77,7 @@ fn picolib_setup(args: args::Run) {
...
@@ -75,6 +77,7 @@ fn picolib_setup(args: args::Run) {
//
//
// Export public API
// Export public API
luamod
.set
(
"rebootstrap"
,
tlua
::
function0
(
rebootstrap
));
luamod
.set
(
"run"
,
tlua
::
function0
(
move
||
start
(
&
args
)));
luamod
.set
(
"run"
,
tlua
::
function0
(
move
||
start
(
&
args
)));
luamod
.set
(
"raft_status"
,
tlua
::
function0
(
raft_status
));
luamod
.set
(
"raft_status"
,
tlua
::
function0
(
raft_status
));
luamod
.set
(
"raft_tick"
,
tlua
::
function1
(
raft_tick
));
luamod
.set
(
"raft_tick"
,
tlua
::
function1
(
raft_tick
));
...
@@ -330,6 +333,25 @@ macro_rules! tarantool_main {
...
@@ -330,6 +333,25 @@ macro_rules! tarantool_main {
}
}
}
}
extern
"C"
{
static
mut
wal_dir_lock
:
i32
;
fn
close
(
fd
:
i32
)
->
i32
;
}
const
REBOOTSTRAP_ENV_VAR
:
&
str
=
"PICODATA_REBOOTSTRAP"
;
static
mut
ARGV
:
Vec
<
String
>
=
vec!
[];
fn
rebootstrap
()
{
std
::
env
::
set_var
(
REBOOTSTRAP_ENV_VAR
,
"1"
);
unsafe
{
tarantool
::
eval
(
"box.cfg{listen=''}; require'fiber'.sleep(0.2)"
);
close
(
dbg!
(
wal_dir_lock
));
tlog!
(
Warning
,
"Calling exec with: {:?}"
,
&
ARGV
);
let
_
=
Command
::
new
(
&
ARGV
[
0
])
.args
(
&
ARGV
[
1
..
])
.exec
();
}
}
fn
run
(
args
:
args
::
Run
)
->
Result
<
(),
String
>
{
fn
run
(
args
:
args
::
Run
)
->
Result
<
(),
String
>
{
// Tarantool implicitly parses some environment variables.
// Tarantool implicitly parses some environment variables.
// We don't want them to affect the behavior and thus filter them out.
// We don't want them to affect the behavior and thus filter them out.
...
@@ -339,10 +361,35 @@ fn run(args: args::Run) -> Result<(), String> {
...
@@ -339,10 +361,35 @@ fn run(args: args::Run) -> Result<(), String> {
}
}
}
}
unsafe
{
ARGV
=
std
::
env
::
args
()
.collect
();
// Used in rebootstrap
}
tarantool_main!
(
args
.tt_args
()
?
,
args
=>
|
args
:
args
::
Run
|
{
tarantool_main!
(
args
.tt_args
()
?
,
args
=>
|
args
:
args
::
Run
|
{
if
std
::
env
::
var
(
REBOOTSTRAP_ENV_VAR
)
.is_ok
()
{
std
::
env
::
remove_var
(
REBOOTSTRAP_ENV_VAR
);
tlog!
(
Warning
,
"re-bootstrapping..."
);
// cleanup data dir
std
::
fs
::
read_dir
(
&
args
.data_dir
)
.expect
(
"failed reading data_dir"
)
.map
(|
entry
|
entry
.unwrap_or_else
(|
e
|
panic!
(
"Failed reading directory entry: {}"
,
e
)))
.map
(|
entry
|
entry
.path
())
.filter
(|
path
|
path
.is_file
())
.filter
(|
f
|
{
f
.extension
()
.map
(|
ext
|
ext
==
"xlog"
||
ext
==
"snap"
)
.unwrap_or
(
false
)
})
.for_each
(|
f
|
{
tlog!
(
Warning
,
"removing file: {}"
,
(
&
f
)
.to_string_lossy
());
std
::
fs
::
remove_file
(
f
)
.unwrap
();
});
};
if
args
.autorun
{
if
args
.autorun
{
start
(
&
args
);
start
(
&
args
);
}
}
picolib_setup
(
args
);
picolib_setup
(
args
);
})
})
}
}
...
...
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