planetarium / libplanet

Blockchain in C#/.NET for on-chain, decentralized gaming
https://docs.libplanet.io/
GNU Lesser General Public License v2.1
506 stars 142 forks source link

Make LiteDBStore.PutTransaction() idempotent #403

Closed longfin closed 5 years ago

longfin commented 5 years ago
08/06/2019 13:01:11 +00:00: Something went wrong during message parsing: "LiteDB.LiteException: Cannot insert duplicate key in unique index '_id'. The duplicate value is '\"tx/a0f44118c388ebe51c4b2d8371247fae32a85b2c6c38c6f5ad21670742d7a2c6\\00000\"'.
  at LiteDB.IndexService.AddNode (LiteDB.CollectionIndex index, LiteDB.BsonValue key, System.Byte level, LiteDB.IndexNode last) [0x00132] in <0e7fe05a592849968cfe23dfc2a26585>:0 
  at LiteDB.IndexService.AddNode (LiteDB.CollectionIndex index, LiteDB.BsonValue key, LiteDB.IndexNode last) [0x00028] in <0e7fe05a592849968cfe23dfc2a26585>:0 
  at LiteDB.LiteEngine.InsertDocument (LiteDB.CollectionPage col, LiteDB.BsonDocument doc, LiteDB.BsonType autoId) [0x001a6] in <0e7fe05a592849968cfe23dfc2a26585>:0 
  at LiteDB.LiteEngine+<>c__DisplayClass22_0.<Insert>b__0 (LiteDB.CollectionPage col) [0x00017] in <0e7fe05a592849968cfe23dfc2a26585>:0 
  at LiteDB.LiteEngine.Transaction[T] (System.String collection, System.Boolean addIfNotExists, System.Func`2[T,TResult] action) [0x0004e] in <0e7fe05a592849968cfe23dfc2a26585>:0 
  at LiteDB.LiteEngine.Insert (System.String collection, System.Collections.Generic.IEnumerable`1[T] docs, LiteDB.BsonType autoId) [0x00041] in <0e7fe05a592849968cfe23dfc2a26585>:0 
  at LiteDB.LiteEngine.Insert (System.String collection, LiteDB.BsonDocument doc, LiteDB.BsonType autoId) [0x00014] in <0e7fe05a592849968cfe23dfc2a26585>:0 
  at LiteDB.LiteFileStream.WriteChunks () [0x0009d] in <0e7fe05a592849968cfe23dfc2a26585>:0 
  at LiteDB.LiteFileStream.Flush () [0x00000] in <0e7fe05a592849968cfe23dfc2a26585>:0 
  at LiteDB.LiteFileStream.Dispose (System.Boolean disposing) [0x00017] in <0e7fe05a592849968cfe23dfc2a26585>:0 
  at System.IO.Stream.Close () [0x00000] in <1f0c1ef1ad524c38bbc5536809c46b48>:0 
  at System.IO.Stream.Dispose () [0x00000] in <1f0c1ef1ad524c38bbc5536809c46b48>:0 
  at LiteDB.LiteStorage.Upload (System.String id, System.String filename, System.IO.Stream stream) [0x00058] in <0e7fe05a592849968cfe23dfc2a26585>:0 
  at Libplanet.Store.LiteDBStore.UploadFile (System.String fileId, System.String filename, System.Byte[] bytes) [0x0001c] in <e16ca518ab934a82bde650ed7164c828>:0 
  at Libplanet.Store.LiteDBStore.PutTransaction[T] (Libplanet.Tx.Transaction`1[T] tx) [0x00022] in <e16ca518ab934a82bde650ed7164c828>:0 
  at Libplanet.Store.TransactionSet`1[T].set_Item (Libplanet.Tx.TxId key, Libplanet.Tx.Transaction`1[T] value) [0x00043] in <e16ca518ab934a82bde650ed7164c828>:0 
  at Libplanet.Blockchain.BlockChain`1[T].StageTransactions (System.Collections.Generic.IDictionary`2[TKey,TValue] transactions) [0x0002f] in <e16ca518ab934a82bde650ed7164c828>:0 
  at Libplanet.Net.Swarm`1+<ProcessTxIds>d__98[T].MoveNext () [0x00174] in <e16ca518ab934a82bde650ed7164c828>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <1f0c1ef1ad524c38bbc5536809c46b48>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <1f0c1ef1ad524c38bbc5536809c46b48>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <1f0c1ef1ad524c38bbc5536809c46b48>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <1f0c1ef1ad524c38bbc5536809c46b48>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <1f0c1ef1ad524c38bbc5536809c46b48>:0 
  at Libplanet.Net.Swarm`1+<ProcessMessageAsync>d__92[T].MoveNext () [0x0026f] in <e16ca518ab934a82bde650ed7164c828>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <1f0c1ef1ad524c38bbc5536809c46b48>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <1f0c1ef1ad524c38bbc5536809c46b48>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <1f0c1ef1ad524c38bbc5536809c46b48>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <1f0c1ef1ad524c38bbc5536809c46b48>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <1f0c1ef1ad524c38bbc5536809c46b48>:0 
  at Libplanet.Net.Swarm`1+<>c__DisplayClass112_0+<<ReceiveMessage>b__0>d[T].MoveNext () [0x0007b] in <e16ca518ab934a82bde650ed7164c828>:0 "

I think we can make LiteDBStore.PutTransaction() idempotent instead of throw duplicate error.

minhoryang commented 5 years ago

Is it unresolved with #413?

earlbread commented 5 years ago

Yes, it is resolved with #413.