Class: Mysql2Replication::Client

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
ext/mysql2-replication/mysql2_replication.c

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Object



892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
# File 'ext/mysql2-replication/mysql2_replication.c', line 892

static VALUE
rbm2_replication_client_initialize(int argc, VALUE *argv, VALUE self)
{
  VALUE rb_client;
  VALUE rb_options;
  VALUE rb_checksum = RUBY_Qnil;

  rb_scan_args(argc, argv, "10:", &rb_client, &rb_options);
  if (!RB_NIL_P(rb_options)) {
    static ID keyword_ids[1];
    VALUE keyword_args[1];
    if (keyword_ids[0] == 0) {
      CONST_ID(keyword_ids[0], "checksum");
    }
    rb_get_kwargs(rb_options, keyword_ids, 0, 1, keyword_args);
    if (keyword_args[0] != RUBY_Qundef) {
      rb_checksum = keyword_args[0];
    }
  }

  rbm2_replication_client_wrapper *wrapper =
    rbm2_replication_client_get_wrapper(self);
  wrapper->rb_client = rb_client;
  wrapper->rpl =
    mariadb_rpl_init(rbm2_replication_client_wrapper_get_client(wrapper));
  if (!wrapper->rpl) {
    rbm2_replication_client_raise(self);
  }

  {
    VALUE rb_query;
    if (RB_NIL_P(rb_checksum)) {
      rb_query = rb_str_new_cstr("SET @master_binlog_checksum = "
                                 "@@global.binlog_checksum");
    } else {
      rb_query = rb_sprintf("SET @master_binlog_checksum = '%"PRIsVALUE"'",
                            rb_checksum);
    }
    ID id_query;
    CONST_ID(id_query, "query");
    rb_funcall(rb_client, id_query, 1, rb_query);
  }
  if (rb_equal(rb_str_new_cstr("NONE"), rb_checksum)) {
    wrapper->force_disable_use_checksum = true;
  } else {
    wrapper->force_disable_use_checksum = false;
  }
  wrapper->format_description_processed = false;

  return RUBY_Qnil;
}

Instance Method Details

#closeObject



1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
# File 'ext/mysql2-replication/mysql2_replication.c', line 1086

static VALUE
rbm2_replication_client_close(VALUE self)
{
  rbm2_replication_client_wrapper *wrapper =
    rbm2_replication_client_get_wrapper(self);
  rb_thread_call_without_gvl(rbm2_replication_client_close_without_gvl,
                             wrapper,
                             RUBY_UBF_IO,
                             0);
  return Qnil;
}

#eachObject



1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
# File 'ext/mysql2-replication/mysql2_replication.c', line 1384

static VALUE
rbm2_replication_client_each(VALUE self)
{
  rbm2_replication_client_wrapper *wrapper =
    rbm2_replication_client_get_wrapper(self);
  MYSQL *client = rbm2_replication_client_wrapper_get_client(wrapper);
  do {
    MARIADB_RPL_EVENT *event =
      rb_thread_call_without_gvl(rbm2_replication_client_fetch_without_gvl,
                                 wrapper,
                                 RUBY_UBF_IO,
                                 0);
    if (mysql_errno(client) != 0) {
      rbm2_replication_client_raise(self);
    }
    if (!event) {
      if (wrapper->rpl->buffer_size == 0) {
        return RUBY_Qnil;
      }
      continue;
    }
    rb_yield(rbm2_replication_event_new(wrapper, event));
  } while (true);
  return RUBY_Qnil;
}

#fetchObject



1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
# File 'ext/mysql2-replication/mysql2_replication.c', line 1359

static VALUE
rbm2_replication_client_fetch(VALUE self)
{
  rbm2_replication_client_wrapper *wrapper =
    rbm2_replication_client_get_wrapper(self);
  MYSQL *client = rbm2_replication_client_wrapper_get_client(wrapper);
  do {
    MARIADB_RPL_EVENT *event =
      rb_thread_call_without_gvl(rbm2_replication_client_fetch_without_gvl,
                                 wrapper,
                                 RUBY_UBF_IO,
                                 0);
    if (mysql_errno(client) != 0) {
      rbm2_replication_client_raise(self);
    }
    if (!event) {
      if (wrapper->rpl->buffer_size == 0) {
        return RUBY_Qnil;
      }
      continue;
    }
    return rbm2_replication_event_new(wrapper, event);
  } while (true);
}

#file_nameObject



944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
# File 'ext/mysql2-replication/mysql2_replication.c', line 944

static VALUE
rbm2_replication_client_get_file_name(VALUE self)
{
  rbm2_replication_client_wrapper *wrapper =
    rbm2_replication_client_get_wrapper(self);
  const char *file_name;
  size_t file_name_length;
  int result = mariadb_rpl_get_optionsv(wrapper->rpl,
                                        MARIADB_RPL_FILENAME,
                                        &file_name,
                                        &file_name_length);
  if (result != 0) {
    rbm2_replication_client_raise(self);
  }
  return rb_str_new(file_name, file_name_length);
}

#file_name=(file_name) ⇒ Object



