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

Unable to start pip after download with sqlite=true #454

Closed
otbutz opened this issue Jun 6, 2019 · 4 comments · Fixed by #458
Closed

Unable to start pip after download with sqlite=true #454

otbutz opened this issue Jun 6, 2019 · 4 comments · Fixed by #458

Comments

@otbutz
Copy link

otbutz commented Jun 6, 2019

Executing the following snippet with sqlite and importPostalcodes enabled:

cd /opt/pelias/whosonfirst
npm run download
cd /opt/pelias/pip-service
npm start

The download finishes properly:

> [email protected] download /opt/pelias/whosonfirst
> ./bin/download

Downloading whosonfirst-data-latest.db.bz2
Downloading whosonfirst-data-admin-ad-latest.db.bz2
Downloading whosonfirst-data-admin-ae-latest.db.bz2
Downloading whosonfirst-data-admin-af-latest.db.bz2
...
done downloading whosonfirst-data-admin-zm-latest.db.bz2
Downloading whosonfirst-data-admin-zw-latest.db.bz2
done downloading whosonfirst-data-admin-zw-latest.db.bz2
done downloading whosonfirst-data-admin-za-latest.db.bz2
done downloading whosonfirst-data-admin-us-latest.db.bz2
done downloading whosonfirst-data-latest.db.bz2
All done!

But the sqlite DBs seem to be locked:

/opt/pelias/pip-service/node_modules/pelias-whosonfirst/src/components/sqliteStream.js:13
      .exec('CREATE INDEX IF NOT EXISTS spr_obsolete ON spr (is_deprecated, is_superseded)')
       ^

/opt/pelias/pip-service/node_modules/pelias-whosonfirst/src/components/sqliteStream.js:13
      .exec('CREATE INDEX IF NOT EXISTS spr_obsolete ON spr (is_deprecated, is_superseded)')
       ^
SqliteError: database is locked
    at new SQLiteStream (/opt/pelias/pip-service/node_modules/pelias-whosonfirst/src/components/sqliteStream.js:13:8)
    at readSqliteRecords (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/readStream.js:21:10)
    at readData (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/readStream.js:42:5)
    at Object.<anonymous> (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/worker.js:34:1)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
SqliteError: database is locked
    at new SQLiteStream (/opt/pelias/pip-service/node_modules/pelias-whosonfirst/src/components/sqliteStream.js:13:8)
    at readSqliteRecords (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/readStream.js:21:10)
    at readData (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/readStream.js:42:5)
    at Object.<anonymous> (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/worker.js:34:1)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)

/opt/pelias/pip-service/node_modules/pelias-whosonfirst/src/components/sqliteStream.js:13
      .exec('CREATE INDEX IF NOT EXISTS spr_obsolete ON spr (is_deprecated, is_superseded)')
       ^
SqliteError: database is locked
    at new SQLiteStream (/opt/pelias/pip-service/node_modules/pelias-whosonfirst/src/components/sqliteStream.js:13:8)
    at readSqliteRecords (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/readStream.js:21:10)
    at readData (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/readStream.js:42:5)
    at Object.<anonymous> (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/worker.js:34:1)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)

/opt/pelias/pip-service/node_modules/pelias-whosonfirst/src/components/sqliteStream.js:13
      .exec('CREATE INDEX IF NOT EXISTS spr_obsolete ON spr (is_deprecated, is_superseded)')
       ^
SqliteError: database is locked
    at new SQLiteStream (/opt/pelias/pip-service/node_modules/pelias-whosonfirst/src/components/sqliteStream.js:13:8)
    at readSqliteRecords (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/readStream.js:21:10)
    at readData (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/readStream.js:42:5)
    at Object.<anonymous> (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/worker.js:34:1)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)

/opt/pelias/pip-service/node_modules/pelias-whosonfirst/src/components/sqliteStream.js:13
      .exec('CREATE INDEX IF NOT EXISTS spr_obsolete ON spr (is_deprecated, is_superseded)')
       ^

/opt/pelias/pip-service/node_modules/pelias-whosonfirst/src/components/sqliteStream.js:13
      .exec('CREATE INDEX IF NOT EXISTS spr_obsolete ON spr (is_deprecated, is_superseded)')
       ^
