Local development with cloud-spanner

2019-04-19 07:53发布

问题:

Is there any way to do local development with cloud spanner? I've taken a look through the docs and the CLI tool and there doesn't seem to be anything there. Alternatively, can someone suggest a SQL database that behaves similarly for reads (not sure what to do about writes)?

EDIT: To clarify, I'm looking for a database which speaks the same flavour of SQL as Cloud Spanner so I can do development locally. The exact performance characteristics are not as important as the API and consistency behaviour. I don't think Cockroach meets these requirements?

回答1:

There is currently no local development option for Cloud Spanner. Your current option would be to start a single node instance on GCP.

There currently isn't another database that operates like Cloud Spanner, however CockroachDB operates on similar principles. Since they don't have access to atomic clocks and GPS units, they do make different trade-offs. In particular around reads & writes and lacking 'stale reads'. You can read more on the Jepsen blog:

Where Spanner waits after every write to ensure linearizability, CockroachDB blocks only on contested reads. As a consequence, its consistency guarantees are slightly weaker.



回答2:

As Dan said, the currently supported way is to have multiple instances (dev, staging, prod) or you can put multiple databases in a single instance so share resource costs across the environments.

We know that a local mock server is high on the list of productivity features that developers need.



回答3:

CockroachDB should behave similarly to Cloud Spanner for reads and you can run it natively on Mac OS X and Linux, and on Windows using Docker. For local development, the lack of TrueTime will not make a difference as everything is running on one machine.

For writes you're out of luck right now. Spanner has a custom API for writes while CockroachDB supports standard INSERT/UPDATE/DELETE statements. The upshot of this is that CockroachDB is more likely to work with your ORM of choice and we're working hard to extend that support.



回答4:

I wrote an emulator for Google Cloud Spanner to ease the development and testing of my open source JDBC driver for Cloud Spanner. The emulator does not in any way try to simulate the performance characteristics of Spanner, only to emulate its API (both read and write). Its intended use is for development and automated testing.

It is however not open source and currently in beta stage, but you can have a look here for a simple test project that runs against the emulator.