Skip to content

Commit a8be8aa

Browse files
committed
Merge pull request #113 from basho/bk-yokozuna
Riak 2 Feature: Yokozuna
2 parents 7cdd73d + d128421 commit a8be8aa

File tree

14 files changed

+1047
-377
lines changed

14 files changed

+1047
-377
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ Gemfile.lock
3838
vendor/erlang
3939
vendor/riak
4040
.ruby-version
41+
tmp

Rakefile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,38 @@ RSpec::Core::RakeTask.new(:ci) do |spec|
7070
spec.rspec_opts = %w[--profile]
7171
end
7272
task :default => :ci
73+
74+
75+
desc "Generate Protocol Buffers message definitions from riak_pb"
76+
task :pb_defs => 'beefcake:pb_defs'
77+
78+
namespace :beefcake do
79+
task :pb_defs => 'lib/riak/client/beefcake/messages.rb'
80+
81+
task :clean do
82+
sh "rm -rf tmp/riak_pb"
83+
sh "rm -rf tmp/riak_kv.pb.rb tmp/riak_search.pb.rb tmp/riak_yokozuna.pb.rb"
84+
end
85+
86+
file 'lib/riak/client/beefcake/messages.rb' => %w{tmp/riak_kv.pb.rb tmp/riak_search.pb.rb tmp/riak_yokozuna.pb.rb} do |t|
87+
sh "cat lib/riak/client/beefcake/header tmp/riak.pb.rb #{t.prerequisites.join ' '} lib/riak/client/beefcake/footer > #{t.name}"
88+
end
89+
90+
file 'tmp/riak_kv.pb.rb' => 'tmp/riak_pb' do |t|
91+
sh "protoc --beefcake_out tmp -I tmp/riak_pb/src tmp/riak_pb/src/riak_kv.proto"
92+
end
93+
94+
file 'tmp/riak_search.pb.rb' => 'tmp/riak_pb' do |t|
95+
sh "protoc --beefcake_out tmp -I tmp/riak_pb/src tmp/riak_pb/src/riak_search.proto"
96+
end
97+
98+
file 'tmp/riak_yokozuna.pb.rb' => 'tmp/riak_pb' do |t|
99+
sh "protoc --beefcake_out tmp -I tmp/riak_pb/src tmp/riak_pb/src/riak_yokozuna.proto"
100+
end
101+
102+
directory 'tmp/riak_pb' do
103+
cd 'tmp' do
104+
sh "git clone -b develop https://github.com/basho/riak_pb.git"
105+
end
106+
end
107+
end

lib/riak/client.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
require 'riak/client/decaying'
99
require 'riak/client/node'
1010
require 'riak/client/search'
11+
require 'riak/client/yokozuna'
1112
require 'riak/client/http_backend'
1213
require 'riak/client/net_http_backend'
1314
require 'riak/client/excon_backend'

lib/riak/client/beefcake/footer

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
end
3+
end
4+
end

lib/riak/client/beefcake/header

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require 'beefcake'
2+
3+
module Riak
4+
class Client
5+
# @private
6+
class BeefcakeProtobuffsBackend

lib/riak/client/beefcake/message_codes.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ module BeefcakeMessageCodes
3939
:CounterUpdateResp => 51,
4040
:CounterGetReq => 52,
4141
:CounterGetResp => 53,
42+
:YokozunaIndexGetReq => 54,
43+
:YokozunaIndexGetResp => 55,
44+
:YokozunaIndexPutReq => 56,
45+
:YokozunaIndexDeleteReq => 57,
46+
:YokozunaSchemaGetReq => 58,
47+
:YokozunaSchemaGetResp => 59,
48+
:YokozunaSchemaPutReq => 60,
4249
}
4350

4451
CODE_TO_MESSAGE = MESSAGE_TO_CODE.invert
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
module Riak
2+
class Client
3+
# @private
4+
class BeefcakeProtobuffsBackend
5+
class RpbIndexReq
6+
module IndexQueryType
7+
EQ = 0
8+
RANGE = 1
9+
end
10+
end
11+
12+
class RpbBucketProps
13+
14+
# "repeated" elements with zero items are indistinguishable
15+
# from a nil, so we have to manage has_precommit/has_postcommit
16+
# flags.
17+
def precommit=(newval)
18+
@precommit = newval
19+
@has_precommit = !!newval
20+
end
21+
22+
def has_precommit=(newval)
23+
@has_precommit = newval
24+
@precommit ||= [] if newval
25+
end
26+
27+
def postcommit=(newval)
28+
@postcommit = newval
29+
@has_postcommit = !!newval
30+
end
31+
32+
def has_postcommit=(newval)
33+
@has_postcommit = newval
34+
@postcommit ||= [] if newval
35+
end
36+
end
37+
38+
class RpbSearchDoc
39+
# rebuild the fields instance method since the
40+
# generated :fields field overwrote this
41+
def fields
42+
self.class.fields
43+
end
44+
repeated :properties, RpbPair, 1
45+
end
46+
47+
end
48+
end
49+
end

0 commit comments

Comments
 (0)