Skip to content

[Spanner] The default value (strong: true) hasn't been set when create a read-only transaction which cause slow data update #2542

@adam0x01

Description

@adam0x01

Hi,

If you follow the steps I listed below, I think you will get a very slow data update operation which will consume larger than 10 seconds(table().update()).
I found that if I add the option {strong: true} to call runTransaction, the update function will run at a reasonable speed.

According to the docs, the default timestamp bound types of the read-only transaction is Strong.
But I think the Spanner SDK ignore the default option in database.runTransaction.

Environment details

  • OS: macOS 10.11.6
  • Node.js version: 8.1.3
  • npm version: 5.0.3
  • google-cloud-node version: 0.7.1

Steps to reproduce

  1. require require('@google-cloud/spanner')
  2. Connect to Spanner
  3. Select an instance and a database without any workload
  4. create a table with this schema:
`CREATE TABLE bar (
	user_id STRING(64) NOT NULL,
	role STRING(64),
	level INT64
) PRIMARY KEY (user_id)`
  1. insert sample data:
let sampleData = [
	{'user_id': '1', 'role': 'coder','level': 1},
	{'user_id': '2', 'role': 'coder', 'level': 1}
];
  1. create a read-only transaction
  2. use this transaction to run the following sql
  3. and then update the record
let options = {
	readOnly: true
};
console.time('Step 1 read-only-transaction consume:');
database.runTransaction(options, function (err, transaction) {
	if (err) {
		throw (err);
	}

	let query1 = {
		sql: 'SELECT * FROM bar as t WHERE t.role = @role',
		params: {
			role: 'coder'
		}
	};
	transaction.run(query1, function (err1, dataset) {
		if (err1) {
			throw err1;
		}
		console.timeEnd('Step 1 read-only-transaction consume:');
		transaction.end();

		console.time('Step 2 DB update consume:');
		let dbOperation = [
			{user_id: '1', level: 2},
			{user_id: '2', level: 2}
		];

		database.table('bar').update(dbOperation, function (err2, apiResponse) {
			if (err2) {
				throw err2;
			}
			console.timeEnd('Step 2 DB update consume:');
		});
	});
});
  1. Get the following result(the step 2 consume large than 10 seconds)
Step 1 read-only-transaction consume:: 1562.155ms
Step 2 DB update consume:: 15148.733ms

Thanks!

Metadata

Metadata

Labels

api: spannerIssues related to the Spanner API.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions