Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
Questdb
提交
c93a85e1
Q
Questdb
项目概览
jobily
/
Questdb
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Q
Questdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c93a85e1
编写于
6月 23, 2019
作者:
V
Vlad Ilyushchenko
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
net: very raw draft of PostgreSQL wire protocol impl
上级
c1b7d531
变更
28
隐藏空白更改
内联
并排
Showing
28 changed file
with
783 addition
and
39 deletion
+783
-39
core/pom.xml
core/pom.xml
+7
-0
core/src/main/java/com/questdb/cutlass/http/HttpChunkedResponseSocket.java
...a/com/questdb/cutlass/http/HttpChunkedResponseSocket.java
+2
-0
core/src/main/java/com/questdb/cutlass/http/HttpConnectionContext.java
.../java/com/questdb/cutlass/http/HttpConnectionContext.java
+1
-4
core/src/main/java/com/questdb/cutlass/http/HttpMultipartContentListener.java
...om/questdb/cutlass/http/HttpMultipartContentListener.java
+3
-0
core/src/main/java/com/questdb/cutlass/http/HttpMultipartContentParser.java
.../com/questdb/cutlass/http/HttpMultipartContentParser.java
+2
-0
core/src/main/java/com/questdb/cutlass/http/HttpRawSocket.java
...src/main/java/com/questdb/cutlass/http/HttpRawSocket.java
+3
-0
core/src/main/java/com/questdb/cutlass/http/HttpRequestProcessor.java
...n/java/com/questdb/cutlass/http/HttpRequestProcessor.java
+2
-0
core/src/main/java/com/questdb/cutlass/http/HttpResponseHeader.java
...ain/java/com/questdb/cutlass/http/HttpResponseHeader.java
+2
-0
core/src/main/java/com/questdb/cutlass/http/HttpResponseSink.java
.../main/java/com/questdb/cutlass/http/HttpResponseSink.java
+2
-0
core/src/main/java/com/questdb/cutlass/http/processors/JsonQueryProcessor.java
...m/questdb/cutlass/http/processors/JsonQueryProcessor.java
+2
-0
core/src/main/java/com/questdb/cutlass/http/processors/StaticContentProcessor.java
...estdb/cutlass/http/processors/StaticContentProcessor.java
+2
-0
core/src/main/java/com/questdb/cutlass/http/processors/TableStatusCheckProcessor.java
...db/cutlass/http/processors/TableStatusCheckProcessor.java
+5
-1
core/src/main/java/com/questdb/cutlass/http/processors/TextImportProcessor.java
.../questdb/cutlass/http/processors/TextImportProcessor.java
+2
-0
core/src/main/java/com/questdb/cutlass/pgwire/WireParser.java
.../src/main/java/com/questdb/cutlass/pgwire/WireParser.java
+320
-0
core/src/main/java/com/questdb/cutlass/pgwire/WireParserConfiguration.java
...a/com/questdb/cutlass/pgwire/WireParserConfiguration.java
+34
-0
core/src/main/java/com/questdb/cutlass/pgwire/codecs/AbstractTypePrefixedHeader.java
...tdb/cutlass/pgwire/codecs/AbstractTypePrefixedHeader.java
+47
-0
core/src/main/java/com/questdb/cutlass/pgwire/codecs/Constants.java
...ain/java/com/questdb/cutlass/pgwire/codecs/Constants.java
+31
-0
core/src/main/java/com/questdb/cutlass/pgwire/codecs/NetworkByteOrderUtils.java
.../questdb/cutlass/pgwire/codecs/NetworkByteOrderUtils.java
+42
-0
core/src/main/java/com/questdb/cutlass/pgwire/codecs/in/QueryRequest.java
...va/com/questdb/cutlass/pgwire/codecs/in/QueryRequest.java
+31
-0
core/src/main/java/com/questdb/cutlass/pgwire/codecs/in/StartupMessage.java
.../com/questdb/cutlass/pgwire/codecs/in/StartupMessage.java
+9
-16
core/src/main/java/com/questdb/cutlass/pgwire/codecs/out/AuthenticationMD5PasswordMsg.java
...tlass/pgwire/codecs/out/AuthenticationMD5PasswordMsg.java
+3
-2
core/src/main/java/com/questdb/cutlass/pgwire/codecs/out/AuthenticationMsg.java
.../questdb/cutlass/pgwire/codecs/out/AuthenticationMsg.java
+33
-0
core/src/main/java/com/questdb/cutlass/pgwire/codecs/out/ParameterStatusMsg.java
...questdb/cutlass/pgwire/codecs/out/ParameterStatusMsg.java
+49
-0
core/src/main/java/com/questdb/cutlass/pgwire/codecs/out/ReadyForQueryMsg.java
...m/questdb/cutlass/pgwire/codecs/out/ReadyForQueryMsg.java
+33
-0
core/src/main/java/com/questdb/network/PeerDisconnectedException.java
...n/java/com/questdb/network/PeerDisconnectedException.java
+2
-2
core/src/main/java/com/questdb/network/PeerIsSlowToReadException.java
...n/java/com/questdb/network/PeerIsSlowToReadException.java
+2
-2
core/src/test/java/com/questdb/cutlass/http/IODispatcherTest.java
.../test/java/com/questdb/cutlass/http/IODispatcherTest.java
+19
-12
core/src/test/java/com/questdb/cutlass/pgwire/WireParserTest.java
.../test/java/com/questdb/cutlass/pgwire/WireParserTest.java
+93
-0
未找到文件。
core/pom.xml
浏览文件 @
c93a85e1
...
@@ -252,5 +252,12 @@
...
@@ -252,5 +252,12 @@
<version>
2.8.1
</version>
<version>
2.8.1
</version>
<scope>
test
</scope>
<scope>
test
</scope>
</dependency>
</dependency>
<dependency>
<groupId>
org.postgresql
</groupId>
<artifactId>
postgresql
</artifactId>
<version>
42.2.5
</version>
<scope>
test
</scope>
</dependency>
</dependencies>
</dependencies>
</project>
</project>
core/src/main/java/com/questdb/cutlass/http/HttpChunkedResponseSocket.java
浏览文件 @
c93a85e1
...
@@ -23,6 +23,8 @@
...
@@ -23,6 +23,8 @@
package
com.questdb.cutlass.http
;
package
com.questdb.cutlass.http
;
import
com.questdb.network.PeerDisconnectedException
;
import
com.questdb.network.PeerIsSlowToReadException
;
import
com.questdb.std.str.CharSink
;
import
com.questdb.std.str.CharSink
;
public
interface
HttpChunkedResponseSocket
extends
CharSink
{
public
interface
HttpChunkedResponseSocket
extends
CharSink
{
...
...
core/src/main/java/com/questdb/cutlass/http/HttpConnectionContext.java
浏览文件 @
c93a85e1
...
@@ -25,10 +25,7 @@ package com.questdb.cutlass.http;
...
@@ -25,10 +25,7 @@ package com.questdb.cutlass.http;
import
com.questdb.log.Log
;
import
com.questdb.log.Log
;
import
com.questdb.log.LogFactory
;
import
com.questdb.log.LogFactory
;
import
com.questdb.network.IOContext
;
import
com.questdb.network.*
;
import
com.questdb.network.IODispatcher
;
import
com.questdb.network.IOOperation
;
import
com.questdb.network.NetworkFacade
;
import
com.questdb.std.*
;
import
com.questdb.std.*
;
import
com.questdb.std.str.DirectByteCharSequence
;
import
com.questdb.std.str.DirectByteCharSequence
;
...
...
core/src/main/java/com/questdb/cutlass/http/HttpMultipartContentListener.java
浏览文件 @
c93a85e1
...
@@ -23,6 +23,9 @@
...
@@ -23,6 +23,9 @@
package
com.questdb.cutlass.http
;
package
com.questdb.cutlass.http
;
import
com.questdb.network.PeerDisconnectedException
;
import
com.questdb.network.PeerIsSlowToReadException
;
public
interface
HttpMultipartContentListener
{
public
interface
HttpMultipartContentListener
{
void
onChunk
(
HttpRequestHeader
partHeader
,
long
lo
,
long
hi
);
void
onChunk
(
HttpRequestHeader
partHeader
,
long
lo
,
long
hi
);
...
...
core/src/main/java/com/questdb/cutlass/http/HttpMultipartContentParser.java
浏览文件 @
c93a85e1
...
@@ -23,6 +23,8 @@
...
@@ -23,6 +23,8 @@
package
com.questdb.cutlass.http
;
package
com.questdb.cutlass.http
;
import
com.questdb.network.PeerDisconnectedException
;
import
com.questdb.network.PeerIsSlowToReadException
;
import
com.questdb.std.Mutable
;
import
com.questdb.std.Mutable
;
import
com.questdb.std.Unsafe
;
import
com.questdb.std.Unsafe
;
import
com.questdb.std.str.DirectByteCharSequence
;
import
com.questdb.std.str.DirectByteCharSequence
;
...
...
core/src/main/java/com/questdb/cutlass/http/HttpRawSocket.java
浏览文件 @
c93a85e1
...
@@ -23,6 +23,9 @@
...
@@ -23,6 +23,9 @@
package
com.questdb.cutlass.http
;
package
com.questdb.cutlass.http
;
import
com.questdb.network.PeerDisconnectedException
;
import
com.questdb.network.PeerIsSlowToReadException
;
public
interface
HttpRawSocket
{
public
interface
HttpRawSocket
{
long
getBufferAddress
();
long
getBufferAddress
();
...
...
core/src/main/java/com/questdb/cutlass/http/HttpRequestProcessor.java
浏览文件 @
c93a85e1
...
@@ -24,6 +24,8 @@
...
@@ -24,6 +24,8 @@
package
com.questdb.cutlass.http
;
package
com.questdb.cutlass.http
;
import
com.questdb.network.IODispatcher
;
import
com.questdb.network.IODispatcher
;
import
com.questdb.network.PeerDisconnectedException
;
import
com.questdb.network.PeerIsSlowToReadException
;
public
interface
HttpRequestProcessor
{
public
interface
HttpRequestProcessor
{
void
onHeadersReady
(
HttpConnectionContext
context
);
void
onHeadersReady
(
HttpConnectionContext
context
);
...
...
core/src/main/java/com/questdb/cutlass/http/HttpResponseHeader.java
浏览文件 @
c93a85e1
...
@@ -23,6 +23,8 @@
...
@@ -23,6 +23,8 @@
package
com.questdb.cutlass.http
;
package
com.questdb.cutlass.http
;
import
com.questdb.network.PeerDisconnectedException
;
import
com.questdb.network.PeerIsSlowToReadException
;
import
com.questdb.std.str.CharSink
;
import
com.questdb.std.str.CharSink
;
public
interface
HttpResponseHeader
extends
CharSink
{
public
interface
HttpResponseHeader
extends
CharSink
{
...
...
core/src/main/java/com/questdb/cutlass/http/HttpResponseSink.java
浏览文件 @
c93a85e1
...
@@ -26,6 +26,8 @@ package com.questdb.cutlass.http;
...
@@ -26,6 +26,8 @@ package com.questdb.cutlass.http;
import
com.questdb.log.Log
;
import
com.questdb.log.Log
;
import
com.questdb.log.LogFactory
;
import
com.questdb.log.LogFactory
;
import
com.questdb.network.NetworkFacade
;
import
com.questdb.network.NetworkFacade
;
import
com.questdb.network.PeerDisconnectedException
;
import
com.questdb.network.PeerIsSlowToReadException
;
import
com.questdb.std.*
;
import
com.questdb.std.*
;
import
com.questdb.std.ex.ZLibException
;
import
com.questdb.std.ex.ZLibException
;
import
com.questdb.std.str.AbstractCharSink
;
import
com.questdb.std.str.AbstractCharSink
;
...
...
core/src/main/java/com/questdb/cutlass/http/processors/JsonQueryProcessor.java
浏览文件 @
c93a85e1
...
@@ -37,6 +37,8 @@ import com.questdb.log.LogFactory;
...
@@ -37,6 +37,8 @@ import com.questdb.log.LogFactory;
import
com.questdb.log.LogRecord
;
import
com.questdb.log.LogRecord
;
import
com.questdb.network.IODispatcher
;
import
com.questdb.network.IODispatcher
;
import
com.questdb.network.IOOperation
;
import
com.questdb.network.IOOperation
;
import
com.questdb.network.PeerDisconnectedException
;
import
com.questdb.network.PeerIsSlowToReadException
;
import
com.questdb.std.*
;
import
com.questdb.std.*
;
import
com.questdb.std.str.CharSink
;
import
com.questdb.std.str.CharSink
;
...
...
core/src/main/java/com/questdb/cutlass/http/processors/StaticContentProcessor.java
浏览文件 @
c93a85e1
...
@@ -28,6 +28,8 @@ import com.questdb.log.Log;
...
@@ -28,6 +28,8 @@ import com.questdb.log.Log;
import
com.questdb.log.LogFactory
;
import
com.questdb.log.LogFactory
;
import
com.questdb.network.IODispatcher
;
import
com.questdb.network.IODispatcher
;
import
com.questdb.network.IOOperation
;
import
com.questdb.network.IOOperation
;
import
com.questdb.network.PeerDisconnectedException
;
import
com.questdb.network.PeerIsSlowToReadException
;
import
com.questdb.std.*
;
import
com.questdb.std.*
;
import
com.questdb.std.str.FileNameExtractorCharSequence
;
import
com.questdb.std.str.FileNameExtractorCharSequence
;
import
com.questdb.std.str.LPSZ
;
import
com.questdb.std.str.LPSZ
;
...
...
core/src/main/java/com/questdb/cutlass/http/processors/TableStatusCheckProcessor.java
浏览文件 @
c93a85e1
...
@@ -25,9 +25,13 @@ package com.questdb.cutlass.http.processors;
...
@@ -25,9 +25,13 @@ package com.questdb.cutlass.http.processors;
import
com.questdb.cairo.CairoEngine
;
import
com.questdb.cairo.CairoEngine
;
import
com.questdb.cairo.TableUtils
;
import
com.questdb.cairo.TableUtils
;
import
com.questdb.cutlass.http.*
;
import
com.questdb.cutlass.http.HttpChunkedResponseSocket
;
import
com.questdb.cutlass.http.HttpConnectionContext
;
import
com.questdb.cutlass.http.HttpRequestProcessor
;
import
com.questdb.network.IODispatcher
;
import
com.questdb.network.IODispatcher
;
import
com.questdb.network.IOOperation
;
import
com.questdb.network.IOOperation
;
import
com.questdb.network.PeerDisconnectedException
;
import
com.questdb.network.PeerIsSlowToReadException
;
import
com.questdb.std.Chars
;
import
com.questdb.std.Chars
;
import
com.questdb.std.Misc
;
import
com.questdb.std.Misc
;
import
com.questdb.std.str.Path
;
import
com.questdb.std.str.Path
;
...
...
core/src/main/java/com/questdb/cutlass/http/processors/TextImportProcessor.java
浏览文件 @
c93a85e1
...
@@ -34,6 +34,8 @@ import com.questdb.log.Log;
...
@@ -34,6 +34,8 @@ import com.questdb.log.Log;
import
com.questdb.log.LogFactory
;
import
com.questdb.log.LogFactory
;
import
com.questdb.network.IODispatcher
;
import
com.questdb.network.IODispatcher
;
import
com.questdb.network.IOOperation
;
import
com.questdb.network.IOOperation
;
import
com.questdb.network.PeerDisconnectedException
;
import
com.questdb.network.PeerIsSlowToReadException
;
import
com.questdb.std.*
;
import
com.questdb.std.*
;
import
com.questdb.std.str.CharSink
;
import
com.questdb.std.str.CharSink
;
...
...
core/src/main/java/com/questdb/cutlass/pgwire/WireParser.java
0 → 100644
浏览文件 @
c93a85e1
/*******************************************************************************
* ___ _ ____ ____
* / _ \ _ _ ___ ___| |_| _ \| __ )
* | | | | | | |/ _ \/ __| __| | | | _ \
* | |_| | |_| | __/\__ \ |_| |_| | |_) |
* \__\_\\__,_|\___||___/\__|____/|____/
*
* Copyright (C) 2014-2019 Appsicle
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
package
com.questdb.cutlass.pgwire
;
import
com.questdb.cutlass.pgwire.codecs.AbstractTypePrefixedHeader
;
import
com.questdb.cutlass.pgwire.codecs.in.StartupMessage
;
import
com.questdb.cutlass.pgwire.codecs.out.AuthenticationMsg
;
import
com.questdb.cutlass.pgwire.codecs.out.ParameterStatusMsg
;
import
com.questdb.cutlass.pgwire.codecs.out.ReadyForQueryMsg
;
import
com.questdb.log.Log
;
import
com.questdb.log.LogFactory
;
import
com.questdb.network.Net
;
import
com.questdb.network.NetworkFacade
;
import
com.questdb.network.PeerDisconnectedException
;
import
com.questdb.network.PeerIsSlowToReadException
;
import
com.questdb.std.Unsafe
;
import
com.questdb.std.str.DirectByteCharSequence
;
import
java.io.Closeable
;
public
class
WireParser
implements
Closeable
{
private
final
static
Log
LOG
=
LogFactory
.
getLog
(
WireParser
.
class
);
private
int
state
=
0
;
private
final
NetworkFacade
nf
;
private
final
long
recvBuffer
;
private
final
long
sendBuffer
;
private
final
int
recvBufferSize
;
private
final
int
sendBufferSize
;
private
long
recvBufferOffset
=
0
;
public
WireParser
(
WireParserConfiguration
configuration
)
{
this
.
nf
=
configuration
.
getNetworkFacade
();
this
.
recvBufferSize
=
configuration
.
getRecvBufferSize
();
this
.
recvBuffer
=
Unsafe
.
malloc
(
this
.
recvBufferSize
);
this
.
sendBufferSize
=
configuration
.
getSendBufferSize
();
this
.
sendBuffer
=
Unsafe
.
malloc
(
this
.
sendBufferSize
);
}
@Override
public
void
close
()
{
Unsafe
.
free
(
sendBuffer
,
sendBufferSize
);
Unsafe
.
free
(
recvBuffer
,
recvBufferSize
);
}
public
void
recv
(
long
fd
)
throws
PeerDisconnectedException
,
PeerIsSlowToReadException
{
final
int
remaining
=
(
int
)
(
recvBufferSize
-
recvBufferOffset
);
if
(
remaining
<
1
)
{
throw
new
RuntimeException
(
"buffer overflow"
);
}
final
int
n
=
Net
.
recv
(
fd
,
recvBuffer
+
recvBufferOffset
,
remaining
);
if
(
n
==
-
1
)
{
throw
PeerDisconnectedException
.
INSTANCE
;
}
if
(
n
==
0
)
{
// todo: stay in tight loop for a bit before giving up
// todo: this exception is misplaced - peer is writing here
throw
PeerIsSlowToReadException
.
INSTANCE
;
}
if
(
parse
(
fd
,
recvBuffer
,
n
))
{
recvBufferOffset
=
0
;
}
else
{
recvBufferOffset
+=
n
;
}
}
private
void
disconnectClient
(
long
fd
)
{
nf
.
close
(
fd
);
}
private
void
executeParseAndSendResult
(
long
fd
,
CharSequence
query
)
{
long
offset
;
// send 'ParseComplete'
AuthenticationMsg
.
setType
(
sendBuffer
,
(
byte
)
'1'
);
AuthenticationMsg
.
setLen
(
sendBuffer
,
4
);
offset
=
5
;
// Net.send(clientFd, sendBuffer, 5);
// send 'ReadyForQuery'
ReadyForQueryMsg
.
setType
(
sendBuffer
+
offset
,
(
byte
)
'Z'
);
ReadyForQueryMsg
.
setLen
(
sendBuffer
+
offset
,
5
);
ReadyForQueryMsg
.
setStatus
(
sendBuffer
+
offset
,
(
byte
)
'I'
);
Net
.
send
(
fd
,
sendBuffer
,
(
int
)
(
offset
+
6
));
}
/**
* returns address of where parsing stopped. If there are remaining bytes left
* int the buffer they need to be passed again in parse function along with
* any additional bytes received
*
* @param address
* @param len
* @return
*/
private
boolean
parse
(
long
fd
,
long
address
,
int
len
)
{
long
limit
=
address
+
len
;
int
msgLen
;
long
msgLimit
;
final
int
remaining
=
(
int
)
(
limit
-
address
);
switch
(
state
)
{
case
0
:
// expect startup request
if
(
remaining
<
4
)
{
return
false
;
}
// there is data for length
// this is quite specific to message type :(
msgLen
=
StartupMessage
.
getLen
(
address
);
// postgesql includes length bytes in length of message
// do we have the rest of the message?
if
(
msgLen
>
remaining
)
{
// we have length - get the rest when ready
return
false
;
}
// 'StartupMessage'
// consume message
// process protocol
int
protocol
=
StartupMessage
.
getProtocol
(
address
);
// todo: validate protocol, see 'NegotiateProtocolVersion'
// extract properties
msgLimit
=
address
+
msgLen
;
long
lo
=
address
+
8
;
// 8 is offset where name value pairs begin
// there is an extra byte at the end and it has to be 0
while
(
lo
<
msgLimit
-
1
)
{
long
hi
=
getStringLength
(
lo
,
msgLimit
);
// todo: close connection when protocol is broken
assert
hi
>
-
1
;
CharSequence
name
=
new
DirectByteCharSequence
().
of
(
lo
,
hi
);
// name is ready
lo
=
hi
+
1
;
hi
=
getStringLength
(
lo
,
msgLimit
);
assert
hi
>
-
1
;
CharSequence
value
=
new
DirectByteCharSequence
().
of
(
lo
,
hi
);
lo
=
hi
+
1
;
LOG
.
info
()
.
$
(
"protocol [major="
).
$
(
protocol
>>
16
)
.
$
(
", minor="
).
$
((
short
)
protocol
)
.
$
(
", name="
).
$
(
name
)
.
$
(
", value="
).
$
(
value
)
.
$
(
']'
).
$
();
}
// todo: close connection if protocol is violated
assert
Unsafe
.
getUnsafe
().
getByte
(
lo
)
==
0
;
// todo: check that there is no more data sent
assert
lo
+
1
==
limit
;
sendClearTextPasswordChallenge
(
fd
);
state
=
3
;
return
true
;
case
3
:
// this is a type-prefixed message
// we will wait until we receive the entire header
if
(
remaining
<
AbstractTypePrefixedHeader
.
LEN
)
{
// we need to be able to read header and length
return
false
;
}
msgLen
=
AbstractTypePrefixedHeader
.
getLen
(
address
);
// msgLen does not take into account type byte
if
(
msgLen
>
remaining
-
1
)
{
return
false
;
}
final
byte
type
=
AbstractTypePrefixedHeader
.
getType
(
address
);
LOG
.
info
().
$
(
"got msg '"
).
$
((
char
)
type
).
$
(
'\''
).
$
();
msgLimit
=
address
+
msgLen
+
1
;
lo
=
address
+
AbstractTypePrefixedHeader
.
LEN
;
// 8 is offset where name value pairs begin
switch
(
type
)
{
case
'p'
:
// +1 is 'type' byte that message length does not account for
long
hi
=
getStringLength
(
lo
,
msgLimit
);
CharSequence
password
=
new
DirectByteCharSequence
().
of
(
lo
,
hi
);
LOG
.
info
().
$
(
"password="
).
$
(
password
).
$
();
// todo: check that this is all client sent
assert
limit
==
msgLimit
;
// send login ok
sendLoginOk
(
fd
);
break
;
case
'P'
:
// 'Parse'
// this appears to be the execution side - we must at least return 'RowDescription'
// possibly more, check QueryExecutionImpl.processResults() in PG driver for more info
hi
=
getStringLength
(
lo
,
msgLimit
);
CharSequence
preparedStatementName
=
new
DirectByteCharSequence
().
of
(
lo
,
hi
);
LOG
.
info
().
$
(
"prepared statement name: "
).
$
(
preparedStatementName
).
$
();
lo
=
hi
+
1
;
hi
=
getStringLength
(
lo
,
msgLimit
);
CharSequence
query
=
new
DirectByteCharSequence
().
of
(
lo
,
hi
);
LOG
.
info
().
$
(
"query: "
).
$
(
query
).
$
();
// todo: read parameter information
executeParseAndSendResult
(
fd
,
query
);
break
;
case
'X'
:
// 'Terminate'
disconnectClient
(
fd
);
state
=
0
;
break
;
}
}
return
true
;
}
private
void
sendClearTextPasswordChallenge
(
long
fd
)
{
AuthenticationMsg
.
setType
(
sendBuffer
,
(
byte
)
'R'
);
AuthenticationMsg
.
setLen
(
sendBuffer
,
8
);
AuthenticationMsg
.
setResponseCode
(
sendBuffer
,
3
);
Net
.
send
(
fd
,
sendBuffer
,
9
);
// todo: deal with incomplete send
}
private
void
sendLoginOk
(
long
fd
)
{
// send login ok
// send authentication challenge
AuthenticationMsg
.
setType
(
sendBuffer
,
(
byte
)
'R'
);
AuthenticationMsg
.
setLen
(
sendBuffer
,
8
);
AuthenticationMsg
.
setResponseCode
(
sendBuffer
,
0
);
// Net.send(clientFd, sendBuffer, 9);
// length so far 9
// send 'ParameterStatus'
long
offset
=
9
;
offset
+=
ParameterStatusMsg
.
setParameterPair
(
sendBuffer
+
offset
,
"TimeZone"
,
"GMT"
);
offset
+=
ParameterStatusMsg
.
setParameterPair
(
sendBuffer
+
offset
,
"application_name"
,
"QuestDB"
);
offset
+=
ParameterStatusMsg
.
setParameterPair
(
sendBuffer
+
offset
,
"server_version_num"
,
"100000"
);
offset
+=
ParameterStatusMsg
.
setParameterPair
(
sendBuffer
+
offset
,
"integer_datetimes"
,
"on"
);
// send 'ReadyForQuery'
ReadyForQueryMsg
.
setType
(
sendBuffer
+
offset
,
(
byte
)
'Z'
);
ReadyForQueryMsg
.
setLen
(
sendBuffer
+
offset
,
5
);
ReadyForQueryMsg
.
setStatus
(
sendBuffer
+
offset
,
(
byte
)
'I'
);
nf
.
send
(
fd
,
sendBuffer
,
(
int
)
(
offset
+
6
));
}
private
long
getStringLength
(
long
x
,
long
limit
)
{
// calculate length
for
(
long
i
=
x
;
i
<
limit
;
i
++)
{
if
(
Unsafe
.
getUnsafe
().
getByte
(
i
)
==
0
)
{
return
i
;
}
}
return
-
1
;
}
@FunctionalInterface
public
interface
MessageHandler
{
int
onMessage
(
int
action
);
}
}
core/src/main/java/com/questdb/cutlass/pgwire/WireParserConfiguration.java
0 → 100644
浏览文件 @
c93a85e1
/*******************************************************************************
* ___ _ ____ ____
* / _ \ _ _ ___ ___| |_| _ \| __ )
* | | | | | | |/ _ \/ __| __| | | | _ \
* | |_| | |_| | __/\__ \ |_| |_| | |_) |
* \__\_\\__,_|\___||___/\__|____/|____/
*
* Copyright (C) 2014-2019 Appsicle
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
package
com.questdb.cutlass.pgwire
;
import
com.questdb.network.NetworkFacade
;
public
interface
WireParserConfiguration
{
NetworkFacade
getNetworkFacade
();
int
getRecvBufferSize
();
int
getSendBufferSize
();
}
core/src/main/java/com/questdb/cutlass/pgwire/codecs/AbstractTypePrefixedHeader.java
0 → 100644
浏览文件 @
c93a85e1
/*******************************************************************************
* ___ _ ____ ____
* / _ \ _ _ ___ ___| |_| _ \| __ )
* | | | | | | |/ _ \/ __| __| | | | _ \
* | |_| | |_| | __/\__ \ |_| |_| | |_) |
* \__\_\\__,_|\___||___/\__|____/|____/
*
* Copyright (C) 2014-2019 Appsicle
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
package
com.questdb.cutlass.pgwire.codecs
;
import
com.questdb.std.Unsafe
;
public
abstract
class
AbstractTypePrefixedHeader
{
public
static
final
int
LEN
=
5
;
public
static
int
getLen
(
long
address
)
{
return
NetworkByteOrderUtils
.
getInt
(
address
+
1
);
}
public
static
byte
getType
(
long
address
)
{
return
Unsafe
.
getUnsafe
().
getByte
(
address
);
}
public
static
void
setLen
(
long
address
,
int
len
)
{
NetworkByteOrderUtils
.
putInt
(
address
+
1
,
len
);
}
public
static
void
setType
(
long
address
,
byte
type
)
{
Unsafe
.
getUnsafe
().
putByte
(
address
,
type
);
}
}
core/src/main/java/com/questdb/cutlass/pgwire/codecs/Constants.java
0 → 100644
浏览文件 @
c93a85e1
/*******************************************************************************
* ___ _ ____ ____
* / _ \ _ _ ___ ___| |_| _ \| __ )
* | | | | | | |/ _ \/ __| __| | | | _ \
* | |_| | |_| | __/\__ \ |_| |_| | |_) |
* \__\_\\__,_|\___||___/\__|____/|____/
*
* Copyright (C) 2014-2019 Appsicle
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
package
com.questdb.cutlass.pgwire.codecs
;
public
final
class
Constants
{
public
static
final
int
AUTHENTICATION_OK
=
0
;
public
static
final
int
AUTHENTICATION_KRBv5
=
2
;
public
static
final
int
AUTHENTICATION_CLEARTEXT_PASSWORD
=
3
;
public
static
final
int
AUTHENTICATION_MD5_PASSWORD
=
5
;
}
core/src/main/java/com/questdb/cutlass/pgwire/codecs/NetworkByteOrderUtils.java
0 → 100644
浏览文件 @
c93a85e1
/*******************************************************************************
* ___ _ ____ ____
* / _ \ _ _ ___ ___| |_| _ \| __ )
* | | | | | | |/ _ \/ __| __| | | | _ \
* | |_| | |_| | __/\__ \ |_| |_| | |_) |
* \__\_\\__,_|\___||___/\__|____/|____/
*
* Copyright (C) 2014-2019 Appsicle
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
package
com.questdb.cutlass.pgwire.codecs
;
import
com.questdb.std.Unsafe
;
public
class
NetworkByteOrderUtils
{
public
static
int
getInt
(
long
address
)
{
int
b
=
Unsafe
.
getUnsafe
().
getByte
(
address
);
b
=
(
b
<<
8
)
|
Unsafe
.
getUnsafe
().
getByte
(
address
+
1
);
b
=
(
b
<<
8
)
|
Unsafe
.
getUnsafe
().
getByte
(
address
+
2
);
return
(
b
<<
8
)
|
Unsafe
.
getUnsafe
().
getByte
(
address
+
3
);
}
public
static
void
putInt
(
long
address
,
int
value
)
{
Unsafe
.
getUnsafe
().
putByte
(
address
,
(
byte
)
(
value
>>>
24
));
Unsafe
.
getUnsafe
().
putByte
(
address
+
1
,
(
byte
)
(
value
>>>
16
));
Unsafe
.
getUnsafe
().
putByte
(
address
+
2
,
(
byte
)
(
value
>>>
8
));
Unsafe
.
getUnsafe
().
putByte
(
address
+
3
,
(
byte
)
(
value
));
}
}
core/src/main/java/com/questdb/cutlass/pgwire/codecs/in/QueryRequest.java
0 → 100644
浏览文件 @
c93a85e1
/*******************************************************************************
* ___ _ ____ ____
* / _ \ _ _ ___ ___| |_| _ \| __ )
* | | | | | | |/ _ \/ __| __| | | | _ \
* | |_| | |_| | __/\__ \ |_| |_| | |_) |
* \__\_\\__,_|\___||___/\__|____/|____/
*
* Copyright (C) 2014-2019 Appsicle
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
package
com.questdb.cutlass.pgwire.codecs.in
;
import
com.questdb.cutlass.pgwire.codecs.AbstractTypePrefixedHeader
;
public
class
QueryRequest
extends
AbstractTypePrefixedHeader
{
}
core/src/main/java/com/questdb/
network/DisconnectReason
.java
→
core/src/main/java/com/questdb/
cutlass/pgwire/codecs/in/StartupMessage
.java
浏览文件 @
c93a85e1
...
@@ -21,23 +21,16 @@
...
@@ -21,23 +21,16 @@
*
*
******************************************************************************/
******************************************************************************/
package
com.questdb.
network
;
package
com.questdb.
cutlass.pgwire.codecs.in
;
public
final
class
DisconnectReason
{
import
com.questdb.cutlass.pgwire.codecs.NetworkByteOrderUtils
;
public
static
final
int
PEER
=
1
;
public
static
final
int
IDLE
=
2
;
public
static
final
int
SILLY
=
3
;
public
static
CharSequence
nameOf
(
int
disconnectReason
)
{
public
class
StartupMessage
{
switch
(
disconnectReason
)
{
public
static
int
getLen
(
long
address
)
{
case
PEER:
return
NetworkByteOrderUtils
.
getInt
(
address
);
return
"PEER"
;
}
case
IDLE:
return
"IDLE"
;
public
static
int
getProtocol
(
long
address
)
{
case
SILLY:
return
NetworkByteOrderUtils
.
getInt
(
address
+
4
);
return
"SILLY"
;
default
:
return
"UNKNOWN"
;
}
}
}
}
}
core/src/main/java/com/questdb/cutlass/
http/HttpFlowControlException
.java
→
core/src/main/java/com/questdb/cutlass/
pgwire/codecs/out/AuthenticationMD5PasswordMsg
.java
浏览文件 @
c93a85e1
...
@@ -21,7 +21,8 @@
...
@@ -21,7 +21,8 @@
*
*
******************************************************************************/
******************************************************************************/
package
com.questdb.cutlass.http
;
package
com.questdb.cutlass.pgwire.codecs.out
;
public
class
AuthenticationMD5PasswordMsg
extends
AuthenticationMsg
{
public
class
HttpFlowControlException
extends
Exception
{
}
}
core/src/main/java/com/questdb/cutlass/pgwire/codecs/out/AuthenticationMsg.java
0 → 100644
浏览文件 @
c93a85e1
/*******************************************************************************
* ___ _ ____ ____
* / _ \ _ _ ___ ___| |_| _ \| __ )
* | | | | | | |/ _ \/ __| __| | | | _ \
* | |_| | |_| | __/\__ \ |_| |_| | |_) |
* \__\_\\__,_|\___||___/\__|____/|____/
*
* Copyright (C) 2014-2019 Appsicle
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
package
com.questdb.cutlass.pgwire.codecs.out
;
import
com.questdb.cutlass.pgwire.codecs.AbstractTypePrefixedHeader
;
import
com.questdb.cutlass.pgwire.codecs.NetworkByteOrderUtils
;
public
class
AuthenticationMsg
extends
AbstractTypePrefixedHeader
{
public
static
void
setResponseCode
(
long
address
,
int
status
)
{
NetworkByteOrderUtils
.
putInt
(
address
+
AbstractTypePrefixedHeader
.
LEN
,
status
);
}
}
core/src/main/java/com/questdb/cutlass/pgwire/codecs/out/ParameterStatusMsg.java
0 → 100644
浏览文件 @
c93a85e1
/*******************************************************************************
* ___ _ ____ ____
* / _ \ _ _ ___ ___| |_| _ \| __ )
* | | | | | | |/ _ \/ __| __| | | | _ \
* | |_| | |_| | __/\__ \ |_| |_| | |_) |
* \__\_\\__,_|\___||___/\__|____/|____/
*
* Copyright (C) 2014-2019 Appsicle
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
package
com.questdb.cutlass.pgwire.codecs.out
;
import
com.questdb.cutlass.pgwire.codecs.AbstractTypePrefixedHeader
;
import
com.questdb.std.Unsafe
;
public
class
ParameterStatusMsg
extends
AbstractTypePrefixedHeader
{
public
static
int
setParameterPair
(
long
address
,
CharSequence
name
,
CharSequence
value
)
{
setType
(
address
,
(
byte
)
'S'
);
long
p
=
address
+
AbstractTypePrefixedHeader
.
LEN
;
final
long
start
=
p
;
p
=
copyStringZ
(
p
,
name
);
p
=
copyStringZ
(
p
,
value
);
int
len
=
(
int
)
(
p
-
start
);
setLen
(
address
,
len
+
AbstractTypePrefixedHeader
.
LEN
-
1
);
return
len
+
AbstractTypePrefixedHeader
.
LEN
;
}
private
static
long
copyStringZ
(
long
p
,
CharSequence
value
)
{
for
(
int
i
=
0
,
m
=
value
.
length
();
i
<
m
;
i
++)
{
Unsafe
.
getUnsafe
().
putByte
(
p
++,
(
byte
)
value
.
charAt
(
i
));
}
Unsafe
.
getUnsafe
().
putByte
(
p
,
(
byte
)
0
);
return
p
+
1
;
}
}
core/src/main/java/com/questdb/cutlass/pgwire/codecs/out/ReadyForQueryMsg.java
0 → 100644
浏览文件 @
c93a85e1
/*******************************************************************************
* ___ _ ____ ____
* / _ \ _ _ ___ ___| |_| _ \| __ )
* | | | | | | |/ _ \/ __| __| | | | _ \
* | |_| | |_| | __/\__ \ |_| |_| | |_) |
* \__\_\\__,_|\___||___/\__|____/|____/
*
* Copyright (C) 2014-2019 Appsicle
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
package
com.questdb.cutlass.pgwire.codecs.out
;
import
com.questdb.cutlass.pgwire.codecs.AbstractTypePrefixedHeader
;
import
com.questdb.std.Unsafe
;
public
class
ReadyForQueryMsg
extends
AbstractTypePrefixedHeader
{
public
static
void
setStatus
(
long
address
,
byte
status
)
{
Unsafe
.
getUnsafe
().
putByte
(
address
+
AbstractTypePrefixedHeader
.
LEN
,
status
);
}
}
core/src/main/java/com/questdb/
cutlass/http
/PeerDisconnectedException.java
→
core/src/main/java/com/questdb/
network
/PeerDisconnectedException.java
浏览文件 @
c93a85e1
...
@@ -21,8 +21,8 @@
...
@@ -21,8 +21,8 @@
*
*
******************************************************************************/
******************************************************************************/
package
com.questdb.
cutlass.http
;
package
com.questdb.
network
;
public
class
PeerDisconnectedException
extends
HttpFlowControl
Exception
{
public
class
PeerDisconnectedException
extends
Exception
{
public
static
final
PeerDisconnectedException
INSTANCE
=
new
PeerDisconnectedException
();
public
static
final
PeerDisconnectedException
INSTANCE
=
new
PeerDisconnectedException
();
}
}
core/src/main/java/com/questdb/
cutlass/http
/PeerIsSlowToReadException.java
→
core/src/main/java/com/questdb/
network
/PeerIsSlowToReadException.java
浏览文件 @
c93a85e1
...
@@ -21,8 +21,8 @@
...
@@ -21,8 +21,8 @@
*
*
******************************************************************************/
******************************************************************************/
package
com.questdb.
cutlass.http
;
package
com.questdb.
network
;
public
class
PeerIsSlowToReadException
extends
HttpFlowControl
Exception
{
public
class
PeerIsSlowToReadException
extends
Exception
{
public
static
final
PeerIsSlowToReadException
INSTANCE
=
new
PeerIsSlowToReadException
();
public
static
final
PeerIsSlowToReadException
INSTANCE
=
new
PeerIsSlowToReadException
();
}
}
core/src/test/java/com/questdb/cutlass/http/IODispatcherTest.java
浏览文件 @
c93a85e1
...
@@ -44,9 +44,8 @@ import com.questdb.std.str.StringSink;
...
@@ -44,9 +44,8 @@ import com.questdb.std.str.StringSink;
import
com.questdb.std.time.MillisecondClock
;
import
com.questdb.std.time.MillisecondClock
;
import
com.questdb.test.tools.TestUtils
;
import
com.questdb.test.tools.TestUtils
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.NotNull
;
import
org.junit.Assert
;
import
org.junit.*
;
import
org.junit.Ignore
;
import
org.junit.rules.TemporaryFolder
;
import
org.junit.Test
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
java.util.concurrent.atomic.AtomicBoolean
;
...
@@ -56,6 +55,14 @@ import java.util.concurrent.locks.LockSupport;
...
@@ -56,6 +55,14 @@ import java.util.concurrent.locks.LockSupport;
public
class
IODispatcherTest
{
public
class
IODispatcherTest
{
private
static
Log
LOG
=
LogFactory
.
getLog
(
IODispatcherTest
.
class
);
private
static
Log
LOG
=
LogFactory
.
getLog
(
IODispatcherTest
.
class
);
@Rule
public
TemporaryFolder
temp
=
new
TemporaryFolder
();
@Before
public
void
setUp
()
throws
Exception
{
temp
.
create
();
}
@Test
@Test
public
void
testBiasWrite
()
throws
Exception
{
public
void
testBiasWrite
()
throws
Exception
{
...
@@ -239,7 +246,7 @@ public class IODispatcherTest {
...
@@ -239,7 +246,7 @@ public class IODispatcherTest {
@Test
@Test
public
void
testImportMultipleOnSameConnection
()
throws
Exception
{
public
void
testImportMultipleOnSameConnection
()
throws
Exception
{
TestUtils
.
assertMemoryLeak
(()
->
{
TestUtils
.
assertMemoryLeak
(()
->
{
final
String
baseDir
=
System
.
getProperty
(
"java.io.tmpdir"
);
final
String
baseDir
=
temp
.
getRoot
().
getAbsolutePath
(
);
final
DefaultHttpServerConfiguration
httpConfiguration
=
createHttpServerConfiguration
(
baseDir
);
final
DefaultHttpServerConfiguration
httpConfiguration
=
createHttpServerConfiguration
(
baseDir
);
try
(
CairoEngine
engine
=
new
CairoEngine
(
new
DefaultCairoConfiguration
(
baseDir
));
try
(
CairoEngine
engine
=
new
CairoEngine
(
new
DefaultCairoConfiguration
(
baseDir
));
...
@@ -402,7 +409,7 @@ public class IODispatcherTest {
...
@@ -402,7 +409,7 @@ public class IODispatcherTest {
@Test
@Test
public
void
testImportMultipleOnSameConnectionFragmented
()
throws
Exception
{
public
void
testImportMultipleOnSameConnectionFragmented
()
throws
Exception
{
TestUtils
.
assertMemoryLeak
(()
->
{
TestUtils
.
assertMemoryLeak
(()
->
{
final
String
baseDir
=
System
.
getProperty
(
"java.io.tmpdir"
);
final
String
baseDir
=
temp
.
getRoot
().
getAbsolutePath
(
);
final
DefaultHttpServerConfiguration
httpConfiguration
=
createHttpServerConfiguration
(
baseDir
);
final
DefaultHttpServerConfiguration
httpConfiguration
=
createHttpServerConfiguration
(
baseDir
);
try
(
CairoEngine
engine
=
new
CairoEngine
(
new
DefaultCairoConfiguration
(
baseDir
));
try
(
CairoEngine
engine
=
new
CairoEngine
(
new
DefaultCairoConfiguration
(
baseDir
));
...
@@ -540,7 +547,7 @@ public class IODispatcherTest {
...
@@ -540,7 +547,7 @@ public class IODispatcherTest {
@Test
@Test
public
void
testImportMultipleOnSameConnectionSlow
()
throws
Exception
{
public
void
testImportMultipleOnSameConnectionSlow
()
throws
Exception
{
TestUtils
.
assertMemoryLeak
(()
->
{
TestUtils
.
assertMemoryLeak
(()
->
{
final
String
baseDir
=
System
.
getProperty
(
"java.io.tmpdir"
);
final
String
baseDir
=
temp
.
getRoot
().
getAbsolutePath
(
);
final
DefaultHttpServerConfiguration
httpConfiguration
=
createHttpServerConfiguration
(
baseDir
);
final
DefaultHttpServerConfiguration
httpConfiguration
=
createHttpServerConfiguration
(
baseDir
);
try
(
try
(
...
@@ -687,7 +694,7 @@ public class IODispatcherTest {
...
@@ -687,7 +694,7 @@ public class IODispatcherTest {
@Test
@Test
public
void
testJsonQuery
()
throws
Exception
{
public
void
testJsonQuery
()
throws
Exception
{
TestUtils
.
assertMemoryLeak
(()
->
{
TestUtils
.
assertMemoryLeak
(()
->
{
final
String
baseDir
=
System
.
getProperty
(
"java.io.tmpdir"
);
final
String
baseDir
=
temp
.
getRoot
().
getAbsolutePath
(
);
final
DefaultHttpServerConfiguration
httpConfiguration
=
createHttpServerConfiguration
(
baseDir
);
final
DefaultHttpServerConfiguration
httpConfiguration
=
createHttpServerConfiguration
(
baseDir
);
try
(
try
(
...
@@ -769,7 +776,7 @@ public class IODispatcherTest {
...
@@ -769,7 +776,7 @@ public class IODispatcherTest {
TestUtils
.
assertMemoryLeak
(()
->
{
TestUtils
.
assertMemoryLeak
(()
->
{
final
NetworkFacade
nf
=
NetworkFacadeImpl
.
INSTANCE
;
final
NetworkFacade
nf
=
NetworkFacadeImpl
.
INSTANCE
;
final
String
baseDir
=
System
.
getProperty
(
"java.io.tmpdir"
);
final
String
baseDir
=
temp
.
getRoot
().
getAbsolutePath
(
);
final
DefaultHttpServerConfiguration
httpConfiguration
=
createHttpServerConfiguration
(
nf
,
baseDir
,
128
);
final
DefaultHttpServerConfiguration
httpConfiguration
=
createHttpServerConfiguration
(
nf
,
baseDir
,
128
);
try
(
CairoEngine
engine
=
new
CairoEngine
(
new
DefaultCairoConfiguration
(
baseDir
));
try
(
CairoEngine
engine
=
new
CairoEngine
(
new
DefaultCairoConfiguration
(
baseDir
));
...
@@ -912,7 +919,7 @@ public class IODispatcherTest {
...
@@ -912,7 +919,7 @@ public class IODispatcherTest {
@Test
@Test
public
void
testJsonQuerySyntaxError
()
throws
Exception
{
public
void
testJsonQuerySyntaxError
()
throws
Exception
{
TestUtils
.
assertMemoryLeak
(()
->
{
TestUtils
.
assertMemoryLeak
(()
->
{
final
String
baseDir
=
System
.
getProperty
(
"java.io.tmpdir"
);
final
String
baseDir
=
temp
.
getRoot
().
getAbsolutePath
(
);
final
DefaultHttpServerConfiguration
httpConfiguration
=
createHttpServerConfiguration
(
baseDir
);
final
DefaultHttpServerConfiguration
httpConfiguration
=
createHttpServerConfiguration
(
baseDir
);
try
(
try
(
...
@@ -1087,7 +1094,7 @@ public class IODispatcherTest {
...
@@ -1087,7 +1094,7 @@ public class IODispatcherTest {
@Test
@Test
public
void
testSCPConnectDownloadDisconnect
()
throws
Exception
{
public
void
testSCPConnectDownloadDisconnect
()
throws
Exception
{
TestUtils
.
assertMemoryLeak
(()
->
{
TestUtils
.
assertMemoryLeak
(()
->
{
final
String
baseDir
=
System
.
getProperty
(
"java.io.tmpdir"
);
final
String
baseDir
=
temp
.
getRoot
().
getAbsolutePath
(
);
final
DefaultHttpServerConfiguration
httpConfiguration
=
createHttpServerConfiguration
(
baseDir
);
final
DefaultHttpServerConfiguration
httpConfiguration
=
createHttpServerConfiguration
(
baseDir
);
try
(
HttpServer
httpServer
=
new
HttpServer
(
httpConfiguration
))
{
try
(
HttpServer
httpServer
=
new
HttpServer
(
httpConfiguration
))
{
...
@@ -1266,7 +1273,7 @@ public class IODispatcherTest {
...
@@ -1266,7 +1273,7 @@ public class IODispatcherTest {
@Test
@Test
public
void
testSCPFullDownload
()
throws
Exception
{
public
void
testSCPFullDownload
()
throws
Exception
{
TestUtils
.
assertMemoryLeak
(()
->
{
TestUtils
.
assertMemoryLeak
(()
->
{
final
String
baseDir
=
System
.
getProperty
(
"java.io.tmpdir"
);
final
String
baseDir
=
temp
.
getRoot
().
getAbsolutePath
(
);
final
DefaultHttpServerConfiguration
httpConfiguration
=
createHttpServerConfiguration
(
baseDir
);
final
DefaultHttpServerConfiguration
httpConfiguration
=
createHttpServerConfiguration
(
baseDir
);
try
(
HttpServer
httpServer
=
new
HttpServer
(
httpConfiguration
))
{
try
(
HttpServer
httpServer
=
new
HttpServer
(
httpConfiguration
))
{
...
@@ -2097,7 +2104,7 @@ public class IODispatcherTest {
...
@@ -2097,7 +2104,7 @@ public class IODispatcherTest {
@Ignore
@Ignore
public
void
testUpload
()
throws
Exception
{
public
void
testUpload
()
throws
Exception
{
TestUtils
.
assertMemoryLeak
(()
->
{
TestUtils
.
assertMemoryLeak
(()
->
{
final
String
baseDir
=
System
.
getProperty
(
"java.io.tmpdir"
);
final
String
baseDir
=
temp
.
getRoot
().
getAbsolutePath
(
);
// final String baseDir = "/home/vlad/dev/123";
// final String baseDir = "/home/vlad/dev/123";
final
DefaultHttpServerConfiguration
httpConfiguration
=
createHttpServerConfiguration
(
baseDir
);
final
DefaultHttpServerConfiguration
httpConfiguration
=
createHttpServerConfiguration
(
baseDir
);
...
...
core/src/test/java/com/questdb/cutlass/pgwire/WireParserTest.java
0 → 100644
浏览文件 @
c93a85e1
/*******************************************************************************
* ___ _ ____ ____
* / _ \ _ _ ___ ___| |_| _ \| __ )
* | | | | | | |/ _ \/ __| __| | | | _ \
* | |_| | |_| | __/\__ \ |_| |_| | |_) |
* \__\_\\__,_|\___||___/\__|____/|____/
*
* Copyright (C) 2014-2019 Appsicle
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
package
com.questdb.cutlass.pgwire
;
import
com.questdb.network.*
;
import
com.questdb.std.Os
;
import
org.junit.Test
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.SQLException
;
import
java.util.Properties
;
public
class
WireParserTest
{
@Test
public
void
testSimple
()
throws
SQLException
{
// start simple server
long
fd
=
Net
.
socketTcp
(
true
);
WireParser
wireParser
=
new
WireParser
(
new
WireParserConfiguration
()
{
@Override
public
NetworkFacade
getNetworkFacade
()
{
return
NetworkFacadeImpl
.
INSTANCE
;
}
@Override
public
int
getRecvBufferSize
()
{
return
1024
*
1024
;
}
@Override
public
int
getSendBufferSize
()
{
return
1024
*
1024
;
}
});
Net
.
setReusePort
(
fd
);
if
(
Net
.
bindTcp
(
fd
,
0
,
9120
))
{
Net
.
listen
(
fd
,
128
);
new
Thread
(()
->
{
final
long
clientFd
=
Net
.
accept
(
fd
);
while
(
true
)
{
try
{
wireParser
.
recv
(
clientFd
);
}
catch
(
PeerDisconnectedException
e
)
{
break
;
}
catch
(
PeerIsSlowToReadException
ignored
)
{
}
}
}).
start
();
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
"user"
,
"xyz"
);
properties
.
setProperty
(
"password"
,
"oh"
);
properties
.
setProperty
(
"sslmode"
,
"disable"
);
final
Connection
connection
=
DriverManager
.
getConnection
(
"jdbc:postgresql://127.0.0.1:9120/nabu_app"
,
properties
);
// Statement statement = connection.createStatement();
// statement.executeQuery("select * from tab");
connection
.
close
();
}
else
{
throw
NetworkError
.
instance
(
Os
.
errno
()).
couldNotBindSocket
();
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录