slave.h 3.69 KB
Newer Older
1 2 3
#ifndef SLAVE_H
#define SLAVE_H

unknown's avatar
unknown committed
4 5
#define SLAVE_NET_TIMEOUT  3600

6
extern ulong slave_net_timeout, master_retry_count;
unknown's avatar
unknown committed
7

8 9 10
typedef struct st_master_info
{
  char log_file_name[FN_REFLEN];
unknown's avatar
unknown committed
11
  ulonglong pos,pending;
unknown's avatar
unknown committed
12 13
  File fd; // we keep the file open, so we need to remember the file pointer
  IO_CACHE file;
14 15 16 17 18 19 20
  // the variables below are needed because we can change masters on the fly
  char host[HOSTNAME_LENGTH+1];
  char user[USERNAME_LENGTH+1];
  char password[HASH_PASSWORD_LENGTH+1];
  uint port;
  uint connect_retry;
  pthread_mutex_t lock;
unknown's avatar
unknown committed
21
  pthread_cond_t cond;
22 23
  bool inited;
  
unknown's avatar
unknown committed
24
  st_master_info():pending(0),fd(-1),inited(0)
25 26
  {
    host[0] = 0; user[0] = 0; password[0] = 0;
27
    pthread_mutex_init(&lock, MY_MUTEX_INIT_FAST);
unknown's avatar
unknown committed
28
    pthread_cond_init(&cond, NULL);
29 30 31 32 33
  }

  ~st_master_info()
  {
    pthread_mutex_destroy(&lock);
unknown's avatar
unknown committed
34
    pthread_cond_destroy(&cond);
35
  }
unknown's avatar
unknown committed
36
  inline void inc_pending(ulonglong val)
37 38 39
  {
    pending += val;
  }
unknown's avatar
unknown committed
40
  inline void inc_pos(ulonglong val)
41 42 43 44
  {
    pthread_mutex_lock(&lock);
    pos += val + pending;
    pending = 0;
unknown's avatar
unknown committed
45
    pthread_cond_broadcast(&cond);
46 47 48 49
    pthread_mutex_unlock(&lock);
  }
  // thread safe read of position - not needed if we are in the slave thread,
  // but required otherwise
unknown's avatar
unknown committed
50
  inline void read_pos(ulonglong& var)
51 52 53 54 55
  {
    pthread_mutex_lock(&lock);
    var = pos;
    pthread_mutex_unlock(&lock);
  }
unknown's avatar
unknown committed
56

unknown's avatar
unknown committed
57
  int wait_for_pos(THD* thd, String* log_name, ulonglong log_pos);
58 59 60 61 62 63 64 65 66 67
} MASTER_INFO;

typedef struct st_table_rule_ent
{
  char* db;
  char* tbl_name;
  uint key_len;
} TABLE_RULE_ENT;

#define TABLE_RULE_HASH_SIZE   16
unknown's avatar
unknown committed
68
#define TABLE_RULE_ARR_SIZE   16
69 70 71 72 73 74 75 76 77 78 79

int flush_master_info(MASTER_INFO* mi);

int mysql_table_dump(THD* thd, char* db, char* tbl_name, int fd = -1);
// if fd is -1, dump to NET
int fetch_nx_table(THD* thd, MASTER_INFO* mi);
// retrieve non-exitent table from master
// the caller must set thd->last_nx_table and thd->last_nx_db first
int show_master_info(THD* thd);
int show_binlog_info(THD* thd);

80 81 82
int tables_ok(THD* thd, TABLE_LIST* tables);
// see if the query uses any tables that should not be replicated

83 84 85 86 87
int db_ok(const char* db, I_List<i_string> &do_list,
	  I_List<i_string> &ignore_list );
// check to see if the database is ok to operate on with respect to the
// do and ignore lists - used in replication

88
int add_table_rule(HASH* h, const char* table_spec);
unknown's avatar
unknown committed
89
int add_wild_table_rule(DYNAMIC_ARRAY* a, const char* table_spec);
90
void init_table_rule_hash(HASH* h, bool* h_inited);
unknown's avatar
unknown committed
91
void init_table_rule_array(DYNAMIC_ARRAY* a, bool* a_inited);
92

93
void end_slave(); // clean up
94
int init_master_info(MASTER_INFO* mi);
95
void end_master_info(MASTER_INFO* mi);
96 97
extern bool opt_log_slave_updates ;
pthread_handler_decl(handle_slave,arg);
98
extern bool volatile abort_loop, abort_slave, slave_running;
99 100 101 102 103
extern uint32 slave_skip_counter;
// needed for problems when slave stops and
// we want to restart it skipping one or more events in the master log that
// have caused errors, and have been manually applied by DBA already

104
extern pthread_t slave_real_id;
105
extern THD* slave_thd;
106 107
extern MASTER_INFO glob_mi;
extern HASH replicate_do_table, replicate_ignore_table;
108 109 110 111
extern DYNAMIC_ARRAY  replicate_wild_do_table, replicate_wild_ignore_table;
extern bool do_table_inited, ignore_table_inited,
	    wild_do_table_inited, wild_ignore_table_inited;
extern bool table_rules_on;
112

unknown's avatar
unknown committed
113
#ifndef DBUG_OFF
114
extern int disconnect_slave_event_count, abort_slave_event_count ;
unknown's avatar
unknown committed
115 116
#endif

117 118 119 120 121 122 123 124 125 126
// the master variables are defaults read from my.cnf or command line
extern uint master_port, master_connect_retry;
extern my_string master_user, master_password, master_host,
  master_info_file;

extern I_List<i_string> replicate_do_db, replicate_ignore_db;
extern I_List<i_string_pair> replicate_rewrite_db;
extern I_List<THD> threads;

#endif
127 128