our use case allows to read stale data (between 10 to 15s) so exploring staleness read using node or java client. In node we have Database.getSnapshot
or Database.runStream(sql, option)
-option we can mention different staleness strategy.
Snapshot
- we can have database, table, transaction snapshot, but database snapshot does not accept any option where as transaction snapshot accept option for Timebound.
My question is which way is effective way to read stale data?
1) using Database.getSnapshot or table.getSnapshot or transaction.getSnapshot?
2) using Database.runStream(sql, option) with max, exact staleness
Update
In node, I followed example mentioned in the link https://googleapis.dev/nodejs/spanner/latest/Snapshot.html#Snapshot-examples. and my code as follows
const timestampBounds = {
strong: false,
maxStaleness: 15000
}
databse.getSnapshot(timestampBounds, async (err, trans) => {
if (err) {
console.error(err);
return;
}
const [qOneRows] = await trans.run(query)
//resolve(qOneRows);
trans.end();
} );
I am getting below error
{ Error: 3 INVALID_ARGUMENT: Bad BeginTransaction request.
at Object.exports.createStatusError (/workspace/session-monitoring/node_modules/grpc/src/common.js:91:15)
at Object.onReceiveStatus (/workspace/session-monitoring/node_modules/grpc/src/client_interceptors.js:1204:28)
at InterceptingListener._callNext (/workspace/session-monitoring/node_modules/grpc/src/client_interceptors.js:568:42)
at InterceptingListener.onReceiveStatus (/workspace/session-monitoring/node_modules/grpc/src/client_interceptors.js:618:8)
at Object.onReceiveStatus (/workspace/session-monitoring/node_modules/grpc-gcp/src/index.ts:155:13)
at InterceptingListener._callNext (/workspace/session-monitoring/node_modules/grpc/src/client_interceptors.js:568:42)
at InterceptingListener.onReceiveStatus (/workspace/session-monitoring/node_modules/grpc/src/client_interceptors.js:618:8)
at callback (/workspace/session-monitoring/node_modules/grpc/src/client_interceptors.js:845:24)
code: 3,
metadata:
Metadata {
_internal_repr:
{ 'google.rpc.badrequest-bin': [Array],
'grpc-status-details-bin': [Array],
'grpc-server-stats-bin': [Array] },
flags: 0 },
details: 'Bad BeginTransaction request.',
note:
'Exception occurred in retry method that was not classified as transient' }
My spanner version is "@google-cloud/spanner": "^4.0.2" Node version is v10.11.0