Repository navigation
CBEF-127: Throw on synchronous I/O by default; opt in with ConfigureWarnings - #188
davidkelly wants to merge 1 commit into
Conversation
74a9bd4 to
199ac4a
Compare
199ac4a to
0a6414e
Compare
emilienbev
left a comment
There was a problem hiding this comment.
Nice change. One behaviour in every build, with the same opt-in as Cosmos, is much easier to explain to users. One blocking issue on sync EnsureCreated(), the rest are small.
Nit. ExceptionHelper.SyncroIONotSupportedException has no callers after this change. Could we delete it?
| @@ -874,11 +878,8 @@ public override void Delete() | |||
| /// </returns> | |||
| public override bool Exists() | |||
There was a problem hiding this comment.
With the opt-in, sync EnsureCreated() runs EF's relational version, not ours. It calls Exists() and then HasTables(), which returns true here. So on an existing bucket it returns without creating collections, sequences or indexes. Could we override EnsureCreated() to check once and block on EnsureCreatedAsync, and add a case to SyncIoTests?
| /// <c>UseCouchbase</c>); when the application ignores or logs it, the caller then runs the | ||
| /// asynchronous operation and blocks on it. | ||
| /// </summary> | ||
| public static void SyncNotSupported<TLoggerCategory>(this IDiagnosticsLogger<TLoggerCategory> diagnostics) |
There was a problem hiding this comment.
Small thing. The check and the blocking call are paired by hand in about 15 places, so a few blocking paths still have no check. Two examples are CouchbaseConnection.Open(), which CreateDbCommand also calls, and CouchbaseDbDataReader.Read(). Could we add one helper that checks and then calls AsyncHelper.RunSync? If CouchbaseConnection.Open() used it, the Open override in CouchbaseRelationalConnection could go too.
| { | ||
| var connLogger = _loggerFactory?.CreateLogger<CouchbaseConnection>(); | ||
| return new CouchbaseConnection(_bucketProvider, _couchbaseDbContextOptionsBuilder, connLogger); | ||
| // Synchronous ADO.NET calls on this connection (BeginTransaction, Commit, Rollback, |
There was a problem hiding this comment.
Nit. BeginTransaction and Rollback don't go through this check, because neither does I/O. So the BeginTransactionAsync and RollbackAsync edits in ConnectionTests and TransactionTests aren't needed either. Could we fix the comment and keep those tests as they were?
|
|
||
| Assert.True(result is 0 or -1, $"Expected ExecuteNonQuery to return 0 or -1 for a SELECT query, but got {result}."); | ||
| outputHelper.WriteLine($"ExecuteNonQuery result: {result}"); | ||
| // Sync option B: synchronous I/O is rejected unless the context opts in |
There was a problem hiding this comment.
Nit. "Sync option B" points to a design discussion that readers of the code won't have. Could we drop it here and in FromRawSqlTests, SyncIoTests and CouchbaseTestStore?
…arnings The Couchbase SDK is asynchronous, so a synchronous EF call has to block a thread on it. Synchronous calls threw NotSupportedException in Release builds and blocked in Debug builds (#if DEBUG), so an application behaved differently in each, and there was no way to opt in. Synchronous calls now raise CouchbaseEventId.SyncNotSupported, a warning that UseCouchbase configures as an error, in every build (as Cosmos does). An application can allow blocking calls with ConfigureWarnings(w => w.Ignore(CouchbaseEventId.SyncNotSupported)), or log each one with w.Log(...). Covered: SaveChanges, synchronous query enumeration (LINQ and FromSql, now done by blocking on the async enumerator instead of throwing), EnsureCreated/EnsureDeleted/Exists, RelationalConnection.Open, sequence values on a synchronous Add, and Commit/Rollback/Execute* on connections a context creates. BeginTransaction on main starts a buffered transaction with no I/O, so it is not checked itself; it opens the connection, which is. SyncIoTests covers throw-by-default, opt-in (query, SaveChanges, transaction) and Log. Tests that used synchronous ADO calls use the async ones. Docs and CHANGELOG describe the opt-in. Spec harness: the test store ignores SyncNotSupported, so the synchronous variants of EF's tests reach their assertions instead of all failing on the rejected call. ConnectionInterceptionCouchbaseTest builds its own options for the bad-connection tests, so it ignores the warning there too.
0a6414e to
0fbd18d
Compare
Synchronous EF calls (
SaveChanges(),.ToList(),EnsureCreated(), ...) threwNotSupportedExceptionin Release builds and blocked in Debug builds, so an app behaveddifferently in each and had no way to opt in. This makes them throw by default in every
build, with an opt-in, as Cosmos does.
Change
CouchbaseEventId.SyncNotSupportedwarning, whichUseCouchbaseconfigures as an error. An app allows them withConfigureWarnings(w => w.Ignore(CouchbaseEventId.SyncNotSupported)), or logs each one withw.Log(...). The#if DEBUGsplits are gone.FromSqlqueries now works when enabled (it blocks onthe async enumerator) instead of throwing
NotImplementedException.assertions. Deletes the
sync-iorow fromroot-causes.tsv.Tests
SyncIoTests(throws by default,opt-in for query, SaveChanges and transaction, Log).
failures; 1,221 baseline failures now pass.
known-failures.txtis regenerated once, in CBEF-128: Generate integer keys from a Couchbase sequence by default #189,from a full CI run of the whole stack (CI fails only on new failures, so this PR is safe to merge
with the current list).
Stacked on #190, so the diff here shows only this change.
Jira: CBEF-127