filecoin-project / dagstore

a sharded store to hold large IPLD graphs efficiently, packaged as location-transparent attachable CAR files, with mechanical sympathy
Other
42 stars 24 forks source link

Mount Instantiate doesn't support reference subfields of mount #161

Open walldiss opened 1 year ago

walldiss commented 1 year ago

Mount Instantiate func, uses clone() function to initialise new value of mount from registered type template. clone() func creates a copy of each field of mount and thats it. So it assumes, that underlying type of mount should have all fields with value type. If any fields of template is a reference type (pointer, interface, map...), it will copy the reference value (e.g. pointer). In our case it resulted in all mounts to share same copy of pointer type and returning same mount on Get call, regardless of key.

So for example type

 type myMount struct{
   mount.Mount
} 

It fully implements mount.Mount interface (thx to embedding). The inner field being interface will be copied by reference. So all shards will have same pointer of the inner interface.

Few ideas how fix: