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

Add manual index names where index names might get too long #1166

Merged
merged 1 commit into from
May 22, 2023

Conversation

zachmullen
Copy link
Member

Some managed mongoDB providers limit index name lengths, and multi-column indexes' default names may exceed this.

Some managed mongoDB providers limit index name lengths, and multi-column indexes' default names may exceed this.
@zachmullen zachmullen requested a review from manthey May 22, 2023 17:38
@zachmullen zachmullen merged commit 40a5490 into master May 22, 2023
@zachmullen zachmullen deleted the custom-idx-names branch May 22, 2023 18:29
@manthey
Copy link
Member

manthey commented May 22, 2023

Hmm... On an existing installation, I see

 Index already exists with a different name: annotationId_1_bbox.lowx_-1_bbox.highx_1_bbox.size_-1, full error: {'ok': 0.0, 'errmsg': 'Index already exists with a different name: annotationId_1_bbox.lowx_-1_bbox.highx_1_bbox.size_-1', 'code': 85, 'codeName': 'IndexOptionsConflict'}

@zachmullen
Copy link
Member Author

Is that an error or just a warning?

@manthey
Copy link
Member

manthey commented May 22, 2023

The complete error is:

10.0.2.2 - - [22/May/2023:14:47:39] "GET /api/v1/wsi_deid/settings HTTP/1.1" 200 4368 "http://parakon:8088/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36"
[2023-05-22 14:47:39,677] ERROR: 500 Error
Traceback (most recent call last):
  File "/home/ubuntu/girder/girder/api/rest.py", line 649, in endpointDecorator
    val = fun(self, path, params)
  File "/home/ubuntu/girder/girder/api/rest.py", line 1238, in POST
    return self.handleRoute(method, path, params)
  File "/home/ubuntu/girder/girder/api/rest.py", line 977, in handleRoute
    val = handler(**kwargs)
  File "/home/ubuntu/girder/girder/api/describe.py", line 729, in wrapped
    return fun(*args, **kwargs)
  File "/home/ubuntu/misc/large_image_3/girder_annotation/girder_large_image_annotation/rest/annotation.py", line 800, in getItemListAnnotationCounts
    if Annotationelement().findOne({'element.girderId': itemId}):
  File "/home/ubuntu/girder/girder/models/model_base.py", line 70, in __call__
    cls._instance = super().__call__(*args, **kwargs)
  File "/home/ubuntu/girder/girder/models/model_base.py", line 103, in __init__
    self.reconnect()
  File "/home/ubuntu/girder/girder/models/model_base.py", line 116, in reconnect
    self._createIndex(index)
  File "/home/ubuntu/girder/girder/models/model_base.py", line 195, in _createIndex
    self.collection.create_index(index[0], **index[1])
  File "/home/ubuntu/girder/env39/lib/python3.9/site-packages/pymongo/collection.py", line 2271, in create_index
    return self.__create_indexes([index], session, **cmd_options)[0]
  File "/home/ubuntu/girder/env39/lib/python3.9/site-packages/pymongo/collection.py", line 2158, in __create_indexes
    self._command(
  File "/home/ubuntu/girder/env39/lib/python3.9/site-packages/pymongo/collection.py", line 250, in _command
    return sock_info.command(
  File "/home/ubuntu/girder/env39/lib/python3.9/site-packages/pymongo/pool.py", line 740, in command
    return command(
  File "/home/ubuntu/girder/env39/lib/python3.9/site-packages/pymongo/network.py", line 177, in command
    helpers._check_command_response(
  File "/home/ubuntu/girder/env39/lib/python3.9/site-packages/pymongo/helpers.py", line 180, in _check_command_response
    raise OperationFailure(errmsg, code, response, max_wire_version)
pymongo.errors.OperationFailure: Index already exists with a different name: annotationId_1_bbox.lowx_-1_bbox.highx_1_bbox.size_-1, full error: {'ok': 0.0, 'errmsg': 'Index already exists with a different name: annotationId_1_bbox.lowx_-1_bbox.highx_1_bbox.size_-1', 'code': 85, 'codeName': 'IndexOptionsConflict'}
Additional info:
  Request URL: POST http://parakon:8088/api/v1/annotation/counts
  Query string:
  Remote IP: 10.0.2.2
  Request UID: 447816c6-480b-4872-bbaf-cb2336996e91

@zachmullen
Copy link
Member Author

It appears there's no way to modify an existing mongodb index. Mongo's docs suggest you'll need to drop and recreate the index.

@manthey
Copy link
Member

manthey commented May 22, 2023

We could modify girder's _createIndex method in model_base.py like so:

    def _createIndex(self, index):
         if isinstance(index, (list, tuple)):
-            self.collection.create_index(index[0], **index[1])
+            try:
+                self.collection.create_index(index[0], **index[1])
+            except pymongo.errors.OperationFailure:
+                self.collection.drop_index(index[0])
+                self.collection.create_index(index[0], **index[1])

@zachmullen
Copy link
Member Author

I like that change.

@manthey
Copy link
Member

manthey commented May 22, 2023

girder/girder#3448

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants