Commit Graph

11 Commits

Author SHA1 Message Date
Torin Sandall 7e5c14f255 storage: Add context parameter to transactions and triggers
These changes update the storage to accept arbitrary key/value
parameters when creating transactions. The container is passed to
trigger callbacks that are invoked when transactions commit.

The use case for this is avoiding parse and compile operations on
modules loaded out of bundles. The parse and compile step on large
bundles can take several seconds. Since the triggers are executed
while the store's read-lock is held, policies queries block.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2019-06-24 11:57:51 -07:00
Stephan Renatus 2f1526c672 fix misspell
Signed-off-by: Stephan Renatus <srenatus@chef.io>
2018-06-05 09:50:13 -07:00
Matthew Mussomele 0b7e33661d Refactor Store interface to eliminate IDs for Trigger registration
The store used to require the user to supply a unique ID in order to
register a trigger. Instead, when registering a trigger, the Store now
returns a handle on which the trigger can be unregistered. This has a
number of benefits, including that the user no longer has to reason
about what IDs they have already used, and only the owner of the handle
can end the trigger.
2017-07-20 17:07:51 -07:00
Matthew Mussomele 5944e598ff Clarify that transactions are aborted when Committing fails
The Store interface was not clear if transactions need to be aborted
if committing them fails. This clarifies that a failed commit must be
equivalent to an abort.
2017-07-20 17:07:51 -07:00
Matthew Mussomele 7d3d379236 Augment Store triggers to provide more detailed information
Previously store triggers only told you whether data changed or
policy changed, they did not specify what data/policy changed or
how they changed. Now, TriggerEvents contain lists describing
all changes to policies and data that were made in a given commit.
2017-07-20 17:07:51 -07:00
Torin Sandall c786fc9d33 Add support for concurrent r/w txns
These changes update the storage layer to support
multi-reader/single-writer txns:

- Writers can read their own writes
- Writers can rollback changes
- Readers only see writes after a successful commit
- Readers can progress during a write txn and only block during a commit

These changes also refactor the trigger interface to better support
transactions.
2017-06-23 13:18:15 -07:00
Torin Sandall 10f22906b5 Refactor storage layer interfaces
This is a large change set that contains a few backwards incompatible
changes. Summary of breaking changes:

- Remove storage.Storage in favour of storage.Store interface.
- Remove mount support.
- Remove storage of compiled policies.
- Modify storage.Store to support rollback.
- Modify storage.Store to support raw policy storage.
- Modify storage.Store to support indexing.
2017-06-23 13:18:15 -07:00
Torin Sandall c3d1542754 Update storage to support context.Context
This includes all of the changes to plumb the context through from the HTTP
server and the REPL.

Also, this removes the Travis CI build for Go 1.6 as the context package is
not part of the standard library before Go 1.7. Once Go 1.8 is released we can
go back to supporting the previous Go release.

Fixes #155
2016-12-07 14:18:15 -08:00
Torin Sandall 26cd8e59ec Updates to use new storage.Path type
These changes refactor the storage layer to use storage.Path instead of ast.Ref
for Read/Write/Begin/Unmount/Mount operations.

Previously, the storage layer used ast.Ref values to refer to locations in
storage. Use of ast.Ref introduced unnecessary complexity for storage plugins
as they had to be aware of various details (e.g., array indices specified as
ast.Number/float64 values, potentially nested references, etc.) that were
unnecessary given that ast.Ref values passed to the storage layer were
intended represent JSON pointers.

These changes also remove the need for storage plugins to be aware of where
they are mounted. That is, the paths passed to the read call will be relative
to the mount point.

The remaining dependencies on the ast package from the storage package are for
(1) indexing and (2) policy storage. It may be possible to further decouple
these packages by revisiting how indexing is done and treating policies as
blobs.

Fixes #159
2016-12-02 10:29:33 -08:00
Torin Sandall 247362606b Update storage interfaces to support writes 2016-08-24 11:30:45 -07:00
Torin Sandall 9ad2f63212 Initial support for pluggable storage backends
These changes add support for pluggable storage backends. Previously, the
storage layer only supported a single, built-in, in-memory storage backend.
Users integrating with OPA would write a shim layer that pushed data into this
backend so that the policy engine could evaluate over it. This approach is not
sufficient when the dataset is too large to replicate or the process of
replication would introduce race conditions into systems integrated with OPA.

With these changes, users can implement their own storage backends for OPA. The
storage backends are "mounted" into the root document at a particular
location. References to data under this location are then served by the
user's storage backend. This allows the storage backend to fetch data from the
source of truth thereby avoiding race conditions (when that is important).

These changes introduce new interfaces in the storage layer:

- Transaction interface
- Store interface (i.e., the pluggable backend)
- Storage object, represents the policy engine's storage layer
- Trigger interface
2016-08-19 09:57:18 -07:00