961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
# File 'ext/mysql2-replication/mysql2_replication.c', line 961

static VALUE
rbm2_replication_client_set_file_name(VALUE self, VALUE file_name)
{
  rbm2_replication_client_wrapper *wrapper =
    rbm2_replication_client_get_wrapper(self);
  int result;
  if (RB_NIL_P(file_name)) {
    result = mariadb_rpl_optionsv(wrapper->rpl,
                                  MARIADB_RPL_FILENAME,
                                  NULL,
                                  0);
  } else {
    result = mariadb_rpl_optionsv(wrapper->rpl,
                                  MARIADB_RPL_FILENAME,
                                  RSTRING_PTR(file_name),
                                  RSTRING_LEN(file_name));
  }
  if (result != 0) {
    rbm2_replication_client_raise(self);
  }
  return file_name;
}

#flagsObject



1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
# File 'ext/mysql2-replication/mysql2_replication.c', line 1042

static VALUE
rbm2_replication_client_get_flags(VALUE self)
{
  rbm2_replication_client_wrapper *wrapper =
    rbm2_replication_client_get_wrapper(self);
  unsigned int flags;
  int result = mariadb_rpl_get_optionsv(wrapper->rpl,
                                        MARIADB_RPL_FLAGS,
                                        &flags);
  if (result != 0) {
    rbm2_replication_client_raise(self);
  }
  return UINT2NUM(flags);
}

#flags=(flags) ⇒ Object



1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
# File 'ext/mysql2-replication/mysql2_replication.c', line 1057

static VALUE
rbm2_replication_client_set_flags(VALUE self, VALUE flags)
{
  rbm2_replication_client_wrapper *wrapper =
    rbm2_replication_client_get_wrapper(self);
  int result = mariadb_rpl_optionsv(wrapper->rpl,
                                    MARIADB_RPL_FLAGS,
                                    NUM2UINT(flags));
  if (result != 0) {
    rbm2_replication_client_raise(self);
  }
  return flags;
}

#openObject



1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
# File 'ext/mysql2-replication/mysql2_replication.c', line 1106

static VALUE
rbm2_replication_client_open(VALUE self)
{
  rbm2_replication_client_wrapper *wrapper =
    rbm2_replication_client_get_wrapper(self);
  int result =
    (intptr_t)rb_thread_call_without_gvl(
      rbm2_replication_client_open_without_gvl,
      wrapper,
      RUBY_UBF_IO,
      0);
  if (result != 0) {
    rbm2_replication_client_raise(self);
  }
  if (rb_block_given_p()) {
    return rb_ensure(rb_yield, self,
                     rbm2_replication_client_close, self);
  } else {
    return Qnil;
  }
}

#server_idObject



1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
# File 'ext/mysql2-replication/mysql2_replication.c', line 1013

static VALUE
rbm2_replication_client_get_server_id(VALUE self)
{
  rbm2_replication_client_wrapper *wrapper =
    rbm2_replication_client_get_wrapper(self);
  unsigned int server_id;
  int result = mariadb_rpl_get_optionsv(wrapper->rpl,
                                        MARIADB_RPL_SERVER_ID,
                                        &server_id);
  if (result != 0) {
    rbm2_replication_client_raise(self);
  }
  return UINT2NUM(server_id);
}

#server_id=(server_id) ⇒ Object



1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
# File 'ext/mysql2-replication/mysql2_replication.c', line 1028

static VALUE
rbm2_replication_client_set_server_id(VALUE self, VALUE server_id)
{
  rbm2_replication_client_wrapper *wrapper =
    rbm2_replication_client_get_wrapper(self);
  int result = mariadb_rpl_optionsv(wrapper->rpl,
                                    MARIADB_RPL_SERVER_ID,
                                    NUM2UINT(server_id));
  if (result != 0) {
    rbm2_replication_client_raise(self);
  }
  return server_id;
}

#start_positionObject



984
985
986
987
988
989
990
991
992
993
994
995
996
997
# File 'ext/mysql2-replication/mysql2_replication.c', line 984

static VALUE
rbm2_replication_client_get_start_position(VALUE self)
{
  rbm2_replication_client_wrapper *wrapper =
    rbm2_replication_client_get_wrapper(self);
  unsigned long start_position;
  int result = mariadb_rpl_get_optionsv(wrapper->rpl,
                                        MARIADB_RPL_START,
                                        &start_position);
  if (result != 0) {
    rbm2_replication_client_raise(self);
  }
  return ULONG2NUM(start_position);
}

#start_position=(start_position) ⇒ Object



999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
# File 'ext/mysql2-replication/mysql2_replication.c', line 999

static VALUE
rbm2_replication_client_set_start_position(VALUE self, VALUE start_position)
{
  rbm2_replication_client_wrapper *wrapper =
    rbm2_replication_client_get_wrapper(self);
  int result = mariadb_rpl_optionsv(wrapper->rpl,
                                    MARIADB_RPL_START,
                                    NUM2ULONG(start_position));
  if (result != 0) {
    rbm2_replication_client_raise(self);
  }
  return start_position;
}