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



825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
# File 'ext/mysql2-replication/mysql2_replication.c', line 825

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;
  }

  return RUBY_Qnil;
}

Instance Method Details

#closeObject



1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
# File 'ext/mysql2-replication/mysql2_replication.c', line 1018

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



1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
# File 'ext/mysql2-replication/mysql2_replication.c', line 1275

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



1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
# File 'ext/mysql2-replication/mysql2_replication.c', line 1250

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



876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
# File 'ext/mysql2-replication/mysql2_replication.c', line 876

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



893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
# File 'ext/mysql2-replication/mysql2_replication.c', line 893

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



974
975
976
977
978
979
980
981
982
983
984
985
986
987
# File 'ext/mysql2-replication/mysql2_replication.c', line 974

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



989
990
991
992
993
994
995
996
997
998
999
1000
1001
# File 'ext/mysql2-replication/mysql2_replication.c', line 989

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



1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
# File 'ext/mysql2-replication/mysql2_replication.c', line 1038

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



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

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



960
961
962
963
964
965
966
967
968
969
970
971
972
# File 'ext/mysql2-replication/mysql2_replication.c', line 960

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



916
917
918
919
920
921
922
923
924
925
926
927
928
929
# File 'ext/mysql2-replication/mysql2_replication.c', line 916

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



931
932
933
934
935
936
937
938
939
940
941
942
943
# File 'ext/mysql2-replication/mysql2_replication.c', line 931

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;
}