Skip to content

Commit

Permalink
implement bidi append
Browse files Browse the repository at this point in the history
  • Loading branch information
thefringeninja committed May 12, 2021
1 parent a853663 commit f89d063
Show file tree
Hide file tree
Showing 28 changed files with 772 additions and 111 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Nullable>disable</Nullable>
<NullableContextOptions>enable</NullableContextOptions>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<LangVersion>8.0</LangVersion>
<LangVersion>9.0</LangVersion>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<DebugType Condition=" '$(Configuration)' == 'Debug' ">full</DebugType>
<DebugType Condition=" '$(Configuration)' == 'Release' ">pdbonly</DebugType>
Expand Down
6 changes: 2 additions & 4 deletions src/EventStore.Client.Common/AsyncStreamReaderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading;

#if GRPC_CORE
namespace Grpc.Core {
using Grpc.Core;
namespace EventStore.Client {
internal static class AsyncStreamReaderExtensions {
public static async IAsyncEnumerable<T> ReadAllAsync<T>(this IAsyncStreamReader<T> reader,
[EnumeratorCancellation] CancellationToken cancellationToken = default) {
Expand All @@ -13,4 +12,3 @@ public static async IAsyncEnumerable<T> ReadAllAsync<T>(this IAsyncStreamReader<
}
}
}
#endif
8 changes: 4 additions & 4 deletions src/EventStore.Client.Common/EventStoreCallOptions.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
using System;
using System.Threading;
using Grpc.Core;

using Timeout_ = System.Threading.Timeout;
#nullable enable
namespace EventStore.Client {
internal static class EventStoreCallOptions {
public static CallOptions Create(EventStoreClientSettings settings,
EventStoreClientOperationOptions operationOptions, UserCredentials? userCredentials,
CancellationToken cancellationToken) => new CallOptions(
CancellationToken cancellationToken) => new(
cancellationToken: cancellationToken,
deadline: DeadlineAfter(operationOptions.TimeoutAfter),
headers: new Metadata(),
credentials: (settings.DefaultCredentials ?? userCredentials) == null
? null
: CallCredentials.FromInterceptor(async (context, metadata) => {
: CallCredentials.FromInterceptor(async (_, metadata) => {
var credentials = settings.DefaultCredentials ?? userCredentials;

var authorizationHeader = await settings.OperationOptions
Expand All @@ -25,7 +25,7 @@ public static CallOptions Create(EventStoreClientSettings settings,

private static DateTime? DeadlineAfter(TimeSpan? timeoutAfter) => !timeoutAfter.HasValue
? new DateTime?()
: timeoutAfter.Value == TimeSpan.MaxValue || timeoutAfter.Value == Timeout.InfiniteTimeSpan
: timeoutAfter.Value == TimeSpan.MaxValue || timeoutAfter.Value == Timeout_.InfiniteTimeSpan
? DateTime.MaxValue
: DateTime.UtcNow.Add(timeoutAfter.Value);
}
Expand Down
186 changes: 186 additions & 0 deletions src/EventStore.Client.Common/protos/code.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package google.rpc;

option go_package = "google.golang.org/genproto/googleapis/rpc/code;code";
option java_multiple_files = true;
option java_outer_classname = "CodeProto";
option java_package = "com.google.rpc";
option objc_class_prefix = "RPC";

// The canonical error codes for gRPC APIs.
//
//
// Sometimes multiple error codes may apply. Services should return
// the most specific error code that applies. For example, prefer
// `OUT_OF_RANGE` over `FAILED_PRECONDITION` if both codes apply.
// Similarly prefer `NOT_FOUND` or `ALREADY_EXISTS` over `FAILED_PRECONDITION`.
enum Code {
// Not an error; returned on success
//
// HTTP Mapping: 200 OK
OK = 0;

// The operation was cancelled, typically by the caller.
//
// HTTP Mapping: 499 Client Closed Request
CANCELLED = 1;

// Unknown error. For example, this error may be returned when
// a `Status` value received from another address space belongs to
// an error space that is not known in this address space. Also
// errors raised by APIs that do not return enough error information
// may be converted to this error.
//
// HTTP Mapping: 500 Internal Server Error
UNKNOWN = 2;

// The client specified an invalid argument. Note that this differs
// from `FAILED_PRECONDITION`. `INVALID_ARGUMENT` indicates arguments
// that are problematic regardless of the state of the system
// (e.g., a malformed file name).
//
// HTTP Mapping: 400 Bad Request
INVALID_ARGUMENT = 3;

// The deadline expired before the operation could complete. For operations
// that change the state of the system, this error may be returned
// even if the operation has completed successfully. For example, a
// successful response from a server could have been delayed long
// enough for the deadline to expire.
//
// HTTP Mapping: 504 Gateway Timeout
DEADLINE_EXCEEDED = 4;

// Some requested entity (e.g., file or directory) was not found.
//
// Note to server developers: if a request is denied for an entire class
// of users, such as gradual feature rollout or undocumented whitelist,
// `NOT_FOUND` may be used. If a request is denied for some users within
// a class of users, such as user-based access control, `PERMISSION_DENIED`
// must be used.
//
// HTTP Mapping: 404 Not Found
NOT_FOUND = 5;

// The entity that a client attempted to create (e.g., file or directory)
// already exists.
//
// HTTP Mapping: 409 Conflict
ALREADY_EXISTS = 6;

// The caller does not have permission to execute the specified
// operation. `PERMISSION_DENIED` must not be used for rejections
// caused by exhausting some resource (use `RESOURCE_EXHAUSTED`
// instead for those errors). `PERMISSION_DENIED` must not be
// used if the caller can not be identified (use `UNAUTHENTICATED`
// instead for those errors). This error code does not imply the
// request is valid or the requested entity exists or satisfies
// other pre-conditions.
//
// HTTP Mapping: 403 Forbidden
PERMISSION_DENIED = 7;

// The request does not have valid authentication credentials for the
// operation.
//
// HTTP Mapping: 401 Unauthorized
UNAUTHENTICATED = 16;

// Some resource has been exhausted, perhaps a per-user quota, or
// perhaps the entire file system is out of space.
//
// HTTP Mapping: 429 Too Many Requests
RESOURCE_EXHAUSTED = 8;

// The operation was rejected because the system is not in a state
// required for the operation's execution. For example, the directory
// to be deleted is non-empty, an rmdir operation is applied to
// a non-directory, etc.
//
// Service implementors can use the following guidelines to decide
// between `FAILED_PRECONDITION`, `ABORTED`, and `UNAVAILABLE`:
// (a) Use `UNAVAILABLE` if the client can retry just the failing call.
// (b) Use `ABORTED` if the client should retry at a higher level
// (e.g., when a client-specified test-and-set fails, indicating the
// client should restart a read-modify-write sequence).
// (c) Use `FAILED_PRECONDITION` if the client should not retry until
// the system state has been explicitly fixed. E.g., if an "rmdir"
// fails because the directory is non-empty, `FAILED_PRECONDITION`
// should be returned since the client should not retry unless
// the files are deleted from the directory.
//
// HTTP Mapping: 400 Bad Request
FAILED_PRECONDITION = 9;

// The operation was aborted, typically due to a concurrency issue such as
// a sequencer check failure or transaction abort.
//
// See the guidelines above for deciding between `FAILED_PRECONDITION`,
// `ABORTED`, and `UNAVAILABLE`.
//
// HTTP Mapping: 409 Conflict
ABORTED = 10;

// The operation was attempted past the valid range. E.g., seeking or
// reading past end-of-file.
//
// Unlike `INVALID_ARGUMENT`, this error indicates a problem that may
// be fixed if the system state changes. For example, a 32-bit file
// system will generate `INVALID_ARGUMENT` if asked to read at an
// offset that is not in the range [0,2^32-1], but it will generate
// `OUT_OF_RANGE` if asked to read from an offset past the current
// file size.
//
// There is a fair bit of overlap between `FAILED_PRECONDITION` and
// `OUT_OF_RANGE`. We recommend using `OUT_OF_RANGE` (the more specific
// error) when it applies so that callers who are iterating through
// a space can easily look for an `OUT_OF_RANGE` error to detect when
// they are done.
//
// HTTP Mapping: 400 Bad Request
OUT_OF_RANGE = 11;

// The operation is not implemented or is not supported/enabled in this
// service.
//
// HTTP Mapping: 501 Not Implemented
UNIMPLEMENTED = 12;

// Internal errors. This means that some invariants expected by the
// underlying system have been broken. This error code is reserved
// for serious errors.
//
// HTTP Mapping: 500 Internal Server Error
INTERNAL = 13;

// The service is currently unavailable. This is most likely a
// transient condition, which can be corrected by retrying with
// a backoff. Note that it is not always safe to retry
// non-idempotent operations.
//
// See the guidelines above for deciding between `FAILED_PRECONDITION`,
// `ABORTED`, and `UNAVAILABLE`.
//
// HTTP Mapping: 503 Service Unavailable
UNAVAILABLE = 14;

// Unrecoverable data loss or corruption.
//
// HTTP Mapping: 500 Internal Server Error
DATA_LOSS = 15;
}
41 changes: 40 additions & 1 deletion src/EventStore.Client.Common/protos/shared.proto
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
syntax = "proto3";
package event_store.client;
option java_package = "com.eventstore.client";
import "google/protobuf/empty.proto";

message UUID {
oneof value {
Expand All @@ -18,5 +19,43 @@ message Empty {

message StreamIdentifier {
reserved 1 to 2;
bytes streamName = 3;
bytes stream_name = 3;
}

message AllStreamPosition {
uint64 commit_position = 1;
uint64 prepare_position = 2;
}

message WrongExpectedVersion {
oneof current_stream_revision_option {
uint64 current_stream_revision = 1;
google.protobuf.Empty current_no_stream = 2;
}
oneof expected_stream_position_option {
uint64 expected_stream_position = 3;
google.protobuf.Empty expected_any = 4;
google.protobuf.Empty expected_stream_exists = 5;
google.protobuf.Empty expected_no_stream = 6;
}
}

message AccessDenied {}

message StreamDeleted {
StreamIdentifier stream_identifier = 1;
}

message Timeout {}

message Unknown {}

message InvalidTransaction {}

message MaximumAppendSizeExceeded {
uint32 maxAppendSize = 1;
}

message BadRequest {
string message = 1;
}
48 changes: 48 additions & 0 deletions src/EventStore.Client.Common/protos/status.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package google.rpc;

import "google/protobuf/any.proto";
import "code.proto";

option cc_enable_arenas = true;
option go_package = "google.golang.org/genproto/googleapis/rpc/status;status";
option java_multiple_files = true;
option java_outer_classname = "StatusProto";
option java_package = "com.google.rpc";
option objc_class_prefix = "RPC";

// The `Status` type defines a logical error model that is suitable for
// different programming environments, including REST APIs and RPC APIs. It is
// used by [gRPC](https://github.com/grpc). Each `Status` message contains
// three pieces of data: error code, error message, and error details.
//
// You can find out more about this error model and how to work with it in the
// [API Design Guide](https://cloud.google.com/apis/design/errors).
message Status {
// The status code, which should be an enum value of [google.rpc.Code][google.rpc.Code].
google.rpc.Code code = 1;

// A developer-facing error message, which should be in English. Any
// user-facing error message should be localized and sent in the
// [google.rpc.Status.details][google.rpc.Status.details] field, or localized by the client.
string message = 2;

// A list of messages that carry the error details. There is a common set of
// message types for APIs to use.
google.protobuf.Any details = 3;
}
Loading

0 comments on commit f89d063

Please sign in to comment.