parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

_PushStatus issue after upgrade to 3.1.x

Open fxchou123 opened this issue 8 years ago • 60 comments

error: Uncaught internal server error. TypeError: Cannot redefine property: _PushStatus at Function.defineProperty () at SchemaData.volatileClasses.forEach.className (/app/node_modules/parse-server/lib/Controllers/SchemaController.js:530:14) at Array.forEach () at new SchemaData (/app/node_modules/parse-server/lib/Controllers/SchemaController.js:529:21) at getAllClasses.then.allSchemas (/app/node_modules/parse-server/lib/Controllers/SchemaController.js:654:27) at process.internalTickCallback (internal/process/next_tick.js:77:7) TypeError: Cannot redefine property: _PushStatus at Function.defineProperty () at SchemaData.volatileClasses.forEach.className (/app/node_modules/parse-server/lib/Controllers/SchemaController.js:530:14) at Array.forEach () at new SchemaData (/app/node_modules/parse-server/lib/Controllers/SchemaController.js:529:21) at getAllClasses.then.allSchemas (/app/node_modules/parse-server/lib/Controllers/SchemaController.js:654:27) at process.internalTickCallback (internal/process/next_tick.js:77:7) TypeError: Cannot redefine property: _PushStatus at Function.defineProperty () at SchemaData.volatileClasses.forEach.className (/app/node_modules/parse-server/lib/Controllers/SchemaController.js:530:14) at Array.forEach () at new SchemaData (/app/node_modules/parse-server/lib/Controllers/SchemaController.js:529:21) at getAllClasses.then.allSchemas (/app/node_modules/parse-server/lib/Controllers/SchemaController.js:654:27) at process.internalTickCallback (internal/process/next_tick.js:77:7)

fxchou123 avatar Nov 01 '18 21:11 fxchou123

Do you happen to have by any chance an _PushStatus object in your _SCHEMA table?

flovilmart avatar Nov 01 '18 22:11 flovilmart

Do you happen to have by any chance an _PushStatus object in your _SCHEMA table?

Yes I do. Parse Server automatically generated this object in version 3.0

Should I delete it instead?

fxchou123 avatar Nov 02 '18 04:11 fxchou123

Do you happen to have by any chance an _PushStatus object in your _SCHEMA table?

I tried to delete this object and got another error instead.

warn: Unable to ensure uniqueness for user email addresses: MongoError: Index with name: email_1 already exists with different options at /app/node_modules/mongodb-core/lib/connection/pool.js:581:63 at authenticateStragglers (/app/node_modules/mongodb-core/lib/connection/pool.js:504:16) at Connection.messageHandler (/app/node_modules/mongodb-core/lib/connection/pool.js:540:5) at emitMessageHandler (/app/node_modules/mongodb-core/lib/connection/connection.js:310:10) at Socket. (/app/node_modules/mongodb-core/lib/connection/connection.js:489:15) at Socket.emit (events.js:182:13) at Socket.EventEmitter.emit (domain.js:441:20) at addChunk (_stream_readable.js:283:12) at readableAddChunk (_stream_readable.js:264:11) at Socket.Readable.push (_stream_readable.js:219:10)

fxchou123 avatar Nov 02 '18 05:11 fxchou123

What version were you running before upgrading to 3.1? The alert you’re seeing is regarding the _User table.

flovilmart avatar Nov 02 '18 11:11 flovilmart

What version were you running before upgrading to 3.1? The alert you’re seeing is regarding the _User table.

From 3.0.0

Everything works fine in version 3.0.0

fxchou123 avatar Nov 02 '18 20:11 fxchou123

I am running parse-server 3.1.0 and also see similar warning when I start up parse-server (npm start).

Warnings on 3 index:

  1. email_1
  2. username_1
  3. name_1

Is there any need to re-create the index on _User table when upgrading to 3.1.0?

