Google Cloud Datastore Emulator - gcloud beta emulators datastore start fails to create local_db.bin

2.1k views Asked by At

I have the Google Cloud SDK installed under Windows, and I'm running commands in Powershell (running as administrator).

I've run the following to make sure all my Google Cloud SDK components are updated:

gcloud component update

I then set the datastore emulator host domain and a project id like this:

set DATASTORE_EMULATOR_HOST=localhost:8081
set DATASTORE_PROJECT_ID=project-id

I'm then running the Google Cloud Datastore Mode Emulator by using the following command:

gcloud beta emulators datastore start

This is meant to create a file local_db.bin, that provides local access to data. When I run the command I get a message in the terminal (Powershell, running as administrator) that the file will be created at the following location:

C:\Users\myUserName\AppData\Roaming\gcloud\emulators\datastore\WEB-INF\appengine-generated\local_db.bin

The file isn't being created, and there is no useful error info. I've done the following:

  • Checked the list of credentialed accounts that are available to the gcloud SDK, using gcloud auth list
  • Ensured that I'm logged in using the intended account, using gcloud auth login 'accountName' and using Google sign in

How can I get additional information on what the cause of the error is? What else could I try?

1

There are 1 answers

0
Andrei Cusnir On BEST ANSWER

The local_db.bin is not failed to be created. It just indicates that the database is empty. You can verify that everything works as expected, if you open your browser and navigate to http://localhost:8081, when the server is running. You should get an ok message as response.

As stated in Running the Datastore mode Emulator > Emulator data directories documentation's section, "To clear the contents of a local_db.bin file, stop the emulator and manually delete the file.". Which means that this way you are clearing all the contents of the database.

I have tried the documentation and indeed the file local_db.bin is missing at the begging. However, after adding some data in the database the file was generated. I managed to do that, by creating an Python application based on Google GitHub samples.

NOTE: I would also suggest to start the emulator inside your own specified directory instead of the default's one, that so you make sure that you have all the permissions of the directory. e.g. To do so follow the steps:

  1. Inside Desktop create a directory called Datastore_Emulator
  2. Execute the command: $ gcloud beta emulators datastore start --data-dir=C:\Users\[USERNAME]\Desktop\Datastore_Emulator\
  3. This will create an empty directory C:\Users\[USERNAME]\Desktop\Datastore_Emulator\WEB-INF\appengine-generated\
  4. Now create for example an Python script, add some data to the database and the local_db.bin file will be generated.

UPDATE

The documentation that you refer to, the commands under Windows section are for Command prompt. The && is not supported to chain commands in Power shell, but you need to use ; instead. Refer to this Stackoverflow answer for more information.

Also there the command gcloud beta emulators datastore env-init > set_vars.cmd && set_vars.cmd is not supported by Power Shell, since when you run it, you might encounter issues with the generated set_vars.cmd file. In the future it is suggested to use Command Prompt to execute commands mentioned in Google documentations.