SqliteError: database is locked
    at new SQLiteStream (/opt/pelias/pip-service/node_modules/pelias-whosonfirst/src/components/sqliteStream.js:13:8)
    at readSqliteRecords (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/readStream.js:21:10)
    at readData (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/readStream.js:42:5)
    at Object.<anonymous> (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/worker.js:34:1)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
SqliteError: database is locked
    at new SQLiteStream (/opt/pelias/pip-service/node_modules/pelias-whosonfirst/src/components/sqliteStream.js:13:8)
    at readSqliteRecords (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/readStream.js:21:10)
    at readData (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/readStream.js:42:5)
    at Object.<anonymous> (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/worker.js:34:1)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)

/opt/pelias/pip-service/node_modules/pelias-whosonfirst/src/components/sqliteStream.js:13
      .exec('CREATE INDEX IF NOT EXISTS spr_obsolete ON spr (is_deprecated, is_superseded)')
       ^

/opt/pelias/pip-service/node_modules/pelias-whosonfirst/src/components/sqliteStream.js:13
      .exec('CREATE INDEX IF NOT EXISTS spr_obsolete ON spr (is_deprecated, is_superseded)')
       ^
SqliteError: database is locked
    at new SQLiteStream (/opt/pelias/pip-service/node_modules/pelias-whosonfirst/src/components/sqliteStream.js:13:8)
    at readSqliteRecords (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/readStream.js:21:10)
    at readData (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/readStream.js:42:5)
    at Object.<anonymous> (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/worker.js:34:1)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
SqliteError: database is locked
    at new SQLiteStream (/opt/pelias/pip-service/node_modules/pelias-whosonfirst/src/components/sqliteStream.js:13:8)
    at readSqliteRecords (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/readStream.js:21:10)
    at readData (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/readStream.js:42:5)
    at Object.<anonymous> (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/worker.js:34:1)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)

/opt/pelias/pip-service/node_modules/pelias-whosonfirst/src/components/sqliteStream.js:13
      .exec('CREATE INDEX IF NOT EXISTS spr_obsolete ON spr (is_deprecated, is_superseded)')
       ^
SqliteError: database is locked
    at new SQLiteStream (/opt/pelias/pip-service/node_modules/pelias-whosonfirst/src/components/sqliteStream.js:13:8)
    at readSqliteRecords (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/readStream.js:21:10)
    at readData (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/readStream.js:42:5)
    at Object.<anonymous> (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/worker.js:34:1)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
2019-06-06T15:51:45.622Z - error: [wof-pip-service:master] neighbourhood worker exited unexpectedly with code 1, signal null

/opt/pelias/pip-service/node_modules/pelias-whosonfirst/src/components/sqliteStream.js:13
      .exec('CREATE INDEX IF NOT EXISTS spr_obsolete ON spr (is_deprecated, is_superseded)')
       ^
SqliteError: database is locked
    at new SQLiteStream (/opt/pelias/pip-service/node_modules/pelias-whosonfirst/src/components/sqliteStream.js:13:8)
    at readSqliteRecords (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/readStream.js:21:10)
    at readData (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/readStream.js:42:5)
    at Object.<anonymous> (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/worker.js:34:1)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)

/opt/pelias/pip-service/node_modules/pelias-whosonfirst/src/components/sqliteStream.js:13
      .exec('CREATE INDEX IF NOT EXISTS spr_obsolete ON spr (is_deprecated, is_superseded)')
       ^

/opt/pelias/pip-service/node_modules/pelias-whosonfirst/src/components/sqliteStream.js:13
      .exec('CREATE INDEX IF NOT EXISTS spr_obsolete ON spr (is_deprecated, is_superseded)')
       ^

/opt/pelias/pip-service/node_modules/pelias-whosonfirst/src/components/sqliteStream.js:13
      .exec('CREATE INDEX IF NOT EXISTS spr_obsolete ON spr (is_deprecated, is_superseded)')
       ^
2019-06-06T15:51:45.627Z - error: [wof-pip-service:master] empire worker exited unexpectedly with code 1, signal null
SqliteError: database is locked
    at new SQLiteStream (/opt/pelias/pip-service/node_modules/pelias-whosonfirst/src/components/sqliteStream.js:13:8)
    at readSqliteRecords (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/readStream.js:21:10)
    at readData (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/readStream.js:42:5)
    at Object.<anonymous> (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/worker.js:34:1)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
