aerospike_native 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb0270c96b7bd4fa49f251d9b5fd406a21ae109b
4
- data.tar.gz: 92c3cdb727dafa076735b779eb198011cb028058
3
+ metadata.gz: c1d71f1edfd8c586f26365cc3d4164e82bd3edf7
4
+ data.tar.gz: c3a672ce0944477a43dae020b55e5656b438e933
5
5
  SHA512:
6
- metadata.gz: 27c8668efda00c0a467844f5f840fce63223dbbab69d71e53d8c9177c1bf6a4c23f69fb5366a3092a6b20eb90be95c372126fa1b4de1653533e3596a4957dcdf
7
- data.tar.gz: 9d4fde1a9e2942ac4bfbe108cbc6babd807fdf37eef6d67e079cb797297458ab8404971716f7613d2bf1542c2c08ed3bbfdaf4df5b035be96521b492167dfde5
6
+ metadata.gz: 2f47a757e7d62cc85edec99c5912b581892d286b9fea1b630d4bd95f55e3d7d34159877304aa9d858995e176e23b23fe463bb2d401ebd79ba71ca1dd69af9430
7
+ data.tar.gz: ded5c49c747f022322ddd58c3a4cdf257f0a01195e31315cd7759d87fb7c5cfd16da4b1fae529d0c6b84043d86cfb3b5852bbffa7c34706704ce54e2296ed0af
@@ -1,4 +1,8 @@
1
- require './common/common'
1
+ require_relative './common/common'
2
+
3
+ def keys(namespace, set, *values)
4
+ values.map{ |value| AerospikeNative::Key.new(namespace, set, value) }
5
+ end
2
6
 
3
7
  def main
4
8
  Common::Common.run_example do |client, namespace, set, logger|
@@ -7,20 +11,16 @@ def main
7
11
  client.put(AerospikeNative::Key.new(namespace, set, "key#{i}"), {'number' => i, 'key' => 'string', 'testbin' => i.to_s})
8
12
  end
9
13
 
10
- keys = []
11
- keys << AerospikeNative::Key.new(namespace, set, 1)
12
- keys << AerospikeNative::Key.new(namespace, set, 10)
13
- keys << AerospikeNative::Key.new(namespace, set, "key5")
14
- keys << AerospikeNative::Key.new(namespace, set, "key26")
14
+ bins = [:number, :key]
15
15
 
16
- records = client.batch.get_exists(keys)
16
+ records = client.batch.exists(keys(namespace, set, 1, 10, "key5", "key26"))
17
17
  logger.info "fetched records metadata: #{records.inspect}"
18
18
 
19
- records = client.batch.get(keys)
20
- logger.info "fetched records with specified bins: #{records.inspect}"
21
-
22
- records = client.batch.get(keys, bins)
19
+ records = client.batch.get(keys(namespace, set, 1, 10, "key5", "key26"))
23
20
  logger.info "fetched records with all bins: #{records.inspect}"
21
+
22
+ records = client.batch.get(keys(namespace, set, 1, 10, "key5", "key26"), bins)
23
+ logger.info "fetched records with specified bins: #{records.inspect}"
24
24
  end
25
25
  end
26
26
 
@@ -1,4 +1,4 @@
1
- require './common/common'
1
+ require_relative './common/common'
2
2
 
3
3
  def main
4
4
  Common::Common.run_example do |client, namespace, set, logger|
@@ -28,4 +28,4 @@ def main
28
28
  end
29
29
  end
30
30
 
31
- main
31
+ main
@@ -0,0 +1,21 @@
1
+ require_relative './common/common'
2
+
3
+ def main
4
+ Common::Common.run_example do |client, namespace, set, logger|
5
+ keys = []
6
+ keys << AerospikeNative::Key.new(namespace, set, 1)
7
+ keys << AerospikeNative::Key.new(namespace, set, "hello")
8
+ keys << AerospikeNative::Key.new(namespace, set, 2.5)
9
+
10
+ keys.each do |key|
11
+ next if client.exists?(key)
12
+
13
+ client.put(key, {'testbin' => 1, 'testbin2' => 2.5, 'testbin3' => "string", 'testbin4' => [1, 2, 3]})
14
+ logger.info "GET #{key.inspect} - #{client.get(key).inspect}"
15
+ client.remove key
16
+ end
17
+ end
18
+ end
19
+
20
+ main
21
+
@@ -1,4 +1,4 @@
1
- require './common/common'
1
+ require_relative './common/common'
2
2
 
3
3
  def main
4
4
  Common::Common.run_example do |client, namespace, set, logger|
@@ -16,4 +16,4 @@ def main
16
16
  end
17
17
  end
18
18
 
