+#include "NewKey.h"
+#include "ByteBuffer.h"
+
+Entry * decode(Slot * slot, ByteBuffer * bb) {
+ int keylength = bb->getInt();
+ Array<char> * key = new Array<char>(keylength);
+ bb->get(key);
+ int64_t machineid = bb->getLong();
+
+ return new NewKey(slot, IoTString.shallow(key), machineid);
+}
+void NewKey::encode(ByteBuffer * bb) {
+ bb->put(TypeNewKey);
+ bb->putInt(key->length());
+ bb->put(key->internalBytes());
+ bb->putLong(machineid);
+}
-/**
- * This Entry records the abort sent by a given machine.
- * @author Ali Younis <ayounis@uci.edu>
- * @version 1.0
- */
-
-
-class NewKey extends Entry {
- IoTString key;
- int64_t machineid;
-
- NewKey(Slot slot, IoTString _key, int64_t _machineid) {
- super(slot);
- key = _key;
- machineid = _machineid;
- }
-
- int64_t getMachineID() {
- return machineid;
- }
-
- IoTString getKey() {
- return key;
- }
-
- void setSlot(Slot s) {
- parentslot = s;
- }
-
- static Entry decode(Slot slot, ByteBuffer bb) {
- int keylength = bb.getInt();
- char[] key = new char[keylength];
- bb.get(key);
- int64_t machineid = bb.getLong();
-
- return new NewKey(slot, IoTString.shallow(key), machineid);
- }
-
- void encode(ByteBuffer bb) {
- bb.put(Entry.TypeNewKey);
- bb.putInt(key.length());
- bb.put(key.internalBytes());
- bb.putLong(machineid);
- }
-
- int getSize() {
- return sizeof(int64_t) + sizeof(char) + sizeof(int32_t) + key.length();
- }
-
- char getType() {
- return Entry.TypeNewKey;
- }
-
- Entry getCopy(Slot s) {
- return new NewKey(s, key, machineid);
- }
+int NewKey::getSize() {
+ return sizeof(int64_t) + sizeof(char) + sizeof(int32_t) + key.length();
}
-
+#ifndef NEWKEY_H
+#define NEWKEY_H
/**
* This Entry records the abort sent by a given machine.
*/
-class NewKey extends Entry {
- private IoTString key;
- private int64_t machineid;
-
- public NewKey(Slot slot, IoTString _key, int64_t _machineid) {
- super(slot);
- key = _key;
- machineid = _machineid;
- }
-
- public int64_t getMachineID() {
- return machineid;
- }
-
- public IoTString getKey() {
- return key;
- }
-
- public void setSlot(Slot s) {
- parentslot = s;
- }
-
- static Entry decode(Slot slot, ByteBuffer bb) {
- int keylength = bb.getInt();
- char[] key = new char[keylength];
- bb.get(key);
- int64_t machineid = bb.getLong();
-
- return new NewKey(slot, IoTString.shallow(key), machineid);
- }
-
- public void encode(ByteBuffer bb) {
- bb.put(Entry.TypeNewKey);
- bb.putInt(key.length());
- bb.put(key.internalBytes());
- bb.putLong(machineid);
- }
-
- public int getSize() {
- return sizeof(int64_t) + sizeof(char) + sizeof(int32_t) + key.length();
- }
-
- public char getType() {
- return Entry.TypeNewKey;
- }
-
- public Entry getCopy(Slot s) {
- return new NewKey(s, key, machineid);
- }
-}
+class NewKey : public Entry {
+ private:
+ IoTString * key;
+ int64_t machineid;
+
+
+ public:
+ NewKey(Slot * slot, IoTString * _key, int64_t _machineid) :
+ Entry(slot),
+ key(_key),
+ machineid(_machineid) {
+ }
+
+ int64_t getMachineID() { return machineid; }
+ IoTString * getKey() { return key; }
+ void setSlot(Slot * s) { parentslot = s; }
+
+
+ void encode(ByteBuffer * bb);
+ int getSize();
+ char getType() { return TypeNewKey; }
+
+ Entry * getCopy(Slot * s) { return new NewKey(s, key, machineid); }
+};
+
+Entry * NewKey_decode(Slot *slot, ByteBuffer *bb);
+
+#include "PendingTransaction.h"
+
+PendingTransaction::PendingTransaction(int64_t _machineId) :
+ keyValueUpdateSet(new Hashset<KeyValue*>()),
+ keyValueGuardSet(new HashSet<KeyValue*>()),
+ arbitrator(-1),
+ clientLocalSequenceNumber(-1),
+ machineId(_machineId),
+ currentDataSize(0) {
+}
+/**
+ * Add a new key value to the updates
+ *
+ */
+void PendingTransaction::addKV(KeyValue * newKV) {
+
+ KeyValue rmKV = NULL;
+
+ // Make sure there are no duplicates
+ for (KeyValue kv : keyValueUpdateSet) {
+ if (kv.getKey().equals(newKV.getKey())) {
+
+ // Remove key if we are adding a newer version of the same key
+ rmKV = kv;
+ break;
+ }
+ }
+
+ // Remove key if we are adding a newer version of the same key
+ if (rmKV != NULL) {
+ keyValueUpdateSet.remove(rmKV);
+ currentDataSize -= rmKV.getSize();
+ }
+
+ // Add the key to the hash set
+ keyValueUpdateSet.add(newKV);
+ currentDataSize += newKV.getSize();
+}
+/**
+ * Add a new key value to the guard set
+ *
+ */
+void PendingTransaction::addKVGuard(KeyValue * newKV) {
+ // Add the key to the hash set
+ keyValueGuardSet.add(newKV);
+ currentDataSize += newKV.getSize();
+}
+/**
+ * Checks if the arbitrator is the same
+ */
+bool PendingTransaction::checkArbitrator(int64_t arb) {
+ if (arbitrator == -1) {
+ arbitrator = arb;
+ return true;
+ }
+
+ return arb == arbitrator;
+}
-class PendingTransaction {
-
- Set<KeyValue> keyValueUpdateSet = NULL;
- Set<KeyValue> keyValueGuardSet = NULL;
- int64_t arbitrator = -1;
- int64_t clientLocalSequenceNumber = -1;
- int64_t machineId = -1;
-
- int currentDataSize = 0;
-
- PendingTransaction(int64_t _machineId) {
- machineId = _machineId;
- keyValueUpdateSet = new HashSet<KeyValue>();
- keyValueGuardSet = new HashSet<KeyValue>();
- }
-
- /**
- * Add a new key value to the updates
- *
- */
- void addKV(KeyValue newKV) {
-
- KeyValue rmKV = NULL;
-
- // Make sure there are no duplicates
- for (KeyValue kv : keyValueUpdateSet) {
- if (kv.getKey().equals(newKV.getKey())) {
-
- // Remove key if we are adding a newer version of the same key
- rmKV = kv;
- break;
- }
- }
-
- // Remove key if we are adding a newer version of the same key
- if (rmKV != NULL) {
- keyValueUpdateSet.remove(rmKV);
- currentDataSize -= rmKV.getSize();
- }
-
- // Add the key to the hash set
- keyValueUpdateSet.add(newKV);
- currentDataSize += newKV.getSize();
- }
-
- /**
- * Add a new key value to the guard set
- *
- */
- void addKVGuard(KeyValue newKV) {
- // Add the key to the hash set
- keyValueGuardSet.add(newKV);
- currentDataSize += newKV.getSize();
- }
-
- /**
- * Checks if the arbitrator is the same
- */
- bool checkArbitrator(int64_t arb) {
- if (arbitrator == -1) {
- arbitrator = arb;
- return true;
- }
-
- return arb == arbitrator;
- }
-
- /**
- * Get the transaction arbitrator
- */
- int64_t getArbitrator() {
- return arbitrator;
- }
-
- /**
- * Get the key value update set
- */
- Set<KeyValue> getKVUpdates() {
- return keyValueUpdateSet;
- }
-
- /**
- * Get the key value update set
- */
- Set<KeyValue> getKVGuard() {
- return keyValueGuardSet;
- }
-
- void setClientLocalSequenceNumber(int64_t _clientLocalSequenceNumber) {
- clientLocalSequenceNumber = _clientLocalSequenceNumber;
- }
-
- int64_t getClientLocalSequenceNumber() {
- return clientLocalSequenceNumber;
- }
-
- int64_t getMachineId() {
- return machineId;
- }
-
- bool evaluateGuard(Map<IoTString, KeyValue> keyValTableCommitted, Map<IoTString, KeyValue> keyValTableSpeculative, Map<IoTString, KeyValue> keyValTablePendingTransSpeculative) {
- for (KeyValue kvGuard : keyValueGuardSet) {
-
- // First check if the key is in the speculative table, this is the value of the latest assumption
- KeyValue kv = keyValTablePendingTransSpeculative.get(kvGuard.getKey());
-
-
- if (kv == NULL) {
- // if it is not in the pending trans table then check the speculative table and use that
- // value as our latest assumption
- kv = keyValTableSpeculative.get(kvGuard.getKey());
- }
-
-
- if (kv == NULL) {
- // if it is not in the speculative table then check the committed table and use that
- // value as our latest assumption
- kv = keyValTableCommitted.get(kvGuard.getKey());
- }
-
- if (kvGuard.getValue() != NULL) {
- if ((kv == NULL) || (!kvGuard.getValue().equals(kv.getValue()))) {
- return false;
- }
- } else {
- if (kv != NULL) {
- return false;
- }
- }
+bool PendingTransaction::evaluateGuard(Hashtable<IoTString *, KeyValue *> keyValTableCommitted, Hashtable<IoTString *, KeyValue *> keyValTableSpeculative, Hashtable<IoTString *, KeyValue *> keyValTablePendingTransSpeculative) {
+ for (KeyValue kvGuard : keyValueGuardSet) {
+
+ // First check if the key is in the speculative table, this is the value of the latest assumption
+ KeyValue kv = keyValTablePendingTransSpeculative.get(kvGuard.getKey());
+
+
+ if (kv == NULL) {
+ // if it is not in the pending trans table then check the speculative table and use that
+ // value as our latest assumption
+ kv = keyValTableSpeculative.get(kvGuard.getKey());
+ }
+
+
+ if (kv == NULL) {
+ // if it is not in the speculative table then check the committed table and use that
+ // value as our latest assumption
+ kv = keyValTableCommitted.get(kvGuard.getKey());
+ }
+
+ if (kvGuard.getValue() != NULL) {
+ if ((kv == NULL) || (!kvGuard.getValue().equals(kv.getValue()))) {
+ return false;
+ }
+ } else {
+ if (kv != NULL) {
+ return false;
+ }
+ }
}
- return true;
- }
-
- Transaction createTransaction() {
-
- Transaction newTransaction = new Transaction();
- int transactionPartCount = 0;
-
- // Convert all the data into a char array so we can start partitioning
- char[] charData = convertDataToBytes();
-
- int currentPosition = 0;
- int remaining = charData.length;
-
- while (remaining > 0) {
-
- Boolean isLastPart = false;
- // determine how much to copy
- int copySize = TransactionPart.MAX_NON_HEADER_SIZE;
- if (remaining <= TransactionPart.MAX_NON_HEADER_SIZE) {
- copySize = remaining;
- isLastPart = true; // last bit of data so last part
- }
-
- // Copy to a smaller version
- char[] partData = new char[copySize];
- System.arraycopy(charData, currentPosition, partData, 0, copySize);
-
- TransactionPart part = new TransactionPart(NULL, machineId, arbitrator, clientLocalSequenceNumber, transactionPartCount, partData, isLastPart);
- newTransaction.addPartEncode(part);
+ return true;
+}
+Transaction * PendingTransaction::createTransaction() {
+ Transaction * newTransaction = new Transaction();
+ int transactionPartCount = 0;
+
+ // Convert all the data into a char array so we can start partitioning
+ Array<char> * charData = convertDataToBytes();
+
+ int currentPosition = 0;
+ int remaining = charData.length;
+
+ while (remaining > 0) {
+
+ Boolean isLastPart = false;
+ // determine how much to copy
+ int copySize = TransactionPart.MAX_NON_HEADER_SIZE;
+ if (remaining <= TransactionPart.MAX_NON_HEADER_SIZE) {
+ copySize = remaining;
+ isLastPart = true; // last bit of data so last part
+ }
+
+ // Copy to a smaller version
+ char[] partData = new char[copySize];
+ System.arraycopy(charData, currentPosition, partData, 0, copySize);
+
+ TransactionPart part = new TransactionPart(NULL, machineId, arbitrator, clientLocalSequenceNumber, transactionPartCount, partData, isLastPart);
+ newTransaction.addPartEncode(part);
+
// Update position, count and remaining
- currentPosition += copySize;
- transactionPartCount++;
- remaining -= copySize;
- }
-
- // Add the Guard Conditions
- for (KeyValue kv : keyValueGuardSet) {
- newTransaction.addGuardKV(kv);
- }
-
- // Add the updates
- for (KeyValue kv : keyValueUpdateSet) {
- newTransaction.addUpdateKV(kv);
- }
-
- return newTransaction;
- }
-
- char[] convertDataToBytes() {
-
- // Calculate the size of the data
- int sizeOfData = 2 * sizeof(int32_t); // Number of Update KV's and Guard KV's
- sizeOfData += currentDataSize;
-
- // Data handlers and storage
- char[] dataArray = new char[sizeOfData];
- ByteBuffer bbEncode = ByteBuffer.wrap(dataArray);
-
- // Encode the size of the updates and guard sets
- bbEncode.putInt(keyValueGuardSet.size());
- bbEncode.putInt(keyValueUpdateSet.size());
-
- // Encode all the guard conditions
- for (KeyValue kv : keyValueGuardSet) {
- kv.encode(bbEncode);
- }
-
- // Encode all the updates
- for (KeyValue kv : keyValueUpdateSet) {
- kv.encode(bbEncode);
- }
+ currentPosition += copySize;
+ transactionPartCount++;
+ remaining -= copySize;
+ }
+
+ // Add the Guard Conditions
+ for (KeyValue kv : keyValueGuardSet) {
+ newTransaction.addGuardKV(kv);
+ }
+
+ // Add the updates
+ for (KeyValue kv : keyValueUpdateSet) {
+ newTransaction.addUpdateKV(kv);
+ }
+
+ return newTransaction;
+}
- return bbEncode.array();
- }
+Arrar<char> * PendingTransaction::convertDataToBytes() {
+ // Calculate the size of the data
+ int sizeOfData = 2 * sizeof(int32_t); // Number of Update KV's and Guard KV's
+ sizeOfData += currentDataSize;
+
+ // Data handlers and storage
+ Array<char> * dataArray = new Array<char>(sizeOfData);
+ ByteBuffer * bbEncode = ByteBuffer_wrap(dataArray);
+
+ // Encode the size of the updates and guard sets
+ bbEncode->putInt(keyValueGuardSet.size());
+ bbEncode->putInt(keyValueUpdateSet.size());
+
+ // Encode all the guard conditions
+ for (KeyValue kv : keyValueGuardSet) {
+ kv->encode(bbEncode);
+ }
+
+ // Encode all the updates
+ for (KeyValue kv : keyValueUpdateSet) {
+ kv->encode(bbEncode);
+ }
+
+ return bbEncode->array();
}
+
+#ifndef PENDINGTRANSACTION_H
+#define PENDINGTRANSACTION_H
-
-
+#include "common.h"
class PendingTransaction {
-
- private Set<KeyValue> keyValueUpdateSet = NULL;
- private Set<KeyValue> keyValueGuardSet = NULL;
- private int64_t arbitrator = -1;
- private int64_t clientLocalSequenceNumber = -1;
- private int64_t machineId = -1;
-
- private int currentDataSize = 0;
-
- public PendingTransaction(int64_t _machineId) {
- machineId = _machineId;
- keyValueUpdateSet = new HashSet<KeyValue>();
- keyValueGuardSet = new HashSet<KeyValue>();
- }
-
- /**
- * Add a new key value to the updates
- *
- */
- public void addKV(KeyValue newKV) {
-
- KeyValue rmKV = NULL;
-
- // Make sure there are no duplicates
- for (KeyValue kv : keyValueUpdateSet) {
- if (kv.getKey().equals(newKV.getKey())) {
-
- // Remove key if we are adding a newer version of the same key
- rmKV = kv;
- break;
- }
- }
-
- // Remove key if we are adding a newer version of the same key
- if (rmKV != NULL) {
- keyValueUpdateSet.remove(rmKV);
- currentDataSize -= rmKV.getSize();
- }
-
- // Add the key to the hash set
- keyValueUpdateSet.add(newKV);
- currentDataSize += newKV.getSize();
- }
-
- /**
- * Add a new key value to the guard set
- *
- */
- public void addKVGuard(KeyValue newKV) {
- // Add the key to the hash set
- keyValueGuardSet.add(newKV);
- currentDataSize += newKV.getSize();
- }
-
- /**
- * Checks if the arbitrator is the same
- */
- public bool checkArbitrator(int64_t arb) {
- if (arbitrator == -1) {
- arbitrator = arb;
- return true;
- }
-
- return arb == arbitrator;
- }
-
- /**
- * Get the transaction arbitrator
- */
- public int64_t getArbitrator() {
- return arbitrator;
- }
-
- /**
- * Get the key value update set
- */
- public Set<KeyValue> getKVUpdates() {
- return keyValueUpdateSet;
- }
-
- /**
- * Get the key value update set
- */
- public Set<KeyValue> getKVGuard() {
- return keyValueGuardSet;
- }
-
- public void setClientLocalSequenceNumber(int64_t _clientLocalSequenceNumber) {
- clientLocalSequenceNumber = _clientLocalSequenceNumber;
- }
-
- public int64_t getClientLocalSequenceNumber() {
- return clientLocalSequenceNumber;
- }
-
- public int64_t getMachineId() {
- return machineId;
- }
-
- public bool evaluateGuard(Map<IoTString, KeyValue> keyValTableCommitted, Map<IoTString, KeyValue> keyValTableSpeculative, Map<IoTString, KeyValue> keyValTablePendingTransSpeculative) {
- for (KeyValue kvGuard : keyValueGuardSet) {
-
- // First check if the key is in the speculative table, this is the value of the latest assumption
- KeyValue kv = keyValTablePendingTransSpeculative.get(kvGuard.getKey());
-
-
- if (kv == NULL) {
- // if it is not in the pending trans table then check the speculative table and use that
- // value as our latest assumption
- kv = keyValTableSpeculative.get(kvGuard.getKey());
- }
-
-
- if (kv == NULL) {
- // if it is not in the speculative table then check the committed table and use that
- // value as our latest assumption
- kv = keyValTableCommitted.get(kvGuard.getKey());
- }
-
- if (kvGuard.getValue() != NULL) {
- if ((kv == NULL) || (!kvGuard.getValue().equals(kv.getValue()))) {
- return false;
- }
- } else {
- if (kv != NULL) {
- return false;
- }
- }
- }
- return true;
- }
-
- public Transaction createTransaction() {
-
- Transaction newTransaction = new Transaction();
- int transactionPartCount = 0;
-
- // Convert all the data into a char array so we can start partitioning
- char[] charData = convertDataToBytes();
-
- int currentPosition = 0;
- int remaining = charData.length;
-
- while (remaining > 0) {
-
- Boolean isLastPart = false;
- // determine how much to copy
- int copySize = TransactionPart.MAX_NON_HEADER_SIZE;
- if (remaining <= TransactionPart.MAX_NON_HEADER_SIZE) {
- copySize = remaining;
- isLastPart = true; // last bit of data so last part
- }
-
- // Copy to a smaller version
- char[] partData = new char[copySize];
- System.arraycopy(charData, currentPosition, partData, 0, copySize);
-
- TransactionPart part = new TransactionPart(NULL, machineId, arbitrator, clientLocalSequenceNumber, transactionPartCount, partData, isLastPart);
- newTransaction.addPartEncode(part);
-
- // Update position, count and remaining
- currentPosition += copySize;
- transactionPartCount++;
- remaining -= copySize;
- }
-
- // Add the Guard Conditions
- for (KeyValue kv : keyValueGuardSet) {
- newTransaction.addGuardKV(kv);
- }
-
- // Add the updates
- for (KeyValue kv : keyValueUpdateSet) {
- newTransaction.addUpdateKV(kv);
- }
-
- return newTransaction;
- }
-
- private char[] convertDataToBytes() {
-
- // Calculate the size of the data
- int sizeOfData = 2 * sizeof(int32_t); // Number of Update KV's and Guard KV's
- sizeOfData += currentDataSize;
-
- // Data handlers and storage
- char[] dataArray = new char[sizeOfData];
- ByteBuffer bbEncode = ByteBuffer.wrap(dataArray);
-
- // Encode the size of the updates and guard sets
- bbEncode.putInt(keyValueGuardSet.size());
- bbEncode.putInt(keyValueUpdateSet.size());
-
- // Encode all the guard conditions
- for (KeyValue kv : keyValueGuardSet) {
- kv.encode(bbEncode);
- }
-
- // Encode all the updates
- for (KeyValue kv : keyValueUpdateSet) {
- kv.encode(bbEncode);
- }
-
- return bbEncode.array();
- }
-}
+ private:
+ Hashset<KeyValue*> * keyValueUpdateSet = NULL;
+ Hashset<KeyValue*> * keyValueGuardSet = NULL;
+ int64_t arbitrator = -1;
+ int64_t clientLocalSequenceNumber = -1;
+ int64_t machineId = -1;
+ int32_T currentDataSize = 0;
+
+ public:
+ PendingTransaction(int64_t _machineId);
+ /**
+ * Add a new key value to the updates
+ *
+ */
+ void addKV(KeyValue newKV);
+ /**
+ * Add a new key value to the guard set
+ *
+ */
+ void addKVGuard(KeyValue newKV);
+ /**
+ * Checks if the arbitrator is the same
+ */
+ bool checkArbitrator(int64_t arb);
+ /**
+ * Get the transaction arbitrator
+ */
+ int64_t getArbitrator();
+ /**
+ * Get the key value update set
+ */
+ Hashset<KeyValue*> * getKVUpdates() { return keyValueUpdateSet; }
+
+ /**
+ * Get the key value update set
+ */
+ public Hashset<KeyValue *> * getKVGuard() { return keyValueGuardSet; }
+
+ void setClientLocalSequenceNumber(int64_t _clientLocalSequenceNumber) { clientLocalSequenceNumber = _clientLocalSequenceNumber; }
+
+ int64_t getClientLocalSequenceNumber() { return clientLocalSequenceNumber; }
+
+ int64_t getMachineId() { return machineId; }
+
+ bool evaluateGuard(Hashtable<IoTString *, KeyValue *> keyValTableCommitted, Hashtable<IoTString *, KeyValue *> keyValTableSpeculative, Hashtable<IoTString *, KeyValue *> keyValTablePendingTransSpeculative);
+
+ Transaction * createTransaction();
+
+ Array<char> * convertDataToBytes();
+};
+#endif
+#include "SlotIndexer.h"
/**
* Slot indexer allows slots in both the slot buffer and the new
* @version 1.0
*/
-class SlotIndexer {
- Slot[] updates;
- SlotBuffer buffer;
- int64_t firstslotseqnum;
-
- SlotIndexer(Slot[] _updates, SlotBuffer _buffer) {
- buffer = _buffer;
- updates = _updates;
- firstslotseqnum = updates[0].getSequenceNumber();
- }
+SlotIndexer::SlotIndexer(Array<Slot*> * _updates, SlotBuffer * _buffer) :
+ buffer(_buffer),
+ updates(_updates),
+ firstslotseqnum(updates->get(0)->getSequenceNumber()) {
+}
- Slot getSlot(int64_t seqnum) {
- if (seqnum >= firstslotseqnum) {
- int offset = (int) (seqnum - firstslotseqnum);
- if (offset >= updates.length)
- throw new Error("Invalid Slot Sequence Number Reference");
- else
- return updates[offset];
- } else
- return buffer.getSlot(seqnum);
- }
+Slot * SlotIndexer::getSlot(int64_t seqnum) {
+ if (seqnum >= firstslotseqnum) {
+ int32_t offset = (int32_t) (seqnum - firstslotseqnum);
+ if (offset >= updates->length())
+ throw new Error("Invalid Slot Sequence Number Reference");
+ else
+ return updates->get(offset);
+ } else
+ return buffer->getSlot(seqnum);
}
-
+#ifndef SLOTINDEXER_H
+#define SLOTINDEXER_H
+#include "common.h"
/**
* Slot indexer allows slots in both the slot buffer and the new
* server response to looked up in a consistent fashion.
*/
class SlotIndexer {
- private Slot[] updates;
- private SlotBuffer buffer;
- private int64_t firstslotseqnum;
-
- SlotIndexer(Slot[] _updates, SlotBuffer _buffer) {
- buffer = _buffer;
- updates = _updates;
- firstslotseqnum = updates[0].getSequenceNumber();
- }
+ private:
+ Array<Slot*> * updates;
+ SlotBuffer * buffer;
+ int64_t firstslotseqnum;
- Slot getSlot(int64_t seqnum) {
- if (seqnum >= firstslotseqnum) {
- int offset = (int) (seqnum - firstslotseqnum);
- if (offset >= updates.length)
- throw new Error("Invalid Slot Sequence Number Reference");
- else
- return updates[offset];
- } else
- return buffer.getSlot(seqnum);
- }
-}
+ public:
+ SlotIndexer(Array<Slot*> * _updates, SlotBuffer * _buffer);
+ Slot* getSlot(int64_t seqnum);
+};
+#endif;
+++ /dev/null
-
-class ThreeTuple<A, B, C> {
- A a;
- B b;
- C c;
-
- ThreeTuple(A a, B b, C c) {
- this.a = a;
- this.b = b;
- this.c = c;
- }
-
- A getFirst() {
- return a;
- }
-
- B getSecond() {
- return b;
- }
-
- C getThird() {
- return c;
- }
-
- String toString() {
- return "<" + a + "," + b + "," + c + ">";
- }
-}
+#ifndef THREETUPLE_H
+#define THREETUPLE_H
-class ThreeTuple<A, B, C> {
- private A a;
- private B b;
- private C c;
+template<typename A, typename B, typename C>
+ class ThreeTuple {
+ private:
+ A a;
+ B b;
+ C c;
- ThreeTuple(A a, B b, C c) {
- this.a = a;
- this.b = b;
- this.c = c;
- }
-
- A getFirst() {
- return a;
- }
-
- B getSecond() {
- return b;
- }
-
- C getThird() {
- return c;
- }
-
- public String toString() {
- return "<" + a + "," + b + "," + c + ">";
- }
-}
+ public:
+ ThreeTuple(A _a, B _b, C _c) :
+ a(_a),
+ b(_b),
+ c(_c) {
+ }
+ A getFirst() {
+ return a;
+ }
+ B getSecond() {
+ return b;
+ }
+ C getThird() {
+ return c;
+ }
+};
+#endif
+++ /dev/null
-
-
-class TimingSingleton {
- static TimingSingleton singleton = new TimingSingleton( );
- static int64_t startTime = 0;
-
- static int64_t totalTime = 0;
-
- TimingSingleton() {
-
- }
-
- static TimingSingleton getInstance( ) {
- return singleton;
- }
-
-
- static void startTime( ) {
- startTime = System.nanoTime();
- }
-
- static void endTime( ) {
- totalTime += System.nanoTime() - startTime;
-
- }
-
- static int64_t getTime( ) {
- return totalTime;
- }
-
-
-}
-
+#ifndef TIMINGSINGLETON_H
+#define TIMINGSINGLETON_H
+#include <sys/time.h>
class TimingSingleton {
- private static TimingSingleton singleton = new TimingSingleton( );
- private static int64_t startTime = 0;
-
- private static int64_t totalTime = 0;
-
- private TimingSingleton() {
-
- }
-
- public static TimingSingleton getInstance( ) {
- return singleton;
- }
-
-
- public static void startTime( ) {
- startTime = System.nanoTime();
- }
-
- public static void endTime( ) {
- totalTime += System.nanoTime() - startTime;
-
- }
-
- public static int64_t getTime( ) {
- return totalTime;
- }
-
-
+ private:
+ static TimingSingleton singleton = new TimingSingleton( );
+ int64_t startTime = 0;
+ int64_t totalTime = 0;
+
+ TimingSingleton() : startTime(0),
+ totalTime(0) {
+ }
+
+ int64_t nanoTime() {
+ int64_t time;
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ return tv.tv_sec*1000000000+tv.tv_usec*1000;
+ }
+
+ public:
+ void startTime() {
+ startTime = nanoTime();
+ }
+
+ void endTime() {
+ totalTime += nanoTime() - startTime;
+ }
+
+ int64_t getTime() {
+ return totalTime;
+ }
+};
+
+TimingSingleton t_singleton;
+TimingSingleton * TimingSingleton_getInstance() {
+ return &t_singleton;
}
+#endif
#include "array.h"
-
+class TimingSingleton;
class Abort;
class Entry;
class Slot;
class KeyValue;
class IoTString;
class RejectedMessage;
+class PendingTransaction;
#endif