-
Notifications
You must be signed in to change notification settings - Fork 212
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
collections permit Presences/vrefs in keyShape/valueShape, but doesn't refcount them #7321
Comments
cc @erights |
@erights reports that we need this, "For example, the ledger uses an AmountPattern with the brand being the specific brand for that currency", and #3167 / #6432 depend upon it. Indeed, when I implemented the prohibition, I got a unit test failure from To fix it properly, we'll need to increment the The creation of the collection happens in response to a specific userspace action (it calls |
The collection schema (keyShape/valueShape) can refer to specific Remotable instances (e.g. Presence, or a durable object), rather than defining a constraint to be a whole category of objects. The collection schema metadata is thus a form of write-once state storage, like a tiny virtual object. Previously, defineKind failed to increment the refcount on the objects' vrefs, so when the collection falls out of memory, the object might be deleted, and then we would be unable to revive the constraint when loading the schema back in later. This changes the code to increment the refcounts of the vrefs in keyShape and valueShape when the collection is created, and decrement them when the collection is deleted. It handles ephemeral Remotables, as well as virtual/durable object Representatives. For durable collections, it also enforces the same `isDurable` check on the schema as it would on keys and values of the collection itself, so you cannot use a `Far()` or a merely-virtual object in the valueShape of a durable collection. closes #7321
The collection schema (keyShape/valueShape) can refer to specific Remotable instances (e.g. Presence, or a durable object), rather than defining a constraint to be a whole category of objects. The collection schema metadata is thus a form of write-once state storage, like a tiny virtual object. Previously, defineKind failed to increment the refcount on the objects' vrefs, so when the collection falls out of memory, the object might be deleted, and then we would be unable to revive the constraint when loading the schema back in later. This changes the code to increment the refcounts of the vrefs in keyShape and valueShape when the collection is created, and decrement them when the collection is deleted. It handles ephemeral Remotables, as well as virtual/durable object Representatives. For durable collections, it also enforces the same `isDurable` check on the schema as it would on keys and values of the collection itself, so you cannot use a `Far()` or a merely-virtual object in the valueShape of a durable collection. closes #7321
The collection schema (keyShape/valueShape) can refer to specific Remotable instances (e.g. Presence, or a durable object), rather than defining a constraint to be a whole category of objects. The collection schema metadata is thus a form of write-once state storage, like a tiny virtual object. Previously, defineKind failed to increment the refcount on the objects' vrefs, so when the collection falls out of memory, the object might be deleted, and then we would be unable to revive the constraint when loading the schema back in later. This changes the code to increment the refcounts of the vrefs in keyShape and valueShape when the collection is created, and decrement them when the collection is deleted. It handles ephemeral Remotables, as well as virtual/durable object Representatives. For durable collections, it also enforces the same `isDurable` check on the schema as it would on keys and values of the collection itself, so you cannot use a `Far()` or a merely-virtual object in the valueShape of a durable collection. closes #7321
The collection schema (keyShape/valueShape) can refer to specific Remotable instances (e.g. Presence, or a durable object), rather than defining a constraint to be a whole category of objects. The collection schema metadata is thus a form of write-once state storage, like a tiny virtual object. Previously, defineKind failed to increment the refcount on the objects' vrefs, so when the collection falls out of memory, the object might be deleted, and then we would be unable to revive the constraint when loading the schema back in later. This changes the code to increment the refcounts of the vrefs in keyShape and valueShape when the collection is created, and decrement them when the collection is deleted. It handles ephemeral Remotables, as well as virtual/durable object Representatives. For durable collections, it also enforces the same `isDurable` check on the schema as it would on keys and values of the collection itself, so you cannot use a `Far()` or a merely-virtual object in the valueShape of a durable collection. closes #7321
The collection schema (keyShape/valueShape) can refer to specific Remotable instances (e.g. Presence, or a durable object), rather than defining a constraint to be a whole category of objects. The collection schema metadata is thus a form of write-once state storage, like a tiny virtual object. Previously, defineKind failed to increment the refcount on the objects' vrefs, so when the collection falls out of memory, the object might be deleted, and then we would be unable to revive the constraint when loading the schema back in later. This changes the code to increment the refcounts of the vrefs in keyShape and valueShape when the collection is created, and decrement them when the collection is deleted. It handles ephemeral Remotables, as well as virtual/durable object Representatives. For durable collections, it also enforces the same `isDurable` check on the schema as it would on keys and values of the collection itself, so you cannot use a `Far()` or a merely-virtual object in the valueShape of a durable collection. closes #7321
The collection schema (keyShape/valueShape) can refer to specific Remotable instances (e.g. Presence, or a durable object), rather than defining a constraint to be a whole category of objects. The collection schema metadata is thus a form of write-once state storage, like a tiny virtual object. Previously, defineKind failed to increment the refcount on the objects' vrefs, so when the collection falls out of memory, the object might be deleted, and then we would be unable to revive the constraint when loading the schema back in later. This changes the code to increment the refcounts of the vrefs in keyShape and valueShape when the collection is created, and decrement them when the collection is deleted. It handles ephemeral Remotables, as well as virtual/durable object Representatives. For durable collections, it also enforces the same `isDurable` check on the schema as it would on keys and values of the collection itself, so you cannot use a `Far()` or a merely-virtual object in the valueShape of a durable collection. closes #7321
Describe the bug
Our virtual/durable collections (i.e.
makeScalarBigMapStore
) accept optionalkeyShape
andvalueShape
patterns, to restrict the kinds of keys and values that can be stored in each one. The patterns are defined with a constraint language, with terms both both categories of data (M.number()
accepts any Number), and specific values (using4
in a pattern will only accept the value4
, no other number). There is anM.remotable()
, which matches things like (imported) Presences and exported objects created withFar
, or virtual/durable Representatives. And if you include a specific Remotable in the pattern, then (apparently) that will only match against the specific instance.A specific Remotable could be used in a
keyShape
orvalueShape
too:However, using a specific Remotable like that is going to be problematic. Both
keyShape
andvalueShape
are serialized and stored in a special per-collectionvatstore
key named|schemata
, so that later vat incarnations (or later reanimations of the collection within the same vat incarnation) will be subject to the constraints as well. But if the shape had Remotables (Presences, Far()-generated ephemerals, or virtual/durable Representatives), the serialized form will have a vref, and we don't perform refcounting on those vrefs like we do for virtual-objectstate
or collection entries.Attempting to unserialize the schemata later might or might not find the corresponding object to be present in slotToVal. If the object was ephemeral, and it had been garbage-collected since the last usage, the
unserialize
will fail.This was less obvious before, because the schemata was held in RAM for the lifetime of the incarnation, so it would only show up in a post-upgrade access to the Remotable-in-valueShape-using collection. We didn't really acknowlege the high cardinality of collections at first, and have places where we hold per-collection data in RAM when it really ought to live primarily in the DB. One consequence of this is a syscall sensitivity to GC of collections, which is being addressed in #6360. That will cause more frequent unserialization of
|schemata
, making this problem become visible within even the current vat incarnation.The Fix
collectionManager.js
should assert thatserializedSchema.slots.length === 0
while creating the collection the first time.As this means
serializedSchema.body
contains the complete description of the schema, I'm tempted to go further and only record.body
, rather than our currentJSON.stringify(serializedSchema)
(including both.body
and.slots
). Then, on restore, dounserialize({ body: vatstoreGet(
..|schemata), slots: [] })
. That would make the saved data slightly smaller and simpler, but also completely excludes the possibility of unserializing vrefs in this context. Doing this would cause us backwards-compatibiltiy problems if we ever decided to find a way to lift this restriction, though.The text was updated successfully, but these errors were encountered: