bug fixes
authorBrian Demsky <bdemsky@plrg.eecs.uci.edu>
Wed, 27 Jul 2016 05:39:24 +0000 (22:39 -0700)
committerBrian Demsky <bdemsky@plrg.eecs.uci.edu>
Wed, 27 Jul 2016 05:39:24 +0000 (22:39 -0700)
src/java/iotcloud/Slot.java
src/java/iotcloud/SlotBuffer.java
src/java/iotcloud/Table.java

index c22d0d9..d23e5c1 100644 (file)
@@ -149,14 +149,16 @@ class Slot implements Liveness {
         * itself.
         */
 
-       Vector<Entry> getLiveEntries() {
+       Vector<Entry> getLiveEntries(boolean resize) {
                Vector<Entry> liveEntries=new Vector<Entry>();
                for(Entry entry: entries) {
-                       if (entry.isLive())
-                               liveEntries.add(entry);
+                       if (entry.isLive()) {
+                               if (!resize || entry.getType() != Entry.TypeTableStatus)
+                                       liveEntries.add(entry);
+                       }
                }
                        
-               if (seqnumlive)
+               if (seqnumlive && !resize)
                        liveEntries.add(new LastMessage(this, machineid, seqnum));
 
                return liveEntries;
index 5d51c1d..ac9dee1 100644 (file)
@@ -42,8 +42,8 @@ class SlotBuffer {
                                index = 0;
                }
                array = newarray;
-               tail = currsize;
-               head = 0;
+               tail = 0;
+               head = currsize;
        }
 
        private void incrementHead() {
index 9e18553..91ddaca 100644 (file)
@@ -31,7 +31,7 @@ final public class Table {
        static final double RESIZE_THRESHOLD = 0.75;
        private int resizethreshold;
        private long lastliveslotseqn;
-       private Random random;
+       private Random random=new Random();
        
        public Table(String baseurl, String password, long _localmachineid) {
                localmachineid=_localmachineid;
@@ -107,7 +107,7 @@ final public class Table {
        }
        
        private void setResizeThreshold() {
-               int resize_lower=(int) RESIZE_THRESHOLD * numslots;
+               int resize_lower=(int) (RESIZE_THRESHOLD * numslots);
                resizethreshold=resize_lower-1+random.nextInt(numslots-resize_lower);
        }
        
@@ -115,10 +115,10 @@ final public class Table {
                Slot s=new Slot(this, sequencenumber+1, localmachineid, buffer.getSlot(sequencenumber).getHMAC());
                int newsize = 0;
                if (liveslotcount > resizethreshold) {
+                       System.out.print("A");
                        resize=true;
                        newsize = (int) (numslots * RESIZE_MULTIPLE);
                }
-
                
                if (resize) {
                        newsize = (int) (numslots * RESIZE_MULTIPLE);
@@ -145,12 +145,13 @@ final public class Table {
                        if (!prevslot.isLive())
                                continue;
                        seenliveslot = true;
-                       Vector<Entry> liveentries = prevslot.getLiveEntries();
+                       Vector<Entry> liveentries = prevslot.getLiveEntries(resize);
                        for(Entry liveentry:liveentries) {
                                if (s.hasSpace(liveentry)) {
                                        s.addEntry(liveentry);
                                } else if (seqn==firstiffull) {
                                        if (!resize) {
+                                               System.out.print("B");
                                                return tryput(key, value, true);
                                        }
                                }
@@ -175,7 +176,7 @@ final public class Table {
                        if (!prevslot.isLive())
                                continue;
                        seenliveslot = true;
-                       Vector<Entry> liveentries = prevslot.getLiveEntries();
+                       Vector<Entry> liveentries = prevslot.getLiveEntries(resize);
                        for(Entry liveentry:liveentries) {
                                if (s.hasSpace(liveentry))
                                        s.addEntry(liveentry);
@@ -217,10 +218,10 @@ final public class Table {
 
                HashSet<Long> machineSet=new HashSet<Long>(lastmessagetable.keySet());
 
-               initExpectedSize();
+               initExpectedSize(firstseqnum);
                for(Slot slot: newslots) {
-                       updateExpectedSize();
                        processSlot(indexer, slot, acceptupdatestolocal, machineSet);
+                       updateExpectedSize();
                }
 
                /* If there is a gap, check to see if the server sent us everything. */
@@ -247,8 +248,8 @@ final public class Table {
                        throw new Error("Server Error: Server did not send all slots.  Expected: "+expectedsize+" Received:"+numslots);
        }
 
-       private void initExpectedSize() {
-               long prevslots = sequencenumber;
+       private void initExpectedSize(long firstsequencenumber) {
+               long prevslots = firstsequencenumber;
                expectedsize = (prevslots < ((long) numslots))?(int) prevslots:numslots;
                currmaxsize = numslots;
        }