}
}
+ public String toString() {
+ return table.toString();
+ }
+
public IoTString put(IoTString key, IoTString value) {
while(true) {
KeyValue oldvalue=table.get(key);
long seqn = buffer.getOldestSeqNum();
if (forcedresize) {
- System.out.println("A");
TableStatus status=new TableStatus(s, FORCED_RESIZE_INCREMENT + numslots);
s.addEntry(status);
}
if ((numslots - buffer.size()) < FREE_SLOTS) {
/* have to check whether we have enough free slots */
- System.out.println("B");
long fullfirstseqn = buffer.getNewestSeqNum() + 1 - numslots;
seqn = fullfirstseqn < 1?1:fullfirstseqn;
for(int i=0; i < FREE_SLOTS; i++, seqn++) {
Slot prevslot=buffer.getSlot(seqn);
- System.out.println(i);
if (!prevslot.isLive())
continue;
- System.out.println("islive");
Vector<Entry> liveentries = prevslot.getLiveEntries();
for(Entry liveentry:liveentries) {
- if (redundant(liveentry))
- continue;
if (s.hasSpace(liveentry))
s.addEntry(liveentry);
else if (i==0) {
continue;
Vector<Entry> liveentries = prevslot.getLiveEntries();
for(Entry liveentry:liveentries) {
- if (redundant(liveentry))
- continue;
if (s.hasSpace(liveentry))
s.addEntry(liveentry);
else
return insertedkv;
}
- boolean redundant(Entry liveentry) {
- if (liveentry.getType()==Entry.TypeLastMessage) {
- LastMessage lastmsg=(LastMessage) liveentry;
- return lastmsg.getMachineID() == localmachineid;
- }
- return false;
- }
-
-
private void validateandupdate(Slot[] newslots, boolean acceptupdatestolocal) {
/* The cloud communication layer has checked slot HMACs already
before decoding */
}
}
}
-
+
+ if (machineid == localmachineid) {
+ /* Our own messages are immediately dead. */
+ if (liveness instanceof LastMessage) {
+ ((LastMessage)liveness).setDead();
+ } else if (liveness instanceof Slot) {
+ ((Slot)liveness).setDead();
+ } else {
+ throw new Error("Unrecognized type");
+ }
+ }
+
+
Pair<Long, Liveness> lastmsgentry = lastmessagetable.put(machineid, new Pair<Long, Liveness>(seqnum, liveness));
if (lastmsgentry == null)
return;
long lastmsgseqnum = lastmsgentry.getFirst();
Liveness lastentry = lastmsgentry.getSecond();
- if (lastentry instanceof LastMessage) {
- ((LastMessage)lastentry).setDead();
- } else if (lastentry instanceof Slot) {
- ((Slot)lastentry).setDead();
- } else {
- throw new Error("Unrecognized type");
+ if (machineid != localmachineid) {
+ if (lastentry instanceof LastMessage) {
+ ((LastMessage)lastentry).setDead();
+ } else if (lastentry instanceof Slot) {
+ ((Slot)lastentry).setDead();
+ } else {
+ throw new Error("Unrecognized type");
+ }
}
-
+
if (machineid == localmachineid) {
if (lastmsgseqnum != seqnum && !acceptupdatestolocal)
throw new Error("Server Error: Mismatch on local machine sequence number");
private void processSlot(SlotIndexer indexer, Slot slot, boolean acceptupdatestolocal, HashSet<Long> machineSet) {
updateLastMessage(slot.getMachineID(), slot.getSequenceNumber(), slot, acceptupdatestolocal, machineSet);
-
for(Entry entry : slot.getEntries()) {
switch(entry.getType()) {
case Entry.TypeKeyValue: