App Engine - LocalDatastoreService load - Failed to load from the backing store

725 views Asked by At

We are using App Engine, Datastore, and Java and we have been trying unsuccessfully to copy our production Google Datastore to a local copy.

(The full migration script I'm using is detailed in a separate Github question)

We use the following to export

gcloud datastore export --namespaces="(default)" gs://$GOOGLE_CLOUD_BUCKET

And then import that looks something like this

'http://' + $LOCAL_DATASTORE_HOSTNAME + ':' + $LOCAL_DATASTORE_PORT + '/v1/projects/' + $PROJECT_ID + ':import'

Running the script creates a "local_db.bin" which appears to be correct however then we copy it into the required location and run it we hit the following error.

com.google.appengine.api.datastore.dev.LocalDatastoreService init INFO: Local Datastore initialized: Type: High Replication Storage: \WEB-INF\appengine-generated\local_db.bin com.google.appengine.api.datastore.dev.LocalDatastoreService load INFO: Failed to load from the backing store, \WEB-INF\appengine-generated\local_db.bin java.lang.ClassNotFoundException: com.google.cloud.datastore.emulator.impl.LocalDatastoreFileStub$FileProfile at java.net.URLClassLoader.findClass(URLClassLoader.java:382) at java.lang.ClassLoader.loadClass(ClassLoader.java:424)

If we then save a new record it blows away the local_db.bin and creates a new one.

Anyone know where in the process this issue might be?

UPDATE:

I've followed the exact process that @Chris Halcrow describes in his answer, to re-import the data. The data is now successfully imported directly into the local_db.bin that App Engine should be seeing, however I still see the error.

We suspect there could be a permissions issue. We've tried changing some of the IAM permission for the account that AppEngine is running under. Specifically, we've tried adding the Project Editor IAM role to the account that we're using for our gcloud login, as documented in activate DataStore permissions for App Engine.

We've also reviewed the following, which details required permissions when we're using the export/import Powershell script detailed in our GitHub question.

https://cloud.google.com/datastore/docs/export-import-entities#permissions

We believe our current roles should be allowing the required permissions that this describes.

1

There are 1 answers

0
Chris Halcrow On

Don't copy the local_db.bin file as this is likely to result in incorrect memory references/pointers. Follow the following procedure instead:

  1. Stop your local AppEngine (terminate in the console, or close Eclipse/IntelliJ or whatever else is running it)
  2. Stop anything that's running the DataStore Emulator (e.g. terminate the process if you're running it via a command prompt).
  3. Determine where your running AppEngine instance is looking for the local_db.bin file (for a Java application that you're running under a local instance of AppEngine, the default location relates to the directory that contains your WAR file e.g. C:\my_app_engine_app\target\my-app-name-1.0-SNAPSHOT\WEB-INF\appengine-generated\local_db.bin)
  4. Delete the contents of the appengine-generated folder
  5. Open a regular Windows Command Prompt (run as Administrator)
  6. cd to the directory that contains your AppEngine app
  7. Run the emulator using the following command (ensure that data-dir specifies the directory you determined in step 3) - gcloud beta emulators datastore start --data-dir=C:\my_app_engine_app\target\my-app-name-1.0-SNAPSHOT\ (see https://cloud.google.com/datastore/docs/tools/datastore-emulator#starting_the_emulator)
  8. Take a note of the port that the DataStore emulator starts on
  9. Ensure that your DataStore import script uses this port as the value of $LOCAL_DATASTORE_PORT
  10. With your local DataStore emulator still running, run your import script again (for a Powershell script, ensure you run the script while running Powershell as Administrator)
  11. If it succeeds you should see messages in the console that may look like some or all of the following: INFO: Adding handler(s) to newly registered Channel INFO: Detected HTTP/2 connection INFO: Detected non-HTTP/2 connection Time to persist datastore: 125 ms
  12. Now check your local_db.bin file e.g. C:\my_app_engine_app\target\my-app-name-1.0-SNAPSHOT\WEB-INF\appengine-generated\local_db.bin - you should see that it has inflated to indicate that it now contains your data.