Permalink
Browse files

Refactored some common error reporting functions.

Added backbones for memcached compatibility tests (pending on
CouchbaseMock).

Make subdirectory distributions for VBucket and Config

Added error constants to reflect newer libcouchbase
  • Loading branch information...
1 parent e7d3f39 commit b4de233a425c571a9afe26b0b16bd922b26b1deb @mnunberg committed Feb 7, 2012
View
@@ -27,7 +27,22 @@ void plcb_cleanup(PLCB_t *object)
_free_cv(cv_compress); _free_cv(cv_decompress);
_free_cv(cv_serialize); _free_cv(cv_deserialize);
#undef _free_cv
+}
+
+void plcb_errstack_push(PLCB_t *object, libcouchbase_error_t err,
+ const char *errinfo)
+{
+ libcouchbase_t instance;
+ SV *errsvs[2];
+ instance = object->instance;
+ if(!errinfo) {
+ errinfo = libcouchbase_strerror(instance, err);
+ }
+ errsvs[0] = newSViv(err);
+ errsvs[1] = newSVpv(errinfo, 0);
+ av_push(object->errors,
+ newRV_noinc( (SV*)av_make(2, errsvs)));
}
/*Construct a new libcouchbase object*/
@@ -72,11 +87,8 @@ SV *PLCB_construct(const char *pkg, AV *options)
blessed_obj = newSV(0);
sv_setiv(newSVrv(blessed_obj, "Couchbase::Client"), PTR2IV(object));
- if( (object->my_flags & PLCBf_NO_CONNECT) == 0 &&
- (err = libcouchbase_connect(instance) == LIBCOUCHBASE_SUCCESS))
- {
- libcouchbase_wait(instance);
- object->connected = 1;
+ if( (object->my_flags & PLCBf_NO_CONNECT) == 0) {
+ PLCB_connect(blessed_obj);
}
return blessed_obj;
@@ -100,13 +112,24 @@ PLCB_connect(SV *self)
libcouchbase_error_t err;
AV *retav;
PLCB_t *object;
+
mk_instance_vars(self, instance, object);
+
+ av_clear(object->errors);
+
if(object->connected) {
+ warn("Already connected");
return 1;
} else {
if( (err = libcouchbase_connect(instance)) == LIBCOUCHBASE_SUCCESS) {
object->connected = 1;
+ libcouchbase_wait(instance);
+ if(av_len(object->errors) > -1) {
+ return 0;
+ }
return 1;
+ } else {
+ plcb_errstack_push(object, err, NULL);
}
}
return 0;
@@ -363,6 +386,8 @@ enum {
SETTINGS_ALIAS_COMP_THRESHOLD
};
+
+
MODULE = Couchbase::Client PACKAGE = Couchbase::Client PREFIX = PLCB_
PROTOTYPES: DISABLE
@@ -588,8 +613,11 @@ PLCB__settings(self, ...)
PREINIT:
int flag;
int new_value;
+ libcouchbase_t instance;
+ PLCB_t *object;
CODE:
+ mk_instance_vars(self, instance, object);
switch(ix) {
case SETTINGS_ALIAS_COMPRESS:
case SETTINGS_ALIAS_COMPRESS_COMPAT:
@@ -626,7 +654,9 @@ PLCB__settings(self, ...)
die("%s: I was given a bad object", GvNAME(GvCV(cv)));
}
- RETVAL = plcb_convert_settings((PLCB_t*)SvRV(self), flag, new_value);
+
+
+ RETVAL = plcb_convert_settings(object, flag, new_value);
OUTPUT:
RETVAL
@@ -671,7 +701,17 @@ PLCB_connect(self)
BOOT:
-boot_Couchbase__Client_multi(aTHX_ cv);
-
+{
+
+ /*because xsubpp is stupid, we can't use an inline macro for this*/
+
+ /*Client_multi.xs*/
+ PUSHMARK(SP);
+ mXPUSHs(newSVpv("Couchbase::Client",0));
+ mXPUSHs(newSVpv(XS_VERSION, 0));
+ PUTBACK;
+ boot_Couchbase__Client_multi(aTHX_ cv);
+ SPAGAIN;
+}
INCLUDE: Async.xs
View
@@ -1,5 +1,6 @@
Changes
MANIFEST
+MANIFEST.SKIP
Makefile.PL
README.pod
@@ -21,6 +22,8 @@ lib/Couchbase/Test/ClientSync.pm
lib/Couchbase/Test/Common.pm
lib/Couchbase/Test/Async.pm
lib/Couchbase/Test/Async/Loop.pm
+lib/Couchbase/Test/Settings.pm
+lib/Couchbase/Test/Interop.pm
Client.xs
Client_multi.xs
View
@@ -0,0 +1,3 @@
+^VBucket/
+^Config/
+^\.
View
@@ -1,3 +1,4 @@
+#!/usr/bin/perl
use strict;
use warnings;
use ExtUtils::MakeMaker;
@@ -13,18 +14,35 @@ my $library_path = $plcb_config->{COUCHBASE_LIBRARY_PATH} || "";
if($include_path) {
$include_path = "-I$include_path";
}
+
if($library_path) {
$library_path = "-L$library_path";
}
+# .c files
+my @source_modules = qw(
+ callbacks
+ convert
+ ctor
+ async
+ async_callbacks
+ async_events
+);
+
+# .xs files
+my @xs_modules = qw(
+ Client
+ Client_multi
+);
+
+my @objects = map {$_ . '.o' } (@source_modules, @xs_modules);
+
WriteMakefile(
NAME => 'Couchbase::Client',
AUTHOR => q{M. Nunberg <mnunberg@haskalah.org>},
VERSION_FROM => 'lib/Couchbase/Client.pm',
ABSTRACT_FROM => 'lib/Couchbase/Client.pm',
- OBJECT => 'callbacks.o convert.o ctor.o Client.o ' .
- 'async.o async_callbacks.o async_events.o ' .
- 'Client_multi.o',
+ OBJECT => join(" ", @objects),
($ExtUtils::MakeMaker::VERSION >= 6.3002
? ('LICENSE'=> 'perl')
@@ -59,7 +77,7 @@ WriteMakefile(
NEEDS_LINKING => 1,
OPTIMIZE => '-O0 -ggdb3 -Wdeclaration-after-statement -Werror -std=gnu89',
#CCFLAGS => '-Wdeclaration-after-statement',
- LIBS => ["$library_path -lcouchbase -lcouchbase_libevent"],
+ LIBS => ["$library_path -lcouchbase -lcouchbase_libevent -lvbucket"],
INC => $include_path,
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
clean => { FILES => 'Couchbase-Client-*' },
View
@@ -9,6 +9,6 @@
#URL from which to download the mock JAR file for tests
COUCHBASE_MOCK_JARURL =>
"http://files.couchbase.com/maven2/org/couchbase/mock/".
- "CouchbaseMock/0.5-SNAPSHOT/CouchbaseMock-0.5-20120103.162550-11.jar",
+ "CouchbaseMock/0.5-SNAPSHOT/CouchbaseMock-0.5-20120202.071818-12.jar",
};
View
@@ -95,22 +95,8 @@ void plcb_callback_error(
const char *errinfo)
{
PLCB_t *object;
- SV *elem_list[2];
- warn("Got error callback");
-
- if(err == LIBCOUCHBASE_SUCCESS) {
- return;
- }
- elem_list[0] = newSViv(err);
- if(errinfo) {
- elem_list[1] = newSVpv(errinfo, 0);
- } else {
- elem_list[1] = &PL_sv_undef;
- }
-
object = (PLCB_t*)libcouchbase_get_cookie(instance);
- av_push(object->errors,
- newRV_noinc((SV*)av_make(2, elem_list)));
+ plcb_errstack_push(object, err, errinfo);
}
#ifdef PLCB_HAVE_CONNFAIL
View
@@ -195,6 +195,7 @@ int plcb_convert_settings(PLCB_t *object, int flag, int new_value)
{
int ret;
+
if(flag == PLCBf_COMPRESS_THRESHOLD) {
/*this isn't really a flag value, but a proper integer*/
ret = object->compress_threshold;
@@ -207,7 +208,6 @@ int plcb_convert_settings(PLCB_t *object, int flag, int new_value)
ret = (object->my_flags & flag);
-
if(new_value > 0) {
object->my_flags |= flag;
} else {
View
@@ -42,7 +42,6 @@ void plcb_ctor_conversion_opts(PLCB_t *object, AV *options)
die("Expected CODE reference at IDX=%d: %s",source_idx, diemsg); \
} \
object->target_field = newRV_inc(SvRV(*tmpsv));
-
if( (tmpsv = av_fetch(options, PLCB_CTORIDX_MYFLAGS, 0))
&& SvIOK(*tmpsv)) {
View
@@ -28,6 +28,7 @@
UNKNOWN_COMMAND
UNKNOWN_HOST
PROTOCOL_ERROR
+ BUCKET_ENOENT
);
foreach my $cbase (@constant_basenames) {
constant('LIBCOUCHBASE_'.$cbase, name => 'COUCHBASE_'.$cbase);
View
@@ -21,6 +21,9 @@
CTORIDX_SERIALIZE_METHODS
+ CTORIDX_TIMEOUT
+ CTORIDX_NO_CONNECT
+
RETIDX_VALUE
RETIDX_ERRSTR
RETIDX_CAS
@@ -34,6 +37,8 @@
USE_COMPRESSION
USE_STORABLE
USE_CONVERT_UTF8
+ NO_CONNECT
+ NO_DECONVERT
);
constant("PLCBf_$_", name => "f$_") for (@ctor_flags);
@@ -90,6 +90,15 @@ sub _MkCtorIDX {
CTORIDX_BUCKET, delete $opts->{bucket});
_make_conversion_settings(\@arglist, $opts);
+
+ my $tmp = delete $opts->{io_timeout} ||
+ delete $opts->{select_timeout} ||
+ delete $opts->{connect_timeout};
+
+ $arglist[CTORIDX_TIMEOUT] = $tmp if defined $tmp;
+ $arglist[CTORIDX_NO_CONNECT] = delete $opts->{no_init_connect};
+
+
if(keys %$opts) {
warn sprintf("Unused keys (%s) in constructor",
join(", ", keys %$opts));
@@ -341,7 +350,7 @@ L<Storable::thaw|Storable/thaw>. I.e. serialization routine takes a
reference and returns a scalar string; it should not fail.
Deserialization routine takes scalar string and returns a reference;
if deserialization fails (say, wrong data format) it should throw an
-exception (call I<die>). The exception will be caught by the module
+exception (call I<die>). The exception will be caught by the module
and L</get> will then pretend that the key hasn't been found.
=back
@@ -1,7 +1,7 @@
package Couchbase::Client::Errors;
# This module was generated automatically by ExtUtils::H2PM from error_constants.pl
-push @EXPORT, 'COUCHBASE_SUCCESS', 'COUCHBASE_AUTH_CONTINUE', 'COUCHBASE_AUTH_ERROR', 'COUCHBASE_DELTA_BADVAL', 'COUCHBASE_E2BIG', 'COUCHBASE_EBUSY', 'COUCHBASE_EINTERNAL', 'COUCHBASE_EINVAL', 'COUCHBASE_ENOMEM', 'COUCHBASE_ERANGE', 'COUCHBASE_ERROR', 'COUCHBASE_ETMPFAIL', 'COUCHBASE_KEY_EEXISTS', 'COUCHBASE_KEY_ENOENT', 'COUCHBASE_LIBEVENT_ERROR', 'COUCHBASE_NETWORK_ERROR', 'COUCHBASE_NOT_MY_VBUCKET', 'COUCHBASE_NOT_STORED', 'COUCHBASE_NOT_SUPPORTED', 'COUCHBASE_UNKNOWN_COMMAND', 'COUCHBASE_UNKNOWN_HOST', 'COUCHBASE_PROTOCOL_ERROR';
+push @EXPORT, 'COUCHBASE_SUCCESS', 'COUCHBASE_AUTH_CONTINUE', 'COUCHBASE_AUTH_ERROR', 'COUCHBASE_DELTA_BADVAL', 'COUCHBASE_E2BIG', 'COUCHBASE_EBUSY', 'COUCHBASE_EINTERNAL', 'COUCHBASE_EINVAL', 'COUCHBASE_ENOMEM', 'COUCHBASE_ERANGE', 'COUCHBASE_ERROR', 'COUCHBASE_ETMPFAIL', 'COUCHBASE_KEY_EEXISTS', 'COUCHBASE_KEY_ENOENT', 'COUCHBASE_LIBEVENT_ERROR', 'COUCHBASE_NETWORK_ERROR', 'COUCHBASE_NOT_MY_VBUCKET', 'COUCHBASE_NOT_STORED', 'COUCHBASE_NOT_SUPPORTED', 'COUCHBASE_UNKNOWN_COMMAND', 'COUCHBASE_UNKNOWN_HOST', 'COUCHBASE_PROTOCOL_ERROR', 'COUCHBASE_BUCKET_ENOENT';
use constant COUCHBASE_SUCCESS => 0;
use constant COUCHBASE_AUTH_CONTINUE => 1;
use constant COUCHBASE_AUTH_ERROR => 2;
@@ -24,5 +24,6 @@ use constant COUCHBASE_NOT_SUPPORTED => 18;
use constant COUCHBASE_UNKNOWN_COMMAND => 19;
use constant COUCHBASE_UNKNOWN_HOST => 20;
use constant COUCHBASE_PROTOCOL_ERROR => 21;
+use constant COUCHBASE_BUCKET_ENOENT => 24;
1;
@@ -1,7 +1,7 @@
package Couchbase::Client::IDXConst;
# This module was generated automatically by ExtUtils::H2PM from idx_constants.pl
-push @EXPORT, 'CTORIDX_SERVERS', 'CTORIDX_USERNAME', 'CTORIDX_PASSWORD', 'CTORIDX_BUCKET', 'CTORIDX_STOREFLAGS', 'CTORIDX_MYFLAGS', 'CTORIDX_COMP_THRESHOLD', 'CTORIDX_COMP_METHODS', 'CTORIDX_SERIALIZE_METHODS', 'RETIDX_VALUE', 'RETIDX_ERRSTR', 'RETIDX_CAS', 'RETIDX_ERRNUM', 'fUSE_COMPAT_FLAGS', 'fUSE_COMPRESSION', 'fUSE_STORABLE', 'fUSE_CONVERT_UTF8', 'CTORIDX_CBEVMOD', 'CTORIDX_CBERR', 'CTORIDX_CBTIMERMOD', 'CTORIDX_CBWAITDONE', 'CTORIDX_BLESS_EVENT', 'COUCHBASE_READ_EVENT', 'COUCHBASE_WRITE_EVENT', 'REQIDX_KEY', 'REQIDX_VALUE', 'REQIDX_EXP', 'REQIDX_CAS', 'REQIDX_ARITH_DELTA', 'REQIDX_ARITH_INITIAL', 'REQIDX_STAT_ARGS', 'PLCBA_CMD_SET', 'PLCBA_CMD_GET', 'PLCBA_CMD_ADD', 'PLCBA_CMD_REPLACE', 'PLCBA_CMD_APPEND', 'PLCBA_CMD_PREPEND', 'PLCBA_CMD_REMOVE', 'PLCBA_CMD_TOUCH', 'PLCBA_CMD_ARITHMETIC', 'PLCBA_CMD_STATS', 'PLCBA_CMD_FLUSH', 'REQTYPE_SINGLE', 'REQTYPE_MULTI', 'CBTYPE_COMPLETION', 'CBTYPE_INCREMENTAL', 'EVIDX_FD', 'EVIDX_DUPFH', 'EVIDX_WATCHFLAGS', 'EVIDX_STATEFLAGS', 'EVIDX_OPAQUE', 'EVIDX_PLDATA', 'EVACTION_WATCH', 'EVACTION_UNWATCH', 'EVACTION_SUSPEND', 'EVACTION_RESUME', 'EVSTATE_INITIALIZED', 'EVSTATE_ACTIVE', 'EVSTATE_SUSPENDED';
+push @EXPORT, 'CTORIDX_SERVERS', 'CTORIDX_USERNAME', 'CTORIDX_PASSWORD', 'CTORIDX_BUCKET', 'CTORIDX_STOREFLAGS', 'CTORIDX_MYFLAGS', 'CTORIDX_COMP_THRESHOLD', 'CTORIDX_COMP_METHODS', 'CTORIDX_SERIALIZE_METHODS', 'CTORIDX_TIMEOUT', 'CTORIDX_NO_CONNECT', 'RETIDX_VALUE', 'RETIDX_ERRSTR', 'RETIDX_CAS', 'RETIDX_ERRNUM', 'fUSE_COMPAT_FLAGS', 'fUSE_COMPRESSION', 'fUSE_STORABLE', 'fUSE_CONVERT_UTF8', 'fNO_CONNECT', 'fNO_DECONVERT', 'CTORIDX_CBEVMOD', 'CTORIDX_CBERR', 'CTORIDX_CBTIMERMOD', 'CTORIDX_CBWAITDONE', 'CTORIDX_BLESS_EVENT', 'COUCHBASE_READ_EVENT', 'COUCHBASE_WRITE_EVENT', 'REQIDX_KEY', 'REQIDX_VALUE', 'REQIDX_EXP', 'REQIDX_CAS', 'REQIDX_ARITH_DELTA', 'REQIDX_ARITH_INITIAL', 'REQIDX_STAT_ARGS', 'PLCBA_CMD_SET', 'PLCBA_CMD_GET', 'PLCBA_CMD_ADD', 'PLCBA_CMD_REPLACE', 'PLCBA_CMD_APPEND', 'PLCBA_CMD_PREPEND', 'PLCBA_CMD_REMOVE', 'PLCBA_CMD_TOUCH', 'PLCBA_CMD_ARITHMETIC', 'PLCBA_CMD_STATS', 'PLCBA_CMD_FLUSH', 'REQTYPE_SINGLE', 'REQTYPE_MULTI', 'CBTYPE_COMPLETION', 'CBTYPE_INCREMENTAL', 'EVIDX_FD', 'EVIDX_DUPFH', 'EVIDX_WATCHFLAGS', 'EVIDX_STATEFLAGS', 'EVIDX_OPAQUE', 'EVIDX_PLDATA', 'EVACTION_WATCH', 'EVACTION_UNWATCH', 'EVACTION_SUSPEND', 'EVACTION_RESUME', 'EVSTATE_INITIALIZED', 'EVSTATE_ACTIVE', 'EVSTATE_SUSPENDED';
use constant CTORIDX_SERVERS => 0;
use constant CTORIDX_USERNAME => 1;
use constant CTORIDX_PASSWORD => 2;
@@ -11,6 +11,8 @@ use constant CTORIDX_MYFLAGS => 4;
use constant CTORIDX_COMP_THRESHOLD => 6;
use constant CTORIDX_COMP_METHODS => 7;
use constant CTORIDX_SERIALIZE_METHODS => 8;
+use constant CTORIDX_TIMEOUT => 10;
+use constant CTORIDX_NO_CONNECT => 11;
use constant RETIDX_VALUE => 0;
use constant RETIDX_ERRSTR => 2;
use constant RETIDX_CAS => 3;
@@ -19,6 +21,8 @@ use constant fUSE_COMPAT_FLAGS => 2;
use constant fUSE_COMPRESSION => 4;
use constant fUSE_STORABLE => 8;
use constant fUSE_CONVERT_UTF8 => 16;
+use constant fNO_CONNECT => 32;
+use constant fNO_DECONVERT => 64;
use constant CTORIDX_CBEVMOD => 10;
use constant CTORIDX_CBERR => 12;
use constant CTORIDX_CBTIMERMOD => 11;
Oops, something went wrong.

0 comments on commit b4de233

Please sign in to comment.