2007-06-04 19:53:19 +10:00
/*
ctdb tunables code
Copyright ( C ) Andrew Tridgell 2007
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-10 15:29:31 +10:00
the Free Software Foundation ; either version 3 of the License , or
2007-06-04 19:53:19 +10:00
( 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 General Public License for more details .
You should have received a copy of the GNU General Public License
2007-07-10 15:29:31 +10:00
along with this program ; if not , see < http : //www.gnu.org/licenses/>.
2007-06-04 19:53:19 +10:00
*/
# include "includes.h"
# include "../include/ctdb_private.h"
static const struct {
const char * name ;
2007-06-04 20:22:44 +10:00
uint32_t default_v ;
size_t offset ;
2007-06-04 19:53:19 +10:00
} tunable_map [ ] = {
2007-06-07 15:18:55 +10:00
{ " MaxRedirectCount " , 3 , offsetof ( struct ctdb_tunable , max_redirect_count ) } ,
2009-04-01 17:21:38 +11:00
{ " SeqnumInterval " , 1000 , offsetof ( struct ctdb_tunable , seqnum_interval ) } ,
2007-06-07 15:18:55 +10:00
{ " ControlTimeout " , 60 , offsetof ( struct ctdb_tunable , control_timeout ) } ,
{ " TraverseTimeout " , 20 , offsetof ( struct ctdb_tunable , traverse_timeout ) } ,
2008-01-06 12:36:58 +11:00
{ " KeepaliveInterval " , 5 , offsetof ( struct ctdb_tunable , keepalive_interval ) } ,
2007-06-11 22:27:23 +10:00
{ " KeepaliveLimit " , 5 , offsetof ( struct ctdb_tunable , keepalive_limit ) } ,
2009-04-24 14:41:21 +10:00
{ " RecoverTimeout " , 20 , offsetof ( struct ctdb_tunable , recover_timeout ) } ,
2007-06-07 15:18:55 +10:00
{ " RecoverInterval " , 1 , offsetof ( struct ctdb_tunable , recover_interval ) } ,
{ " ElectionTimeout " , 3 , offsetof ( struct ctdb_tunable , election_timeout ) } ,
2010-11-10 14:46:45 +11:00
{ " TakeoverTimeout " , 9 , offsetof ( struct ctdb_tunable , takeover_timeout ) } ,
2007-06-07 15:18:55 +10:00
{ " MonitorInterval " , 15 , offsetof ( struct ctdb_tunable , monitor_interval ) } ,
2007-07-20 15:05:55 +10:00
{ " TickleUpdateInterval " , 20 , offsetof ( struct ctdb_tunable , tickle_update_interval ) } ,
2009-10-28 09:07:43 +11:00
{ " EventScriptTimeout " , 30 , offsetof ( struct ctdb_tunable , script_timeout ) } ,
2009-12-14 15:53:23 +11:00
{ " EventScriptTimeoutCount " , 1 , offsetof ( struct ctdb_tunable , script_timeout_count ) } ,
2009-12-16 09:51:17 +11:00
{ " EventScriptUnhealthyOnTimeout " , 0 , offsetof ( struct ctdb_tunable , script_unhealthy_on_timeout ) } , /* OBSOLETE */
2009-04-24 14:41:21 +10:00
{ " RecoveryGracePeriod " , 120 , offsetof ( struct ctdb_tunable , recovery_grace_period ) } ,
2007-06-07 15:18:55 +10:00
{ " RecoveryBanPeriod " , 300 , offsetof ( struct ctdb_tunable , recovery_ban_period ) } ,
2010-10-11 07:09:18 +11:00
{ " DatabaseHashSize " , 100001 , offsetof ( struct ctdb_tunable , database_hash_size ) } ,
2008-01-05 09:36:53 +11:00
{ " DatabaseMaxDead " , 5 , offsetof ( struct ctdb_tunable , database_max_dead ) } ,
2007-07-04 08:36:59 +10:00
{ " RerecoveryTimeout " , 10 , offsetof ( struct ctdb_tunable , rerecovery_timeout ) } ,
2007-10-15 13:22:58 +10:00
{ " EnableBans " , 1 , offsetof ( struct ctdb_tunable , enable_bans ) } ,
2011-08-15 10:23:50 +10:00
{ " DeterministicIPs " , 0 , offsetof ( struct ctdb_tunable , deterministic_public_ips ) } ,
{ " LCP2PublicIPs " , 1 , offsetof ( struct ctdb_tunable , lcp2_public_ip_assignment ) } ,
2008-03-03 12:52:16 +11:00
{ " ReclockPingPeriod " , 60 , offsetof ( struct ctdb_tunable , reclock_ping_period ) } ,
{ " NoIPFailback " , 0 , offsetof ( struct ctdb_tunable , no_ip_failback ) } ,
2010-11-09 15:19:06 +11:00
{ " DisableIPFailover " , 0 , offsetof ( struct ctdb_tunable , disable_ip_failover ) } ,
2008-04-01 15:34:54 +11:00
{ " VerboseMemoryNames " , 0 , offsetof ( struct ctdb_tunable , verbose_memory_names ) } ,
2009-06-18 09:20:18 +10:00
{ " RecdPingTimeout " , 60 , offsetof ( struct ctdb_tunable , recd_ping_timeout ) } ,
{ " RecdFailCount " , 10 , offsetof ( struct ctdb_tunable , recd_ping_failcount ) } ,
2008-10-30 12:49:53 +11:00
{ " LogLatencyMs " , 0 , offsetof ( struct ctdb_tunable , log_latency_ms ) } ,
2009-05-14 10:33:25 +10:00
{ " RecLockLatencyMs " , 1000 , offsetof ( struct ctdb_tunable , reclock_latency_ms ) } ,
2010-11-09 12:59:05 +11:00
{ " RecoveryDropAllIPs " , 120 , offsetof ( struct ctdb_tunable , recovery_drop_all_ips ) } ,
2009-05-01 01:18:27 +10:00
{ " VerifyRecoveryLock " , 1 , offsetof ( struct ctdb_tunable , verify_recovery_lock ) } ,
2010-12-20 21:43:41 +01:00
{ " VacuumDefaultInterval " , 10 , offsetof ( struct ctdb_tunable , vacuum_default_interval ) } ,
2009-07-29 13:31:12 +10:00
{ " VacuumMaxRunTime " , 30 , offsetof ( struct ctdb_tunable , vacuum_max_run_time ) } ,
2009-07-28 23:09:28 +03:00
{ " RepackLimit " , 10000 , offsetof ( struct ctdb_tunable , repack_limit ) } ,
2009-09-29 13:20:18 +10:00
{ " VacuumLimit " , 5000 , offsetof ( struct ctdb_tunable , vacuum_limit ) } ,
2010-12-20 21:43:41 +01:00
{ " VacuumMinInterval " , 10 , offsetof ( struct ctdb_tunable , vacuum_min_interval ) } ,
{ " VacuumMaxInterval " , 10 , offsetof ( struct ctdb_tunable , vacuum_max_interval ) } ,
2010-12-20 17:42:25 +01:00
{ " VacuumFastPathCount " , 60 , offsetof ( struct ctdb_tunable , vacuum_fast_path_count ) } ,
2010-02-04 09:54:06 +11:00
{ " MaxQueueDropMsg " , 1000000 , offsetof ( struct ctdb_tunable , max_queue_depth_drop_msg ) } ,
2009-12-07 13:28:11 +01:00
{ " UseStatusEvents " , 0 , offsetof ( struct ctdb_tunable , use_status_events_for_monitoring ) } ,
2010-09-30 14:39:54 +10:00
{ " AllowUnhealthyDBRead " , 0 , offsetof ( struct ctdb_tunable , allow_unhealthy_db_read ) } ,
2011-02-23 15:46:36 +11:00
{ " StatHistoryInterval " , 1 , offsetof ( struct ctdb_tunable , stat_history_interval ) } ,
2011-09-02 16:42:10 +02:00
{ " DeferredAttachTO " , 120 , offsetof ( struct ctdb_tunable , deferred_attach_timeout ) } ,
{ " AllowClientDBAttach " , 1 , offsetof ( struct ctdb_tunable , allow_client_db_attach ) }
2007-06-04 19:53:19 +10:00
} ;
2007-06-04 20:22:44 +10:00
/*
set all tunables to defaults
*/
void ctdb_tunables_set_defaults ( struct ctdb_context * ctdb )
{
int i ;
for ( i = 0 ; i < ARRAY_SIZE ( tunable_map ) ; i + + ) {
* ( uint32_t * ) ( tunable_map [ i ] . offset + ( uint8_t * ) & ctdb - > tunable ) = tunable_map [ i ] . default_v ;
}
}
2007-06-04 19:53:19 +10:00
/*
get a tunable
*/
int32_t ctdb_control_get_tunable ( struct ctdb_context * ctdb , TDB_DATA indata ,
TDB_DATA * outdata )
{
struct ctdb_control_get_tunable * t =
( struct ctdb_control_get_tunable * ) indata . dptr ;
char * name ;
uint32_t val ;
int i ;
if ( indata . dsize < sizeof ( * t ) | |
t - > length > indata . dsize - offsetof ( struct ctdb_control_get_tunable , name ) ) {
2008-02-04 20:07:15 +11:00
DEBUG ( DEBUG_ERR , ( " Bad indata in ctdb_control_get_tunable \n " ) ) ;
2007-06-04 19:53:19 +10:00
return - 1 ;
}
name = talloc_strndup ( ctdb , ( char * ) t - > name , t - > length ) ;
CTDB_NO_MEMORY ( ctdb , name ) ;
for ( i = 0 ; i < ARRAY_SIZE ( tunable_map ) ; i + + ) {
if ( strcasecmp ( name , tunable_map [ i ] . name ) = = 0 ) break ;
}
talloc_free ( name ) ;
if ( i = = ARRAY_SIZE ( tunable_map ) ) {
return - 1 ;
}
val = * ( uint32_t * ) ( tunable_map [ i ] . offset + ( uint8_t * ) & ctdb - > tunable ) ;
outdata - > dptr = ( uint8_t * ) talloc ( outdata , uint32_t ) ;
CTDB_NO_MEMORY ( ctdb , outdata - > dptr ) ;
* ( uint32_t * ) outdata - > dptr = val ;
outdata - > dsize = sizeof ( uint32_t ) ;
return 0 ;
}
/*
set a tunable
*/
int32_t ctdb_control_set_tunable ( struct ctdb_context * ctdb , TDB_DATA indata )
{
struct ctdb_control_set_tunable * t =
( struct ctdb_control_set_tunable * ) indata . dptr ;
char * name ;
int i ;
if ( indata . dsize < sizeof ( * t ) | |
t - > length > indata . dsize - offsetof ( struct ctdb_control_set_tunable , name ) ) {
2008-02-04 20:07:15 +11:00
DEBUG ( DEBUG_ERR , ( " Bad indata in ctdb_control_set_tunable \n " ) ) ;
2007-06-04 19:53:19 +10:00
return - 1 ;
}
name = talloc_strndup ( ctdb , ( char * ) t - > name , t - > length ) ;
CTDB_NO_MEMORY ( ctdb , name ) ;
for ( i = 0 ; i < ARRAY_SIZE ( tunable_map ) ; i + + ) {
if ( strcasecmp ( name , tunable_map [ i ] . name ) = = 0 ) break ;
}
2009-06-25 14:45:17 +10:00
if ( ! strcmp ( name , " VerifyRecoveryLock " ) & & t - > value ! = 0
& & ctdb - > recovery_lock_file = = NULL ) {
DEBUG ( DEBUG_ERR , ( " Can not activate tunable \" VerifyRecoveryLock \" since there is no recovery lock file set. \n " ) ) ;
talloc_free ( name ) ;
return - 1 ;
}
2007-06-04 19:53:19 +10:00
talloc_free ( name ) ;
if ( i = = ARRAY_SIZE ( tunable_map ) ) {
return - 1 ;
}
2009-06-25 14:45:17 +10:00
2007-06-04 19:53:19 +10:00
* ( uint32_t * ) ( tunable_map [ i ] . offset + ( uint8_t * ) & ctdb - > tunable ) = t - > value ;
return 0 ;
}
/*
list tunables
*/
int32_t ctdb_control_list_tunables ( struct ctdb_context * ctdb , TDB_DATA * outdata )
{
char * list = NULL ;
int i ;
struct ctdb_control_list_tunable * t ;
list = talloc_strdup ( outdata , tunable_map [ 0 ] . name ) ;
CTDB_NO_MEMORY ( ctdb , list ) ;
for ( i = 1 ; i < ARRAY_SIZE ( tunable_map ) ; i + + ) {
list = talloc_asprintf_append ( list , " :%s " , tunable_map [ i ] . name ) ;
CTDB_NO_MEMORY ( ctdb , list ) ;
}
outdata - > dsize = offsetof ( struct ctdb_control_list_tunable , data ) +
strlen ( list ) + 1 ;
outdata - > dptr = talloc_size ( outdata , outdata - > dsize ) ;
CTDB_NO_MEMORY ( ctdb , outdata - > dptr ) ;
t = ( struct ctdb_control_list_tunable * ) outdata - > dptr ;
t - > length = strlen ( list ) + 1 ;
memcpy ( t - > data , list , t - > length ) ;
talloc_free ( list ) ;
return 0 ;
}