19
- main
19
+ main
@@ -0,0 +1,17 @@
1
+ require_relative './common/common'
2
+
3
+ def main
4
+ Common::Common.run_example do |client, namespace, set, logger|
5
+ 20.times do |i|
6
+ client.put(AerospikeNative::Key.new(namespace, set, i), {'number' => i, 'key' => 'number', 'testbin' => i.to_s})
7
+ end
8
+
9
+ records = client.scan(namespace, set).exec
10
+ logger.info "scan records with all bins: #{records.inspect}"
11
+
12
+ records = client.scan(namespace, set).select(:number, :testbin).exec
13
+ logger.info "scan records with specified bins: #{records.inspect}"
14
+ end
15
+ end
16
+
17
+ main
@@ -6,15 +6,19 @@
6
6
  #include "policy.h"
7
7
  #include "query.h"
8
8
  #include "batch.h"
9
+ #include "scan.h"
9
10
 
10
11
  VALUE AerospikeNativeClass;
12
+ VALUE MsgPackClass;
11
13
 
12
14
  void Init_aerospike_native()
13
15
  {
16
+ MsgPackClass = rb_const_get(rb_cObject, rb_intern("MessagePack"));
14
17
  AerospikeNativeClass = rb_define_module("AerospikeNative");
15
18
  define_exception();
16
19
  define_logger();
17
20
  define_query();
21
+ define_scan();
18
22
  define_batch();
19
23
  define_native_key();
20
24
  define_record();
@@ -6,6 +6,7 @@
6
6
  #include <aerospike/aerospike_index.h>
7
7
 
8
8
  RUBY_EXTERN VALUE AerospikeNativeClass;
9
+ RUBY_EXTERN VALUE MsgPackClass;
9
10
 
10
11
  enum IndexType {
11
12
  INDEX_STRING = AS_INDEX_STRING,
@@ -15,11 +15,8 @@ VALUE batch_initialize(VALUE vSelf, VALUE vClient)
15
15
  bool batch_read_callback(const as_batch_read* results, uint32_t n, void* udata)
16
16
  {
17
17
  uint32_t i = 0;
18
- VALUE vLogger;
19
18
  char sMsg[1000];
20
19
 
21
- vLogger = rb_cv_get(ClientClass, "@@logger");
22
-
23
20
  for(i = 0; i < n; i++) {
24
21
  switch(results[i].result) {
25
22
  case AEROSPIKE_OK: {
@@ -35,11 +32,11 @@ bool batch_read_callback(const as_batch_read* results, uint32_t n, void* udata)
35
32
  }
36
33
  case AEROSPIKE_ERR_RECORD_NOT_FOUND:
37
34
  sprintf(sMsg, "Aerospike batch read record not found %d", i);
38
- rb_funcall(vLogger, rb_intern("warn"), 1, rb_str_new2(sMsg));
35
+ rb_funcall(LoggerInstance, rb_intern("warn"), 1, rb_str_new2(sMsg));
39
36
  break;
40
37
  default:
41
38
  sprintf(sMsg, "Aerospike batch read error %d", results[i].result);
42
- rb_funcall(vLogger, rb_intern("error"), 1, rb_str_new2(sMsg));
39
+ rb_funcall(LoggerInstance, rb_intern("error"), 1, rb_str_new2(sMsg));
43
40
  }
44
41
  }
45
42
 
@@ -82,7 +79,7 @@ VALUE batch_get(int argc, VALUE* vArgs, VALUE vSelf)
82
79
  bins_idx = RARRAY_LEN(vBins);
83
80
 
84
81
  if (TYPE(vArgs[2]) != T_NIL) {
85
- SET_POLICY(policy, vArgs[2]);
82
+ SET_BATCH_POLICY(policy, vArgs[2]);
86
83
  }
87
84
  } else {
88
85
  switch(TYPE(vArgs[1])) {
@@ -173,7 +170,7 @@ VALUE batch_exists(int argc, VALUE* vArgs, VALUE vSelf)
173
170
 
174
171
  as_policy_batch_init(&policy);
175
172
  if (argc == 2 && TYPE(vArgs[1]) != T_NIL) {
176
- SET_POLICY(policy, vArgs[1]);
173
+ SET_BATCH_POLICY(policy, vArgs[1]);
177
174
  }
178
175
 
179
176
  idx = RARRAY_LEN(vKeys);
@@ -4,6 +4,7 @@
4
4
  #include "record.h"
5
5
  #include "query.h"
6
6
  #include "batch.h"
7
+ #include "scan.h"
7
8
  #include <aerospike/as_key.h>
8
9
  #include <aerospike/as_operations.h>
9
10
  #include <aerospike/aerospike_key.h>
@@ -11,12 +12,13 @@
11
12
  #include <aerospike/aerospike_query.h>
12
13
 
13
14
  VALUE ClientClass;
15
+ VALUE LoggerInstance;
14
16
 
15
- void check_aerospike_client(VALUE vKey)
17
+ void check_aerospike_client(VALUE vClient)
16
18
  {
17
19
  char sName[] = "AerospikeNative::Client";
18
20
 
19
- if (strcmp(sName, rb_obj_classname(vKey)) != 0) {
21
+ if (strcmp(sName, rb_obj_classname(vClient)) != 0) {
20
22
  rb_raise(rb_eArgError, "Incorrect type (expected %s)", sName);
21
23
  }
22
24
  }
@@ -45,7 +47,7 @@ static VALUE client_allocate(VALUE klass)
45
47
  * new() -> AerospikeNative::Client
46
48
  * new(hosts) -> AerospikeNative::Client
47
49
  *
48
- * initialize new client, use \{'host' => ..., 'port' => ...\} for each hosts element
50
+ * initialize new client, use host' => ..., 'port' => ... for each hosts element
49
51
  */
50
52
  VALUE client_initialize(int argc, VALUE* argv, VALUE self)
51
53
  {
@@ -641,20 +643,22 @@ VALUE client_query(VALUE vSelf, VALUE vNamespace, VALUE vSet)
641
643
 
642
644
  VALUE client_set_logger(VALUE vSelf, VALUE vNewLogger)
643
645
  {
644
- VALUE vLogger = rb_cv_get(vSelf, "@@logger");
645
- rb_iv_set(vLogger, "@internal", vNewLogger);
646
-
647
- return vLogger;
646
+ rb_iv_set(LoggerInstance, "@internal", vNewLogger);
647
+ return LoggerInstance;
648
648
  }
649
649
 
650
650
  VALUE client_set_log_level(VALUE vSelf, VALUE vLevel)
651
651
  {
652
- VALUE vLogger = rb_cv_get(vSelf, "@@logger");
653
652
  Check_Type(vLevel, T_SYMBOL);
654
-
655
- return rb_funcall(vLogger, rb_intern("set_level"), 1, vLevel);
653
+ return rb_funcall(LoggerInstance, rb_intern("set_level"), 1, vLevel);
656
654
  }
657
655
 
656
+ /*
657
+ * call-seq:
658
+ * batch -> AerospikeNative::Batch
659
+ *
660
+ * Instantiate new batch
661
+ */
658
662
  VALUE client_batch(VALUE vSelf)
659
663
  {
660
664
  VALUE vParams[1];
@@ -663,6 +667,47 @@ VALUE client_batch(VALUE vSelf)
663
667
  return rb_class_new_instance(1, vParams, BatchClass);
664
668
  }
665
669
 
670
+ /*
671
+ * call-seq:
672
+ * scan(namespace, set) -> AerospikeNative::Scan
673
+ *
674
+ * Instantiate new scan
675
+ */
676
+ VALUE client_scan(VALUE vSelf, VALUE vNamespace, VALUE vSet)
677
+ {
678
+ VALUE vParams[3];
679
+
680
+ vParams[0] = vSelf;
681
+ vParams[1] = vNamespace;
682
+ vParams[2] = vSet;
683
+
684
+ return rb_class_new_instance(3, vParams, ScanClass);
685
+ }
686
+
687
+ /*
688
+ * call-seq:
689
+ * scan_info(scan_id) -> Hash
690
+ * scan_info(scan_id, scan_policy) -> Hash
691
+ *
692
+ * return scan info
693
+ */
694
+ VALUE client_scan_info(int argc, VALUE* vArgs, VALUE vSelf)
695
+ {
696
+ VALUE vParams[3];
697
+ if (argc > 1) { // there should only be 1 or 2 argument
698
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1..2)", argc);
699
+ }
700
+
701
+ vParams[0] = vSelf;
702
+ vParams[1] = vArgs[0];
703
+ vParams[2] = Qnil;
704
+ if (argc == 2) {
705
+ vParams[2] = vArgs[1];
706
+ }
707
+
708
+ return rb_funcall2(ScanClass, rb_intern("info"), 3, vParams);
709
+ }
710
+
666
711
  void define_client()
667
712
  {
668
713
  ClientClass = rb_define_class_under(AerospikeNativeClass, "Client", rb_cObject);
@@ -678,8 +723,11 @@ void define_client()
678
723
  rb_define_method(ClientClass, "drop_index", client_drop_index, -1);
679
724
  rb_define_method(ClientClass, "query", client_query, 2);
680
725
  rb_define_method(ClientClass, "batch", client_batch, 0);
726
+ rb_define_method(ClientClass, "scan", client_scan, 2);
727
+ rb_define_method(ClientClass, "scan_info", client_scan_info, -1);
681
728
 
682
- rb_cv_set(ClientClass, "@@logger", rb_class_new_instance(0, NULL, LoggerClass));
729
+ LoggerInstance = rb_class_new_instance(0, NULL, LoggerClass);
730
+ rb_cv_set(ClientClass, "@@logger", LoggerInstance);
683
731
  rb_define_singleton_method(ClientClass, "set_logger", client_set_logger, 1);
684
732
  rb_define_singleton_method(ClientClass, "set_log_level", client_set_log_level, 1);
685
733
  }
@@ -4,7 +4,8 @@
4
4
  #include "aerospike_native.h"
5
5
 
6
6
  RUBY_EXTERN VALUE ClientClass;
7
+ RUBY_EXTERN VALUE LoggerInstance;
7
8
  void define_client();
8
- void check_aerospike_client(VALUE vKey);
9
+ void check_aerospike_client(VALUE vClient);
9
10
 
10
11
  #endif // CLIENT_H
@@ -180,5 +180,29 @@ VALUE rb_hash_keys(VALUE hash);
180
180
  policy.check_bounds = RTEST(vCheckBounds); \
181
181
  }
182
182
 
183
+ #define SET_SCAN_POLICY(policy, vSettings) \
184
+ VALUE vFailOnClusterChange; \
185
+ SET_POLICY(policy, vSettings); \
186
+ vFailOnClusterChange = rb_hash_aref(vSettings, rb_str_new2("fail_on_cluster_change")); \
187
+ if (TYPE(vFailOnClusterChange) != T_NIL) { \
188
+ policy.fail_on_cluster_change = RTEST(vFailOnClusterChange); \
189
+ }
190
+
191
+ #define SET_BATCH_POLICY(policy, vSettings) \
192
+ VALUE vConcurrent, vAllowInline, vUseBatchDirect; \
193
+ SET_POLICY(policy, vSettings); \
194
+ vConcurrent = rb_hash_aref(vSettings, rb_str_new2("concurrent")); \
195
+ if (TYPE(vConcurrent) != T_NIL) { \
196
+ policy.concurrent = RTEST(vConcurrent); \
197
+ } \
198
+ vUseBatchDirect = rb_hash_aref(vSettings, rb_str_new2("use_batch_direct"));\
199
+ if (TYPE(vUseBatchDirect) != T_NIL) { \
200
+ policy.use_batch_direct = RTEST(vUseBatchDirect); \
201
+ } \
202
+ vAllowInline = rb_hash_aref(vSettings, rb_str_new2("allow_inline")); \
203
+ if (TYPE(vAllowInline) != T_NIL) { \
204
+ policy.allow_inline = RTEST(vAllowInline); \
205
+ }
206
+
183
207
  #endif // COMMON_H
184
208
 
@@ -50,7 +50,7 @@ VALUE key_initialize(int argc, VALUE* vArgs, VALUE vSelf)
50
50
 
51
51
  Data_Get_Struct(vSelf, as_key, ptr);
52
52
 
53
- if(TYPE(vValue) == T_STRING || TYPE(vValue) == T_FIXNUM) {
53
+ if(TYPE(vValue) != T_NIL) {
54
54
  switch(TYPE(vValue)) {
55
55
  case T_FIXNUM:
56
56
  as_key_init_int64(ptr, StringValueCStr( vNamespace ), StringValueCStr( vSet ), FIX2LONG( vValue ));
@@ -58,8 +58,10 @@ VALUE key_initialize(int argc, VALUE* vArgs, VALUE vSelf)
58
58
  case T_STRING:
59
59
  as_key_init_str(ptr, StringValueCStr( vNamespace ), StringValueCStr( vSet ), StringValueCStr( vValue ));
60
60
  break;
61
- default:
62
- rb_raise(rb_eArgError, "Expected FIXNUM or STRING as value");
61
+ default: {
62
+ VALUE vBytes = rb_funcall(vValue, rb_intern("to_msgpack"), 0);
63
+ as_key_init_raw(ptr, StringValueCStr( vNamespace ), StringValueCStr( vSet ), StringValuePtr(vBytes), RSTRING_LEN(vBytes));
64
+ }
63
65
  }
64
66
  } else {
65
67
  Check_Type(vValue, T_NIL);
@@ -8,15 +8,14 @@ bool aerospike_log_callback(as_log_level level, const char *func, const char *fi
8
8
  {
9
9
  char msg[1024] = {0};
10
10
  va_list ap;
11
- VALUE vLogger = rb_cv_get(ClientClass, "@@logger");
12
11
 
13
12
  va_start(ap, fmt);
14
13
  vsnprintf(msg, 1024, fmt, ap);
15
14
  msg[1023] = '\0';
16
15
  va_end(ap);
17
16
 
18
- if(TYPE(vLogger) != T_NIL) {
19
- rb_funcall(vLogger, rb_intern("write"), 2, INT2FIX(level), rb_str_new2(msg));
17
+ if(TYPE(LoggerInstance) != T_NIL) {
18
+ rb_funcall(LoggerInstance, rb_intern("write"), 2, INT2FIX(level), rb_str_new2(msg));
20
19
  }
21
20
 
22
21
  return true;
@@ -18,6 +18,13 @@ VALUE query_initialize(VALUE vSelf, VALUE vClient, VALUE vNamespace, VALUE vSet)
18
18
  return vSelf;
19
19
  }
20
20
 
21
+ /*
22
+ * call-seq:
23
+ * select(bins) -> AerospikeNative::Query
24
+ * select(bin1, bin2, bin3, ...) -> AerospikeNative::Query
25
+ *
26
+ * set specified bins
27
+ */
21
28
  VALUE query_select(int argc, VALUE* vArgs, VALUE vSelf)
22
29
  {
23
30
  VALUE vBins;
@@ -5,6 +5,7 @@
5
5
 
6
6
  RUBY_EXTERN VALUE QueryClass;
7
7
  void define_query();
8
+ bool query_callback(const as_val *value, void *udata);
8
9
 
9
10
  #endif // QUERY_H
10
11
 
@@ -28,8 +28,6 @@ VALUE record_initialize(VALUE vSelf, VALUE vKey, VALUE vBins, VALUE vGen, VALUE
28
28
  VALUE rb_record_from_c(as_record* record, as_key* key)
29
29
  {
30
30
  VALUE vKeyParams[5], vParams[4];
31
- VALUE vLogger;
32
- VALUE vMsgPackClass;
33
31
  as_key current_key;
34
32
  as_bin bin;
35
33
  int n;
@@ -55,6 +53,11 @@ VALUE rb_record_from_c(as_record* record, as_key* key)
55
53
  vKeyParams[2] = rb_str_new2(as_string_get(current_key.valuep));
56
54
  }
57
55
  break;
56
+ case AS_BYTES: {
57
+ VALUE vString = rb_str_new(as_bytes_get(current_key.valuep), as_bytes_size(current_key.valuep));
58
+ vKeyParams[2] = rb_funcall(MsgPackClass, rb_intern("unpack"), 1, vString);
59
+ break;
60
+ }
58
61
  }
59
62
  }
60
63
  vKeyParams[3] = rb_str_new(current_key.digest.value, AS_DIGEST_VALUE_SIZE);
@@ -64,7 +67,7 @@ VALUE rb_record_from_c(as_record* record, as_key* key)
64
67
  vParams[2] = UINT2NUM(record->gen);
65
68
  vParams[3] = UINT2NUM(record->ttl);
66
69
 
67
- vMsgPackClass = rb_const_get(rb_cObject, rb_intern("MessagePack"));
70
+ MsgPackClass = rb_const_get(rb_cObject, rb_intern("MessagePack"));
68
71
  for(n = 0; n < record->bins.size; n++) {
69
72
  bin = record->bins.entries[n];
70
73
  switch( as_val_type(bin.valuep) ) {
@@ -78,16 +81,14 @@ VALUE rb_record_from_c(as_record* record, as_key* key)
78
81
  rb_hash_aset(vParams[1], rb_str_new2(bin.name), rb_str_new2(as_string_get(bin.valuep)));
79
82
  break;
80
83
  case AS_BYTES: {
81
- // as_bytes_get();
82
- VALUE vString = rb_str_new(bin.valuep->bytes.value, bin.valuep->bytes.size);
83
- rb_hash_aset(vParams[1], rb_str_new2(bin.name), rb_funcall(vMsgPackClass, rb_intern("unpack"), 1, vString));
84
+ VALUE vString = rb_str_new(as_bytes_get(bin.valuep), as_bytes_size(bin.valuep));
85
+ rb_hash_aset(vParams[1], rb_str_new2(bin.name), rb_funcall(MsgPackClass, rb_intern("unpack"), 1, vString));
84
86
  break;
85
87
  }
86
88
  case AS_UNDEF:
87
89
  default:
88
- vLogger = rb_cv_get(ClientClass, "@@logger");
89
90
  sprintf(msg, "unhandled val type: %d\n", as_val_type(bin.valuep));
90
- rb_funcall(vLogger, rb_intern("warn"), 1, rb_str_new2(msg));
91
+ rb_funcall(LoggerInstance, rb_intern("warn"), 1, rb_str_new2(msg));
91
92
  break;
92
93
  }
93
94
  }
@@ -0,0 +1,271 @@
1
+ #include "scan.h"
2
+ #include "query.h"
3
+ #include "client.h"
4
+ #include <aerospike/aerospike_scan.h>
5
+
6
+ VALUE ScanClass;
7
+
8
+ static void scan_deallocate(void *p)
9
+ {
10
+ as_scan* ptr = p;
11
+ as_scan_destroy(ptr);
12
+ }
13
+
14
+ VALUE scan_initialize(VALUE vSelf, VALUE vClient, VALUE vNamespace, VALUE vSet)
15
+ {
16
+ Check_Type(vNamespace, T_STRING);
17
+ Check_Type(vSet, T_STRING);
18
+ check_aerospike_client(vClient);
19
+
20
+ rb_iv_set(vSelf, "@client", vClient);
21
+ rb_iv_set(vSelf, "@namespace", vNamespace);
22
+ rb_iv_set(vSelf, "@set", vSet);
23
+
24
+ return vSelf;
25
+ }
26
+
27
+ /*
28
+ * call-seq:
29
+ * select(bins) -> AerospikeNative::Scan
30
+ * select(bin1, bin2, bin3, ...) -> AerospikeNative::Scan
31
+ *
32
+ * set specified bins
33
+ */
34
+ VALUE scan_select(int argc, VALUE* vArgs, VALUE vSelf)
35
+ {
36
+ VALUE vBins;
37
+ int i;
38
+
39
+ if (argc == 0) { // there should be greater than 0
40
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1..n)", argc);
41
+ }
42
+
43
+ vBins = rb_iv_get(vSelf, "@select_bins");
44
+ if(TYPE(vBins) == T_NIL) {
45
+ vBins = rb_ary_new();
46
+ }
47
+ if (argc == 1) {
48
+ int idx;
49
+ VALUE vArray = vArgs[0];
50
+ Check_Type(vArray, T_ARRAY);
51
+ idx = RARRAY_LEN(vArray);
52
+ for(i = 0; i < idx; i++) {
53
+ VALUE vString = rb_ary_entry(vArray, i);
54
+ GET_STRING(vString);
55
+ rb_ary_push(vBins, vString);
56
+ }
57
+ } else {
58
+ for(i = 0; i < argc; i++) {
59
+ VALUE vString = vArgs[i];
60
+ GET_STRING(vString);
61
+ rb_ary_push(vBins, vString);
62
+ }
63
+ }
64
+
65
+ rb_iv_set(vSelf, "@select_bins", vBins);
66
+ return vSelf;
67
+ }
68
+
69
+ VALUE scan_concurrent(VALUE vSelf, VALUE vValue)
70
+ {
71
+ rb_iv_set(vSelf, "@concurrent", vValue);
72
+ return vSelf;
73
+ }
74
+
75
+ VALUE scan_percent(VALUE vSelf, VALUE vValue)
76
+ {
77
+ rb_iv_set(vSelf, "@percent", vValue);
78
+ return vSelf;
79
+ }
80
+
81
+ VALUE scan_priority(VALUE vSelf, VALUE vValue)
82
+ {
83
+ rb_iv_set(vSelf, "@priority", vValue);
84
+ return vSelf;
85
+ }
86
+
87
+ VALUE scan_no_bins(VALUE vSelf, VALUE vValue)
88
+ {
89
+ rb_iv_set(vSelf, "@no_bins", vValue);
90
+ return vSelf;
91
+ }
92
+
93
+ VALUE scan_background(VALUE vSelf, VALUE vValue)
94
+ {
95
+ rb_iv_set(vSelf, "@background", vValue);
96
+ return vSelf;
97
+ }
98
+
99
+ /*
100
+ * call-seq:
101
+ * exec -> records
102
+ * exec(scan_policy) -> records
103
+ * exec { |record| ... } -> Nil
104
+ * exec(scan_policy) { |record| ... } -> Nil
105
+ *
106
+ * perform scan
107
+ */
108
+ VALUE scan_exec(int argc, VALUE* vArgs, VALUE vSelf)
109
+ {
110
+ VALUE vClient, vNamespace, vSet;
111
+ VALUE vArray;
112
+ VALUE vConcurrent, vPercent, vPriority, vBins, vNoBins, vBackground;
113
+ as_scan scan;
114
+ as_policy_scan policy;
115
+ as_error err;
116
+ aerospike* ptr;
117
+
118
+ int n, idx = 0;
119
+ bool is_background = false;
120
+
121
+ if (argc > 1) { // there should only be 0 or 1 argument
122
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..1)", argc);
123
+ }
124
+
125
+ as_policy_scan_init(&policy);
126
+ if(argc == 1) {
127
+ SET_SCAN_POLICY(policy, vArgs[0]);
128
+ }
129
+
130
+ vClient = rb_iv_get(vSelf, "@client");
131
+ vNamespace = rb_iv_get(vSelf, "@namespace");
132
+ vSet = rb_iv_get(vSelf, "@set");
133
+ vConcurrent = rb_iv_get(vSelf, "@concurrent");
134
+ vPercent = rb_iv_get(vSelf, "@percent");
135
+ vPriority = rb_iv_get(vSelf, "@priority");
136
+ vNoBins = rb_iv_get(vSelf, "@no_bins");
137
+ vBins = rb_iv_get(vSelf, "@select_bins");
138
+ vBackground = rb_iv_get(vSelf, "@background");
139
+ as_scan_init(&scan, StringValueCStr(vNamespace), StringValueCStr(vSet));
140
+
141
+ if (TYPE(vPercent) == T_FIXNUM) {
142
+ as_scan_set_percent(&scan, FIX2INT(vPercent));
143
+ }
144
+
145
+ if (TYPE(vPriority) == T_FIXNUM) {
146
+ as_scan_set_priority(&scan, FIX2INT(vPriority));
147
+ }
148
+
149
+ if (TYPE(vConcurrent) != T_NIL) {
150
+ as_scan_set_priority(&scan, RTEST(vConcurrent));
151
+ }
152
+
153
+ if (TYPE(vNoBins) != T_NIL) {
154
+ as_scan_set_nobins(&scan, RTEST(vNoBins));
155
+ }
156
+
157
+ if (TYPE(vBackground) != T_NIL) {
158
+ is_background = RTEST(vBackground);
159
+ }
160
+
161
+ if (TYPE(vBins) == T_ARRAY && (idx = RARRAY_LEN(vBins)) > 0) {
162
+ as_scan_select_inita(&scan, idx);
163
+ for(n = 0; n < idx; n++) {
164
+ VALUE vEntry = rb_ary_entry(vBins, n);
165
+ as_scan_select(&scan, StringValueCStr(vEntry));
166
+ }
167
+ }
168
+
169
+ Data_Get_Struct(vClient, aerospike, ptr);
170
+
171
+ vArray = rb_ary_new();
172
+ if(is_background) {
173
+ uint64_t scan_id = 0;
174
+ if (aerospike_scan_background(ptr, &err, &policy, &scan, &scan_id) != AEROSPIKE_OK) {
175
+ as_scan_destroy(&scan);
176
+ raise_aerospike_exception(err.code, err.message);
177
+ }
178
+ as_scan_destroy(&scan);
179
+ return ULONG2NUM(scan_id);
180
+ }
181
+
182
+ if (aerospike_scan_foreach(ptr, &err, &policy, &scan, query_callback, &vArray) != AEROSPIKE_OK) {
183
+ as_scan_destroy(&scan);
184
+ raise_aerospike_exception(err.code, err.message);
185
+ }
186
+
187
+ as_scan_destroy(&scan);
188
+ if ( rb_block_given_p() ) {
189
+ return Qnil;
190
+ }
191
+
192
+ return vArray;
193
+ }
194
+
195
+
196
+ /*
197
+ * call-seq:
198
+ * info(client, scan_id) -> Hash
199
+ * info(client, scan_id, scan_policy) -> Hash
200
+ *
201
+ * return scan info
202
+ */
203
+ VALUE scan_info(int argc, VALUE* vArgs, VALUE vSelf)
204
+ {
205
+ VALUE vClient, vHash;
206
+ as_scan_info info;
207
+ as_policy_scan policy;
208
+ as_error err;
209
+ aerospike* ptr;
210
+ uint64_t scan_id;
211
+
212
+ if (argc > 3 || argc < 2) { // there should only be 2 or 3 arguments
213
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 2..3)", argc);
214
+ }
215
+
216
+ vClient = vArgs[0];
217
+ check_aerospike_client(vClient);
218
+
219
+ Check_Type(vArgs[1], T_FIXNUM);
220
+ scan_id = FIX2ULONG(vArgs[1]);
221
+
222
+ as_policy_scan_init(&policy);
223
+ if(argc == 3 && TYPE(vArgs[2]) != T_NIL) {
224
+ SET_SCAN_POLICY(policy, vArgs[2]);
225
+ }
226
+
227
+ Data_Get_Struct(vClient, aerospike, ptr);
228
+
229
+ if (aerospike_scan_info(ptr, &err, &policy, scan_id, &info) != AEROSPIKE_OK) {
230
+ raise_aerospike_exception(err.code, err.message);
231
+ }
232
+
233
+ vHash = rb_hash_new();
234
+ rb_hash_aset(vHash, rb_str_new2("progress_percent"), ULONG2NUM(info.progress_pct));
235
+ rb_hash_aset(vHash, rb_str_new2("records_scanned"), ULONG2NUM(info.records_scanned));
236
+ rb_hash_aset(vHash, rb_str_new2("status"), INT2NUM(info.status));
237
+
238
+ return vHash;
239
+ }
240
+
241
+ void define_scan()
242
+ {
243
+ ScanClass = rb_define_class_under(AerospikeNativeClass, "Scan", rb_cObject);
244
+ rb_define_method(ScanClass, "initialize", scan_initialize, 3);
245
+ rb_define_method(ScanClass, "exec", scan_exec, -1);
246
+ rb_define_method(ScanClass, "select", scan_select, -1);
247
+ rb_define_method(ScanClass, "set_concurrent", scan_concurrent, 1);
248
+ rb_define_method(ScanClass, "set_percent", scan_percent, 1);
249
+ rb_define_method(ScanClass, "set_priority", scan_priority, 1);
250
+ rb_define_method(ScanClass, "set_no_bins", scan_no_bins, 1);
251
+ // rb_define_method(ScanClass, "set_background", scan_background, 1);
252
+ rb_define_singleton_method(ScanClass, "info", scan_info, -1);
253
+
254
+ rb_define_attr(ScanClass, "client", 1, 0);
255
+ rb_define_attr(ScanClass, "select_bins", 1, 0);
256
+ rb_define_attr(ScanClass, "concurrent", 1, 0);
257
+ rb_define_attr(ScanClass, "percent", 1, 0);
258
+ rb_define_attr(ScanClass, "priority", 1, 0);
259
+ rb_define_attr(ScanClass, "no_bins", 1, 0);
260
+ rb_define_attr(ScanClass, "background", 1, 0);
261
+
262
+ rb_define_const(ScanClass, "STATUS_UNDEFINED", INT2FIX(AS_SCAN_STATUS_UNDEF));
263
+ rb_define_const(ScanClass, "STATUS_INPROGRESS", INT2FIX(AS_SCAN_STATUS_INPROGRESS));
264
+ rb_define_const(ScanClass, "STATUS_ABORTED", INT2FIX(AS_SCAN_STATUS_ABORTED));
265
+ rb_define_const(ScanClass, "STATUS_COMPLETED", INT2FIX(AS_SCAN_STATUS_COMPLETED));
266
+
267
+ rb_define_const(ScanClass, "PRIORITY_AUTO", INT2FIX(AS_SCAN_PRIORITY_AUTO));
268
+ rb_define_const(ScanClass, "PRIORITY_HIGH", INT2FIX(AS_SCAN_PRIORITY_HIGH));
269
+ rb_define_const(ScanClass, "PRIORITY_MEDIUM", INT2FIX(AS_SCAN_PRIORITY_MEDIUM));
270
+ rb_define_const(ScanClass, "PRIORITY_LOW", INT2FIX(AS_SCAN_PRIORITY_LOW));
271
+ }
@@ -0,0 +1,10 @@
1
+ #ifndef SCAN_H
2
+ #define SCAN_H
3
+
4
+ #include "aerospike_native.h"
5
+
6
+ RUBY_EXTERN VALUE ScanClass;
7
+ void define_scan();
8
+
9
+ #endif // SCAN_H
10
+
@@ -1,3 +1,3 @@
1
1
  module AerospikeNative
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aerospike_native
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Ziablitskii
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-23 00:00:00.000000000 Z
11
+ date: 2015-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -98,7 +98,9 @@ files:
98
98
  - examples/batch.rb
99
99
  - examples/common/common.rb
100
100
  - examples/operate.rb
101
+ - examples/put_get_remove.rb
101
102
  - examples/query_and_index.rb
103
+ - examples/scan.rb
102
104
  - ext/aerospike_native/aerospike_native.c
103
105
  - ext/aerospike_native/aerospike_native.h
104
106
  - ext/aerospike_native/batch.c
@@ -124,6 +126,8 @@ files:
124
126
  - ext/aerospike_native/query.h
125
127
  - ext/aerospike_native/record.c
126
128
  - ext/aerospike_native/record.h
129
+ - ext/aerospike_native/scan.c
130
+ - ext/aerospike_native/scan.h
127
131
  - lib/aerospike_native.rb
128
132
  - lib/aerospike_native/version.rb
129
133
  homepage: https://github.com/rainlabs/aerospike_native