warn: Unable to ensure uniqueness for user email addresses: MongoError: Index with name: email_1 already exists with different options at /Users/Nebi/Documents/heroku/xxx/node_modules/mongodb-core/lib/connection/pool.js:581:63 at authenticateStragglers (/Users/Nebi/Documents/heroku/xxx/node_modules/mongodb-core/lib/connection/pool.js:504:16) at Connection.messageHandler (/Users/Nebi/Documents/heroku/xxx/node_modules/mongodb-core/lib/connection/pool.js:540:5) at emitMessageHandler (/Users/Nebi/Documents/heroku/xxx/node_modules/mongodb-core/lib/connection/connection.js:310:10) at Socket. (/Users/Nebi/Documents/heroku/xxx/node_modules/mongodb-core/lib/connection/connection.js:453:17) at Socket.emit (events.js:182:13) at Socket.EventEmitter.emit (domain.js:442:20) at addChunk (_stream_readable.js:283:12) at readableAddChunk (_stream_readable.js:264:11) at Socket.Readable.push (_stream_readable.js:219:10) (node:86452) UnhandledPromiseRejectionWarning: MongoError: Index with name: email_1 already exists with different options at /Users/Nebi/Documents/heroku/xxx/node_modules/mongodb-core/lib/connection/pool.js:581:63 at authenticateStragglers (/Users/Nebi/Documents/heroku/xxx/node_modules/mongodb-core/lib/connection/pool.js:504:16) at Connection.messageHandler (/Users/Nebi/Documents/heroku/xxx/node_modules/mongodb-core/lib/connection/pool.js:540:5) at emitMessageHandler (/Users/Nebi/Documents/heroku/xxx/node_modules/mongodb-core/lib/connection/connection.js:310:10) at Socket. (/Users/Nebi/Documents/heroku/xxx/node_modules/mongodb-core/lib/connection/connection.js:453:17) at Socket.emit (events.js:182:13) at Socket.EventEmitter.emit (domain.js:442:20) at addChunk (_stream_readable.js:283:12) at readableAddChunk (_stream_readable.js:264:11) at Socket.Readable.push (_stream_readable.js:219:10) (node:86452) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:86452) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. warn: Unable to ensure uniqueness for usernames: MongoError: Index with name: username_1 already exists with different options at /Users/Nebi/Documents/heroku/xxx/node_modules/mongodb-core/lib/connection/pool.js:581:63 at authenticateStragglers (/Users/Nebi/Documents/heroku/xxx/node_modules/mongodb-core/lib/connection/pool.js:504:16) at Connection.messageHandler (/Users/Nebi/Documents/heroku/xxx/node_modules/mongodb-core/lib/connection/pool.js:540:5) at emitMessageHandler (/Users/Nebi/Documents/heroku/xxx/node_modules/mongodb-core/lib/connection/connection.js:310:10) at Socket. (/Users/Nebi/Documents/heroku/xxx/node_modules/mongodb-core/lib/connection/connection.js:489:15) at Socket.emit (events.js:182:13) at Socket.EventEmitter.emit (domain.js:442:20) at addChunk (_stream_readable.js:283:12) at readableAddChunk (_stream_readable.js:264:11) at Socket.Readable.push (_stream_readable.js:219:10) warn: Unable to ensure uniqueness for role name: MongoError: Index with name: name_1 already exists with different options at /Users/Nebi/Documents/heroku/xxx/node_modules/mongodb-core/lib/connection/pool.js:581:63 at authenticateStragglers (/Users/Nebi/Documents/heroku/xxx/node_modules/mongodb-core/lib/connection/pool.js:504:16) at Connection.messageHandler (/Users/Nebi/Documents/heroku/xxx/node_modules/mongodb-core/lib/connection/pool.js:540:5) at emitMessageHandler (/Users/Nebi/Documents/heroku/xxx/node_modules/mongodb-core/lib/connection/connection.js:310:10) at Socket. (/Users/Nebi/Documents/heroku/xxx/node_modules/mongodb-core/lib/connection/connection.js:489:15) at Socket.emit (events.js:182:13) at Socket.EventEmitter.emit (domain.js:442:20) at addChunk (_stream_readable.js:283:12) at readableAddChunk (_stream_readable.js:264:11) at Socket.Readable.push (_stream_readable.js:219:10)

nebitrams avatar Nov 07 '18 23:11 nebitrams

Are you able to provide the indexes from mongo perspective? We may have inadvertently mis implemented a feature in 3.1

flovilmart avatar Nov 07 '18 23:11 flovilmart

@flovilmart, I believe these are the 3 indices. First two on _User and the last one on _Role.

{ "v": 1, "key": { "email": 1 }, "name": "email_1", "ns": "xxx._User", "background": true }

{ "v": 1, "key": { "username": 1 }, "name": "username_1", "ns": "xxx._User", "background": true }

{ "v": 1, "unique": true, "key": { "name": 1 }, "name": "name_1", "ns": "xxx._Role" }

nebitrams avatar Nov 08 '18 00:11 nebitrams

According this this thread, you might have added unique constraints in 3.1.0.

