提交 64233ac8 编写于 作者: L liquidsnake@sapo.pt

Copied bug fixes from branch to main trunk, part 1

上级 8e6247b6
......@@ -40,7 +40,6 @@ import navigators.smart.tom.core.DeliveryThread;
import navigators.smart.tom.core.TOMLayer;
import navigators.smart.tom.demo.keyvalue.BFTTableMap;
import navigators.smart.tom.leaderchange.LCManager;
import navigators.smart.tom.server.DefaultApplicationState;
import navigators.smart.tom.server.Recoverable;
import navigators.smart.tom.util.Logger;
import navigators.smart.tom.util.TOMUtil;
......@@ -306,7 +305,7 @@ public class StateManager {
for (int i = 0; i < st.length; i++) {
for (int j = i; j < st.length; j++) {
for (int j = 0; j < st.length; j++) {
if (st[i].state.equals(st[j].state) && st[j].state.hasState()) count++;
......
......@@ -154,7 +154,7 @@ public class RequestsTimer {
long t = (shortTimeout > -1 ? shortTimeout : timeout);
System.out.println("(RequestTimerTask.run) I SOULD NEVER RUN WHEN THERE IS NO TIMEOUT");
//System.out.println("(RequestTimerTask.run) I SOULD NEVER RUN WHEN THERE IS NO TIMEOUT");
rwLock.readLock().lock();
LinkedList<TOMMessage> pendingRequests = new LinkedList<TOMMessage>();
......
......@@ -18,8 +18,8 @@ import navigators.smart.tom.ServiceProxy;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
/**
*
......@@ -77,7 +77,13 @@ public class BFTMap implements Map<String, Map<String,byte[]>> {
dos.writeInt(KVRequestType.TAB_CREATE);
dos.writeUTF(key);
ObjectOutputStream out1 = new ObjectOutputStream(out) ;
out1.writeObject(value);
if (value != null) {
out1.writeBoolean(true);
out1.writeObject(value);
}
else {
out1.writeBoolean(false);
}
out1.close();
byte[] rep = KVProxy.invokeOrdered(out.toByteArray());
ByteArrayInputStream bis = new ByteArrayInputStream(rep) ;
......@@ -240,7 +246,7 @@ public class BFTMap implements Map<String, Map<String,byte[]>> {
throw new UnsupportedOperationException("Not supported yet.");
}
public HashMap<String, byte[]> get(Object key) {
public TreeMap<String, byte[]> get(Object key) {
throw new UnsupportedOperationException("Not supported yet.");
}
......
......@@ -4,6 +4,7 @@
*/
package navigators.smart.tom.demo.keyvalue;
import navigators.smart.tom.server.defaultservices.DefaultApplicationState;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
......@@ -14,7 +15,7 @@ import java.io.ObjectOutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Collection;
import java.util.HashMap;
import java.util.TreeMap;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Level;
......@@ -23,10 +24,9 @@ import navigators.smart.statemanagment.ApplicationState;
import navigators.smart.tom.MessageContext;
import navigators.smart.tom.ReplicaContext;
import navigators.smart.tom.ServiceReplica;
import navigators.smart.tom.server.DefaultApplicationState;
import navigators.smart.tom.server.Recoverable;
import navigators.smart.tom.server.SingleExecutable;
import navigators.smart.tom.server.StateLog;
import navigators.smart.tom.server.defaultservices.StateLog;
import navigators.smart.tom.server.defaultservices.DefaultRecoverable;
import navigators.smart.tom.util.Logger;
......@@ -54,12 +54,15 @@ public class BFTMapImpl implements SingleExecutable, Recoverable {
super();
replica = new ServiceReplica(id, this, this);
checkpointPeriod = replicaContext.getStaticConfiguration().getCheckpointPeriod();
log = new StateLog(checkpointPeriod);
try {
md = MessageDigest.getInstance("MD5"); // TODO: shouldn't it be SHA?
} catch (NoSuchAlgorithmException ex) {
java.util.logging.Logger.getLogger(DefaultRecoverable.class.getName()).log(Level.SEVERE, null, ex);
}
byte[] initialState = getSnapshot();
log = new StateLog(checkpointPeriod, initialState, computeHash(initialState));
}
public static void main(String[] args){
......@@ -270,7 +273,7 @@ public class BFTMapImpl implements SingleExecutable, Recoverable {
DataInputStream dis = new DataInputStream(bais);
while(dis.available() > 0) {
Map<String, byte[]> table = new HashMap<String, byte[]>();
Map<String, byte[]> table = new TreeMap<String, byte[]>();
String tableName = dis.readUTF();
tableMap.addTable(tableName, table);
int tableSize = dis.readInt();
......
......@@ -4,10 +4,11 @@
*/
package navigators.smart.tom.demo.keyvalue;
import java.util.HashMap;
//import java.util.HashMap;
import java.util.Map;
import java.io.Serializable;
import java.util.TreeMap;
/**
*
......@@ -20,9 +21,13 @@ public class BFTTableMap implements Serializable {
private Map<String, Map<String,byte[]>> tableMap = null;
public BFTTableMap() {
tableMap=new HashMap<String, Map<String,byte[]>>();
tableMap=new TreeMap<String, Map<String,byte[]>>();
}
public Map<String, Map<String,byte[]>> getTables() {
return tableMap;
}
public Map<String,byte[]> addTable(String key, Map<String, byte[]> table) {
return tableMap.put(key, table);
}
......@@ -50,10 +55,6 @@ public class BFTTableMap implements Serializable {
return tableMap.size();
}
public Map<String, Map<String,byte[]>> getTables() {
return tableMap;
}
public int getSize(String tableName) {
Map<String,byte[]> table = tableMap.get(tableName);
return table.size();
......
......@@ -9,7 +9,7 @@ import java.util.Random;
import java.util.Scanner;
import java.io.Console;
import java.util.HashMap;
import java.util.TreeMap;
/**
*
......@@ -53,7 +53,7 @@ public class KVClient {
tableExists = bftMap.containsKey(tableName);
if (!tableExists) {
//if the table name does not exist then create the table
bftMap.put(tableName, new HashMap<String,byte[]>());
bftMap.put(tableName, new TreeMap<String,byte[]>());
}
} while(tableExists);
break;
......
......@@ -26,7 +26,7 @@ import java.util.logging.Logger;
import navigators.smart.tom.MessageContext;
import navigators.smart.tom.ReplicaContext;
import navigators.smart.tom.ServiceReplica;
import navigators.smart.tom.server.DefaultRecoverable;
import navigators.smart.tom.server.defaultservices.DefaultRecoverable;
/**
*
......
......@@ -21,7 +21,7 @@
* and open the template in the editor.
*/
package navigators.smart.tom.server;
package navigators.smart.tom.server.defaultservices;
import java.io.Serializable;
import java.util.Arrays;
......
package navigators.smart.tom.server.defaultservices;
/**
* Copyright (c) 2007-2009 Alysson Bessani, Eduardo Alchieri, Paulo Sousa, and the authors indicated in the @author tags
*
......@@ -16,11 +18,23 @@
* You should have received a copy of the GNU General Public License along with SMaRt. If not, see <http://www.gnu.org/licenses/>.
*/
package navigators.smart.tom.server;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import navigators.smart.statemanagment.ApplicationState;
import navigators.smart.tom.demo.keyvalue.BFTTableMap;
/**
* This classe represents a state tranfered from a replica to another. The state associated with the last
......@@ -210,12 +224,6 @@ public class DefaultApplicationState implements ApplicationState {
}
}
}
//System.out.print("[DefaultApplicationState] returing.........");
//System.out.println(Arrays.equals(this.stateHash, tState.stateHash) + " && " +
// (tState.lastCheckpointEid == this.lastCheckpointEid) + " && " +
// (tState.lastCheckpointRound == this.lastCheckpointRound) + " && " +
// (tState.lastCheckpointLeader == this.lastCheckpointLeader) + " && " +
// (tState.lastEid == this.lastEid) + " && " + (tState.hasState == this.hasState));
return (Arrays.equals(this.stateHash, tState.stateHash) &&
tState.lastCheckpointEid == this.lastCheckpointEid &&
tState.lastCheckpointRound == this.lastCheckpointRound &&
......
......@@ -11,9 +11,7 @@ import java.util.logging.Level;
import navigators.smart.statemanagment.ApplicationState;
import navigators.smart.tom.MessageContext;
import navigators.smart.tom.server.BatchExecutable;
import navigators.smart.tom.server.DefaultApplicationState;
import navigators.smart.tom.server.Recoverable;
import navigators.smart.tom.server.StateLog;
import navigators.smart.tom.util.Logger;
/**
......@@ -33,12 +31,14 @@ public abstract class DefaultRecoverable implements Recoverable, BatchExecutable
private StateLog log;
public DefaultRecoverable() {
log = new StateLog(CHECKPOINT_PERIOD);
try {
md = MessageDigest.getInstance("MD5"); // TODO: shouldn't it be SHA?
} catch (NoSuchAlgorithmException ex) {
java.util.logging.Logger.getLogger(DefaultRecoverable.class.getName()).log(Level.SEVERE, null, ex);
}
byte[] state = getSnapshot();
log = new StateLog(CHECKPOINT_PERIOD, state, computeHash(state));
}
public byte[][] executeBatch(byte[][] commands, MessageContext[] msgCtxs) {
......
......@@ -16,8 +16,10 @@
* You should have received a copy of the GNU General Public License along with SMaRt. If not, see <http://www.gnu.org/licenses/>.
*/
package navigators.smart.tom.server;
package navigators.smart.tom.server.defaultservices;
import navigators.smart.tom.server.defaultservices.CommandsInfo;
import navigators.smart.tom.server.defaultservices.DefaultApplicationState;
import org.apache.commons.codec.binary.Base64;
/**
......@@ -43,14 +45,14 @@ public class StateLog {
* Constructs a State log
* @param k The chekpoint period
*/
public StateLog(int k) {
public StateLog(int k, byte[] initialState, byte[] initialHash) {
this.messageBatches = new CommandsInfo[k - 1];
this.lastCheckpointEid = -1;
this.lastCheckpointRound = -1;
this.lastCheckpointLeader = -1;
this.state = null;
this.stateHash = null;
this.state = initialState;
this.stateHash = initialHash;
this.position = 0;
this.lastEid = -1;
}
......@@ -208,7 +210,7 @@ public class StateLog {
public DefaultApplicationState getApplicationState(int eid, boolean setState) {
System.out.println("lastCheckpointEid: " + lastCheckpointEid + "eid: " + eid);
if (lastCheckpointEid > -1 && eid >= lastCheckpointEid) {
if (/*lastCheckpointEid > -1 && */eid >= lastCheckpointEid) {
CommandsInfo[] batches = null;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册