def n1ql_index_watch(self, indexes, timeout=30, interval=1, watch_primary=False): """ Await completion of index building This method will wait up to `timeout` seconds for every index in `indexes` to have been built. It will poll the cluster every `interval` seconds. :param list indexes: A list of indexes to check. This is returned by :meth:`build_deferred_indexes` :param float timeout: How long to wait for the indexes to become ready. :param float interval: How often to poll the cluster. :param bool watch_primary: Whether to also watch the primary index. This parameter should only be used when manually constructing a list of string indexes :raise: :exc:`~.TimeoutError` if the timeout was reached before all indexes were built :raise: :exc:`~.NotFoundError` if one of the indexes passed no longer exists. """ kwargs = { 'timeout_us': int(timeout * 1000000), 'interval_us': int(interval * 1000000) } ixlist = [N1qlIndex.from_any(x, self._cb.bucket) for x in indexes] if watch_primary: ixlist.append( N1qlIndex.from_any(N1QL_PRIMARY_INDEX, self._cb.bucket)) return IxmgmtRequest(self._cb, 'watch', ixlist, **kwargs).execute()
def _mk_index_def(self, ix, primary=False): if isinstance(ix, N1qlIndex): return N1qlIndex(ix) info = N1qlIndex() info.keyspace = self._cb.bucket info.primary = primary if ix: info.name = ix elif not primary: raise ValueError('Missing name for non-primary index') return info
def n1ql_index_build_deferred(self, other_buckets=False): """ Instruct the server to begin building any previously deferred index definitions. This method will gather a list of all pending indexes in the cluster (including those created using the `defer` option with :meth:`create_index`) and start building them in an efficient manner. :param bool other_buckets: Whether to also build indexes found in other buckets, if possible :return: list[couchbase._ixmgmt.Index] objects. This list contains the indexes which are being built and may be passed to :meth:`n1ql_index_watch` to poll their build statuses. You can use the :meth:`n1ql_index_watch` method to wait until all indexes have been built:: mgr.n1ql_index_create('ix_fld1', fields=['field1'], defer=True) mgr.n1ql_index_create('ix_fld2', fields['field2'], defer=True) mgr.n1ql_index_create('ix_fld3', fields=['field3'], defer=True) indexes = mgr.n1ql_index_build_deferred() # [IndexInfo('field1'), IndexInfo('field2'), IndexInfo('field3')] mgr.n1ql_index_watch(indexes, timeout=30, interval=1) """ info = N1qlIndex() if not other_buckets: info.keyspace = self._cb.bucket return IxmgmtRequest(self._cb, 'build', info).execute()
def n1ql_index_list(self, other_buckets=False): """ List indexes in the cluster. :param bool other_buckets: Whether to also include indexes belonging to other buckets (i.e. buckets other than the current `Bucket` object) :return: list[couchbase._ixmgmt.Index] objects """ info = N1qlIndex() if not other_buckets: info.keyspace = self._cb.bucket return IxmgmtRequest(self._cb, 'list', info).execute()