Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
Questdb
提交
7328cd25
Q
Questdb
项目概览
jobily
/
Questdb
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
7328cd25
编写于
1月 16, 2015
作者:
V
Vlad Ilyushchenko
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cluster bits (issue #29)
上级
e9aff645
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
188 addition
and
19 deletion
+188
-19
nfsdb-core/src/main/java/com/nfsdb/JournalWriter.java
nfsdb-core/src/main/java/com/nfsdb/JournalWriter.java
+1
-2
nfsdb-core/src/main/java/com/nfsdb/exceptions/ClusterLossException.java
.../main/java/com/nfsdb/exceptions/ClusterLossException.java
+23
-0
nfsdb-core/src/main/java/com/nfsdb/net/JournalClient.java
nfsdb-core/src/main/java/com/nfsdb/net/JournalClient.java
+39
-11
nfsdb-core/src/main/java/com/nfsdb/net/JournalServer.java
nfsdb-core/src/main/java/com/nfsdb/net/JournalServer.java
+15
-1
nfsdb-core/src/main/java/com/nfsdb/net/JournalServerAgent.java
...-core/src/main/java/com/nfsdb/net/JournalServerAgent.java
+18
-2
nfsdb-core/src/main/java/com/nfsdb/net/config/ServerConfig.java
...core/src/main/java/com/nfsdb/net/config/ServerConfig.java
+10
-1
nfsdb-core/src/main/java/com/nfsdb/net/model/Command.java
nfsdb-core/src/main/java/com/nfsdb/net/model/Command.java
+2
-1
nfsdb-core/src/main/java/com/nfsdb/tx/Tx.java
nfsdb-core/src/main/java/com/nfsdb/tx/Tx.java
+2
-1
nfsdb-core/src/test/java/com/nfsdb/net/ClusterTest.java
nfsdb-core/src/test/java/com/nfsdb/net/ClusterTest.java
+78
-0
未找到文件。
nfsdb-core/src/main/java/com/nfsdb/JournalWriter.java
浏览文件 @
7328cd25
/*
* Copyright (c) 2014
-2015
. Vlad Ilyushchenko
* Copyright (c) 2014. Vlad Ilyushchenko
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -729,7 +729,6 @@ public class JournalWriter<T> extends Journal<T> {
Partition
<
T
>
partition
=
lastNonEmptyNonLag
();
Partition
<
T
>
lag
=
getIrregularPartition
();
Tx
tx
=
new
Tx
();
tx
.
command
=
command
;
tx
.
prevTxAddress
=
txLog
.
getTxAddress
();
tx
.
journalMaxRowID
=
partition
==
null
?
0
:
Rows
.
toRowID
(
partition
.
getPartitionIndex
(),
partition
.
size
());
...
...
nfsdb-core/src/main/java/com/nfsdb/exceptions/ClusterLossException.java
0 → 100644
浏览文件 @
7328cd25
/*
* Copyright (c) 2014. Vlad Ilyushchenko
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com.nfsdb.exceptions
;
public
class
ClusterLossException
extends
JournalNetworkException
{
public
ClusterLossException
()
{
super
(
"Cluster already has a master. LOST."
);
}
}
nfsdb-core/src/main/java/com/nfsdb/net/JournalClient.java
浏览文件 @
7328cd25
/*
* Copyright (c) 2014
-2015
. Vlad Ilyushchenko
* Copyright (c) 2014. Vlad Ilyushchenko
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -198,21 +198,49 @@ public class JournalClient {
intResponseConsumer
.
reset
();
}
private
void
handshake
()
throws
JournalNetworkException
{
SocketChannel
channel
=
config
.
openSocketChannel
();
public
boolean
pingServer
()
{
try
{
statsChannel
=
new
StatsCollectingReadableByteChannel
(
channel
.
getRemoteAddress
());
}
catch
(
IOException
e
)
{
throw
new
JournalNetworkException
(
"Cannot get remote address"
,
e
);
openChannel
();
sendProtocolVersion
();
return
true
;
}
catch
(
JournalNetworkException
e
)
{
return
false
;
}
}
SslConfig
sslConfig
=
config
.
getSslConfig
();
if
(
sslConfig
.
isSecure
())
{
this
.
channel
=
new
SecureByteChannel
(
channel
,
sslConfig
);
}
else
{
this
.
channel
=
channel
;
boolean
sendClusterWin
(
int
instance
)
throws
JournalNetworkException
{
openChannel
();
commandProducer
.
write
(
channel
,
Command
.
CLUSTER_WIN
);
intResponseProducer
.
write
(
channel
,
instance
);
stringResponseConsumer
.
reset
();
stringResponseConsumer
.
read
(
channel
);
if
(!
stringResponseConsumer
.
isComplete
())
{
LOGGER
.
info
(
"Received incomplete response from cluster member."
);
return
false
;
}
return
"OK"
.
equals
(
stringResponseConsumer
.
getValue
());
}
private
void
openChannel
()
throws
JournalNetworkException
{
if
(
this
.
channel
==
null
)
{
SocketChannel
channel
=
config
.
openSocketChannel
();
try
{
statsChannel
=
new
StatsCollectingReadableByteChannel
(
channel
.
getRemoteAddress
());
}
catch
(
IOException
e
)
{
throw
new
JournalNetworkException
(
"Cannot get remote address"
,
e
);
}
SslConfig
sslConfig
=
config
.
getSslConfig
();
if
(
sslConfig
.
isSecure
())
{
this
.
channel
=
new
SecureByteChannel
(
channel
,
sslConfig
);
}
else
{
this
.
channel
=
channel
;
}
}
}
private
void
handshake
()
throws
JournalNetworkException
{
openChannel
();
sendProtocolVersion
();
sendKeys
();
checkAuthAndSendCredential
();
...
...
nfsdb-core/src/main/java/com/nfsdb/net/JournalServer.java
浏览文件 @
7328cd25
/*
* Copyright (c) 2014
-2015
. Vlad Ilyushchenko
* Copyright (c) 2014. Vlad Ilyushchenko
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -19,6 +19,7 @@ package com.nfsdb.net;
import
com.nfsdb.JournalKey
;
import
com.nfsdb.JournalWriter
;
import
com.nfsdb.concurrent.NamedDaemonThreadFactory
;
import
com.nfsdb.exceptions.ClusterLossException
;
import
com.nfsdb.exceptions.JournalDisconnectedChannelException
;
import
com.nfsdb.exceptions.JournalNetworkException
;
import
com.nfsdb.factory.JournalReaderFactory
;
...
...
@@ -161,6 +162,10 @@ public class JournalServer {
return
channels
.
size
();
}
public
int
getClusterInstance
()
{
return
config
.
getClusterInstance
();
}
int
getWriterIndex
(
JournalKey
key
)
{
for
(
int
i
=
0
,
sz
=
writers
.
size
();
i
<
sz
;
i
++)
{
JournalKey
jk
=
writers
.
get
(
i
).
getKey
();
...
...
@@ -232,6 +237,7 @@ public class JournalServer {
@Override
public
void
run
()
{
boolean
haltServer
=
false
;
try
{
while
(
true
)
{
if
(!
running
.
get
())
{
...
...
@@ -241,6 +247,10 @@ public class JournalServer {
agent
.
process
(
holder
.
byteChannel
);
}
catch
(
JournalDisconnectedChannelException
e
)
{
break
;
}
catch
(
ClusterLossException
e
)
{
haltServer
=
true
;
LOGGER
.
info
(
e
.
getMessage
());
break
;
}
catch
(
JournalNetworkException
e
)
{
if
(
running
.
get
())
{
LOGGER
.
info
(
"Client died: "
+
holder
.
socketAddress
);
...
...
@@ -263,6 +273,10 @@ public class JournalServer {
agent
.
close
();
removeChannel
(
holder
);
}
if
(
haltServer
)
{
halt
();
}
}
}
}
nfsdb-core/src/main/java/com/nfsdb/net/JournalServerAgent.java
浏览文件 @
7328cd25
/*
* Copyright (c) 2014
-2015
. Vlad Ilyushchenko
* Copyright (c) 2014. Vlad Ilyushchenko
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -20,6 +20,7 @@ import com.nfsdb.Journal;
import
com.nfsdb.JournalKey
;
import
com.nfsdb.collections.DirectIntList
;
import
com.nfsdb.collections.Lists
;
import
com.nfsdb.exceptions.ClusterLossException
;
import
com.nfsdb.exceptions.JournalDisconnectedChannelException
;
import
com.nfsdb.exceptions.JournalException
;
import
com.nfsdb.exceptions.JournalNetworkException
;
...
...
@@ -99,6 +100,22 @@ public class JournalServerAgent {
commandConsumer
.
reset
();
}
break
;
case
CLUSTER_WIN:
checkAuthorized
(
channel
);
intResponseConsumer
.
read
(
channel
);
if
(
intResponseConsumer
.
isComplete
())
{
boolean
loss
=
intResponseConsumer
.
getValue
()
>
server
.
getClusterInstance
();
intResponseConsumer
.
reset
();
commandConsumer
.
reset
();
if
(
loss
)
{
ok
(
channel
);
throw
new
ClusterLossException
();
}
else
{
error
(
channel
,
"WIN"
);
}
}
break
;
case
HANDSHAKE_COMPLETE:
if
(
authorized
)
{
ok
(
channel
);
...
...
@@ -184,7 +201,6 @@ public class JournalServerAgent {
}
else
{
error
(
channel
,
"Unsupported protocol version. Client: "
+
version
+
", Server: "
+
Version
.
PROTOCOL_VERSION
);
}
}
private
<
T
>
void
createReader
(
int
index
,
JournalKey
<
T
>
key
)
throws
JournalException
{
...
...
nfsdb-core/src/main/java/com/nfsdb/net/config/ServerConfig.java
浏览文件 @
7328cd25
/*
* Copyright (c) 2014
-2015
. Vlad Ilyushchenko
* Copyright (c) 2014. Vlad Ilyushchenko
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -33,6 +33,7 @@ public class ServerConfig extends NetworkConfig {
private
static
final
Logger
LOGGER
=
Logger
.
getLogger
(
ServerConfig
.
class
);
private
long
heartbeatFrequency
=
DEFAULT_HEARTBEAT_FREQUENCY
;
private
int
eventBufferSize
=
RING_BUFFER_SIZE
;
private
int
clusterInstance
=
0
;
public
long
getHeartbeatFrequency
()
{
return
heartbeatFrequency
;
...
...
@@ -67,4 +68,12 @@ public class ServerConfig extends NetworkConfig {
throw
new
JournalNetworkException
(
"Cannot open server socket"
,
e
);
}
}
public
int
getClusterInstance
()
{
return
clusterInstance
;
}
public
void
setClusterInstance
(
int
clusterInstance
)
{
this
.
clusterInstance
=
clusterInstance
;
}
}
nfsdb-core/src/main/java/com/nfsdb/net/model/Command.java
浏览文件 @
7328cd25
/*
* Copyright (c) 2014
-2015
. Vlad Ilyushchenko
* Copyright (c) 2014. Vlad Ilyushchenko
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -28,6 +28,7 @@ public enum Command {
PROTOCOL_VERSION
(
0x08
),
HANDSHAKE_COMPLETE
(
0x09
),
AUTHORIZATION
(
0x0a
),
CLUSTER_WIN
(
0x0b
),
UNAUTHENTIC
(
0xFC
),
UNKNOWN_CMD
(
0xFE
);
...
...
nfsdb-core/src/main/java/com/nfsdb/tx/Tx.java
浏览文件 @
7328cd25
/*
* Copyright (c) 2014
-2015
. Vlad Ilyushchenko
* Copyright (c) 2014. Vlad Ilyushchenko
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -22,6 +22,7 @@ public class Tx {
public
static
final
byte
TX_NORMAL
=
0
;
public
static
final
byte
TX_FORCE
=
1
;
public
static
final
byte
TX_PRECOMMIT
=
2
;
// transient
public
long
address
;
// 8
...
...
nfsdb-core/src/test/java/com/nfsdb/net/ClusterTest.java
0 → 100644
浏览文件 @
7328cd25
/*
* Copyright (c) 2014. Vlad Ilyushchenko
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com.nfsdb.net
;
import
com.nfsdb.net.config.ClientConfig
;
import
com.nfsdb.net.config.ServerConfig
;
import
com.nfsdb.test.tools.AbstractTest
;
import
org.junit.Test
;
import
java.util.concurrent.TimeUnit
;
public
class
ClusterTest
extends
AbstractTest
{
@Test
public
void
testBasicClusterWin
()
throws
Exception
{
JournalServer
server
=
new
JournalServer
(
new
ServerConfig
()
{{
setHostname
(
"localhost"
);
setPort
(
7079
);
setHeartbeatFrequency
(
TimeUnit
.
MILLISECONDS
.
toMillis
(
100
));
setEnableMulticast
(
false
);
}},
factory
);
JournalClient
client
=
new
JournalClient
(
new
ClientConfig
()
{{
setHostname
(
"localhost"
);
setPort
(
7080
);
}},
factory
);
if
(!
client
.
pingServer
())
{
server
.
start
();
if
(
client
.
pingServer
()
&&
!
client
.
sendClusterWin
(
server
.
getClusterInstance
()))
{
server
.
halt
();
}
}
System
.
out
.
println
(
server
.
isRunning
());
JournalServer
server2
=
new
JournalServer
(
new
ServerConfig
()
{{
setHostname
(
"localhost"
);
setPort
(
7080
);
setHeartbeatFrequency
(
TimeUnit
.
MILLISECONDS
.
toMillis
(
100
));
setEnableMulticast
(
false
);
}},
factory
);
JournalClient
client2
=
new
JournalClient
(
new
ClientConfig
()
{{
setHostname
(
"localhost"
);
setPort
(
7079
);
}},
factory
);
if
(!
client2
.
pingServer
())
{
server2
.
start
();
if
(
client2
.
pingServer
()
&&
!
client2
.
sendClusterWin
(
server
.
getClusterInstance
()))
{
server
.
halt
();
}
}
client2
.
halt
();
System
.
out
.
println
(
server2
.
isRunning
());
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录