Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
JDChain
Bftsmart
提交
877af08a
B
Bftsmart
项目概览
JDChain
/
Bftsmart
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
Bftsmart
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
877af08a
编写于
1月 18, 2010
作者:
L
liquidsnake@sapo.pt
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
I have re-done some early work on the StateLog and TransferableState class
上级
6772744f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
79 addition
and
34 deletion
+79
-34
src/navigators/smart/statemanagment/StateLog.java
src/navigators/smart/statemanagment/StateLog.java
+50
-21
src/navigators/smart/statemanagment/TransferableState.java
src/navigators/smart/statemanagment/TransferableState.java
+22
-9
src/navigators/smart/tom/core/DeliveryThread.java
src/navigators/smart/tom/core/DeliveryThread.java
+2
-2
src/navigators/smart/tom/core/TOMLayer.java
src/navigators/smart/tom/core/TOMLayer.java
+5
-2
未找到文件。
src/navigators/smart/statemanagment/StateLog.java
浏览文件 @
877af08a
...
...
@@ -29,11 +29,12 @@ package navigators.smart.statemanagment;
public
class
StateLog
{
private
byte
[][]
messageBatches
;
// batches received since the last checkpoint.
private
int
lastEid
;
// Execution ID for the last checkpoint
private
int
last
Checkpoint
Eid
;
// Execution ID for the last checkpoint
private
byte
[]
state
;
// State associated with the last checkpoint
private
int
k
;
// checkpoint period
private
int
position
;
// next position in the array of batches to be written
private
int
execCounter
;
// number of executions so far
//private int execCounter; // number of executions so far
private
int
lastEid
;
// Execution ID for the last messages batch delivered to the application
/**
* Constructs a State log
...
...
@@ -43,10 +44,11 @@ public class StateLog {
this
.
k
=
k
;
this
.
messageBatches
=
new
byte
[
k
][];
this
.
last
Eid
=
0
;
this
.
last
CheckpointEid
=
-
1
;
this
.
state
=
null
;
this
.
position
=
0
;
this
.
execCounter
=
0
;
//this.execCounter = 0;
this
.
lastEid
=
-
1
;
}
/**
...
...
@@ -59,8 +61,8 @@ public class StateLog {
messageBatches
[
i
]
=
null
;
position
=
0
;
las
tEid
+=
k
;
execCounter
++;
//lastCheckpoin
tEid += k;
//
execCounter++;
this
.
state
=
state
;
/************************* TESTE *************************
System.out.println("###################################");
...
...
@@ -80,12 +82,39 @@ public class StateLog {
}
/**
* Retrieves the execution ID for the last
checkpoint
* @return Execution ID for the last
checkpoint, or -1 if no checkpoint was yet execut
ed
* Retrieves the execution ID for the last
messages batch delivered to the application
* @return Execution ID for the last
messages batch delivered to the application, or -1 if none was deliver
ed
*/
public
int
getCurrentCheckpointEid
()
{
public
void
setLastCheckpointEid
(
int
lastCheckpointEid
)
{
this
.
lastCheckpointEid
=
lastCheckpointEid
;
}
/**
* Retrieves the execution ID for the last messages batch delivered to the application
* @return Execution ID for the last messages batch delivered to the application, or -1 if none was delivered
*/
public
int
getLastCheckpointEid
()
{
return
lastEid
-
1
;
return
lastCheckpointEid
;
}
/**
* Sets the execution ID for the last messages batch delivered to the application
* @param lastEid the execution ID for the last messages batch delivered to the application
*/
public
void
setLastEid
(
int
lastEid
)
{
this
.
lastEid
=
lastEid
;
}
/**
* Retrieves the execution ID for the last messages batch delivered to the application
* @return Execution ID for the last messages batch delivered to the application
*/
public
int
getLastEid
()
{
return
lastEid
;
}
/**
...
...
@@ -109,11 +138,11 @@ public class StateLog {
messageBatches
[
position
]
=
batch
;
position
++;
execCounter
++;
//
execCounter++;
/************************* TESTE *************************
/
/************************* TESTE *************************
System.out.println("posicao: " + position);
System
.
out
.
println
(
"execucoes: "
+
execCounter
);
System.out.println("execucoes: " +
lastEid
);
/************************* TESTE *************************/
return
true
;
...
...
@@ -128,8 +157,8 @@ public class StateLog {
* @return The batch of messages associated with the batch correspondent execution ID
*/
public
byte
[]
getMessageBatch
(
int
eid
)
{
if
(
eid
>=
last
Eid
&&
eid
<=
execCounter
)
{
return
messageBatches
[
eid
-
lastEid
];
if
(
eid
>=
last
CheckpointEid
&&
eid
<=
lastEid
)
{
return
messageBatches
[
eid
-
last
Checkpoint
Eid
];
}
else
return
null
;
}
...
...
@@ -155,14 +184,14 @@ public class StateLog {
//System.out.println("Ultimo checkpoint: " + lastEid);
//System.exit(0);
if
(
eid
>=
last
Eid
&&
eid
<=
execCounter
)
{
if
(
eid
>=
last
CheckpointEid
&&
eid
<=
lastEid
)
{
byte
[][]
batches
=
new
byte
[
eid
-
lastEid
+
1
][];
byte
[][]
batches
=
new
byte
[
eid
-
last
Checkpoint
Eid
+
1
][];
for
(
int
i
=
0
;
i
<
(
eid
-
lastEid
+
1
);
i
++)
for
(
int
i
=
0
;
i
<
(
eid
-
last
Checkpoint
Eid
+
1
);
i
++)
batches
[
i
]
=
messageBatches
[
i
];
return
new
TransferableState
(
batches
,
lastEid
,
state
);
return
new
TransferableState
(
batches
,
last
CheckpointEid
,
last
Eid
,
state
);
}
else
return
null
;
...
...
@@ -178,10 +207,10 @@ public class StateLog {
this
.
messageBatches
[
i
]
=
transState
.
getMessageBatches
()[
i
];
}
this
.
lastEid
=
transState
.
getCurrentCheckpointEid
()
+
1
;
this
.
last
Checkpoint
Eid
=
transState
.
getCurrentCheckpointEid
()
+
1
;
this
.
state
=
transState
.
getState
();
this
.
execCounter
=
this
.
las
tEid
+
position
;
this
.
lastEid
=
this
.
lastCheckpoin
tEid
+
position
;
}
}
src/navigators/smart/statemanagment/TransferableState.java
浏览文件 @
877af08a
...
...
@@ -31,8 +31,9 @@ import java.util.Arrays;
public
class
TransferableState
implements
Serializable
{
private
byte
[][]
messageBatches
;
// batches received since the last checkpoint.
private
int
nex
tEid
;
// Execution ID for the last checkpoint
private
int
lastCheckpoin
tEid
;
// Execution ID for the last checkpoint
private
byte
[]
state
;
// State associated with the last checkpoint
private
int
lastEid
=
-
1
;
// Execution ID for the last messages batch delivered to the application
/**
* Constructs a TansferableState
...
...
@@ -40,17 +41,18 @@ public class TransferableState implements Serializable {
* @param nextEid Execution ID for the last checkpoint
* @param state State associated with the last checkpoint
*/
public
TransferableState
(
byte
[][]
messageBatches
,
int
nex
tEid
,
byte
[]
state
)
{
public
TransferableState
(
byte
[][]
messageBatches
,
int
lastCheckpointEid
,
int
las
tEid
,
byte
[]
state
)
{
this
.
messageBatches
=
messageBatches
;
// batches received since the last checkpoint.
this
.
nextEid
=
nextEid
;
// Execution ID for the last checkpoint
this
.
lastCheckpointEid
=
lastCheckpointEid
;
// Execution ID for the last checkpoint
this
.
lastEid
=
lastEid
;
// Execution ID for the last messages batch delivered to the application
this
.
state
=
state
;
// State associated with the last checkpoint
}
public
TransferableState
()
{
this
.
messageBatches
=
null
;
// batches received since the last checkpoint.
this
.
nex
tEid
=
0
;
// Execution ID for the last checkpoint
this
.
lastCheckpoin
tEid
=
0
;
// Execution ID for the last checkpoint
this
.
state
=
null
;
// State associated with the last checkpoint
}
/**
...
...
@@ -67,8 +69,8 @@ public class TransferableState implements Serializable {
* @return The batch of messages associated with the batch correspondent execution ID
*/
public
byte
[]
getMessageBatch
(
int
eid
)
{
if
(
eid
>=
nextEid
&&
eid
<
(
nex
tEid
+
messageBatches
.
length
))
{
return
messageBatches
[
eid
-
nex
tEid
];
if
(
eid
>=
lastCheckpointEid
&&
eid
<
(
lastCheckpoin
tEid
+
messageBatches
.
length
))
{
return
messageBatches
[
eid
-
lastCheckpoin
tEid
];
}
else
return
null
;
}
...
...
@@ -79,7 +81,16 @@ public class TransferableState implements Serializable {
*/
public
int
getCurrentCheckpointEid
()
{
return
nextEid
-
1
;
return
lastCheckpointEid
;
}
/**
* Retrieves the execution ID for the last messages batch delivered to the application
* @return Execution ID for the last messages batch delivered to the application
*/
public
int
getLastEid
()
{
return
lastEid
;
}
/**
...
...
@@ -106,7 +117,8 @@ public class TransferableState implements Serializable {
for
(
int
i
=
0
;
i
<
this
.
messageBatches
.
length
;
i
++)
if
(!
Arrays
.
equals
(
this
.
messageBatches
[
i
],
tState
.
messageBatches
[
i
]))
return
false
;
return
(
Arrays
.
equals
(
this
.
state
,
tState
.
state
)
&&
tState
.
nextEid
==
this
.
nextEid
);
return
(
Arrays
.
equals
(
this
.
state
,
tState
.
state
)
&&
tState
.
lastCheckpointEid
==
this
.
lastCheckpointEid
&&
tState
.
lastEid
==
this
.
lastEid
);
}
return
false
;
}
...
...
@@ -114,7 +126,8 @@ public class TransferableState implements Serializable {
@Override
public
int
hashCode
()
{
int
hash
=
1
;
hash
=
hash
*
31
+
this
.
nextEid
;
hash
=
hash
*
31
+
this
.
lastCheckpointEid
;
hash
=
hash
*
31
+
this
.
lastEid
;
if
(
this
.
state
!=
null
)
for
(
int
i
=
0
;
i
<
this
.
state
.
length
;
i
++)
hash
=
hash
*
31
+
(
int
)
this
.
state
[
i
];
else
hash
=
hash
*
31
+
0
;
...
...
src/navigators/smart/tom/core/DeliveryThread.java
浏览文件 @
877af08a
...
...
@@ -179,12 +179,12 @@ public class DeliveryThread extends Thread {
if
((
cons
.
getId
()
>
0
)
&&
(
cons
.
getId
()
%
conf
.
getCheckpoint_period
()
==
0
))
{
Logger
.
println
(
"(DeliveryThread.run) Performing checkpoint for consensus "
+
cons
.
getId
());
byte
[]
state
=
receiver
.
getState
();
tomLayer
.
saveState
(
state
);
tomLayer
.
saveState
(
state
,
cons
.
getId
()
);
//TODO: possivelmente fazer mais alguma coisa
}
else
{
Logger
.
println
(
"(DeliveryThread.run) Storing message batch in the state log for consensus "
+
cons
.
getId
());
tomLayer
.
saveBatch
(
cons
.
getDecision
());
tomLayer
.
saveBatch
(
cons
.
getDecision
()
,
cons
.
getId
()
);
//TODO: possivelmente fazer mais alguma coisa
}
}
...
...
src/navigators/smart/tom/core/TOMLayer.java
浏览文件 @
877af08a
...
...
@@ -899,8 +899,10 @@ public final class TOMLayer extends Thread implements RequestReceiver {
/** ISTO E CODIGO DO JOAO, PARA TRATAR DOS CHECKPOINTS */
private
StateManager
stateManager
=
null
;
public
void
saveState
(
byte
[]
state
)
{
public
void
saveState
(
byte
[]
state
,
int
lastEid
)
{
stateManager
.
getLog
().
newCheckpoint
(
state
);
stateManager
.
getLog
().
setLastEid
(
lastEid
);
stateManager
.
getLog
().
setLastCheckpointEid
(
lastEid
);
/************************* TESTE *************************
int value = 0;
for (int i = 0; i < 4; i++) {
...
...
@@ -913,8 +915,9 @@ public final class TOMLayer extends Thread implements RequestReceiver {
System.out.println("//////////////////////////////////////////////////");
/************************* TESTE *************************/
}
public
void
saveBatch
(
byte
[]
batch
)
{
public
void
saveBatch
(
byte
[]
batch
,
int
lastEid
)
{
stateManager
.
getLog
().
addMessageBatch
(
batch
);
stateManager
.
getLog
().
setLastEid
(
lastEid
);
}
/** ISTO E CODIGO DO JOAO, PARA TRATAR DA TRANSFERENCIA DE ESTADO */
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录