com.scalar.db.exception.storage.NoMutationException:没有应用突变。使用 ScalarDB 时出错
com.scalar.db.exception.storage.NoMutationException: no mutation was applied. error when using ScalarDB
问题是关于标量数据库 (https://github.com/scalar-labs/scalardb)。
以下代码给出了 com.scalar.db.exception.storage.NoMutationException: no mutation was applied.
导致此错误的原因以及我该如何解决?
def updateConfirmedStatusAndDeleteToken(user:User,token:UserToken) = Future {
val transaction: DistributedTransaction = transactionService.start
logger.trace("transaction started: " + transaction);
//Perform the operations you want to group in the transaction
val pUserKey = new Key(new IntValue("bucket", utilities.bucketIDFromEmail(user.profile.externalProfileDetails.email)),
new TextValue("email", user.profile.externalProfileDetails.email)
)
val cUserKey = new Key(
new TextValue("authprovider", "credentials"),
new TextValue("firstname", user.profile.externalProfileDetails.firstName),
new TextValue("lastname", user.profile.externalProfileDetails.lastName)
)
logger.trace("created keys. ")
val putUser: Put = new Put(pUserKey, cUserKey)
.forNamespace("cj")
.forTable("users")
.withValue(new BooleanValue("confirmed", true))
logger.trace(s"putting user with confirmed status ${putUser}")
transaction.put(putUser)
logger.trace(s"reading token before deleting")
val pGetToken = new Key(new TextValue("token_id",token.tokenId.toString))
val getToken:Get = new Get(pGetToken)
.forNamespace("cj")
.forTable("user_authentication_token")
transaction.get(getToken)
logger.trace(s"deleting token. Preparing keys using ${token}, ${token.tokenId.toString}")
val pDeleteTokenKey = new Key(new TextValue("token_id",token.tokenId.toString))
logger.trace(s"delete key is ${pDeleteTokenKey}")
val deleteToken:Delete = new Delete(pDeleteTokenKey)
.forNamespace("cj")
.forTable("user_authentication_token")
transaction.delete(deleteToken)
try{
logger.trace(s"committing")
transaction.commit()
} catch {
case e1:UnknownTransactionStatusException =>{
logger.error("error in commiting. Unknowns status")
throw e1;
}
case e2:CommitException =>{
logger.error("error in commiting. Rolling back")
transaction.abort();
throw e2;
}
}
}
问题出在我对 DistributedTransaction 的使用上。我正在创建单独的 DistributedTransaction 实例,而不是在不同的数据库操作中使用单个实例。我在 updateConfirmedStatusAndDeleteToken
中创建了一个,但类似地在其他操作中创建了新的。现在我从顶层传递实例,以便所有操作都使用相同的实例。
问题是关于标量数据库 (https://github.com/scalar-labs/scalardb)。
以下代码给出了 com.scalar.db.exception.storage.NoMutationException: no mutation was applied.
导致此错误的原因以及我该如何解决?
def updateConfirmedStatusAndDeleteToken(user:User,token:UserToken) = Future {
val transaction: DistributedTransaction = transactionService.start
logger.trace("transaction started: " + transaction);
//Perform the operations you want to group in the transaction
val pUserKey = new Key(new IntValue("bucket", utilities.bucketIDFromEmail(user.profile.externalProfileDetails.email)),
new TextValue("email", user.profile.externalProfileDetails.email)
)
val cUserKey = new Key(
new TextValue("authprovider", "credentials"),
new TextValue("firstname", user.profile.externalProfileDetails.firstName),
new TextValue("lastname", user.profile.externalProfileDetails.lastName)
)
logger.trace("created keys. ")
val putUser: Put = new Put(pUserKey, cUserKey)
.forNamespace("cj")
.forTable("users")
.withValue(new BooleanValue("confirmed", true))
logger.trace(s"putting user with confirmed status ${putUser}")
transaction.put(putUser)
logger.trace(s"reading token before deleting")
val pGetToken = new Key(new TextValue("token_id",token.tokenId.toString))
val getToken:Get = new Get(pGetToken)
.forNamespace("cj")
.forTable("user_authentication_token")
transaction.get(getToken)
logger.trace(s"deleting token. Preparing keys using ${token}, ${token.tokenId.toString}")
val pDeleteTokenKey = new Key(new TextValue("token_id",token.tokenId.toString))
logger.trace(s"delete key is ${pDeleteTokenKey}")
val deleteToken:Delete = new Delete(pDeleteTokenKey)
.forNamespace("cj")
.forTable("user_authentication_token")
transaction.delete(deleteToken)
try{
logger.trace(s"committing")
transaction.commit()
} catch {
case e1:UnknownTransactionStatusException =>{
logger.error("error in commiting. Unknowns status")
throw e1;
}
case e2:CommitException =>{
logger.error("error in commiting. Rolling back")
transaction.abort();
throw e2;
}
}
}
问题出在我对 DistributedTransaction 的使用上。我正在创建单独的 DistributedTransaction 实例,而不是在不同的数据库操作中使用单个实例。我在 updateConfirmedStatusAndDeleteToken
中创建了一个,但类似地在其他操作中创建了新的。现在我从顶层传递实例,以便所有操作都使用相同的实例。