Thanks for investigating this, Kristian. Some comments inline...
Kristian Waagan wrote:
On 26.04.10 22:00, Rick Hillegas wrote:
I saw the following error in StreamingColumnTest when run as part of
the full JUnit suite on the 10.6 branch. I did not see this error
when I ran that test standalone on that branch or on the trunk. Has
anyone else seen this instability?
Hi Rick,
I hadn't, but when I tried harder it manifested on my system as well.
The message in the stack trace below was introduced by DERBY-2017, but
that's a red herring.
Obviously the bug is timing dependent, and the issues at play here are
DERBY-4315, DERBY-4531 and DERBY-2017. The direct cause is DERBY-4531,
where the finalizer closes the character stream. Depending on whether
Java is able to run the finalizer, the stream state differs (as
observed by the Derby client driver):
o returns -1 on read, results in XN017 [1] (stream open, EOF)
o throws IOException ("Stream closed"), results in XN014 [2].
Although XN017 is technically correct, one may argue that we could
introduce a special SQLState for the case where there is no data in
the user stream.
The JDBC spec seems to me to be vague in this area. At this time, the
major implementors may disagree on what the correct behavior is.
The simplest way to fix the instability is probably to fix DERBY-4531.
Before adjusting Derby, it probably would be worthwhile to survey the
JDBC expert group for their opinions about what is correct.
Opinions?
In the meantime, I think that we should put some defensive code in the
test in order to mask this non-deterministic behavior.
Also note that the embedded Derby driver is able to "reuse streams"
for certain data types. This is due to the fact that the source is
represented as a DVD, in this case SQLVarchar, and the DVD will
materialize the stream the first time it is inserted. I don't think
this will work [in all cases] if the column is BLOB or CLOB.
The question is whether we should disallow this usage or not. It can
be seen as a nice optimization, but to me this behavior isn't
intuitive. The same "optimization" can be achieved by using setString
instead of setXStream. The problem with keeping the current behavior
is that the code will work with embedded, but not with the client driver.
I'm afraid that I didn't follow this part of your analysis. Let me try
to restate what I think you may have said. Consider the following example:
ps.set???Stream( 1, userSuppliedStream, userSuppliedLength );
ps.executeUpdate();
ps.executeUpdate();
The JDBC spec does not explain what should happen on the second update.
Major implementors may handle the second update differently,
particularly if the stream is actually longer than userSuppliedLength (I
think there is wiggle room in the spec around whether the stream's
length is EXACTLY or AT LEAST userSuppliedLength).
Are you saying that Derby's behavior on the second update:
1) Differs depending on what the data type is
2) Differs depending on whether you are using the client or embedded driver
3) Differs depending on what kind of stream is being used (binary,
ascii, character)
4) Is non-deterministic
Thanks,
-Rick
Regards,