Azure / Azure/elastic-db-tools

Fix corner cases MultiShardDataReader's child reader handling

Open
#68 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
147
Forks
108
PR merge metrics
No merged PRs in 30d

Description

The MultiShardDataReader code which handles child readers (i.e. adding them, counting them, iterating through them) is confusing and internally incorrect. In particular, the below lines in the MultiShardDataReader constructor causes the MultiShardDataReader to immediately become closed, so when customer code calls .Read() a MultiShardReaderClosed exception is thrown. This is an extremely confusing exception for a customer to receive.
// Transition the reader to closed if there are no readers
if (_numReadersExpected == 0)
{
this.Close();
}
The MultiShardDataReader should either:
1. throw an exception in construction that bubbles up through ExecuteReader(), or
2. it should just return false for the first Read() (my preference, since it more closely matches SqlDataReader's behavior)

This fix will require some refactoring of the current code. MultiShardDataReader is a large and somewhat monolithic class with many private fields that make it difficult to reason about. My suggestion is that we extract the child reader iterating aspect into a separate class with a well-defined interface based on ConcurrentQueue, and extract the schema table comparison aspect into a separate class.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.