Unnecessary locks and data share in MemoryDatastore struct implementation
As storageNodes
and virtualStorages
are read-only fields after struct initialization there is no need to protect access to them with lock.
Because entities are stored in the memory and shared between different goroutines by such methods as PickAPrimary
, GetPrimary
, GetRepository
we need to make them return a copy of the entity, so no concurrent modifications would be possible (same for the entities that have slices as their fields like models.Repository
for which Replicas
field needs to be cloned to use another array to prevent element modifications in the shared one between two repositories).