https://stackoverflow.com/questions/30232081/mongoexception-index-with-name-code-already-exists-with-different-options/30232270

nebitrams avatar Nov 08 '18 00:11 nebitrams

Would you be able to start a parse-server on a clean DB, and tell me what what do the indexes look like?

flovilmart avatar Nov 08 '18 00:11 flovilmart

I have migrated my DB from parse.com since 2 years ago. I didn't know how to start from a clean DB. Could you point me to some documentation on this? I will try again about 12 hours from now. :-)

nebitrams avatar Nov 08 '18 00:11 nebitrams

Just start a local mongo database. Look into the starting guides on the http://docs.parseplatform.org website

flovilmart avatar Nov 08 '18 00:11 flovilmart

Might have a solution to this. We got the same error: Unable to ensure uniqueness for role name: MongoError: Index with name: name_1 already exists with different options when trying to start with our old DB from parse.com with parse-server 3.1.1.

The issue was that we had an index { "name": 1 } on _Role, but with sparse set to false. So we just deleted the index and parse-server created a new one (the same index, but with sparse set to true on start up.

johanarnor avatar Nov 08 '18 15:11 johanarnor

I created a blank local database and started parse server connecting to the local database. It automatically creates the _User, _SCHEMA, _Role with indexes. This is the mongod log with schema and indexes details.

2018-11-09T06:35:53.161+0800 I COMMAND  [conn3327] command parse._SCHEMA command: insert { insert: "_SCHEMA", documents: [ { _id: "_User", objectId: "string", updatedAt: "date", createdAt: "date", username: "string", email: "string", emailVerified: "boolean", authData: "object" } ], ordered: true } ninserted:1 keyUpdates:0 writeConflicts:0 numYields:0 reslen:40 locks:{ Global: { acquireCount: { r: 2, w: 2 } }, Database: { acquireCount: { w: 1, W: 1 } }, Collection: { acquireCount: { W: 1 } } } protocol:op_query 124ms
2018-11-09T06:35:53.166+0800 I COMMAND  [conn3329] command parse._Hooks command: find { find: "_Hooks", filter: {}, sort: {}, projection: {}, returnKey: false, showRecordId: false } planSummary: EOF keysExamined:0 docsExamined:0 cursorExhausted:1 keyUpdates:0 writeConflicts:0 numYields:0 nreturned:0 reslen:118 locks:{ Global: { acquireCount: { r: 2 } }, Database: { acquireCount: { r: 1 }, acquireWaitCount: { r: 1 }, timeAcquiringMicros: { r: 109172 } }, Collection: { acquireCount: { r: 1 } } } protocol:op_query 109ms
2018-11-09T06:35:53.209+0800 I COMMAND  [conn3328] command parse._SCHEMA command: insert { insert: "_SCHEMA", documents: [ { _id: "_Role", objectId: "string", updatedAt: "date", createdAt: "date", name: "string", users: "relation<_User>", roles: "relation<_Role>" } ], ordered: true } ninserted:1 keyUpdates:0 writeConflicts:0 numYields:0 reslen:40 locks:{ Global: { acquireCount: { r: 1, w: 1 } }, Database: { acquireCount: { w: 1 }, acquireWaitCount: { w: 1 }, timeAcquiringMicros: { w: 121407 } }, Collection: { acquireCount: { w: 1 } } } protocol:op_query 173ms
2018-11-09T06:35:53.339+0800 I INDEX    [conn3329] build index on: parse._User properties: { v: 1, unique: true, key: { username: 1 }, name: "username_1", ns: "parse._User", background: true, sparse: true }
2018-11-09T06:35:53.389+0800 I INDEX    [conn3327] build index on: parse._User properties: { v: 1, unique: true, key: { email: 1 }, name: "email_1", ns: "parse._User", background: true, sparse: true }
2018-11-09T06:35:53.389+0800 I INDEX    [conn3329] build index done.  scanned 0 total records. 0 secs
2018-11-09T06:35:53.389+0800 I INDEX    [conn3327] build index done.  scanned 0 total records. 0 secs
2018-11-09T06:35:53.401+0800 I COMMAND  [conn3328] command parse._SCHEMA command: find { find: "_SCHEMA", filter: {}, returnKey: false, showRecordId: false } planSummary: COLLSCAN keysExamined:0 docsExamined:2 cursorExhausted:1 keyUpdates:0 writeConflicts:0 numYields:0 nreturned:2 reslen:445 locks:{ Global: { acquireCount: { r: 2 } }, Database: { acquireCount: { r: 1 }, acquireWaitCount: { r: 1 }, timeAcquiringMicros: { r: 176282 } }, Collection: { acquireCount: { r: 1 } } } protocol:op_query 188ms
2018-11-09T06:35:53.403+0800 I COMMAND  [conn3329] command parse.$cmd command: createIndexes { createIndexes: "_User", indexes: [ { name: "username_1", key: { username: 1 }, unique: true, background: true, sparse: true } ] } keyUpdates:0 writeConflicts:0 numYields:0 reslen:113 locks:{ Global: { acquireCount: { r: 1, w: 1 } }, Database: { acquireCount: { w: 1, W: 2 }, acquireWaitCount: { w: 1, W: 2 }, timeAcquiringMicros: { w: 48296, W: 48466 } }, Collection: { acquireCount: { w: 1 } } } protocol:op_query 231ms
2018-11-09T06:35:53.406+0800 I COMMAND  [conn3327] command parse.$cmd command: createIndexes { createIndexes: "_User", indexes: [ { name: "email_1", key: { email: 1 }, unique: true, background: true, sparse: true } ] } keyUpdates:0 writeConflicts:0 numYields:0 reslen:113 locks:{ Global: { acquireCount: { r: 1, w: 1 } }, Database: { acquireCount: { w: 1, W: 2 }, acquireWaitCount: { W: 2 }, timeAcquiringMicros: { W: 182237 } }, Collection: { acquireCount: { w: 1 } } } protocol:op_query 235ms
2018-11-09T06:35:53.584+0800 I INDEX    [conn3328] build index on: parse._Role properties: { v: 1, unique: true, key: { name: 1 }, name: "name_1", ns: "parse._Role", background: true, sparse: true }
2018-11-09T06:35:53.584+0800 I INDEX    [conn3328] build index done.  scanned 0 total records. 0 secs
2018-11-09T06:35:53.587+0800 I COMMAND  [conn3328] command parse.$cmd command: createIndexes { createIndexes: "_Role", indexes: [ { name: "name_1", key: { name: 1 }, unique: true, background: true, sparse: true } ] } keyUpdates:0 writeConflicts:0 numYields:0 reslen:113 locks:{ Global: { acquireCount: { r: 1, w: 1 } }, Database: { acquireCount: { w: 1, W: 2 }, acquireWaitCount: { W: 1 }, timeAcquiringMicros: { W: 1817 } }, Collection: { acquireCount: { w: 1 } } } protocol:op_query 179ms

nebitrams avatar Nov 08 '18 22:11 nebitrams

Ok so the main issue is that now we create the indexes as unique + sparse, as you initially envisioned. Now I am not sure of the best resolution:

  • ignore the warning
  • delete and replace the index
  • create the new index under a different name (and then perhaps delete the existing one)

What do you think?

flovilmart avatar Nov 08 '18 23:11 flovilmart

Is "sparse" is used when a field could be left as "undefined". Are these 3 fields optional?

If the "sparse" is required, I suggest to delete and replace the index upon parse-server start up. Does parse-server has sufficient right to drop index? We should not leave unused Index because indices took up precious disk space and cpu time.

nebitrams avatar Nov 08 '18 23:11 nebitrams

Yeah, they do, temporarily, we could create the new one and replace the old one.

Is it something you’d like to implement?

flovilmart avatar Nov 08 '18 23:11 flovilmart

The best way to give back when you receive a favour is to contribute code :-) However, I am not so sure at the moment. Let's me explore a bit further on parse-server codebase.

nebitrams avatar Nov 09 '18 00:11 nebitrams

There is a workaround, and the setup is not completely broken. You could destroy your indexes and restart the server this would ‘just work’. But not as clean as doing a migration.

And as a long time user (as you said), it’s always good to have his hand dirty :)

flovilmart avatar Nov 09 '18 00:11 flovilmart

It works.

I have dropped these indices and then new indices automatically created in next parse-server restart.

_User.email_1
_User.username_1
_Role.name_1

Recreated index on _User { "v": 2, "unique": true, "key": { "email": 1 }, "name": "email_1", "ns": "xxx._User", "background": true, "sparse": true }

{ "v": 2, "unique": true, "key": { "username": 1 }, "name": "username_1", "ns": "xxx._User", "background": true, "sparse": true }

Recreated index on _Role { "v": 2, "unique": true, "key": { "name": 1 }, "name": "name_1", "ns": "xxx._Role", "background": true, "sparse": true }

nebitrams avatar Nov 25 '18 02:11 nebitrams