Uploaded image for project: 'Couchbase Python Client Library'
  1. Couchbase Python Client Library
  2. PYCBC-1427

Improve Search Index Management SearchIndex validation

    XMLWordPrintable

Details

    • Task
    • Resolution: Unresolved
    • Minor
    • 4.1.x
    • 4.0.0, 4.1.0
    • None
    • None
    • 0

    Description

      When creating a SearchIndex, if the parameters are not passed in as kwargs, then it is possible a segmentation fault occurs as the order of the parameters then matter. The validation of the SearchIndex should be improved to check types and valid values (as much as possible).

      Example:

      import pathlib
      import json
      from os import path
       
      from couchbase.auth import PasswordAuthenticator
      from couchbase.cluster import Cluster
      from couchbase.options import ClusterOptions
       
      from couchbase.management.search import SearchIndex
       
       
      TEST_INDEX_NAME = 'test-search-index'
      TEST_INDEX_PATH = path.join(pathlib.Path(__file__).parent,
                                  'tests',
                                  'test_cases',
                                  f'{TEST_INDEX_NAME}-params.json')
       
       
      def load_idx(cluster):
          sixm = cluster.search_indexes()
          with open(TEST_INDEX_PATH) as params_file:
              input = params_file.read()
              params_json = json.loads(input)
              plan_params = {
                  'maxPartitionsPerPIndex': 171,
                  'numReplicas': 0,
                  'indexPartitions': 6
              }
       
              # Segmentation fault when not using kwargs
              # idx = SearchIndex(TEST_INDEX_NAME,
              #                   'fulltext-index',
              #                   'default',
              #                   '',
              #                   params_json,
              #                   '',
              #                   {},
              #                   'couchbase',
              #                   plan_params)
       
              # this works
              idx = SearchIndex(name=TEST_INDEX_NAME,
                                idx_type='fulltext-index',
                                source_name='default',
                                uuid='',
                                params=params_json,
                                source_uuid='',
                                source_params={},
                                source_type='couchbase',
                                plan_params=plan_params)
              sixm.upsert_index(idx)
       
       
      if __name__ == '__main__':
          auth = PasswordAuthenticator('Administrator', 'password')
          cluster = Cluster.connect('couchbase://localhost', ClusterOptions(auth))
          bucket = cluster.bucket('default')
          coll = bucket.default_collection()
          load_idx(cluster)
      
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            jared.casey Jared Casey
            jared.casey Jared Casey
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty