Commit 3ce3009c authored by gerd's avatar gerd

new nn_dump_dir config parameter

new Nn_dumps module for managing dumps.


git-svn-id: https://gps.dynxs.de/private/svn/app-plasma/trunk@651 55289a75-7b90-4627-9e07-ffb4263930b2
parent 41804328
......@@ -69,7 +69,8 @@ fi
for host in $hosts; do
echo "Deploying to $host:"
ssh $host \
"mkdir -p '$prefix/bin' '$prefix/etc' '$prefix/log' '$prefix/data'"
"mkdir -p '$prefix/bin' '$prefix/etc' '$prefix/log' '$prefix/data' \
'$prefix/dump'"
scp -p \
instances/$inst/*.conf instances/$inst/*.hosts instances/$inst/*.sh \
instances/$inst/password_proot instances/$inst/password_pnobody \
......
......@@ -34,6 +34,7 @@ netplex {
alive_min = "all";
replication = 1;
rank_script = "<PREFIX>/etc/rank.sh";
dump_dir = "<PREFIX>/dump";
elect_timeout = 60.0;
inodecache { port = 2740 };
};
......
......@@ -33,6 +33,7 @@ OCamlGeneratedFiles(nn_db_schema.ml)
#
FILES[] =
nn_dumps
nn_ug
nn_authticket
nn_inodecache
......
......@@ -36,6 +36,7 @@ object
method nn_replication : int
method nn_lock_timeout : float
method nn_pool_size : int
method nn_dump_dir : string
method nn_consistency_checks : bool
method dn_blocksize : int
method dn_port : int
......@@ -134,7 +135,7 @@ let extract_node_config (cf:Netplex_types.config_file) =
let (nn_nodes, nn_clustername, nn_hostname, nn_node_timeout,
nn_node_alive_min, nn_node_alive_min_startup, nn_rank,
nn_elect_timeout, nn_inodecaches, nn_replication, nn_lock_timeout,
nn_pool_size, nn_consistency_checks) =
nn_pool_size, nn_consistency_checks, nn_dump_dir) =
match namenodes with
| [] ->
failwith "missing 'namenodes' config"
......@@ -260,9 +261,16 @@ let extract_node_config (cf:Netplex_types.config_file) =
with
| Not_found ->
false in
let dump_dir =
try
let p = cf#resolve_parameter nn "dump_dir" in
cf#string_param p
with
| Not_found ->
failwith "missing 'namenodes.dump_dir' parameter" in
(addrs, clustername, hostname, timeout, alive_min, alive_min_startup,
rank, elect_timeout, ic_addrs, replication, lock_timeout, pool_size,
consistency_checks
consistency_checks, dump_dir
)
in
( object
......@@ -279,6 +287,7 @@ let extract_node_config (cf:Netplex_types.config_file) =
method nn_lock_timeout = nn_lock_timeout
method nn_pool_size = nn_pool_size
method nn_consistency_checks = nn_consistency_checks
method nn_dump_dir = nn_dump_dir
method dn_port = dn_port
method dn_node_timeout = dn_node_timeout
method dn_blocksize = dn_blocksize
......
......@@ -58,6 +58,8 @@ object
(** How much pool RAM is allocated (shared memory) *)
method nn_consistency_checks : bool
(** Whether to do more consistency checks, even the time-consuming ones *)
method nn_dump_dir : string
(** A local directory for data dumps (e.g. checkpoints, logs) *)
method dn_blocksize : int
(** Expected blocksize of datanodes *)
method dn_port : int
......@@ -107,6 +109,7 @@ val extract_node_config : Netplex_types.config_file -> nn_node_config
node { addr = "hostname:port" };
...
rank = "0"; (* mandatory *)
dump_dir = "/var/lib/plasma"; (* mandatory *)
hostname = "hostname"; (* optional *)
timeout = 60.0; (* optional *)
alive_min = 1; (* optional *)
......
(*
Copyright 2013 Gerd Stolpmann
This file is part of Plasma, a distributed filesystem and a
map/reduce computation framework. Unless you have a written license
agreement with the copyright holder (Gerd Stolpmann), the following
terms apply:
Plasma is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Plasma is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*)
(* $Id$ *)
open Printf
class type dump_config =
object
method nn_dump_dir : string
end
type dump_entry =
{ dump_prefix : string;
dump_ref : string;
dump_suffix : string;
dump_finished : bool;
dump_timestamp : float
}
let create_dump config (prefix,nref) =
let dir = config # nn_dump_dir in
let rec next k =
if k = 100_000 then
failwith "Nn_dumps.create_dump: cannot create dump directory";
let name = sprintf "%s_%s_%05d" prefix nref k in
let full_name = sprintf "%s/%s" dir name in
try
Unix.mkdir full_name 0o700;
k
with
| Unix.Unix_error(Unix.EEXIST,_,_) ->
next (k+1)
in
let k = next 0 in
{ dump_prefix = prefix;
dump_ref = nref;
dump_suffix = sprintf "%05d" k;
dump_finished = false;
dump_timestamp = Unix.time()
}
let dump_directory config entry =
let name =
sprintf "%s_%s_%s" entry.dump_prefix entry.dump_ref entry.dump_suffix in
sprintf "%s/%s" config#nn_dump_dir name
let finish_dump config entry =
let full_dir = dump_directory config entry in
let f = open_out (sprintf "%s/dump_succeeded" full_dir) in
let st = Unix.fstat (Unix.descr_of_out_channel f) in
close_out f;
{ entry with
dump_finished = true;
dump_timestamp = Unix.(st.st_mtime)
}
let name_re = Netstring_str.regexp "^\\([^_]+\\)_\\(.*\\)_\\([0-9]+\\)$"
let list_dumps config =
let dir = config # nn_dump_dir in
let p = Sys.readdir dir in
let l =
List.filter
(fun name ->
let fulldir = sprintf "%s/%s" dir name in
Sys.is_directory fulldir &&
Netstring_str.string_match name_re name 0 <> None
)
(Array.to_list p) in
List.map
(fun name ->
match Netstring_str.string_match name_re name 0 with
| None -> assert false
| Some m ->
let prefix = Netstring_str.matched_group m 1 name in
let nref = Netstring_str.matched_group m 2 name in
let suffix = Netstring_str.matched_group m 3 name in
let fin_file = sprintf "%s/%s/dump_succeeded" dir name in
let ex_fin_file = Sys.file_exists fin_file in
let ts_file =
if ex_fin_file then fin_file else sprintf "%s/%s" dir name in
let st = Unix.stat ts_file in
{ dump_prefix = prefix;
dump_ref = nref;
dump_suffix = suffix;
dump_finished = ex_fin_file;
dump_timestamp = Unix.(st.st_mtime);
}
)
l
let get_dump_files config entry =
let d = dump_directory config entry in
let l = Array.to_list (Sys.readdir d) in
List.flatten
(List.map
(fun n ->
if n.[0] = '.' || n.[String.length n - 1] = '~' ||
n = "dump_succeeded"
then
[]
else
let p = sprintf "%s/%s" d n in
let st = Unix.LargeFile.stat p in
[ n, Unix.LargeFile.(st.st_size) ]
)
l
)
let remove_dump config entry =
let d = dump_directory config entry in
let cmd = sprintf "rm -rf %s" (Filename.quote d) in
let code = Sys.command cmd in
if code <> 0 then
failwith ("Command not successful: " ^ cmd)
(*
Copyright 2013 Gerd Stolpmann
This file is part of Plasma, a distributed filesystem and a
map/reduce computation framework. Unless you have a written license
agreement with the copyright holder (Gerd Stolpmann), the following
terms apply:
Plasma is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Plasma is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*)
(* $Id$ *)
(** Dump file management
Dump files are stored in the local file system in the [config#nn_dump_dir]
directory. Dump files are used for checkpoints and for log data
(transaction deltas).
In the [config#nn_dump_dir] directory every dump gets its own subdirectory.
These subdirectories have names of the form <prefix>_<ref>_<suffix> where
- <prefix> denotes the kind of dump ("checkpoint", "log")
- <ref> is the name of the dump, see below
- <suffix> makes the directory name unique if there are several instances
for the same ref
For checkpoints:
- <prefix> is always "checkpoint"
- <ref> is the timestamp in the format "YYYYMMDDHHMMSS"
For log files:
- <prefix> is always "log"
- <ref> is the <ref>_<suffix> string of the checkpoint the log files
refer to
Examples:
- checkpoint_20130604145547_0000
- log_20130604145547_0000_0001
The dump directories are only considered valid if they contain a file
"dump_succeeded".
*)
class type dump_config =
object
method nn_dump_dir : string
end
type dump_entry =
{ dump_prefix : string;
dump_ref : string;
dump_suffix : string;
dump_finished : bool;
dump_timestamp : float
}
val create_dump : #dump_config -> (string * string) -> dump_entry
(** [create_dump conf (prefix, ref)]: Creates a new dump directory
and returns the entry.
*)
val finish_dump : #dump_config -> dump_entry -> dump_entry
(** [finish_dump conf entry]: creates the "dump_succeeded" file
and returns the updated entry (new timestamp, finished=true).
*)
val list_dumps : #dump_config -> dump_entry list
(** List all dump directories (including unfinished ones) *)
val dump_directory : #dump_config -> dump_entry -> string
(** Return the absolute path to this dump *)
val get_dump_files : #dump_config -> dump_entry -> (string * int64) list
(** Returns the files in the dump directory, together with the file
size in bytes. The file "dump_succeeded" is not returned by this
function.
Files starting with a dot or ending in ~ are also not returned.
*)
val remove_dump : #dump_config -> dump_entry -> unit
(** Deletes a dump directory *)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment