Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id B4A139FB232 for ; Mon, 16 Jul 2007 11:49:32 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 97144-05 for ; Mon, 16 Jul 2007 11:49:17 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from wa-out-1112.google.com (wa-out-1112.google.com [209.85.146.181]) by postgresql.org (Postfix) with ESMTP id CD38C9FB4DA for ; Mon, 16 Jul 2007 11:49:25 -0300 (ADT) Received: by wa-out-1112.google.com with SMTP id k40so1812529wah for ; Mon, 16 Jul 2007 07:49:14 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=k4cqRTtxbhbz51n3p/r1SkH64hnXlq42pfMXEX97DniJeCgNK2sYKCa/hwrVuarN+EyaUiBSg94rkOxA0a3zrycDrQqwtyDOZcj17NamLvsmpeaJhFGuhMChb9B77FZ8u7v7XLvThJG286mRSiXEpAqAfFQAYMwkzPHqgKDB/1U= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=eWKy/2NomHUMt345twuMX2kMtG5nu/Cw29PjIF/e/I87FkjjIlRHObj9gjZE5pYoAYcecuGeAWjHqeZFmB6fzYXHYT5K1To/4t9r6zZQyFo/1XzV9p3h9WYnBVUbkk+cTzb6xIQY/Xn1AgdojTjNOhFZVOVGACpjLn3AtyeAf80= Received: by 10.114.14.1 with SMTP id 1mr4222230wan.1184597354248; Mon, 16 Jul 2007 07:49:14 -0700 (PDT) Received: by 10.114.151.9 with HTTP; Mon, 16 Jul 2007 07:49:14 -0700 (PDT) Message-ID: Date: Mon, 16 Jul 2007 17:49:14 +0300 From: "Kalle Hallivuori" To: "Kris Jurka" Subject: Re: Stream Copy for 8.1 - 8.3dev Cc: pgsql-jdbc@postgresql.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: X-Google-Sender-Auth: c0f21fa7829ba093 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/73 X-Sequence-Number: 17247 Hi again. Fixed versions of copy patches and drivers are now available at http://kato.iki.fi/sw/db/postgresql/jdbc/copy/ Unit tests do pass, but I had to postpone any more extensive tests for now. 2007/7/16, Kris Jurka : > 1) Your CopyObjects example pays no attention to encoding or escaping. > Calling getBytes() will give you bytes in the JVM's character set which > can easily be different than the client_encoding which the driver will > always set to UTF-8 (for 7.3 and up). You also have to think about what > happens when your data contains a null escape, delimiter, or newline > itself. Example dropped for now. Once the core implementation is considered acceptable, I'll add documentation and helper classes. > 2) I'm not sure it's helpful to have the copy methods throw both an IO and > SQL exception. Why not just wrap any IOExceptions inside a SQLException? Wrapped as suggested. > 3) What is the purpose of the reuse_buffer parameter? What is the use > case for someone wanting a "fresh" buffer every time? Dropped as unnecessary. > 4) buildCopyQuery doesn't handle quoting/escaping of identifiers. By > providing something like this you're now responsible for all the "hard" > stuff. I would leave it out unless you're prepared to do a lot more > thinking about it. It also doesn't handle all the possible copy options. > Perhaps you should split this into core copy functionality and a helper > class that builds upon it and can provide other useful things (escaping / > conversion of java objects to pg datatypes). Dropped as unnecessary. > 5) The coding in QueryExecutorImpl is unsafe because once you get > CopyInResponse you loop firing away data without listening for any return > data. Consider a table which had a trigger on it which issued a notice > for each row it received. If you don't read from the server the server > will block and then you'll block sending it data. See the comments in > core/v3/QueryExecutorImpl near MAX_BUFFERED_QUERIES for more details. Changed so that data is sent only while the server stays quiet. (Apparently I should write a test for this.) > 6) You mix warnings and errors together. They should be kept separate. Separated warnings from errors. After succesful recovery from copy subprotocol state: - if any errors were catched, they're thrown and warnings get dropped as a side effect; - if any warnings got collected, they're thrown, since I'm unsure about how to handle them. > 7) When you get CopyResponses and the user hasn't provided the appropriate > stream you bail leaving the protocol in an unknown state. You should > issue a CopyFail and wait for ReadyForQuery so the whole connection isn't > lost. Fixed as suggested. -- Kalle Hallivuori +358-41-5053073 http://korpiq.iki.fi/