Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set consistency to N1P_CONSISTENCY_REQUEST #20

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ Gemfile-custom
*.gem

*.dll

vendor/*
2 changes: 1 addition & 1 deletion lib/libcouchbase/bucket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ def subdoc(key, quiet: @quiet, **opts)
end

def subdoc_execute!(sd, extended: false, async: false, **opts)
promise = @connection.subdoc(sd, opts).then { |resp|
promise = @connection.subdoc(sd, **opts).then { |resp|
raise resp.value if resp.value.is_a?(::Exception)
extended ? resp : resp.value
}
Expand Down
18 changes: 14 additions & 4 deletions lib/libcouchbase/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,6 @@ def parse_document(raw_string)
val
end


private


Expand Down Expand Up @@ -752,7 +751,7 @@ def subdoc_common(resp, req, cb)
end

# Return the single result instead of an array if single
is_single = resp[:rflags] & Ext::RESPFLAGS[:resp_f_sdsingle] > 0
is_single = (resp[:rflags] & Ext::RESPFLAGS[:resp_f_sdsingle]) > 0
if is_single
values = values.first
elsif values.empty? # multiple mutate arrays should return true (same as a single mutate)
Expand Down Expand Up @@ -855,7 +854,7 @@ def query_callback_common(row_data)
view = @requests[row_data[:cookie].address]

if row_data[:rc] == :success
value = JSON.parse(row_data[:row].read_string(row_data[:nrow]), DECODE_OPTIONS)
value = JSON.parse(row_text(row_data), DECODE_OPTIONS)

if (row_data[:rflags] & Ext::RESPFLAGS[:resp_f_final]) > 0
# We can assume this is JSON
Expand All @@ -867,13 +866,24 @@ def query_callback_common(row_data)
error_klass = Error.lookup(row_data[:rc])
if error_klass == Error::HttpError
http_resp = row_data[:htresp]
view.error error_klass.new(body_text(http_resp))
body_text = body_text(http_resp)
body_text = row_text(row_data) if body_text.empty?
view.error error_klass.new(body_text)
else
view.error error_klass.new
end
end
end

# Extracts the row content of a response
def row_text(row_data)
if row_data[:nrow] > 0
row_data[:row].read_string(row_data[:nrow])
else
''
end
end

# Extracts the body content of a HTTP response
def body_text(http_resp)
if http_resp[:nbody] > 0
Expand Down
4 changes: 3 additions & 1 deletion lib/libcouchbase/n1ql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class N1QL
:build_index, :create_index, :drop_index, :create_primary_index,
:drop_primary_index, :grant, :on, :to, :infer, :select, :insert_into,
:delete_from, :update, :from, :with, :use_keys, :unnest, :join, :where,
:group_by, :order_by, :limit, :offset, :upsert_into, :merge_into
:group_by, :order_by, :limit, :offset, :upsert_into, :merge_into, :query
]

def initialize(bucket, explain: false, **options)
Expand Down Expand Up @@ -45,6 +45,8 @@ def explain(val = nil)
def to_s
res = String.new
res << "EXPLAIN\n" if @explain
return (res << @query) if @query

Ordering.each do |statement|
val = public_send statement
unless val.nil?
Expand Down
30 changes: 16 additions & 14 deletions lib/libcouchbase/query_n1ql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Libcouchbase
class QueryN1QL
N1P_QUERY_STATEMENT = 1

N1P_CONSISTENCY_REQUEST = 2

def initialize(connection, reactor, n1ql, **opts)
@connection = connection
Expand All @@ -13,10 +13,8 @@ def initialize(connection, reactor, n1ql, **opts)
@request_handle = FFI::MemoryPointer.new :pointer, 1
end


attr_reader :connection, :n1ql


def get_count(metadata)
metadata[:metrics][:resultCount]
end
Expand Down Expand Up @@ -46,27 +44,31 @@ def perform(limit: nil, **options, &blk)

@cmd = Ext::CMDN1QL.new
@params = Ext.n1p_new
err = Ext.n1p_setquery(@params, @query_text, @query_text.bytesize, N1P_QUERY_STATEMENT)
err = Ext.n1p_setconsistency(@params, N1P_CONSISTENCY_REQUEST)
if err == :success

err = Ext.n1p_mkcmd(@params, @cmd)
err = Ext.n1p_setquery(@params, @query_text, @query_text.bytesize, N1P_QUERY_STATEMENT)
if err == :success

pointer = @cmd.to_ptr
@connection.requests[pointer.address] = self
err = Ext.n1p_mkcmd(@params, @cmd)
if err == :success
pointer = @cmd.to_ptr
@connection.requests[pointer.address] = self

@cmd[:callback] = @connection.get_callback(:n1ql_callback)
@cmd[:handle] = @request_handle
@cmd[:callback] = @connection.get_callback(:n1ql_callback)
@cmd[:handle] = @request_handle

err = Ext.n1ql_query(@connection.handle, pointer, @cmd)
if err != :success
err = Ext.n1ql_query(@connection.handle, pointer, @cmd)
if err != :success
error(Error.lookup(err).new('full text search not scheduled'))
end
else
error(Error.lookup(err).new('failed to build full text search command'))
end
else
error(Error.lookup(err).new('failed to build full text search command'))
error(Error.lookup(err).new('failed to build full text search query structure'))
end
else
error(Error.lookup(err).new('failed to build full text search query structure'))
error(Error.lookup(err).new('failed set consistency value'))
end
}
end
Expand Down
Loading