--- /dev/null
+
+Use gen1.c for file generation
+
+compile:
+gcc -g gen1.c
+
+run:
+./a.out 8 300 newdata
+
+num threads = 8
+num of commands in each file = 300
+name of file = newdata
#define DIR_FILE "dirname"
#define FILE_NAME "file"
-#define HOME_DIR "home"
+#define HOME_DIR "tmp"
#define STR_SIZE 256
#define CREAT_FILE "creates.txt"
-#define FACTOR (0.05)
+#define FACTOR (0.20)
unsigned int num_lines;
void generateCrData(char fileName[],int numCmd,char** wordList,int numWord);
-void generateRdData(char *filename, int numRdCmd);
+void generateRdData(char *filename, int numRdCmd, int numCrCmd);
/* to read word tokens*/
char** readList(char* fileName,int* num);
for (i = 0; i < numFile; i++) {
printf("Generating Reads %s%d...\n",prefix,i);
sprintf(fileName,"%s%d",prefix,i);
- generateRdData(fileName, numRdCmd);
+ generateRdData(fileName, numRdCmd, numCrCmd);
}
-
-
}
-void generateRdData(char *filename, int numRdCmd)
+void generateRdData(char *filename, int numRdCmd, int numCrCmd)
{
- FILE *fp = fopen(filename, "a+");
- FILE *fp_creates = fopen(CREAT_FILE, "r");
- char *rd_data[num_lines];
+ FILE *fp = fopen(filename, "r+");
+ char *rd_data[numCrCmd];
int i;
+ int num_lines = 0;
- if (!fp || !fp_creates) {
+ if (!fp) {
printf("error");
return;
}
- for (i = 0; i < num_lines; i++) {
+ for (i = 0; i < numCrCmd; i++) {
if ((rd_data[i] = (char *) calloc(sizeof(char), STR_SIZE)) < 0) {
perror("");
printf("Error at %d\n");
}
}
- for (i = 0; i < num_lines; i++) {
- fgets(rd_data[i], STR_SIZE, fp_creates);
+ for (i = 0; i < numCrCmd; i++) {
+ fgets(rd_data[i], STR_SIZE, fp);
}
for (i = 0; i < numRdCmd; i++) {
- int idx = rand() % num_lines;
+ int idx = rand() % numCrCmd;
rd_data[idx][0] = 'r';
fprintf(fp, "%s", rd_data[idx]);
}
fclose(fp);
- fclose(fp_creates);
return;
}
--- /dev/null
+/*
+ It generates random data files which contain a certain amount of command
+ for File System benchmark
+
+ usage :
+ ./gen <num_file> <num_command> <File prefix>
+ */
+
+#include<stdio.h>
+#include<stdlib.h>
+#include<string.h>
+#include<time.h>
+
+#define DIR_FILE "dirname"
+#define FILE_NAME "file"
+#define HOME_DIR "home/adash"
+#define STR_SIZE 256
+#define CREAT_FILE "creates.txt"
+#define FACTOR (0.05)
+
+unsigned int num_lines;
+
+//void generateCrData(char fileName[],int numCmd,char** wordList,int numWord);
+void generateCrData(int numCmd,char** wordList,int numWord);
+void generateRdData(char *filename, int numRdCmd, int numCrCmd, int numCmd);
+
+/* to read word tokens*/
+char** readList(char* fileName,int* num);
+void freeList(char** list,int num);
+
+int main(int argn,char** argv)
+{
+ char** wordList;
+ int numWord;
+ int numFile;
+ int numCmd;
+ char* prefix;
+ char fileName[256];
+ int i;
+ int numCrCmd, numRdCmd;
+ srand(0);
+
+ if(argn < 4) {
+ printf("Usage : ./gen <# of file to generate> <# of command> <File prefix>\n");
+ printf(" Ex) ./gen 8 800 data\n");
+ printf("It generates 8 files(data0...data7) which contain 800 commands\n");
+ exit(0);
+ }
+ else {
+ sscanf(argv[1]," %d",&numFile);
+ sscanf(argv[2]," %d",&numCmd);
+ prefix = argv[3];
+ }
+
+ printf("# of file : %d\n",numFile);
+ printf("# of Command : %d\n",numCmd);
+ numCrCmd = (int) (numCmd * FACTOR);
+ numRdCmd = (int) (numCmd * (1.0 - FACTOR));
+ printf("# of Read Command : %d\n",numRdCmd);
+ printf("# of Create Command : %d\n", numCrCmd);
+
+ wordList = readList(DIR_FILE,&numWord);
+
+ /* Truncate the file */
+ FILE *fp = fopen(CREAT_FILE, "w+");
+ fclose(fp);
+
+ generateCrData(numCrCmd,wordList,numWord);
+
+ freeList(wordList,numWord);
+
+ for (i = 0; i < numFile; i++) {
+ printf("Generating Reads %s%d...\n",prefix,i);
+ sprintf(fileName,"%s%d",prefix,i);
+ generateRdData(fileName, numRdCmd, numCrCmd, numCmd);
+ }
+}
+
+void generateRdData(char *filename, int numRdCmd, int numCrCmd, int numCmd)
+{
+ //FILE *fp = fopen(filename, "r+");
+ FILE *fp = fopen(filename, "w");
+ FILE *fp_creates = fopen(CREAT_FILE, "r+");
+ char *rd_data[numCrCmd];
+ int i;
+ int num_lines = 0;
+
+ if (!fp) {
+ printf("error");
+ return;
+ }
+ for (i = 0; i < numCrCmd; i++) {
+ if ((rd_data[i] = (char *) calloc(sizeof(char), STR_SIZE)) < 0) {
+ perror("");
+ printf("Error at %d\n");
+ }
+ }
+ for (i = 0; i < numCrCmd; i++) {
+ fgets(rd_data[i], STR_SIZE, fp_creates);
+ }
+
+ for (i = 0; i < numCmd; i++) {
+ int idx = rand() % numCrCmd;
+ int test = rand() % 100;
+ if(test < 10 ) {
+ rd_data[idx][0] = 'c';
+ fprintf(fp, "%s", rd_data[idx]);
+ } else {
+ rd_data[idx][0] = 'r';
+ fprintf(fp, "%s", rd_data[idx]);
+ }
+ }
+ /*
+ for (i = 0; i < numRdCmd; i++) {
+ int idx = rand() % numCrCmd;
+ rd_data[idx][0] = 'r';
+ fprintf(fp, "%s", rd_data[idx]);
+ }
+ */
+ fclose(fp);
+ fclose(fp_creates);
+
+ return;
+}
+
+void generateCrData(int numCmd,char** wordList,int numWord)
+{
+ FILE* fp_creates = fopen(CREAT_FILE,"a+"); /* This is superset of all creates */
+ char cmdString[STR_SIZE];
+ char subCmdString[STR_SIZE];
+ char* wordToken;
+ int rand_index;
+ int token;
+ int i;
+
+ // create initial directory on home
+ sprintf(cmdString,"c /%s/%s/",HOME_DIR,"newdata");
+ fprintf(fp_creates,"%s\n",cmdString);
+ num_lines++;
+ numCmd--;
+
+ while(numCmd > 0) {
+
+ // creating directory
+ wordToken = wordList[rand() % numWord];
+ sprintf(subCmdString,"%s%s/",cmdString,wordToken);
+ fprintf(fp_creates,"%s\n",subCmdString);
+ num_lines++;
+ numCmd--;
+
+ if(numCmd == 0 )
+ break;
+
+ rand_index = (rand() % numCmd);
+ rand_index /= 2;
+
+ // creating files in the directory
+ for(i = 0;i <rand_index && numCmd > 0;i++) {
+ sprintf(subCmdString,"%s%s/%s%d",cmdString,wordToken,FILE_NAME,i);
+ fprintf(fp_creates,"%s\n",subCmdString);
+ num_lines++;
+ numCmd--;
+ }
+ }
+ fclose(fp_creates);
+}
+
+char** readList(char* fileName,int* num)
+{
+ char ** list;
+ int cnt = 0 ;
+ char buffer[100];
+ int size;
+
+ FILE* fp = fopen(fileName,"r");
+
+ while((fscanf(fp," %s",buffer)) != EOF) cnt++; // to count the number of elements
+
+ list = (char**)malloc(sizeof(char*) * cnt);
+
+ rewind(fp);
+
+ *num = 0;
+
+ while((fscanf(fp," %s",buffer)) != EOF) // read actual list
+ {
+ size = strlen(buffer); // to get length of the word,url, or account
+ list[*num] = (char*)malloc(sizeof(char) * size + 1);
+ strcpy(list[*num],buffer);
+ (*num)++;
+ }
+
+ fclose(fp);
+ return list;
+}
+
+void freeList(char** list,int num)
+{
+ int i;
+
+ for(i=0;i<num;i++)
+ {
+ free(list[i]);
+ }
+
+ free(list);
+}
--- /dev/null
+##### This file creates empty directories under /home/<adash>/<filename>/....... ####
+### first generate the directories before creating files under it #####
+### To run this script: ./generate_dirs.sh creates.txt, where creates.txt in the file with the list of directories to be created #######
+
+#!/bin/bash
+
+# Read from $1 and create dirs
+
+file=$1
+
+for line in `cat $file | awk '{print $2}'`
+do
+ dir=`echo $line | grep -v 'file[0-9]*'`
+ if [ $? -eq 0 ];
+ then
+ echo "Creating $dir "
+ mkdir -p $dir
+ fi
+done
LinkedList todoList = new LinkedList();\r
fillTodoList(inputfile, todoList);\r
\r
+ long st = System.currentTimeMillis();\r
+ long fi;\r
while (!todoList.isEmpty()) {\r
t = (Transaction)(todoList.removeFirst());\r
\r
isDir = false;\r
\r
if (command == 'r') {\r
- System.out.println("["+command+"] ["+key+"]");\r
+ //System.out.println("["+command+"] ["+key+"]");\r
if (isDir == true) {\r
readDirectory(key);\r
}\r
}\r
}\r
else if (command == 'c') {\r
- System.out.println("["+command+"] ["+key+"]");\r
+ //System.out.println("["+command+"] ["+key+"]");\r
if (isDir == true) {\r
createDirectory(key);\r
}\r
}\r
}\r
}\r
+ fi = System.currentTimeMillis();\r
+ System.out.println("\n\n\n I'm done - Time Elapse : "+ ((double)(fi-st)/1000) + "\n\n\n");\r
\r
- output();\r
+ //output();\r
\r
// RecoveryStat.printRecoveryStat();\r
}\r
\r
while (iter.hasNext()) {\r
str = (String)(iter.next());\r
- System.printString(str + "\n");\r
+ //System.printString(str + "\n");\r
}\r
}\r
\r
\r
public static void main(String[] args) {\r
String filename;\r
+ int NUM_THREADS = 1;\r
\r
- if (args.length == 1) {\r
- filename = args[0];\r
+ if (args.length == 2) {\r
+ NUM_THREADS = Integer.parseInt(args[0]);\r
+ filename = args[1];\r
}\r
else {\r
- System.out.println("usage: ./FileSystem.bin <data>");\r
+ System.out.println("usage: ./FileSystem.bin <numthreads> <data>");\r
System.exit(0);\r
}\r
\r
/*\r
+ System.out.println(key);\r
Usage :\r
./FileSystem.bin <num thread> <datafile prefix>\r
*/\r
\r
-\r
-\r
public class FileSystem extends Thread {\r
DistributedHashMap dir; // Directory \r
DistributedHashMap fs; // File \r
DistributedLinkedList list; \r
\r
atomic {\r
- path = global new GlobalString("/home/"); // root is 'home'\r
+ path = global new GlobalString("/tmp/"); // root is 'tmp'\r
list = global new DistributedLinkedList();\r
\r
dir.put(path, list);\r
}\r
}\r
\r
- public void run() {\r
-\r
- Transaction t;\r
-\r
- char command;\r
- String key;\r
- String val;\r
- GlobalString gkey;\r
- GlobalString gval;\r
- boolean isDir;\r
-\r
- int index;\r
- String file;\r
- atomic {\r
- file = inputfile.toLocalString();\r
- }\r
-\r
- LinkedList todoList = new LinkedList();\r
- fillTodoList(file, todoList);\r
-\r
- long st = System.currentTimeMillis();\r
- long fi;\r
-\r
- atomic {\r
- while (!todoList.isEmpty()) {\r
- t = (Transaction)(todoList.removeFirst());\r
-\r
- command = t.getCommand();\r
- key = t.getKey();\r
-\r
- gkey = global new GlobalString(key);\r
- \r
-\r
- index = key.lastindexOf('/');\r
- if (index+1 == key.length()) \r
- isDir = true;\r
- else \r
- isDir = false;\r
- \r
- if (command == 'r') {\r
-// System.out.println("["+command+"] ["+key+"]");\r
- if (isDir == true) {\r
- readDirectory(gkey);\r
- }\r
- else {\r
- readFile(gkey);\r
- }\r
- }\r
- else if (command == 'c') {\r
-// System.out.println("["+command+"] ["+key+"]");\r
- if (isDir == true) {\r
- createDirectory(gkey);\r
- }\r
- else {\r
- val = t.getValue();\r
- gval = global new GlobalString(val);\r
- createFile(gkey, gval);\r
- }\r
- }\r
+ public void run() {\r
+ System.out.println("Inside run method\n");\r
+ Transaction t;\r
+ char command;\r
+ String key;\r
+ String val;\r
+ GlobalString gkey;\r
+ GlobalString gval;\r
+ boolean isDir;\r
+\r
+ int index;\r
+ String file;\r
+ atomic {\r
+ System.out.println("trans1");\r
+ file = inputfile.toLocalString();\r
+ }\r
+\r
+ System.out.println("file= " + file);\r
+\r
+ LinkedList todoList = new LinkedList();\r
+ fillTodoList(file, todoList);\r
+\r
+ long st = System.currentTimeMillis();\r
+ long fi;\r
+ long tot1;\r
+\r
+ if(todoList.isEmpty())\r
+ System.out.println("todoList is Empty\n");\r
+\r
+ int iter = 0;\r
+ while (!todoList.isEmpty()) {\r
+ //System.out.println("iter= " + iter + "\n");\r
+ int count = 5;\r
+ atomic {\r
+ //System.out.println("trans2");\r
+ while(count>0 && !todoList.isEmpty()) { //commit 5 transactions\r
+ t = (Transaction)(todoList.removeFirst());\r
+ if(t==null) {\r
+ count--;\r
+ continue;\r
+ }\r
+ command = t.getCommand();\r
+ key = t.getKey();\r
+ //System.out.println(key + "\n");\r
+ gkey = global new GlobalString(key);\r
+\r
+ index = key.lastindexOf('/');\r
+ if (index+1 == key.length()) \r
+ isDir = true;\r
+ else \r
+ isDir = false;\r
+\r
+ long st1 = 0L;\r
+ long fi1 = 0L;\r
+ if (command == 'r') {\r
+ st1 = System.currentTimeMillis();\r
+ //System.out.println("["+command+"] ["+key+"]");\r
+ if (isDir == true) {\r
+ readDirectory(gkey);\r
+ }\r
+ else {\r
+ readFile(gkey);\r
+ }\r
+ fi1 = System.currentTimeMillis();\r
+ }\r
+ tot1 += fi1 - st1;\r
+ if (command == 'c') {\r
+ //System.out.println("["+command+"] ["+key+"]");\r
+ if (isDir == true) {\r
+ createDirectory(gkey);\r
+ }\r
+ else {\r
+ val = t.getValue();\r
+ gval = global new GlobalString(val);\r
+ createFile(gkey, gval);\r
+ }\r
+ }\r
+ count--;\r
+ }//end of inside loop\r
+ }//end of atomic\r
+ iter++;\r
+ }\r
+ fi = System.currentTimeMillis();\r
+\r
+ // sleep(3000000);\r
+ // atomic {\r
+ // output();\r
+ // }\r
+\r
+ RecoveryStat.printRecoveryStat();\r
+\r
+ System.out.println("\n\n\n I'm done - Time Elapse : "+ ((double)(fi-st)/1000) + "\n\n\n");\r
+ System.out.println("\n Reading - Time Elapse : "+ ((double)tot1/1000) + "\n");\r
+ while(true) {\r
+ sleep(100000);\r
+ }\r
}\r
\r
- }\r
- fi = System.currentTimeMillis();\r
-\r
- sleep(3000000);\r
- atomic {\r
- output();\r
- }\r
-\r
- RecoveryStat.printRecoveryStat();\r
-\r
- System.out.println("\n\n\n I'm done - Time Elapse : "+ ((double)(fi-st)/1000) + "\n\n\n");\r
-\r
- while(true) {\r
- sleep(100000);\r
- }\r
-\r
- }\r
-\r
+ /*\r
public void output() { \r
Iterator iter;\r
GlobalString gstr;\r
-/*\r
iter = dir_list.iterator();\r
\r
while (iter.hasNext()) {\r
gstr = (GlobalString)(iter.next());\r
System.printString(gstr.toLocalString() + "\n");\r
- }*/\r
+ }\r
}\r
+ */\r
\r
public void readFile(GlobalString gkey) {\r
- GlobalString gval;\r
- String val;\r
-\r
- atomic {\r
- gval = (GlobalString)(fs.get(gkey));\r
- val = gval.toLocalString();\r
- }\r
+ GlobalString gval=null;\r
+ String val=null;\r
+\r
+ //atomic {\r
+ gval = (GlobalString)(fs.get(gkey));\r
+ if(gval!=null) {\r
+ val = gval.toLocalString();\r
+ //Add some useless extra work for now\r
+ //to increase read time\r
+ int hashVal = gval.hashCode();\r
+ int a=0;\r
+ for(int t=0; t<hashVal; t++) {\r
+ for(int z=0; z<val.hashCode(); z++) {\r
+ a = a + t + z;\r
+ }\r
+ }\r
+ }\r
+ //}\r
if (val != null) {\r
-// System.out.println("<"+val+">");\r
+ //System.out.println("<"+val+">");\r
}\r
else {\r
-// System.out.println("No such file or directory");\r
+ //System.out.println("No such file or directory");\r
}\r
}\r
\r
iter = list.iterator();\r
while (iter.hasNext() == true) {\r
gval = (GlobalString)(iter.next());\r
-// System.out.print("["+gval.toLocalString()+"] ");\r
+ //System.out.print("["+gval.toLocalString()+"] ");\r
+ //Add some useless extra work for now\r
+ int hashVal = gval.hashCode();\r
+ int a=0;\r
+ for(int t=0; t<hashVal; t++) {\r
+ a = a + t;\r
+ }\r
}\r
-// System.out.println("");\r
+ //System.out.println("");\r
}\r
else {\r
-// System.out.println("No such file or directory");\r
+ //System.out.println("No such file or directory");\r
}\r
}\r
\r
index = gkey.lastindexOf('/');\r
gpath = gkey.subString(0, index+1);\r
gtarget = gkey.subString(index+1);\r
+ //System.out.println(" createFile() gpath= " + gpath.toLocalString() + " gtarget= " + gtarget.toLocalString());\r
+ if(dir==null)\r
+ System.out.println("dir is null");\r
\r
if (dir.containsKey(gpath)) {\r
- list = (DistributedLinkedList)(dir.get(gpath));\r
- list.push(gtarget);\r
- dir.put(gpath, list);\r
+ //list = (DistributedLinkedList)(dir.get(gpath));\r
+ //list.push(gtarget);\r
+ //dir.put(gpath, list);\r
fs.put(gkey, gval);\r
}\r
else {\r
- System.out.println("Cannot create file");\r
+ //System.out.println("Cannot create file");\r
}\r
}\r
\r
DistributedLinkedList list;\r
\r
index = gkey.lastindexOf('/', gkey.length()-2);\r
+ //System.out.println("index= " + index + " gkey= " + gkey.toLocalString());\r
\r
if (index != -1) {\r
gpath = gkey.subString(0, index+1);\r
gtarget = gkey.subString(index+1);\r
-\r
+ //System.out.println("createDirectory() gpath= " + gpath.toLocalString() + " gtarget= " + gtarget.toLocalString());\r
if (dir.containsKey(gpath)) {\r
- list = (DistributedLinkedList)(dir.get(gpath));\r
- list.push(gtarget);\r
- dir.put(gpath, list);\r
+ //list = (DistributedLinkedList)(dir.get(gpath));\r
+ //list.push(gtarget);\r
+ //dir.put(gpath, list);\r
\r
list = global new DistributedLinkedList();\r
dir.put(gkey, list);\r
- dir_list.add(gkey);\r
+ //System.out.println("Create directory");\r
+ //dir_list.add(gkey);\r
}\r
else {\r
-// System.out.println("Cannot create directory");\r
+ //System.out.println("Cannot create directory");\r
}\r
}\r
else {\r
-// System.out.println("Cannot create directory");\r
+ System.out.println("Cannot create directory");\r
}\r
}\r
\r
\r
return obj;\r
}\r
- \r
- public static void main(String[] args) {\r
- int NUM_THREADS = 3;\r
- String filename = new String();\r
-\r
- if (args.length == 2) {\r
- NUM_THREADS = Integer.parseInt(args[0]);\r
- filename = args[1];\r
- }\r
- else {\r
- System.out.println("./FileSystem.bin master <num_thread> <data>");\r
- System.exit(0);\r
- }\r
- \r
- int[] mid = new int[8];\r
- /*\r
- mid[0] = (128<<24)|(195<<16)|(180<<8)|21;//dw-2\r
- mid[1] = (128<<24)|(195<<16)|(180<<8)|26;//dw-7\r
- */\r
- mid[0] = (128<<24)|(195<<16)|(136<<8)|162;//dc-1\r
- mid[1] = (128<<24)|(195<<16)|(136<<8)|163;//dc-2\r
- mid[2] = (128<<24)|(195<<16)|(136<<8)|164;//dc-3\r
- mid[3] = (128<<24)|(195<<16)|(136<<8)|165;//dc-4\r
- mid[4] = (128<<24)|(195<<16)|(136<<8)|166;//dc-5\r
- mid[5] = (128<<24)|(195<<16)|(136<<8)|167;//dc-6\r
- mid[6] = (128<<24)|(195<<16)|(136<<8)|168;//dc-7\r
- mid[7] = (128<<24)|(195<<16)|(136<<8)|169;//dc-8\r
- \r
- FileSystem[] lus;\r
- FileSystem initLus;\r
- \r
- atomic {\r
- DistributedHashMap fs = global new DistributedHashMap(500, 500, 0.75f);\r
- DistributedHashMap dir = global new DistributedHashMap(500, 500, 0.75f);\r
- DistributedLinkedList dir_list = global new DistributedLinkedList();\r
- \r
- initLus = global new FileSystem(dir, fs, dir_list);\r
- initLus.init();\r
-\r
- lus = global new FileSystem[NUM_THREADS];\r
- for(int i = 0; i < NUM_THREADS; i++) {\r
- lus[i] = global new FileSystem(initLus.dir, initLus.fs, initLus.dir_list, filename, i,mid[i]);\r
- }\r
- }\r
\r
- FileSystem tmp;\r
- /* Start threads */\r
- for(int i = 0; i < NUM_THREADS; i++) {\r
- atomic {\r
- tmp = lus[i];\r
- }\r
- Thread.myStart(tmp, mid[i]);\r
- }\r
- \r
- /* Join threads */\r
- for(int i = 0; i < NUM_THREADS; i++) {\r
- atomic {\r
- tmp = lus[i];\r
- }\r
- tmp.join();\r
- }\r
- \r
- System.printString("Finished\n");\r
- }\r
+ public static void main(String[] args) {\r
+ int NUM_THREADS = 3;\r
+ String filename = new String();\r
+\r
+ if (args.length == 2) {\r
+ NUM_THREADS = Integer.parseInt(args[0]);\r
+ filename = args[1];\r
+ System.out.println("filename= " + filename);\r
+ }\r
+ else {\r
+ System.out.println("./FileSystem.bin master <num_thread> <data>");\r
+ System.exit(0);\r
+ }\r
+\r
+ int[] mid = new int[8];\r
+ /*\r
+ mid[0] = (128<<24)|(195<<16)|(180<<8)|21;//dw-2\r
+ mid[1] = (128<<24)|(195<<16)|(180<<8)|26;//dw-7\r
+ */\r
+ mid[0] = (128<<24)|(195<<16)|(136<<8)|162;//dc-1\r
+ mid[1] = (128<<24)|(195<<16)|(136<<8)|163;//dc-2\r
+ mid[2] = (128<<24)|(195<<16)|(136<<8)|164;//dc-3\r
+ mid[3] = (128<<24)|(195<<16)|(136<<8)|165;//dc-4\r
+ mid[4] = (128<<24)|(195<<16)|(136<<8)|166;//dc-5\r
+ mid[5] = (128<<24)|(195<<16)|(136<<8)|167;//dc-6\r
+ mid[6] = (128<<24)|(195<<16)|(136<<8)|168;//dc-7\r
+ mid[7] = (128<<24)|(195<<16)|(136<<8)|169;//dc-8\r
+\r
+ FileSystem[] lus;\r
+ FileSystem initLus;\r
+\r
+ atomic {\r
+ DistributedHashMap fs = global new DistributedHashMap(500, 100, 0.75f);\r
+ DistributedHashMap dir = global new DistributedHashMap(500, 100, 0.75f);\r
+ DistributedLinkedList dir_list = global new DistributedLinkedList();\r
+\r
+ initLus = global new FileSystem(dir, fs, dir_list);\r
+ initLus.init();\r
+\r
+ lus = global new FileSystem[NUM_THREADS];\r
+ for(int i = 0; i < NUM_THREADS; i++) {\r
+ lus[i] = global new FileSystem(initLus.dir, initLus.fs, initLus.dir_list, filename, i,mid[i]);\r
+ }\r
+ }\r
+\r
+ FileSystem tmp;\r
+ /* Start threads */\r
+ for(int i = 0; i < NUM_THREADS; i++) {\r
+ atomic {\r
+ tmp = lus[i];\r
+ }\r
+ Thread.myStart(tmp, mid[i]);\r
+ }\r
+\r
+ /* Join threads */\r
+ for(int i = 0; i < NUM_THREADS; i++) {\r
+ atomic {\r
+ tmp = lus[i];\r
+ }\r
+ tmp.join();\r
+ }\r
+\r
+ System.printString("Finished\n");\r
+ }\r
}\r
\r
public class Transaction { // object for todoList\r
- char command; // r: read, w: write\r
- String key;\r
- String val;\r
- \r
- Transaction (char c, String key) {\r
- command = c;\r
- \r
- this.key = new String(key);\r
- this.val = new String();\r
- }\r
- \r
- Transaction (char c, String key, String val) {\r
- command = c;\r
- \r
- this.key = new String(key);\r
- this.val = new String(val);\r
- }\r
- \r
- public char getCommand() {\r
- return command;\r
- }\r
- \r
- public String getKey() {\r
- return key;\r
- }\r
- \r
- public String getValue() {\r
- return val;\r
- }\r
+ char command; // r: read, w: write\r
+ String key;\r
+ String val;\r
+\r
+ Transaction (char c, String key) {\r
+ command = c;\r
+\r
+ this.key = new String(key);\r
+ this.val = new String();\r
+ }\r
+\r
+ Transaction (char c, String key, String val) {\r
+ command = c;\r
+\r
+ this.key = new String(key);\r
+ this.val = new String(val);\r
+ }\r
+\r
+ public char getCommand() {\r
+ return command;\r
+ }\r
+\r
+ public String getKey() {\r
+ return key;\r
+ }\r
+\r
+ public String getValue() {\r
+ return val;\r
+ }\r
}\r
DistributedLinkedList list; \r
\r
atomic {\r
- path = global new GlobalString("/tmp/"); // root is 'tmp'\r
+ path = global new GlobalString("/home/adash/"); // root is 'home'\r
list = global new DistributedLinkedList();\r
dir.put(path, list);\r
- dir_list.add(path);\r
}\r
}\r
\r
System.out.println("todoList is Empty\n");\r
\r
while (!todoList.isEmpty()) {\r
- int count = 5;\r
+ int count = 10;\r
atomic {\r
while(count>0 && !todoList.isEmpty()) { //commit 5 transactions\r
t = (Transaction)(todoList.removeFirst());\r
val = gval.toLocalString();\r
//Add some useless extra work for now\r
//to increase read time\r
- int hashVal = gval.hashCode();\r
+ int hashVal = val.hashCode();\r
int a=0;\r
for(int t=0; t<hashVal; t++) {\r
- for(int z=0; z<val.hashCode(); z++) {\r
- a = a + t + z;\r
- }\r
+ a = a + t;\r
}\r
- System.out.println("a= " + a);\r
- }\r
- if (val != null) {\r
- //System.out.println("<"+val+">");\r
}\r
- else {\r
- //System.out.println("No such file or directory");\r
+ if (val == null) {\r
+ System.out.println("No such file or directory");\r
}\r
}\r
\r
iter = list.iterator();\r
while (iter.hasNext() == true) {\r
gval = (GlobalString)(iter.next());\r
- //System.out.print("["+gval.toLocalString()+"] ");\r
- //Add some useless extra work for now\r
- int hashVal = gval.hashCode();\r
- int a=0;\r
- for(int t=0; t<hashVal; t++) {\r
- a = a + t;\r
- }\r
- System.out.println("a= " + a);\r
}\r
}\r
else {\r
- //System.out.println("No such file or directory");\r
+ System.out.println("No such file or directory");\r
}\r
}\r
\r
index = gkey.lastindexOf('/');\r
gpath = gkey.subString(0, index+1);\r
gtarget = gkey.subString(index+1);\r
- FileOutputStream fos = new FileOutputStream(gpath.toLocalString()+gtarget.toLocalString());\r
- fos.FileOutputStream(gpath.toLocalString()+gtarget.toLocalString());\r
+ String s = gpath.toLocalString()+gtarget.toLocalString();\r
+ FileOutputStream fos = new FileOutputStream(s);\r
+ fos.FileOutputStream(s);\r
+ byte[] b = new byte[1];\r
for(int i=0; i<10; i++) {\r
- byte[] b = new byte[1];\r
b[0] = (byte) i;\r
- fos.write(i);\r
+ fos.write(b);\r
fos.flush();\r
}\r
fos.close();\r
DistributedLinkedList list;\r
\r
index = gkey.lastindexOf('/', gkey.length()-2);\r
- //System.out.println("index= " + index + " gkey= " + gkey.toLocalString());\r
\r
if (index != -1) {\r
gpath = gkey.subString(0, index+1);\r
dir.put(gkey, list);\r
}\r
else {\r
- //System.out.println("Cannot create directory- HERE1");\r
+ System.out.println("Cannot create directory- HERE1");\r
}\r
}\r
else {\r
- //System.out.println("Cannot create directory-- HERE2");\r
+ System.out.println("Cannot create directory-- HERE2");\r
}\r
}\r
\r
//Create and populate the distributed hash map\r
boolean isDir;\r
while((comm = fis.readLine()) != null) {\r
- System.out.println("comm= " + comm);\r
char command = comm.charAt(0);\r
String key = comm.subString(2);\r
GlobalString gkey = global new GlobalString(key);\r
if(isDir == true) {\r
initLus.createDirectory(gkey);\r
} else {\r
- String val = new String();\r
+ GlobalString target = gkey.subString(index+1);\r
+ String val = new String(target.toLocalString());\r
GlobalString gval = global new GlobalString(val);\r
initLus.createFile(gkey, gval);\r
}\r
+128.195.136.162
+128.195.136.163
+#128.195.136.164
+#128.195.136.165
+#128.195.136.166
+#128.195.136.167
+#128.195.136.168
+#128.195.136.169