Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EF key lookup bugs #1194

Closed
gmriggs opened this issue Dec 29, 2018 · 5 comments
Closed

EF key lookup bugs #1194

gmriggs opened this issue Dec 29, 2018 · 5 comments
Assignees

Comments

@gmriggs
Copy link
Collaborator

gmriggs commented Dec 29, 2018

Bug Report or Feature Request (mark with an x)

- [* ] bug report -> please search issues before submitting
- [ ] feature request

Repro steps.

create a new char, /addallspells, log out

The log given by the failure.

2018-12-29 14:26:18,371 ERROR: SaveBiota failed with exception: System.InvalidOperationException: The instance of entity type 'BiotaPropertiesSpellBook' cannot be tracked because another instance with the same key value for {'Id'} is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the conflicting key values.
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IdentityMap1.ThrowIdentityConflict(InternalEntityEntry entry) at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IdentityMap1.Add(TKey key, InternalEntityEntry entry, Boolean updateDuplicate)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.StartTracking(InternalEntityEntry entry)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState oldState, EntityState newState, Boolean acceptChanges)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityGraphAttacher.PaintAction(EntityEntryGraphNode node, Boolean force)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityEntryGraphIterator.TraverseGraph[TState](EntityEntryGraphNode node, TState state, Func3 handleNode) at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.NavigationCollectionChanged(InternalEntityEntry entry, INavigation navigation, IEnumerable1 added, IEnumerable1 removed) at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntryNotifier.NavigationCollectionChanged(InternalEntityEntry entry, INavigation navigation, IEnumerable1 added, IEnumerable`1 removed)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectNavigationChange(InternalEntityEntry entry, INavigation navigation)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectChanges(InternalEntityEntry entry)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectChanges(IStateManager stateManager)
at Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean acceptAllChangesOnSuccess)
at ACE.Database.ShardDatabase.SaveBiota(Biota biota, ReaderWriterLockSlim rwLock) in C:\dev\gmriggs\ACE\Source\ACE.Database\ShardDatabase.cs:line 225

Here is also a similar error reported by fartwhif, possibly related:

SaveBiota failed with exception: EFC.DbUpdateException: An error occurred while updating the entries. See inner ---> MySql.Data.MySqlClient.MySqlException: Duplicate entry '1342177281-629-1' for key 'wcid_enchantmentregistry_objectId_spellId_layerId_uidx' ---> MySql.Data.MySqlClient.MySqlException: Duplicate entry '1342177281-629-1' for key 'wcid_enchantmentregistry_objectId_spellId_layerId_uidx'
at MySqlConnector.Core.ResultSet.ReadResultSetHeaderAsync(IOBehavior ioBehavior) in src\MySqlConnector\Core\ResultSet.cs:line 44
--- End of inner ---
at MySql.Data.MySqlClient.MySqlDataReader.ActivateResultSet(ResultSet resultSet) in src\sqlcl\MySqlDataReader.cs:line 93
at MySql.Data.MySqlClient.MySqlDataReader.NextResultAsync(IOBehavior ioBehavior, CancellationToken cancellationToken) in src\sqlcl\MySqlDataReader.cs:line 62
at MySql.Data.MySqlClient.MySqlDataReader.NextResult() in src\sqlcl\MySqlDataReader.cs:line 26
at EFC.Update.AffectedCountModificationCommandBatch.Consume(RelationalDataReader reader)
--- End of inner ---
at EFC.Update.AffectedCountModificationCommandBatch.Consume(RelationalDataReader reader)
at EFC.Update.ReaderModificationCommandBatch.Execute(IRelationalConnection connection)
at EFC.Update.Internal.BatchExecutor.Execute(DbContext _, ValueTuple2 parameters) at Pomelo.EntityFrameworkCore.MySql.Storage.Internal.MySqlExecutionStrategy.Execute[TState,TResult](TState state, Func3 operation, Func3 verifySucceeded) at EFC.Update.Internal.BatchExecutor.Execute(IEnumerable1 commandBatches, IRelationalConnection connection)
at EFC.ChangeTracking.Internal.StateManager.SaveChanges(IReadOnlyList`1 entriesToSave)
at EFC.ChangeTracking.Internal.StateManager.SaveChanges(Boolean acceptAllChangesOnSuccess)
at EFC.DbContext.SaveChanges(Boolean acceptAllChangesOnSuccess)
at ACE.Database.ShardDatabase.SaveBiota(Biota biota, ReaderWriterLockSlim rwLock)

Desired functionality.

not crash

Mention any other details that might be useful.

@fartwhif
Copy link
Collaborator

fartwhif commented Dec 30, 2018

https://pastebin.com/Tz8a3qyX (this is with optionsBuilder.EnableSensitiveDataLogging(true);)

shardbugged.zip

log in with fartwhif, use any of the gems in the main backpack, do /save-now, and it happens

@Mag-nus
Copy link
Member

Mag-nus commented Dec 31, 2018

More simple instructions to duplicate:

/ci 9425
use the added gem
/save-now
/ci 9425
use the added gem
/save-now
... crash

@Mag-nus
Copy link
Member

Mag-nus commented Dec 31, 2018

Partially fixed wiht #1203

@gmriggs
Copy link
Collaborator Author

gmriggs commented Jan 3, 2019

XP lever bug:

Testing with this PR: #1213

/die
/save-now

2019-01-03 17:00:42,943 ERROR: SaveBiota failed with exception: Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException: Database operation expected to affect 1 row(s) but actually affected 0 row(s). Data may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=527962 for information on understanding and handling optimistic concurrency exceptions.
at Microsoft.EntityFrameworkCore.Update.AffectedCountModificationCommandBatch.ThrowAggregateUpdateConcurrencyException(Int32 commandIndex, Int32 expectedRowsAffected, Int32 rowsAffected)
at Microsoft.EntityFrameworkCore.Update.AffectedCountModificationCommandBatch.ConsumeResultSetWithPropagation(Int32 commandIndex, RelationalDataReader reader)
at Microsoft.EntityFrameworkCore.Update.AffectedCountModificationCommandBatch.Consume(RelationalDataReader reader)
at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute(IRelationalConnection connection)
at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(DbContext _, ValueTuple2 parameters) at Pomelo.EntityFrameworkCore.MySql.Storage.Internal.MySqlExecutionStrategy.Execute[TState,TResult](TState state, Func3 operation, Func3 verifySucceeded) at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(IEnumerable1 commandBatches, IRelationalConnection connection)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(IReadOnlyList`1 entriesToSave)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(Boolean acceptAllChangesOnSuccess)
at Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean acceptAllChangesOnSuccess)
at ACE.Database.ShardDatabase.SaveBiota(Biota biota, ReaderWriterLockSlim rwLock) in C:\dev\gmriggs\ACE\Source\ACE.Database\ShardDatabase.cs:line 225

@gmriggs gmriggs changed the title EF duplicate key EF key lookup bugs Jan 3, 2019
@gmriggs
Copy link
Collaborator Author

gmriggs commented Jan 4, 2019

This latest bug (expected to affect 1 row, but instead 0) seems to be fixed in #1213

@LtRipley36706 discovered the key insight, none of the data in a composite key column can be 0

Since vitae is the only spell that uses layer id 0, this is why we have only been seeing it with the vitae spell

The fix was to use layer id 1 for vitae internally in the db. Just to make sure everything matches up with retail exactly, when the vitae enchantment is sent across the network, it still sends layer 0 there

@gmriggs gmriggs closed this as completed Jan 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants