我正在创建一些python脚本来自动测试某些Couchbase操作。
执行此代码时发生了意外情况:
for i in range(0, BUCKETS_AMOUNT): # BUCKETS_AMOUNT = 4
bucket_name = '%s%s' % (BUCKET_NAME_PREFIX, i) # BUCKET_NAME_PREFIX = 'test_bck_'
print('Creating bucket: %s' % bucket_name)
admin.bucket_create(bucket_name, ram_quota=512, replicas=1)
print('Opening bucket: %s' % bucket_name)
bucket = cluster.open_bucket(bucket_name)
print('Bucket: %s' % bucket)
inserted_data[bucket_name] = _fill_bucket(bucket)
<Key='/pools/default/buckets/test_bck_1', RC=0x3B[HTTP Operation failed. Inspect status code for details], HTTP Request failed. Examine 'objextra' for full result, Results=1, C Source=(src/http.c,144), OBJ=HttpResult<rc=0x0, value=b'Requested resource not found.\r\n', http_status=404, url=/pools/default/buckets/test_bck_1, tracing_context=0, tracing_output=None>, Tracing Output={"/pools/default/buckets/test_bck_1": null}>
Creating bucket: test_bck_0
Opening bucket: test_bck_0
E
======================================================================
ERROR: test_backup (__main__.TestBackup)
----------------------------------------------------------------------
Traceback (most recent call last):
File "couchbase_backup_test.py", line 29, in test_backup
expected = create_and_fill_test_buckets(self.cluster, self.admin)
File "/u01/app/couchbase/bucket_data_util.py", line 41, in create_and_fill_test_buckets
bucket = cluster.open_bucket(bucket_name)
File "/u01/app/couchbase/env_cb/lib/python3.6/site-packages/couchbase/cluster.py", line 144, in open_bucket
rv = self.bucket_class(str(connstr), **kwargs)
File "/u01/app/couchbase/env_cb/lib/python3.6/site-packages/couchbase/bucket.py", line 273, in __init__
self._do_ctor_connect()
File "/u01/app/couchbase/env_cb/lib/python3.6/site-packages/couchbase/bucket.py", line 282, in _do_ctor_connect
self._connect()
couchbase.exceptions._ProtocolError_0x16 (generated, catch ProtocolError): <RC=0x16[Data received on socket was not in the expected format], There was a problem while trying to send/receive your request over the network. This may be a result of a bad network or a misconfigured client or server, C Source=(src/bucket.c,1066)>
----------------------------------------------------------------------
在此示例中,创建并填充了存储桶test_bck_0
,但是似乎在尝试创建test_bck_1
之前就试图打开它。
当我远程执行此代码时-一切正常。但是我需要从实际节点本地运行。
版本略有差异,但我无法将其对齐。
Couchbase服务器版本: 5.1
它可从以下位置远程工作:
不适用于:
答案 0 :(得分:1)
另外,问题是创建存储桶是异步操作,因此在发出创建存储桶请求和打开存储桶之间需要有一定的延迟。
在创建和打开存储桶之间添加类似的内容会有所帮助:
import time
time.sleep(5);
在远程集群上运行脚本时,您可能不会看到这种情况,因为它可能是具有更多资源(CPU / RAM)的专用集群,而且网络延迟也会增加一点。
答案 1 :(得分:-1)
您可以使用couchbase-cli bucket-create
创建存储区,并执行比SDK API公开更多的操作。