From 431d1a9c4616ae27a3b51256a1d12b4358c66279 Mon Sep 17 00:00:00 2001 From: erubow Date: Sat, 10 Mar 2007 00:21:57 +0000 Subject: [PATCH] Added trans.c for transaction funtions. Implemented transStart() and transCreateObj() (untested!). Added dstmInit() to dstmserver.c Resolved a name conflict in *lookup.h's: the structs had the same name, so I prefixed them with m,l, or cache to match the typedef. In dstm.h: defined DIRTY and NEW bits for objheader status flag. --- Robust/src/Runtime/DSTM/interface/clookup.h | 6 +-- Robust/src/Runtime/DSTM/interface/dstm.h | 9 +++-- .../src/Runtime/DSTM/interface/dstmserver.c | 23 ++++++++++- Robust/src/Runtime/DSTM/interface/llookup.h | 6 +-- Robust/src/Runtime/DSTM/interface/mlookup.h | 6 +-- Robust/src/Runtime/DSTM/interface/trans.c | 38 +++++++++++++++++++ 6 files changed, 75 insertions(+), 13 deletions(-) create mode 100644 Robust/src/Runtime/DSTM/interface/trans.c diff --git a/Robust/src/Runtime/DSTM/interface/clookup.h b/Robust/src/Runtime/DSTM/interface/clookup.h index a90d9287..9425102f 100644 --- a/Robust/src/Runtime/DSTM/interface/clookup.h +++ b/Robust/src/Runtime/DSTM/interface/clookup.h @@ -7,13 +7,13 @@ #define LOADFACTOR 0.75 #define HASH_SIZE 100 -typedef struct hashlistnode { +typedef struct cachehashlistnode { unsigned int key; void *val; //this can be cast to another type or used to point to a larger structure - struct hashlistnode *next; + struct cachehashlistnode *next; } cachehashlistnode_t; -typedef struct hashtable { +typedef struct cashehashtable { cachehashlistnode_t *table; // points to beginning of hash table unsigned int size; unsigned int numelements; diff --git a/Robust/src/Runtime/DSTM/interface/dstm.h b/Robust/src/Runtime/DSTM/interface/dstm.h index 9651f3dc..d7278ea6 100644 --- a/Robust/src/Runtime/DSTM/interface/dstm.h +++ b/Robust/src/Runtime/DSTM/interface/dstm.h @@ -4,8 +4,11 @@ #include #include #include +#include "clookup.h" -enum status {CLEAN, DIRTY}; +//bit designations for status field of objheader +#define DIRTY 0x01 +#define NEW 0x02 typedef struct objheader { unsigned int oid; @@ -23,11 +26,11 @@ typedef struct objstr { typedef struct transrecord { objstr_t *cache; - hashtable_t *lookupTable; + cachehashtable_t *lookupTable; } transrecord_t; /* Initialize main object store and lookup tables, start server thread. */ -void dstmInit(void); +int dstmInit(void); /* Prototypes for object header */ unsigned int getNewOID(void); diff --git a/Robust/src/Runtime/DSTM/interface/dstmserver.c b/Robust/src/Runtime/DSTM/interface/dstmserver.c index 998ff514..49a5dc4b 100644 --- a/Robust/src/Runtime/DSTM/interface/dstmserver.c +++ b/Robust/src/Runtime/DSTM/interface/dstmserver.c @@ -4,12 +4,33 @@ #include #include #include -#include "dstmserver.h" +#include "dstm.h" +#include "mlookup.h" +#include "llookup.h" #define LISTEN_PORT 2153 #define BACKLOG 10 //max pending connections #define RECIEVE_BUFFER_SIZE 1500 + +int dstmInit(void) +{ + //todo:initialize main object store + //do we want this to be a global variable, or provide + //separate access funtions and hide the structure? + + if (mhashCreate(HASH_SIZE, LOADFACTOR)) + return 1; //failure + + if (lhashCreate(HASH_SIZE, LOADFACTOR)) + return 1; //failure + + pthread_t threadListen; + pthread_create(&threadListen, NULL, dstmListen, NULL); + + return 0; +} + void *dstmListen() { int listenfd, acceptfd; diff --git a/Robust/src/Runtime/DSTM/interface/llookup.h b/Robust/src/Runtime/DSTM/interface/llookup.h index f936078f..719e68cb 100644 --- a/Robust/src/Runtime/DSTM/interface/llookup.h +++ b/Robust/src/Runtime/DSTM/interface/llookup.h @@ -7,13 +7,13 @@ #define LOADFACTOR 0.75 #define HASH_SIZE 100 -typedef struct hashlistnode { +typedef struct lhashlistnode { unsigned int oid; unsigned int mid; - struct hashlistnode *next; + struct lhashlistnode *next; } lhashlistnode_t; -typedef struct hashtable { +typedef struct lhashtable { lhashlistnode_t *table; // points to beginning of hash table unsigned int size; unsigned int numelements; diff --git a/Robust/src/Runtime/DSTM/interface/mlookup.h b/Robust/src/Runtime/DSTM/interface/mlookup.h index b2f81219..9e45b880 100644 --- a/Robust/src/Runtime/DSTM/interface/mlookup.h +++ b/Robust/src/Runtime/DSTM/interface/mlookup.h @@ -7,13 +7,13 @@ #define LOADFACTOR 0.75 #define HASH_SIZE 100 -typedef struct hashlistnode { +typedef struct mhashlistnode { unsigned int key; void *val; //this can be cast to another type or used to point to a larger structure - struct hashlistnode *next; + struct mhashlistnode *next; } mhashlistnode_t; -typedef struct hashtable { +typedef struct mhashtable { mhashlistnode_t *table; // points to beginning of hash table unsigned int size; unsigned int numelements; diff --git a/Robust/src/Runtime/DSTM/interface/trans.c b/Robust/src/Runtime/DSTM/interface/trans.c new file mode 100644 index 00000000..d2971df7 --- /dev/null +++ b/Robust/src/Runtime/DSTM/interface/trans.c @@ -0,0 +1,38 @@ +#include "dstm.h" +#include "clookup.h" +#include "mlookup.h" +#include "llookup.h" + +transrecord_t *transStart() +{ + transrecord_t *tmp = malloc(sizeof(transrecord_t)); + tmp->cache = objstrCreate(1048576); + tmp->lookupTable = cachehashCreate(HASH_SIZE, LOADFACTOR); + return tmp; +} + +objheader_t *transRead(transrecord_t *record, unsigned int oid) +{ + //check cache + //else check machine lookup table + //else check location lookup table + //else broadcast +} + +objheader_t *transCreateObj(transrecord_t *record, unsigned short type) +{ + objheader_t *tmp = objstrAlloc(record->cache, classsize[type]); + tmp->oid = getNewOID(); + tmp->type = type; + tmp->version = 1; + tmp->rcount = 0; //? not sure how to handle this yet + tmp->status |= NEW; + cachehashInsert(record->lookupTable, tmp->oid, tmp); + return tmp; +} + +int transCommit(transrecord_t *record) +{ + +} + -- 2.34.1