more bug fixes
authorBrian Demsky <bdemsky@plrg.eecs.uci.edu>
Sun, 24 Jul 2016 22:29:08 +0000 (15:29 -0700)
committerBrian Demsky <bdemsky@plrg.eecs.uci.edu>
Sun, 24 Jul 2016 22:29:08 +0000 (15:29 -0700)
src/java/iotcloud/Table.java
src/java/iotcloud/Test.java
src/server/iotquery.cpp

index d4a62c6..ced979d 100644 (file)
@@ -31,6 +31,11 @@ final public class Table {
                cloud=_cloud;
        }
 
+       public void rebuild() {
+               Slot[] newslots=cloud.getSlots(sequencenumber+1);
+               validateandupdate(newslots, true);
+       }
+       
        public void update() {
                Slot[] newslots=cloud.getSlots(sequencenumber+1);
 
@@ -150,7 +155,7 @@ search:
        }
 
 
-       private void validateandupdate(Slot[] newslots, boolean isput) {
+       private void validateandupdate(Slot[] newslots, boolean acceptupdatestolocal) {
                //The cloud communication layer has checked slot HMACs already
                //before decoding
                if (newslots.length==0)
@@ -166,7 +171,7 @@ search:
                initExpectedSize();
                for(Slot slot: newslots) {
                        updateExpectedSize();
-                       processSlot(indexer, slot, isput);
+                       processSlot(indexer, slot, acceptupdatestolocal);
                }
 
                //If there is a gap, check to see if the server sent us everything
@@ -249,7 +254,7 @@ search:
                lastTableStatus = entry;
        }
 
-       private void updateLastMessage(long machineid, long seqnum, Liveness liveness, boolean isput) {
+       private void updateLastMessage(long machineid, long seqnum, Liveness liveness, boolean acceptupdatestolocal) {
                Pair<Long, Liveness> lastmsgentry = lastmessagetable.put(machineid, new Pair<Long, Liveness>(seqnum, liveness));
                if (lastmsgentry == null)
                        return;
@@ -265,7 +270,7 @@ search:
                }
 
                if (machineid == localmachineid) {
-                       if (lastmsgseqnum != seqnum && !isput)
+                       if (lastmsgseqnum != seqnum && !acceptupdatestolocal)
                                throw new Error("Server Error: Mismatch on local machine sequence number");
                } else {
                        if (lastmsgseqnum > seqnum)
@@ -273,8 +278,8 @@ search:
                }
        }
 
-       private void processSlot(SlotIndexer indexer, Slot slot, boolean isput) {
-               updateLastMessage(slot.getMachineID(), slot.getSequenceNumber(), slot, isput);
+       private void processSlot(SlotIndexer indexer, Slot slot, boolean acceptupdatestolocal) {
+               updateLastMessage(slot.getMachineID(), slot.getSequenceNumber(), slot, acceptupdatestolocal);
 
                for(Entry entry : slot.getEntries()) {
                        switch(entry.getType()) {
index 101ca77..dcd4f1e 100644 (file)
@@ -6,9 +6,61 @@ public class Test {
                        test1();
                else if(args[0].equals("2"))
                        test2();
+               else if(args[0].equals("3"))
+                       test3();
+               else if(args[0].equals("4"))
+                       test4();
 
        }
 
+       static Thread buildThread(String prefix, Table t) {
+               return new Thread() {
+                       public void run() {
+                               for(int i=0; i<600; i++) {
+                                       String a=prefix+i;
+                                       IoTString ia=new IoTString(a);
+                                       t.put(ia, ia);
+                                       System.out.println(ia+"->"+t.get(ia));
+                               }               
+                       }
+               };
+       }
+       
+       static void test4() {
+               Table t1=new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
+               Table t2=new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
+               t1.rebuild();
+               t2.rebuild();
+               Thread thr1=buildThread("p1", t1);
+               Thread thr2=buildThread("p2", t2);
+               thr1.start();
+               thr2.start();
+               try {
+                       thr1.join();
+                       thr2.join();
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+       }
+       
+       static void test3() {
+               Table t1=new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
+               Table t2=new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
+               t1.rebuild();
+               t2.rebuild();
+               for(int i=0; i<600; i++) {
+                       String a="STR"+i;
+                       String b="ABR"+i;
+                       IoTString ia=new IoTString(a);
+                       IoTString ib=new IoTString(b);
+                       t1.put(ia, ia);
+                       t2.put(ib, ib);
+                       t1.update();
+                       System.out.println(ib+"->"+t1.get(ib));
+                       System.out.println(ia+"->"+t2.get(ia));
+               }
+       }
+
        static void test2() {
                Table t1=new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
                t1.initTable();
index faec3b5..8d708cb 100644 (file)
@@ -84,7 +84,7 @@ void IoTQuery::decodeQuery() {
        char * numqueueentries_str = tok_ptr;
        if (numqueueentries_str != NULL &&
                        strncmp(numqueueentries_str, "max=", 4) == 0) {
-               numqueueentries_str = strchr(numqueueentries_str + 1, '=');
+               numqueueentries_str = strchr(numqueueentries_str, '=') + 1;
                numqueueentries = strtoll(numqueueentries_str, NULL, 10);
        }
 
@@ -150,7 +150,6 @@ void IoTQuery::getSlot() {
        memcpy(response, header, sizeof(header)-1);
        offset+=sizeof(header)-1;
        int numreq=htonl(numrequeststosend);
-       cerr << numrequeststosend << " " << numreq << endl;
        memcpy(response + offset, &numreq, sizeof(numreq));
        offset+=sizeof(numrequeststosend);
        for(int i=0; i<numrequeststosend; i++) {