#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;
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#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;
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);
#include <pthread.h>
#include <netdb.h>
#include <fcntl.h>
-#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;
#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;
#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;
--- /dev/null
+#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)
+{
+
+}
+