Squashed Last bugs
[iotcloud.git] / version2 / src / java / iotcloud / Table.java
index 99dc9bac945d02aea2dac5387eb8886542b73015..d42679d8add869edf9273074f6dd7b4e2f3965ae 100644 (file)
@@ -39,12 +39,12 @@ final public class Table {
        private TableStatus lastTableStatus;
        static final int FREE_SLOTS = 10; //number of slots that should be kept free
        static final int SKIP_THRESHOLD = 10;
-       public long liveslotcount = 0;  // TODO:  MAKE PRIVATE
+       private long liveslotcount = 0; 
        private int chance;
        static final double RESIZE_MULTIPLE = 1.2;
        static final double RESIZE_THRESHOLD = 0.75;
        static final int REJECTED_THRESHOLD = 5;
-       public int resizethreshold;     // TODO:  MAKE PRIVATE
+       private int resizethreshold;
        private long lastliveslotseqn;  //smallest sequence number with a live entry
        private Random random = new Random();
        private long lastUncommittedTransaction = 0;
@@ -53,13 +53,12 @@ final public class Table {
        private Queue<PendingTransaction> pendingTransQueue = null; // Queue of pending transactions
        private Map<Long, Commit> commitMap = null; // List of all the most recent live commits
        private Map<Long, Abort> abortMap = null; // Set of the live aborts
-       private Map<IoTString, Commit> committedMapByKey = null; // Table of committed KV       TODO: Make Private
-       public  Map<IoTString, KeyValue> commitedTable = null; // Table of committed KV       TODO: Make Private
+       private Map<IoTString, Commit> committedMapByKey = null; // Table of committed KV   
+       private  Map<IoTString, KeyValue> commitedTable = null; // Table of committed KV    
        private Map<IoTString, KeyValue> speculativeTable = null; // Table of speculative KV
-       public Map<Long, Transaction> uncommittedTransactionsMap = null; // TODO: make private
+       private Map<Long, Transaction> uncommittedTransactionsMap = null;
        private Map<IoTString, Long> arbitratorTable = null; // Table of arbitrators
        private Map<IoTString, NewKey> newKeyTable = null; // Table of speculative KV
-       // private Set<Abort> arbitratorTable = null; // Table of arbitrators
        private Map<Long, Commit> newCommitMap = null; // Map of all the new commits
        private Map<Long, Long> lastCommitSeenSeqNumMap = null; // sequence number of the last commit that was seen grouped by arbitrator
        private Map<Long, Long> lastAbortSeenSeqNumMap = null; // sequence number of the last commit that was seen grouped by arbitrator
@@ -110,44 +109,44 @@ final public class Table {
        }
 
        // TODO: delete method
-       public void printSlots() {
-               long o = buffer.getOldestSeqNum();
-               long n = buffer.getNewestSeqNum();
-
-               int[] types = new int[10];
-
-               int num = 0;
-
-               int livec = 0;
-               int deadc = 0;
-               for (long i = o; i < (n + 1); i++) {
-                       Slot s = buffer.getSlot(i);
-
-                       Vector<Entry> entries = s.getEntries();
-
-                       for (Entry e : entries) {
-                               if (e.isLive()) {
-                                       int type = e.getType();
-                                       types[type] = types[type] + 1;
-                                       num++;
-                                       livec++;
-                               } else {
-                                       deadc++;
-                               }
-                       }
-               }
-
-               for (int i = 0; i < 10; i++) {
-                       System.out.println(i + "    " + types[i]);
-               }
-               System.out.println("Live count:   " + livec);
-               System.out.println("Dead count:   " + deadc);
-               System.out.println("Old:   " + o);
-               System.out.println("New:   " + n);
-               System.out.println("Size:   " + buffer.size());
-               System.out.println("Commits Map:   " + commitedTable.size());
-               System.out.println("Commits List:   " + commitMap.size());
-       }
+       // public void printSlots() {
+       //      long o = buffer.getOldestSeqNum();
+       //      long n = buffer.getNewestSeqNum();
+
+       //      int[] types = new int[10];
+
+       //      int num = 0;
+
+       //      int livec = 0;
+       //      int deadc = 0;
+       //      for (long i = o; i < (n + 1); i++) {
+       //              Slot s = buffer.getSlot(i);
+
+       //              Vector<Entry> entries = s.getEntries();
+
+       //              for (Entry e : entries) {
+       //                      if (e.isLive()) {
+       //                              int type = e.getType();
+       //                              types[type] = types[type] + 1;
+       //                              num++;
+       //                              livec++;
+       //                      } else {
+       //                              deadc++;
+       //                      }
+       //              }
+       //      }
+
+       //      for (int i = 0; i < 10; i++) {
+       //              System.out.println(i + "    " + types[i]);
+       //      }
+       //      System.out.println("Live count:   " + livec);
+       //      System.out.println("Dead count:   " + deadc);
+       //      System.out.println("Old:   " + o);
+       //      System.out.println("New:   " + n);
+       //      System.out.println("Size:   " + buffer.size());
+       //      System.out.println("Commits Map:   " + commitedTable.size());
+       //      System.out.println("Commits List:   " + commitMap.size());
+       // }
 
        public IoTString getCommitted(IoTString key) {
                KeyValue kv = commitedTable.get(key);
@@ -167,6 +166,10 @@ final public class Table {
                }
        }
 
+       public Long getArbitrator(IoTString key) {
+               return arbitratorTable.get(key);
+       }
+
        public void initTable() {
                cloud.setSalt();//Set the salt
                Slot s = new Slot(this, 1, localmachineid);
@@ -314,7 +317,6 @@ final public class Table {
                        }
 
                        if (tryput(keyName, machineId, false)) {
-
                                // If successfully inserted
                                return true;
                        }
@@ -323,7 +325,6 @@ final public class Table {
 
        public void decrementLiveCount() {
                liveslotcount--;
-               // System.out.println("Decrement Live Count");
        }
 
        private void setResizeThreshold() {
@@ -485,9 +486,6 @@ final public class Table {
                                } else if (seqn == firstiffull) { //if there's no space but the entry is about to fall off the queue
                                        if (!resize) {
                                                System.out.println("B"); //?
-
-                                               // TODO delete
-                                               System.out.println("==============================NEEEEDDDD RESIZING");
                                                return new ThreeTuple<Boolean, Boolean, Long>(true, seenliveslot, seqn);
                                        }
                                }
@@ -515,19 +513,8 @@ final public class Table {
                        KeyValue keyVal = (KeyValue)(ut.getkeyValueUpdateSet().toArray())[0];
                        // Check if this machine arbitrates for this transaction
                        if (arbitratorTable.get( keyVal.getKey() ) != localmachineid ) {
-
-                               // TODO delete
-                               // if (localmachineid == 351) {
-                               //      System.out.println("Mis match Machine: " + localmachineid + "   Key: " + keyVal.getKey().toString());
-                               // }
                                continue;
                        }
-                       // else {
-                       //      // TODO delete
-                       //      if (localmachineid == 351) {
-                       //              System.out.println("Full Match Machine: " + localmachineid + "   Key: " + keyVal.getKey().toString());
-                       //      }
-                       // }
 
                        // we did have something to arbitrate on
                        didNeedArbitration = true;
@@ -609,18 +596,7 @@ final public class Table {
                        inserted = false;
                }
 
-
-               // TODO remove Timers
-               // long startTime = System.currentTimeMillis();
-               /* update data structure */
                validateandupdate(array, true);
-               // long endTime = System.currentTimeMillis();
-
-               // long diff = endTime - startTime;
-               // if (diff >= 1) {
-               //      System.out.println("Time Taken: " + diff);
-               // }
-
                return inserted;
        }