SqliteError: database is locked
    at new SQLiteStream (/opt/pelias/pip-service/node_modules/pelias-whosonfirst/src/components/sqliteStream.js:13:8)
    at readSqliteRecords (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/readStream.js:21:10)
    at readData (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/readStream.js:42:5)
    at Object.<anonymous> (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/worker.js:34:1)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
SqliteError: database is locked
    at new SQLiteStream (/opt/pelias/pip-service/node_modules/pelias-whosonfirst/src/components/sqliteStream.js:13:8)
    at readSqliteRecords (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/readStream.js:21:10)
    at readData (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/readStream.js:42:5)
    at Object.<anonymous> (/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/worker.js:34:1)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)

/opt/pelias/pip-service/node_modules/pelias-wof-admin-lookup/src/pip/index.js:166
        throw `${layer} worker shutdown unexpectedly`;
        ^
neighbourhood worker shutdown unexpectedly
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `./bin/start`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

I tried it multiple times even with a ps -aux between download and start but it seems that all processes start by download have properly finished.

Are there any lock files i'm missing?

Edit: noticed that i posted parts the log of my first run in which i used the pip-service download instead of the whosonfirst one.

@otbutz
Copy link
Author

otbutz commented Jun 7, 2019

Update: it seems to only crash on the first start. If i retry to start the pip-service it works.

Maybe it's related to #453

Edit: it is.... #431

orangejulius added a commit that referenced this issue Aug 2, 2019
The creation of the `spr_obsolete` index is problematic for the PIP
service and any of the admin lookup workers running in the importers.

Because there are always multiple processes doing admin lookup, and each
one tries to create the index if it doesn't exist, most end up failing.
SQLite only allows a single write lock on the DB, so all but one will
fail to achieve it.

However, in my testing, all it takes to solve this gracefully is to wrap
the index creation in a try/catch block. The index will be created by
one of the worker processes, and all subsequent queries appear to have
the performance improvements of the index (about 30-50% faster time to
load admin data).

Supercedes #431
Fixes #453
Connects #454 (we should not
actually remove the index creation quite yet)
orangejulius added a commit that referenced this issue Aug 2, 2019
The creation of the `spr_obsolete` index is problematic for the PIP
service and any of the admin lookup workers running in the importers.

Because there are always multiple processes doing admin lookup, and each
one tries to create the index if it doesn't exist, most end up failing.
SQLite only allows a single write lock on the DB, so all but one will
fail to achieve it.

However, in my testing, all it takes to solve this gracefully is to wrap
the index creation in a try/catch block. The index will be created by
one of the worker processes, and all subsequent queries appear to have
the performance improvements of the index (about 30-50% faster time to
load admin data).

Supersedes #431
Fixes #453
Connects #454 (we should not
actually remove the index creation quite yet)
orangejulius added a commit that referenced this issue Aug 2, 2019
The creation of the `spr_obsolete` index is problematic for the PIP
service and any of the admin lookup workers running in the importers.

Because there are always multiple processes doing admin lookup, and each
one tries to create the index if it doesn't exist, most end up failing.
SQLite only allows a single write lock on the DB, so all but one will
fail to achieve it.

However, in my testing, all it takes to solve this gracefully is to wrap
the index creation in a try/catch block. The index will be created by
one of the worker processes, and all subsequent queries appear to have
the performance improvements of the index (about 30-50% faster time to
load admin data).

Supersedes #431
Fixes #454
Connects #453 (we should not
actually remove the index creation quite yet)
@orangejulius
Copy link
Member

Hi @otbutz,
We just merged #458, which should make any issues with the database lock error go away. We're now creating the database index in a way that handles failure gracefully, so even though not all the distfiles from dist.whosonfirst.org have that index, it shouldn't cause any issues in the meantime.

Let us know if there are still any problems.

@otbutz
Copy link
Author

otbutz commented Aug 12, 2019

Thanks, will give it a spin ;)

@otbutz
Copy link
Author

otbutz commented Aug 13, 2019

It works flawlessly now 👍

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 a pull request may close this issue.

2 participants