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

Move relationship bulk import and export into permissions service #116

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
repos:
- repo: "https://github.com/bufbuild/buf"
rev: "v1.6.0"
hooks:
- id: "buf-lint"
- repo: "https://github.com/adrienverge/yamllint.git"
rev: "v1.29.0"
hooks:
- id: "yamllint"
72 changes: 71 additions & 1 deletion authzed/api/v1/permission_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,31 @@ service PermissionsService {
body: "*"
};
}

// ImportBulkRelationships is a faster path to writing a large number of
// relationships at once. It is both batched and streaming. For maximum
// performance, the caller should attempt to write relationships in as close
// to relationship sort order as possible: (resource.object_type,
// resource.object_id, relation, subject.object.object_type,
// subject.object.object_id, subject.optional_relation)
rpc ImportBulkRelationships(stream ImportBulkRelationshipsRequest)
returns (ImportBulkRelationshipsResponse) {
option (google.api.http) = {
post: "/v1/experimental/relationships/bulkimport"
body: "*"
};
}

// ExportBulkRelationships is the fastest path available to exporting
// relationships from the server. It is resumable, and will return results
// in an order determined by the server.
rpc ExportBulkRelationships(ExportBulkRelationshipsRequest)
returns (stream ExportBulkRelationshipsResponse) {
option (google.api.http) = {
post: "/v1/experimental/relationships/bulkexport"
body: "*"
};
}
}

// Consistency will define how a request is handled by the backend.
Expand Down Expand Up @@ -628,4 +653,49 @@ message ResolvedSubject {

// partial_caveat_info holds information of a partially-evaluated caveated response
PartialCaveatInfo partial_caveat_info = 3 [ (validate.rules).message.required = false ];
}
}

// ImportBulkRelationshipsRequest represents one batch of the streaming
// ImportBulkRelationships API. The maximum size is only limited by the backing
// datastore, and optimal size should be determined by the calling client
// experimentally.
message ImportBulkRelationshipsRequest {
repeated Relationship relationships = 1
[ (validate.rules).repeated .items.message.required = true ];
}

// ImportBulkRelationshipsResponse is returned on successful completion of the
// bulk load stream, and contains the total number of relationships loaded.
message ImportBulkRelationshipsResponse {
uint64 num_loaded = 1;
}

// ExportBulkRelationshipsRequest represents a resumable request for
// all relationships from the server.
message ExportBulkRelationshipsRequest {
Consistency consistency = 1;

// optional_limit, if non-zero, specifies the limit on the number of
// relationships the server can return in one page. By default, the server
// will pick a page size, and the server is free to choose a smaller size
// at will.
uint32 optional_limit = 2 [(validate.rules).uint32 = {gte:0}];

// optional_cursor, if specified, indicates the cursor after which results
// should resume being returned. The cursor can be found on the
// BulkExportRelationshipsResponse object.
Cursor optional_cursor = 3;

// optional_relationship_filter, if specified, indicates the
// filter to apply to each relationship to be exported.
RelationshipFilter optional_relationship_filter = 4;
}

// ExportBulkRelationshipsResponse is one page in a stream of relationship
// groups that meet the criteria specified by the originating request. The
// server will continue to stream back relationship groups as quickly as it can
// until all relationships have been transmitted back.
message ExportBulkRelationshipsResponse {
Cursor after_result_cursor = 1;
repeated Relationship relationships = 2;
}
Loading