*** empty log message ***
authorhkhang <hkhang>
Fri, 12 Feb 2010 00:35:17 +0000 (00:35 +0000)
committerhkhang <hkhang>
Fri, 12 Feb 2010 00:35:17 +0000 (00:35 +0000)
Robust/src/Benchmarks/Recovery/FileSystem/FileSystem.java

index 3822e5915dc5bd035a4b545c1b44bc219322fccc..ffae3b38d45a2c4c1d0d9ce8454591b4f09c270d 100644 (file)
@@ -73,10 +73,9 @@ public class FileSystem extends Thread {
                char command;\r
                String key;\r
                String val;\r
-               boolean isDir;\r
-\r
                GlobalString gkey;\r
                GlobalString gval;\r
+               boolean isDir;\r
 \r
                int index;\r
                String file;\r
@@ -93,39 +92,43 @@ public class FileSystem extends Thread {
                        command = t.getCommand();\r
                        key = t.getKey();\r
 \r
+                       atomic {\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
-                       atomic {\r
-                               gkey = global new GlobalString(key);\r
-                       }\r
-\r
                        if (command == 'r') {\r
-                               System.out.println("["+command+"] ["+key+"]");\r
-               atomic {\r
-                               if (isDir == true) {\r
-                                               readDirectory(gkey);\r
-                               }\r
-                               else {\r
+                       System.out.println("["+command+"] ["+key+"]");\r
+                               if (isDir == true) {\r
+                                       atomic {\r
+                                               readDirectory(gkey);\r
+                                       }\r
+                       }\r
+                       else {\r
+                                       atomic {\r
                                                readFile(gkey);\r
-                                 }\r
+                                       }\r
                          }\r
-      }\r
+                       }\r
                        else if (command == 'c') {\r
-                                       System.out.println("["+command+"] ["+key+"]");\r
-                               atomic {\r
-                               if (isDir == true) {\r
-                                               createDirectory(gkey);\r
-                       }\r
-                               else {\r
-                                       val = t.getValue();\r
+                               System.out.println("["+command+"] ["+key+"]");\r
+                       if (isDir == true) {\r
+                                       atomic {\r
+                                               createDirectory(gkey);\r
+                                       }\r
+               }\r
+                       else {\r
+                                       val = t.getValue();\r
+                                       atomic {\r
                                                gval = global new GlobalString(val);\r
                                                createFile(gkey, gval);\r
-                                 }\r
-                       }\r
+                                       }\r
+                         }\r
                }\r
     }\r
 \r
@@ -151,10 +154,14 @@ public class FileSystem extends Thread {
 \r
        public void readFile(GlobalString gkey) {\r
                GlobalString gval;\r
+               String val;\r
 \r
-               gval = (GlobalString)(fs.get(gkey));\r
-               if (gval != null) {\r
-//                     System.out.println("<"+gval.toLocalString()+">");\r
+               atomic {\r
+                       gval = (GlobalString)(fs.get(gkey));\r
+                       val = gval.toLocalString();\r
+               }\r
+               if (val != null) {\r
+//                     System.out.println("<"+val+">");\r
                }\r
                else {\r
                        System.out.println("No such file or directory");\r
@@ -182,19 +189,21 @@ public class FileSystem extends Thread {
        }\r
 \r
        public void createFile(GlobalString gkey, GlobalString gval) {\r
-               GlobalString path;\r
-               GlobalString target;\r
+               String path;\r
+               String target;\r
+               GlobalString gpath;\r
+               GlobalString gtarget;\r
                int index;\r
                DistributedLinkedList list;\r
 \r
                index = gkey.lastindexOf('/');\r
-               path = gkey.subString(0, index+1);\r
-               target = gkey.subString(index+1);\r
+               gpath = gkey.subString(0, index+1);\r
+               gtarget = gkey.subString(index+1);\r
 \r
-               if (dir.containsKey(path)) {\r
-                       list = (DistributedLinkedList)(dir.get(path));\r
-                       list.push(target);\r
-                       dir.put(path, list);\r
+               if (dir.containsKey(gpath)) {\r
+                       list = (DistributedLinkedList)(dir.get(gpath));\r
+                       list.push(gtarget);\r
+                       dir.put(gpath, list);\r
                        fs.put(gkey, gval);\r
                }\r
                else {\r
@@ -204,20 +213,20 @@ public class FileSystem extends Thread {
 \r
        public void createDirectory(GlobalString gkey) {\r
                int index;\r
-               GlobalString path;\r
-               GlobalString target;\r
+               GlobalString gpath;\r
+               GlobalString gtarget;\r
                DistributedLinkedList list;\r
 \r
                index = gkey.lastindexOf('/', gkey.length()-2);\r
 \r
                if (index != -1) {\r
-                       path = gkey.subString(0, index+1);\r
-                       target = gkey.subString(index+1);\r
+                       gpath = gkey.subString(0, index+1);\r
+                       gtarget = gkey.subString(index+1);\r
 \r
-                       if (dir.containsKey(path)) {\r
-                               list = (DistributedLinkedList)(dir.get(path));\r
-                               list.push(target);\r
-                               dir.put(path, list);\r
+                       if (dir.containsKey(gpath)) {\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
@@ -227,6 +236,9 @@ public class FileSystem extends Thread {
                                System.out.println("Cannot create directory");\r
                        }\r
                }\r
+               else {\r
+                       System.out.println("Cannot create directory");\r
+               }\r
        }\r
        \r
        public Object read(DistributedHashMap mydhmap, GlobalString key) {\r
@@ -237,10 +249,16 @@ public class FileSystem extends Thread {
        \r
        public static void main(String[] args) {\r
                int NUM_THREADS = 3;\r
-               String filename;\r
+               String filename = new String();\r
 \r
-               NUM_THREADS = Integer.parseInt(args[0]);\r
-               filename = args[1];\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
                mid[0] = (128<<24)|(195<<16)|(180<<8)|21;//dw-2\r