Google cloud platform 云扳手错误代码错误:9失败\u

Google cloud platform 云扳手错误代码错误:9失败\u,google-cloud-platform,google-cloud-functions,google-cloud-spanner,Google Cloud Platform,Google Cloud Functions,Google Cloud Spanner,当my cloud函数处于重载状态时开始接收此错误,触发次数超过5次/秒 Error: 9 FAILED_PRECONDITION: This transaction has been invalidated by a later transaction in the same session. 我正在用nodejs客户端运行一个读写事务 文件说: Operation was rejected because the system is not in a state required f

当my cloud函数处于重载状态时开始接收此错误,触发次数超过5次/秒

Error: 9 FAILED_PRECONDITION: This transaction has been invalidated by 
a later transaction in the same session. 
我正在用nodejs客户端运行一个读写事务

文件说:

Operation was rejected because the system is not in a state required 
for the operation's execution.
事务将芬兰语化,并将数据保存到扳手,因此不会拒绝事务。有人知道这是什么意思吗

这是我的密码:

“严格使用”;
const{span}=require('@googlecloud/span');
常数=要求('./常数');
const tableNames=constants.tableNames;
常量扳手=新扳手({projectId:constants.projectId});
exports.span同步=异步(数据、上下文)=>{
const instance=span.instance(constants.instanceId);
const database=instance.database(constants.databaseId);
试一试{
让它存在;
const[qOneRows]=等待存在(attrA、attrB、数据库);
if(qOneRows.length!==0&&qOneRows!==未定义){
profileExists=true;
}
upsertNewProfile(attrA、attrB、profileExists、数据库);
}捕获(错误){
console.log(错误);
}
};
函数存在(attrA、attrB、数据库){
常量查询={
sql:{
DML_配置文件_存在
},
参数:{
attr:attrA,
attrB:attrB
}
};
返回数据库。运行(查询);
}
函数deleteProfile(attrA、attrB、事务){
常量查询={
sql:DML_删除_配置文件,
参数:{
attr:attrA,
attrB:attrB
}
};
返回事务。运行更新(查询);
}
函数existsintable(attrB、attrA、数据库){
常量查询={
sql:EXISTS\U DML\U查询,
参数:{
阿特拉:阿特拉,
attrB:attrB
}
}
返回数据库。运行(查询);
}
异步函数upsertNewProfile(
attrA,attrB,
如果存在,
数据库
) {
让不活动=属性状态;
database.runTransaction(异步(错误,事务)=>{
如果(错误){
console.error('运行事务时出错:'+err);
回来
}
如果(存在){
试一试{
const deleted=等待删除配置文件(attrA、attrB、,
交易);
}捕获(错误){
console.log(“错误”+错误);
}
}
事务.upsert(tableNames.A,attrA);
事务.upsert(tableNames.B,attrB);
事务.upsert(tableNames.C,attrB.attrA);
事务.upsert(tableNames.D,attrB.attrB);
事务.upsert(tableNames.E,attrB.attrC);
事务.upsert(tableNames.F,attrB.attrD);
事务.upsert(tableNames.G,attrB.attrE);
事务.upsert(tableNames.H,attrB.attrF);
事务.upsert(tableNames.I,attrB.attrG);
事务.upsert(tableNames.J,attrB.attrH);
事务.upsert(tableNames.F,attrB.attrI);
如果(非活动){
let[pidExistInBL]=等待existsintable(attrA、attrB、数据库);
if(pidExistInBL.length==0){
upsert(tableNames.B,getObject(attrA,attrB));
}
}
试一试{
事务提交((错误)=>{
如果(!错误){
日志(“成功更新的表”);
}否则{
console.log(“错误”+错误);
}
});
}捕获(错误){
console.log(“错误”+错误);
}最后{
transaction.end();
}
});

}
云扳手一次只能在一台计算机上执行一个事务。您收到的错误消息表明您已在已具有活动事务的会话上启动了第二个事务

尝试对第一个不再有效的事务执行语句/查询时,将返回错误消息。第二次交易通常会成功

听起来您好像遇到了某种竞赛条件/会话泄漏问题。您是否有产生此错误的代码示例或更多详细信息


代码示例后编辑

我想知道如果

const deleted=wait deleteProfile(attrA、attrB、事务)
失败,因为这将在不显式结束事务的情况下终止事务。如果是可重试的错误,将在同一会话上自动重试新事务。由于初始事务尚未显式结束,该事务可能会生成您描述的错误消息,而重试的事务将成功


您可以尝试将该语句放在与提交类似的try-catch块中,看看这是否解决了问题。

Cloud Spaner一次只能在一个服务器上执行一个事务。您收到的错误消息表明您已在已具有活动事务的会话上启动了第二个事务

尝试对第一个不再有效的事务执行语句/查询时,将返回错误消息。第二次交易通常会成功

听起来您好像遇到了某种竞赛条件/会话泄漏问题。您是否有产生此错误的代码示例或更多详细信息


代码示例后编辑

我想知道如果

const deleted=wait deleteProfile(attrA、attrB、事务)
失败,因为这将在不显式结束事务的情况下终止事务。如果是可重试的错误,将在同一会话上自动重试新事务。由于初始事务尚未显式结束,该事务可能会生成您描述的错误消息,而重试的事务将成功

你可以