experimental rados_cluster recovery backend
cover experimental rados_cluster recovery backend
From: Jeff Layton <[email protected]>
This is a very rough and early draft of a clustered recovery backend built on top of a shared RADOS object. To be clear, this is not at all ready for merge, but should serve as a basis for further development. The intended use case here is allowing loosely-aggregated, parallel ganesha servers to run on top of cephfs.
One of the cases we have to handle is recovery from a catastrophic outage that takes out all the clustered ganeshas + the ceph MDSs, but leaves some subset of clients running. Once we bring the cluster back up, and start the NFS servers, the clients will attempt to reconnect and reestablish their state to the individual servers. During this period, no server in the cluster can allow the establishment of new state. All servers must continue to enforce the grace period until no server in the cluster is still allowing recovery.
This patchset extends the recovery_backend interface to hook in the grace period management as well. This allows us to do more involved things when starting the local grace period (like joining an existing cluster-wide grace period), and to gate the lifting of the local grace period on whether any other node in the cluster still requires it.
For now, if any node in the cluster crashes, this implementation requires that you manually declare a new grace period (using an included command-line tool), and restart the whole set of servers when bringing it back up.
We have some (handwavy) plans to improve that by allowing a ganesha server to reclaim ceph state it held earlier. That's just vaporware at this point, but the code is designed in such a way that we should be able to plug that in later.
Comments and suggestions welcome.
Jeff Layton (6):
SAL: make some rados_kv symbols public
SAL: add new try_lift_grace recovery operation
SAL: add nodeid config value to RADOS_KV section
support: add a rados_grace support library
tools: add new rados_grace manipulation tool
SAL: add new clustered RADOS recovery backend
src/SAL/CMakeLists.txt | 3 +- src/SAL/nfs4_recovery.c | 29 +- src/SAL/recovery/recovery_fs.c | 1 + src/SAL/recovery/recovery_fs_ng.c | 1 + src/SAL/recovery/recovery_rados.h | 11 + src/SAL/recovery/recovery_rados_cluster.c | 203 ++++++++++++++ src/SAL/recovery/recovery_rados_kv.c | 13 +- src/SAL/recovery/recovery_rados_ng.c | 5 +- src/config_samples/config.txt | 2 + src/doc/man/ganesha-core-config.rst | 4 + src/include/rados_grace.h | 33 +++ src/include/sal_functions.h | 3 + src/support/CMakeLists.txt | 4 + src/support/rados_grace.c | 441 ++++++++++++++++++++++++++++++ src/tools/CMakeLists.txt | 4 + src/tools/rados_grace_tool.c | 211 ++++++++++++++ 16 files changed, 957 insertions(+), 11 deletions(-) create mode 100644 src/SAL/recovery/recovery_rados_cluster.c create mode 100644 src/include/rados_grace.h create mode 100644 src/support/rados_grace.c create mode 100644 src/tools/rados_grace_tool.c
Signature · 1 line
2.14.3
A message that is not in the archive (sent off-list or not yet received): 20180131141219.16929-1-jlayton-vpEMnDpepFuMZCB2o+C8xQ@public.gmane.org
RFC PATCH 4/6 support: add a rados_grace support library
From: Jeff Layton <[email protected]>
Add a new support library for coordinating a grace period between multiple nodes. The basic idea is to use a shared RADOS object to mediate requests for a grace period.
Typically, each node will perform a read operation on the database and (then possibly) a write operation. In order to ensure atomicity, we assert that the object version has not changed between the read and write ops. If it has, then we start over again from scratch.
--- src/include/rados_grace.h | 33 ++++ src/support/CMakeLists.txt | 4 + src/support/rados_grace.c | 441 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 478 insertions(+) create mode 100644 src/include/rados_grace.h create mode 100644 src/support/rados_grace.c
src/include/rados_grace.h new file +33 -0
@@ -0,0 +1,33 @@ +#ifndef _RADOS_GRACE_H +#define _RADOS_GRACE_H +/* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public License +* as published by the Free Software Foundation; either version 3 of +* the License, or (at your option) any later version. +* +* This program 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +* 02110-1301 USA +* +* --------------------------------------- +*/ +int rados_grace_create (rados_ioctx_t io_ctx,const char *oid); +int rados_grace_dump (rados_ioctx_t io_ctx,const char *oid); +int rados_grace_start (rados_ioctx_t io_ctx,const char *oid,int nodes, +char **nodeids); +int rados_grace_start (rados_ioctx_t io_ctx,const char *oid,int nodes, +char **nodeids); +int rados_grace_join (rados_ioctx_t io_ctx,const char *oid,uint32_t nodeid, +uint64_t *pcur,uint64_t *prec); +int rados_grace_lift (rados_ioctx_t io_ctx,const char *oid,int nodes, +char **nodeids); +int rados_grace_done (rados_ioctx_t io_ctx,const char *oid,uint32_t nodeid, +uint64_t *pcur,uint64_t *prec); +#endif /* _RADOS_GRACE_H */
src/support/CMakeLists.txt +4 -0
@@ -41,6 +41,10 @@ set(netgroup_cache_SRCS add_library(netgroup_cache STATIC ${netgroup_cache_SRCS}) add_sanitizers(netgroup_cache) +if (USE_RADOS_RECOV) + add_library(rados_grace STATIC rados_grace.c) +endif(USE_RADOS_RECOV) + ########### next target ############### SET(support_STAT_SRCS
src/support/rados_grace.c new file +441 -0
441 lines not on this page · raw message
Signature · 6 lines
2.14.3 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
RFC PATCH 1/6 SAL: make some rados_kv symbols public
In reply to [email protected]From: Jeff Layton <[email protected]>
--- src/SAL/recovery/recovery_rados.h | 9 +++++++++ src/SAL/recovery/recovery_rados_kv.c | 6 +++--- 2 files changed, 12 insertions(+), 3 deletions(-)
src/SAL/recovery/recovery_rados.h +9 -0
@@ -28,6 +28,7 @@extern rados_t rados_recov_cluster;extern rados_ioctx_t rados_recov_io_ctx;extern char rados_recov_oid[NI_MAXHOST ]; +extern char rados_recov_old_oid[NI_MAXHOST ];struct rados_kv_parameter {/** Connection to ceph cluster */
@@ -51,10 +52,18 @@ typedef struct pop_args {int rados_kv_connect (rados_ioctx_t *io_ctx,const char *userid,const char *conf,const char *pool);void rados_kv_shutdown (void ); +int rados_kv_put (char *key,char *val,char *object);int rados_kv_get (char *key,char **val,size_t *val_len,char *object); +void rados_kv_add_clid (nfs_client_id_t *clientid); +void rados_kv_rm_clid (nfs_client_id_t *clientid); +void rados_kv_add_revoke_fh (nfs_client_id_t *delr_clid,nfs_fh4 *delr_handle);void rados_kv_create_key (nfs_client_id_t *clientid,char *key);void rados_kv_create_val (nfs_client_id_t *clientid,char *val);int rados_kv_traverse (pop_clid_entry_t pop_func,pop_args_t pop_args,const char *object);void rados_kv_append_val_rdfh (char *val,char *rdfh,int rdfh_len); +void rados_kv_pop_clid_entry (char *key,char *val, +add_clid_entry_hook add_clid_entry, +add_rfh_entry_hook add_rfh_entry, +bool old,bool takeover);#endif /* _RECOVERY_RADOS_H */
src/SAL/recovery/recovery_rados_kv.c +3 -3
@@ -21,7 +21,7 @@static rados_t clnt;rados_ioctx_t rados_recov_io_ctx;char rados_recov_oid[NI_MAXHOST ]; -static char rados_recov_old_oid[NI_MAXHOST ]; +char rados_recov_old_oid[NI_MAXHOST ];struct rados_kv_parameter rados_kv_param;
@@ -132,7 +132,7 @@ void rados_kv_create_val(nfs_client_id_t *clientid, char *val) clientid->cid_recov_tag); } -static int rados_kv_put (char *key,char *val,char *object) +int rados_kv_put (char *key,char *val,char *object) {int ret;char *keys[1 ];
@@ -444,7 +444,7 @@ void rados_kv_rm_clid(nfs_client_id_t *clientid) clientid->cid_recov_tag =NULL ; } -static void rados_kv_pop_clid_entry(char *key, +void rados_kv_pop_clid_entry(char *key, char *val, add_clid_entry_hook add_clid_entry, add_rfh_entry_hook add_rfh_entry,
Signature · 1 line
2.14.3
RFC PATCH 2/6 SAL: add new try_lift_grace recovery operation
In reply to [email protected]From: Jeff Layton <[email protected]>
When running in a clustered environment, we can't just lift the grace period once the local machine is ready. We must instead wait until no other cluster nodes still need it.
Add a new can_lift_grace op, and use that to do extra vetting before allowing the local grace period to be lifted. If it returns true, then we can go ahead and lift the grace period.
--- src/SAL/nfs4_recovery.c | 27 ++++++++++++++++++++++++--- src/SAL/recovery/recovery_fs.c | 1 + src/SAL/recovery/recovery_fs_ng.c | 1 + src/SAL/recovery/recovery_rados_kv.c | 1 + src/SAL/recovery/recovery_rados_ng.c | 1 + src/include/sal_functions.h | 2 ++ 6 files changed, 30 insertions(+), 3 deletions(-)
src/SAL/nfs4_recovery.c +24 -3
@@ -196,12 +196,31 @@ bool nfs_in_grace(void)return atomic_fetch_time_t (¤t_grace); } +/** +* @brief Determine whether we can lift the grace period +* +* @retval true if so +* @retval false if not +* +* In a clustered environment, we must take care not to lift the grace period +* until it's no longer needed cluster-wide. Try to lift the grace period, and +* return true or false depending on whether it succeeded. +* +* In the case of a single host, we always assume that the grace period can +* be lifted. +*/ +bool simple_try_lift_grace (void ) +{ +return true; +} +void nfs_try_lift_grace (void ) {bool in_grace = true;int32_t rc_count =0 ;time_t current =atomic_fetch_time_t (¤t_grace); +/* Already lifted? Just return */ if (!current)return ;
@@ -223,9 +242,11 @@ void nfs_try_lift_grace(void)* try to do it. */ if (!in_grace) { -PTHREAD_MUTEX_lock (&grace_mutex); -nfs_lift_grace_locked (current); -PTHREAD_MUTEX_unlock (&grace_mutex); +if (recovery_backend->try_lift_grace ()) { +PTHREAD_MUTEX_lock (&grace_mutex); +nfs_lift_grace_locked (current); +PTHREAD_MUTEX_unlock (&grace_mutex); + } } }
src/SAL/recovery/recovery_fs.c +1 -0
@@ -784,6 +784,7 @@ struct nfs4_recovery_backend fs_backend = { .add_clid = fs_add_clid, .rm_clid = fs_rm_clid, .add_revoke_fh = fs_add_revoke_fh, + .try_lift_grace = simple_try_lift_grace, };void fs_backend_init (struct nfs4_recovery_backend **backend)
src/SAL/recovery/recovery_fs_ng.c +1 -0
@@ -377,6 +377,7 @@ static struct nfs4_recovery_backend fs_ng_backend = { .add_clid = fs_add_clid, .rm_clid = fs_rm_clid, .add_revoke_fh = fs_add_revoke_fh, + .try_lift_grace = simple_try_lift_grace, };void fs_ng_backend_init (struct nfs4_recovery_backend **backend)
src/SAL/recovery/recovery_rados_kv.c +1 -0
@@ -601,6 +601,7 @@ struct nfs4_recovery_backend rados_kv_backend = { .add_clid = rados_kv_add_clid, .rm_clid = rados_kv_rm_clid, .add_revoke_fh = rados_kv_add_revoke_fh, + .try_lift_grace = simple_try_lift_grace, };void rados_kv_backend_init (struct nfs4_recovery_backend **backend)
src/SAL/recovery/recovery_rados_ng.c +1 -0
@@ -318,6 +318,7 @@ struct nfs4_recovery_backend rados_ng_backend = { .add_clid = rados_ng_add_clid, .rm_clid = rados_ng_rm_clid, .add_revoke_fh = rados_ng_add_revoke_fh, + .try_lift_grace = simple_try_lift_grace, };void rados_ng_backend_init (struct nfs4_recovery_backend **backend)
src/include/sal_functions.h +2 -0
@@ -967,6 +967,7 @@ void blocked_lock_polling(struct fridgethr_context *ctx);void nfs_start_grace (nfs_grace_start_t *gsp);bool nfs_in_grace (void ); +bool simple_try_lift_grace (void );void nfs_try_lift_grace (void );void nfs4_add_clid (nfs_client_id_t *);void nfs4_rm_clid (nfs_client_id_t *);
@@ -1012,6 +1013,7 @@ struct nfs4_recovery_backend {void (*add_clid)(nfs_client_id_t *);void (*rm_clid)(nfs_client_id_t *);void (*add_revoke_fh)(nfs_client_id_t *,nfs_fh4 *); +bool (*try_lift_grace)(void ); };void fs_backend_init (struct nfs4_recovery_backend **);
Signature · 1 line
2.14.3
RFC PATCH 3/6 SAL: add nodeid config value to RADOS_KV section
In reply to [email protected]From: Jeff Layton <[email protected]>
The global "clustered" configuration value is true by default. Its only meaning is as an indicator of whether the g_nodeid value is valid, and that value is only used in the recovery backends.
The g_nodeid however, is almost always zero. The only exception is when GPFS creates an export, at which point it'll ask the cluster about its nodeid and set the value. That value is apparently never zero.
My suspicion is that the intersection of people using the RADOS recovery backends with GPFS is probably quite small.
Allow the admin to set a nodeid value in the RADOS_KV configuration block. This value defaults to UINT32_MAX which will make the RADOS_KV store act as non-clustered by default (using the hostname as the basis of the OID name).
With this, the RADOS recovery backends will just ignore the "clustered" config option.
--- src/SAL/recovery/recovery_rados.h | 2 ++ src/SAL/recovery/recovery_rados_kv.c | 6 ++++-- src/SAL/recovery/recovery_rados_ng.c | 4 ++-- src/config_samples/config.txt | 2 ++ src/doc/man/ganesha-core-config.rst | 4 ++++ 5 files changed, 14 insertions(+), 4 deletions(-)
src/SAL/recovery/recovery_rados.h +2 -0
@@ -37,6 +37,8 @@ struct rados_kv_parameter {char *userid;/** Pool for client info */ char *pool; +/** Node ID for this cluster node */ +uint32_t nodeid; };extern struct rados_kv_parameter rados_kv_param;
src/SAL/recovery/recovery_rados_kv.c +4 -2
@@ -32,6 +32,8 @@ static struct config_item rados_kv_params[] = { rados_kv_parameter, userid),CONF_ITEM_STR ("pool" ,1 ,MAXPATHLEN ,DEFAULT_POOL , rados_kv_parameter, pool), +CONF_ITEM_UI32 ("nodeid" ,0 ,UINT32_MAX ,UINT32_MAX , + rados_kv_parameter, nodeid), CONFIG_EOL };
@@ -350,8 +352,8 @@ void rados_kv_init(void)int ret;char host[NI_MAXHOST ]; -if (nfs_param.core_param.clustered) { -snprintf (host,sizeof (host),"node%d" , g_nodeid); +if (rados_kv_param.nodeid !=UINT32_MAX ) { +snprintf (host,sizeof (host),"node%d" , rados_kv_param.nodeid); }else { ret =gethostname (host,sizeof (host));if (ret) {
src/SAL/recovery/recovery_rados_ng.c +2 -2
@@ -117,8 +117,8 @@ static void rados_ng_init(void)char host[NI_MAXHOST ];rados_write_op_t op; -if (nfs_param.core_param.clustered) { -snprintf (host,sizeof (host),"node%d" , g_nodeid); +if (rados_kv_param.nodeid !=UINT32_MAX ) { +snprintf (host,sizeof (host),"node%d" , rados_kv_param.nodeid); }else { ret =gethostname (host,sizeof (host));if (ret) {
src/config_samples/config.txt +2 -0
@@ -730,6 +730,8 @@ RADOS_KV {} pool(string, no default) + nodeid(uint32, default UINT32_MAX) + RADOS_URLS {} --------
src/doc/man/ganesha-core-config.rst +4 -0
@@ -305,3 +305,7 @@ userid(path, no default) pool(string, no default) Pool for client info. + +nodeid(uint32, range 0 to UINT32_MAX, default UINT32_MAX) + The nodeid value for this cluster node. Defaults to UINT32_MAX which is a + special value meaning "non-clustered".
Signature · 1 line
2.14.3
RFC PATCH 5/6 tools: add new rados_grace manipulation tool
In reply to [email protected]From: Jeff Layton <[email protected]>
Add a new command-line tool for manipulating and querying the grace database.
Run with no arguments to see the current state of the gracedb. Pass it numeric integers to tell it which hosts want to start or join an existing grace period. We can also remove the grace period request for a set of nodes by passing it the -l flag.
--- src/tools/CMakeLists.txt | 4 + src/tools/rados_grace_tool.c | 211 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 215 insertions(+) create mode 100644 src/tools/rados_grace_tool.c
src/tools/CMakeLists.txt +4 -0
@@ -1,3 +1,7 @@ +if (USE_RADOS_RECOV) + add_executable(rados_grace_tool rados_grace_tool.c) + target_link_libraries(rados_grace_tool rados_grace ${RADOS_LIBRARIES}) +endif(USE_RADOS_RECOV) ########### install files ###############
src/tools/rados_grace_tool.c new file +211 -0
211 lines not on this page · raw message
Signature · 1 line
2.14.3
RFC PATCH 6/6 SAL: add new clustered RADOS recovery backend
In reply to [email protected]From: Jeff Layton <[email protected]>
Add a new clustered RADOS recovery backend driver. This uses a common RADOS object to coordinate a cluster-wide grace period.
Each node in the cluster should be assigned a unique nodeid (uint64_t), which we then use to check/request a grace period, and determine from which database to allow recovery.
--- src/SAL/CMakeLists.txt | 3 +- src/SAL/nfs4_recovery.c | 2 + src/SAL/recovery/recovery_rados_cluster.c | 203 ++++++++++++++++++++++++++++++ src/include/sal_functions.h | 1 + 4 files changed, 208 insertions(+), 1 deletion(-) create mode 100644 src/SAL/recovery/recovery_rados_cluster.c
src/SAL/CMakeLists.txt +2 -1
@@ -38,6 +38,7 @@ if(USE_RADOS_RECOV) ${sal_STAT_SRCS} recovery/recovery_rados_kv.c recovery/recovery_rados_ng.c + recovery/recovery_rados_cluster.c ) endif(USE_RADOS_RECOV)
@@ -46,7 +47,7 @@ add_sanitizers(sal) if(USE_RADOS_RECOV) include_directories(${RADOS_INCLUDE_DIR}) - target_link_libraries(sal ${RADOS_LIBRARIES}) + target_link_libraries(sal rados_grace ${RADOS_LIBRARIES}) endif(USE_RADOS_RECOV) ########### install files ###############
src/SAL/nfs4_recovery.c +2 -0
@@ -423,6 +423,8 @@ static int load_backend(const char *name)rados_kv_backend_init (&recovery_backend); else if (!strcmp(name, "rados_ng"))rados_ng_backend_init (&recovery_backend); + else if (!strcmp(name, "rados_cluster")) +rados_cluster_backend_init (&recovery_backend);#endif else if (!strcmp(name, "fs_ng"))fs_ng_backend_init (&recovery_backend);
src/SAL/recovery/recovery_rados_cluster.c new file +203 -0
203 lines not on this page · raw message
src/include/sal_functions.h +1 -0
@@ -1022,6 +1022,7 @@ void fs_ng_backend_init(struct nfs4_recovery_backend **);int rados_kv_set_param_from_conf (config_file_t ,struct config_error_type *);void rados_kv_backend_init (struct nfs4_recovery_backend **);void rados_ng_backend_init (struct nfs4_recovery_backend **); +void rados_cluster_backend_init (struct nfs4_recovery_backend **backend);#endif #endif /* SAL_FUNCTIONS_H */
Signature · 1 line
2.14.3